/*
 * david.manages.me — phone-first field-tech theme (loaded after /assets/app.css).
 * Palette: Slate 900 header · Slate 50 background · Slate 800 text · Sky 600 action
 *          Green 700 ok · Amber 700 warn · Red 700 critical. Touch targets >= 48px.
 */
@font-face {
  font-family: 'VT323';
  src: url('/fonts/VT323.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
:root {
  color-scheme: light;
  --header: #0F172A;
  --bg: #F8FAFC;
  --bg-elev: #FFFFFF;
  --bg-panel: #FFFFFF;
  --text: #1E293B;
  --muted: #475569;
  --border: #CBD5E1;
  --border-soft: #E2E8F0;
  --action: #0284C7;
  --action-dark: #0369A1;
  --action-tint: #E0F2FE;
  --ok: #15803D;
  --warn: #B45309;
  --danger: #B91C1C;
  --cream: #1E293B;
  --navy-deep: #F8FAFC;
  --navy: #FFFFFF;
  --navy-mid: #E0F2FE;
  --accent: #0284C7;
  --accent-2: #0284C7;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
  --radius: 14px;
  --tap: 48px;
}

[hidden] { display: none !important; }
html, body { background: var(--bg); }
body { color: var(--text); background: var(--bg); -webkit-text-size-adjust: 100%; }
a { color: var(--action-dark); }

/* ---------- Header (Slate 900) ---------- */
.topbar {
  background: var(--header); border-bottom: none; backdrop-filter: none;
  color: #F8FAFC;
  padding-top: max(.6rem, env(safe-area-inset-top));
}
.brand-text { color: #F8FAFC; }
.brand-text span { color: #94A3B8; }
.brand-mark { background: var(--action); box-shadow: none; }
.topbar .panel-toggle,
.topbar .btn.topbar-refresh {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: #E2E8F0; border: 1px solid #334155; border-radius: 12px;
}
.topbar .panel-toggle svg { width: 22px; height: 22px; }
.topbar .panel-toggle:hover, .topbar .btn.topbar-refresh:hover { color: #FFFFFF; border-color: #64748B; }
.userchip { color: #CBD5E1; }
.userchip a {
  color: #7DD3FC; font-weight: 600;
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 .25rem;
}

/* ---------- Surfaces ---------- */
.sidebar { background: var(--bg-elev); border-right: 1px solid var(--border-soft); }
.panel, .tenant-server-badge {
  background: var(--bg-elev); border: 1px solid var(--border-soft); box-shadow: var(--shadow);
}
.tenant-server-name { color: var(--text); font-weight: 700; }
.label, .sidebar-accordion-title { color: var(--muted); font-weight: 600; }
.hint, .meta { color: var(--muted); }
.agent-model-locked { color: var(--action-dark); font-weight: 600; }
.sidebar-accordion { border-top-color: var(--border-soft); }
.sidebar-accordion > summary { min-height: var(--tap); }
.sidebar-accordion > summary::before { color: var(--muted); font-size: .8rem; }

/* ---------- Inputs & buttons ---------- */
.select, .input, .textarea {
  background: #FFFFFF; color: var(--text); border: 1px solid #94A3B8;
  font-size: 16px; /* stops iOS zoom-on-focus */
  min-height: var(--tap);
}
select.select, select.select option, select.select optgroup,
.kiosk-select, .kiosk-select option {
  color-scheme: light; background-color: #FFFFFF; color: var(--text);
}
.select:focus, .input:focus, .textarea:focus {
  outline: 3px solid rgba(2, 132, 199, .35); border-color: var(--action);
}
.textarea::placeholder, .input::placeholder { color: #64748B; }
.btn {
  background: var(--action); color: #FFFFFF; border: none; border-radius: 12px;
  min-height: var(--tap); font-weight: 700;
}
.btn:hover { filter: none; background: var(--action-dark); }
.btn.secondary {
  background: #FFFFFF; color: var(--text); border: 1px solid var(--border);
}
.btn.secondary:hover { background: #F1F5F9; }
.btn:disabled { opacity: .5; }
.sidebar-accordion-action { min-width: var(--tap); min-height: var(--tap); font-size: 1.2rem; }

/* ---------- Connection status ---------- */
.conn { background: #FFFFFF; border-color: var(--border); color: var(--muted); min-height: var(--tap); font-weight: 600; }
.conn-dot { width: 12px; height: 12px; background: #94A3B8; }
.conn[data-state="connecting"] { color: var(--warn); border-color: rgba(180, 83, 9, .45); background: #FFFBEB; }
.conn[data-state="connecting"] .conn-dot { background: var(--warn); box-shadow: none; }
.conn[data-state="connected"] { color: var(--ok); border-color: rgba(21, 128, 61, .45); background: #F0FDF4; }
.conn[data-state="connected"] .conn-dot { background: var(--ok); }
.conn[data-state="error"] { color: var(--danger); border-color: rgba(185, 28, 28, .45); background: #FEF2F2; }
.conn[data-state="error"] .conn-dot { background: var(--danger); }
.err { color: var(--danger); }

/* ---------- Lists (chats, saved prompts, kiosks) ---------- */
.noterow { border-color: var(--border-soft); background: #FFFFFF; }
.note-use { min-height: var(--tap); color: var(--text); }
.note-use:hover, .note-btns button:hover { background: #F1F5F9; }
.note-title { color: var(--text); font-weight: 600; }
.note-preview { color: var(--muted); }
.note-btns button { min-width: 44px; min-height: 44px; color: var(--muted); }
.session-chat.active { border-color: var(--action); background: var(--action-tint); }
.session-chat.pending { border-color: rgba(180, 83, 9, .45); background: #FFFBEB; box-shadow: none; }
.kiosk-selected { color: var(--text); font-weight: 600; }
.kiosk-history-turn { border-bottom-color: var(--border-soft); }
.kiosk-tailscale-online, .sidebar-accordion-hint.kiosk-tailscale-online { color: var(--ok); }
.kiosk-tailscale-offline, .sidebar-accordion-hint.kiosk-tailscale-offline { color: var(--danger); }
.kiosk-tailscale-checking { color: var(--warn); }
.kiosk-active-banner { background: var(--action-tint); border-color: #7DD3FC; color: var(--text); }
.kiosk-active-label { color: var(--muted); }

/* ---------- Chat ---------- */
.active-chat-bar, .active-chat-bar[data-state="loading"] {
  background: #FFFFFF; border: 1px solid var(--border-soft); box-shadow: var(--shadow);
}
.active-chat-title { color: var(--text); text-shadow: none; }
.active-chat-meta { box-shadow: none; }
.active-chat-rename { border-color: var(--border); }
.active-chat-rename:hover:not(:disabled) { border-color: var(--action); background: var(--action-tint); }
.session-switch-overlay { background: rgba(248, 250, 252, .7); }
.session-switch-overlay-inner { background: #FFFFFF; border-color: var(--border); color: var(--text); }
.session-switch-spinner { border-color: var(--border); border-top-color: var(--action); }

.bubble { font-size: 1rem; line-height: 1.55; color: var(--text); box-shadow: 0 1px 2px rgba(15, 23, 42, .05); }
.bubble.assistant { background: #FFFFFF; border-color: var(--border-soft); }
.bubble.user { background: var(--action-tint); border-color: #7DD3FC; }

/* ---------- AI thinking: old-school CRT terminal (black, green phosphor, amber status) ---------- */
.bubble.thinking, .agent-activity {
  --crt-bg: #050805;
  --crt-green: #4AF626;
  --crt-green-dim: #2FA81A;
  --crt-amber: #FFB000;
  --crt-font: 'VT323', 'IBM Plex Mono', ui-monospace, monospace;
}
.bubble.thinking {
  background: var(--crt-bg);
  background-image: repeating-linear-gradient(0deg, rgba(0, 0, 0, .35) 0 1px, transparent 1px 3px);
  border: 1px solid #1B3D14; border-radius: 10px;
  color: var(--crt-green);
  font-family: var(--crt-font); font-size: 1.2rem; line-height: 1.25;
  text-shadow: 0 0 4px rgba(74, 246, 38, .45);
  box-shadow: inset 0 0 28px rgba(74, 246, 38, .07), 0 1px 3px rgba(15, 23, 42, .25);
}
.bubble.thinking .who { color: var(--crt-green-dim); font-family: var(--crt-font); font-size: 1rem; letter-spacing: .12em; }
.bubble.thinking .think-status { color: var(--crt-amber); font-weight: 400; text-shadow: 0 0 5px rgba(255, 176, 0, .5); }
.bubble.thinking .think-label::before { content: '> '; }
.bubble.thinking .think-label::after { content: '\2588'; margin-left: .2rem; animation: crt-blink 1s steps(1) infinite; }
@keyframes crt-blink { 50% { opacity: 0; } }
.bubble.thinking .think-pulse {
  border-radius: 0; width: 10px; height: 10px; background: var(--crt-amber);
  box-shadow: 0 0 6px var(--crt-amber); animation: crt-blink 1s steps(1) infinite;
}
.bubble.thinking .think-stop {
  font-family: var(--crt-font); font-size: 1.1rem; letter-spacing: .08em; text-transform: uppercase;
  background: transparent; color: var(--crt-amber); border: 1px solid var(--crt-amber);
  border-radius: 4px; text-shadow: 0 0 4px rgba(255, 176, 0, .5);
}
.bubble.thinking .think-stop:hover { background: rgba(255, 176, 0, .12); }
.bubble.thinking .think-tools { font-family: var(--crt-font); font-size: 1.1rem; color: var(--crt-amber); }
.bubble.thinking .think-tool[data-status="completed"] { color: var(--crt-green); }
.bubble.thinking .think-tool[data-status="error"] { color: #FF5F56; }
.bubble.thinking .think-body {
  background: transparent; border: 1px dashed #1B3D14; border-radius: 4px;
  color: var(--crt-green); font-family: var(--crt-font); font-size: 1.2rem; line-height: 1.3;
  max-height: 40vh;
}
.bubble.thinking .think-body::after { content: '\2588'; animation: crt-blink 1s steps(1) infinite; }

/* Saved "agent activity" log under finished replies uses the same terminal look. */
.agent-activity { background: var(--crt-bg); border-color: #1B3D14; font-family: var(--crt-font); }
.agent-activity > summary { color: var(--crt-amber); font-family: var(--crt-font); font-size: 1.1rem; min-height: 44px; display: flex; align-items: center; }
.agent-activity > summary::before { color: var(--crt-amber); }
.agent-activity-body { border-top-color: #1B3D14; }
.agent-event-head, .agent-event-command .agent-event-head, .agent-event-file_edit .agent-event-head {
  color: var(--crt-amber); font-family: var(--crt-font); font-size: 1.05rem;
}
.agent-event-body {
  background: #000; border-color: #1B3D14; color: var(--crt-green);
  font-family: var(--crt-font); font-size: 1.1rem; line-height: 1.25;
  text-shadow: 0 0 3px rgba(74, 246, 38, .35);
}
.bubble.agent-fail { border-color: var(--danger); background: #FEF2F2; }
.bubble .who, .bubble-when { color: var(--muted); }
.bubble-model-tag { border-color: rgba(2, 132, 199, .35); background: #F0F9FF; color: var(--action-dark); }
.bubble .chat-link, .kiosk-history-assistant .chat-link, .kiosk-history-user .chat-link { color: var(--action-dark); text-decoration: underline; }
.chat-code { background: #F1F5F9; border-color: var(--border); color: #0F172A; }
.meta code { color: var(--text); }
.chat-heading { color: #0F172A; }

/* Short Answer / Recommended Response run on non-Composer models. */
.composer-followup-row, .bubble-followup-actions, .bubble-inline-short-answer { display: none !important; }

.composer { border-top: 1px solid var(--border-soft); background: var(--bg); }
.composer.drag { outline-color: var(--action); }
#prompt { min-height: 6rem; }

/* ---------- Sign-in ---------- */
.login-card .brand-text { color: var(--text); }
.login-card .brand-text span { color: var(--muted); }
.login-card h1 { color: #0F172A; }
.login-card .input { min-height: 52px; }
.login-card .btn[type="submit"] { width: 100%; min-height: 52px; font-size: 1.05rem; margin-top: .35rem; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 4.75rem; }
.pw-toggle {
  position: absolute; top: 50%; right: .3rem; transform: translateY(-50%);
  min-width: 64px; min-height: 44px; border: 0; border-radius: 10px;
  background: transparent; color: var(--action-dark); font: inherit; font-weight: 700; cursor: pointer;
}
.pw-toggle:hover { background: var(--action-tint); }

@media (max-width: 900px), (pointer: coarse) {
  .login-wrap { display: block; min-height: 100dvh; padding: 0; }
  .login-card {
    width: 100%; max-width: none; min-height: 100dvh; display: flex; flex-direction: column;
    padding: 0 0 calc(1.25rem + env(safe-area-inset-bottom));
    border: 0; border-radius: 0; box-shadow: none; background: var(--bg);
    font-size: 1.15rem;
  }
  .login-card .brand {
    display: flex; align-items: center; gap: .9rem; margin: 0 !important;
    padding: max(1.5rem, env(safe-area-inset-top)) 1.5rem 2.75rem;
    background: var(--header); color: #F8FAFC;
    border-radius: 0 0 26px 26px;
  }
  .login-card .brand-mark { width: 54px; height: 54px; border-radius: 14px; }
  .login-card .brand-text { color: #F8FAFC; font-size: 1.6rem; white-space: normal; flex: 1; }
  .login-card .brand-text span { display: block; margin: .15rem 0 0; color: #94A3B8; font-size: 1.05rem; font-weight: 500; }
  .login-card h1 { margin: 2rem 1.5rem .45rem; font-size: 2.4rem; }
  .login-card > p { margin: 0 1.5rem 1.75rem; font-size: 1.15rem; line-height: 1.45; }
  .login-card .err {
    margin: 0 1.5rem 1.15rem; padding: .9rem 1rem; border-radius: 14px; font-size: 1.05rem;
    background: #FEF2F2; border: 1px solid rgba(185, 28, 28, .35); font-weight: 600;
  }
  .login-card .field { margin: 0 1.5rem 1.35rem; }
  .login-card .label { font-size: 1rem; margin-bottom: .55rem; }
  .login-card .input { min-height: 64px; font-size: 20px; padding: 0 1.1rem; border-radius: 16px; border-width: 2px; }
  .login-card .pw-wrap .input { padding-right: 5.5rem; }
  .login-card .pw-toggle { min-width: 76px; min-height: 52px; font-size: 1.05rem; }
  .login-card .btn[type="submit"] {
    width: calc(100% - 3rem); margin: .75rem 1.5rem 0; min-height: 64px;
    font-size: 1.3rem; border-radius: 16px;
  }
  .login-card .hint { margin: auto 1.5rem 0; padding-top: 2rem; text-align: center; font-size: 1rem; }
}

/* Refresh button injected into the sign-in header by theme.js. */
.login-refresh {
  margin-left: auto; flex-shrink: 0;
  min-width: 48px; min-height: 48px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; border: 1px solid var(--border); background: #FFFFFF; color: var(--text);
  font-size: 1.35rem; line-height: 1; cursor: pointer;
}
.login-refresh:hover { background: #F1F5F9; }
.login-refresh.spin { animation: topbar-spin .65s ease-in-out; }
@media (max-width: 900px), (pointer: coarse) {
  .login-refresh {
    min-width: 56px; min-height: 56px; font-size: 1.6rem;
    background: transparent; color: #E2E8F0; border-color: #334155; border-radius: 14px;
  }
}

/* ================= Phone layout ================= */
@media (max-width: 900px) {
  html, body { height: 100%; overflow: hidden; }
  .shell { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }

  .topbar { padding: max(.5rem, env(safe-area-inset-top)) .75rem .5rem; gap: .5rem; }
  .topbar .brand { display: flex; }
  .brand-mark { width: 28px; height: 28px; border-radius: 8px; }
  .brand-text { font-size: 1.05rem; }
  .brand-text span { display: none; }
  .userchip { font-size: .95rem; }

  .layout { display: flex; flex-direction: column; position: relative; overflow: hidden; flex: 1; min-height: 0; }
  .sidebar-resizer { display: none !important; }

  /* Sidebar becomes a slide-over drawer; the menu button toggles it. */
  .sidebar {
    position: absolute; z-index: 30; top: 0; left: 0; bottom: 0;
    width: min(88vw, 380px); max-height: none;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    border-right: 1px solid var(--border-soft); border-bottom: none;
    box-shadow: 0 10px 40px rgba(15, 23, 42, .25);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    transform: translateX(0); transition: transform .22s ease;
    opacity: 1; visibility: visible; pointer-events: auto;
  }
  .layout.layout-left-collapsed .sidebar {
    display: block; transform: translateX(-105%);
    opacity: 1; visibility: hidden; padding: 1rem; border-color: transparent;
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  .layout:not(.layout-left-collapsed)::after {
    content: ''; position: absolute; inset: 0; z-index: 25;
    background: rgba(15, 23, 42, .45);
  }

  .chat { flex: 1; min-height: 0; padding: .5rem .6rem 0; }
  .messages { min-height: 0; gap: .65rem; padding: .25rem 0 .75rem; }
  .bubble { max-width: 100%; padding: .8rem .85rem; border-radius: 14px; }
  .bubble.user { margin-left: 1.5rem; }
  .bubble.assistant { margin-right: .5rem; }
  .active-chat-bar { margin-bottom: .4rem; }

  /* Composer pinned to the bottom: prompt on top, big touch buttons below. */
  .composer {
    display: flex; flex-direction: column; gap: .5rem;
    padding: .6rem 0 calc(.6rem + env(safe-area-inset-bottom));
    position: sticky; bottom: 0;
  }
  #prompt { min-height: 3.4rem; max-height: 30vh; border-radius: 14px; }
  .composer-actions {
    flex-direction: row; flex-wrap: nowrap; gap: .45rem; align-items: stretch;
  }
  .composer-actions > .btn, .composer-actions > label.btn {
    flex: 0 0 auto; width: auto; min-width: var(--tap); padding: 0 .7rem;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .9rem; white-space: nowrap;
  }
  #newlineBtn { display: none; }
  .composer-send-stack { flex: 1 1 auto; }
  #sendBtn { min-height: var(--tap); font-size: 1.05rem; letter-spacing: .02em; }
}
