/* ============================================================================
   JARVIS Web UI — Liquid-Glass design tokens + index page styles.

   Inspired by Apple's iOS 26 Liquid Glass system: translucent surfaces with
   backdrop-filter blur, layered shadows, generous radii, and SF Pro stack.
   Tokens (--bg, --fg, --accent, --radius, etc.) are the single source of
   truth for all sub-pages (voice.css, proposals.css, dashboard.css). Don't
   inline colors below — extend the token list at the top.
   ============================================================================ */

:root {
  /* Surfaces (dark mode default — light mode at the bottom of this block). */
  --bg: #0b0d12;
  --bg-2: #141821;
  --bg-3: #1c2230;
  --bg-glass: rgba(20, 24, 33, 0.62);
  --bg-glass-strong: rgba(11, 13, 18, 0.78);

  /* Foreground */
  --fg: #ecedf2;
  --fg-dim: #9aa3b8;
  --fg-faint: #5a627a;

  /* Brand + accents — softer cyan-blue, less neon */
  --accent: #5ec8ff;
  --accent-dim: #1f6f99;
  --accent-glow: rgba(94, 200, 255, 0.18);
  --user: #ffd28a;
  --tool: #c9a8ff;
  --error: #ff7a7a;
  --ok: #6fe3c7;

  /* Strokes */
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  /* Radii — Apple-ish: small chips 10, controls 14, cards 18, surfaces 22 */
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;

  /* Shadows — layered, soft */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.18);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.28), 0 1px 2px rgba(0, 0, 0, 0.18);
  --shadow-3: 0 12px 32px rgba(0, 0, 0, 0.36), 0 2px 6px rgba(0, 0, 0, 0.22);

  /* Spring-y motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Typography */
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Segoe UI", system-ui, "Inter", "Helvetica Neue", Arial, sans-serif;

  /* Safe-area helpers (iOS notch / Android gesture bar) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f8;
    --bg-2: #ffffff;
    --bg-3: #eef0f6;
    --bg-glass: rgba(255, 255, 255, 0.72);
    --bg-glass-strong: rgba(255, 255, 255, 0.86);

    --fg: #14171f;
    --fg-dim: #5b6478;
    --fg-faint: #9098ad;

    --accent: #0a84ff;        /* iOS system blue */
    --accent-dim: #0070dd;
    --accent-glow: rgba(10, 132, 255, 0.16);
    --user: #c98a00;
    --tool: #7c3aed;
    --error: #ff3b30;
    --ok: #34c759;

    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.14);

    --shadow-1: 0 1px 2px rgba(20, 23, 31, 0.06);
    --shadow-2: 0 4px 16px rgba(20, 23, 31, 0.08), 0 1px 2px rgba(20, 23, 31, 0.06);
    --shadow-3: 0 12px 32px rgba(20, 23, 31, 0.10), 0 2px 6px rgba(20, 23, 31, 0.08);
  }
}

/* ============================================================================
   Base
   ============================================================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(1200px 700px at 30% -10%, var(--accent-glow), transparent 60%),
    radial-gradient(900px 600px at 90% 110%, rgba(124, 58, 237, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1, "ss01" 1;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* Scrollbar — minimal, theme-aware */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================================
   Header — Liquid Glass
   ============================================================================ */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, var(--safe-top)) clamp(14px, 4vw, 28px) 10px;
  background: var(--bg-glass);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.08em;
  font-size: 14px;
}
.brand .name {
  background: linear-gradient(135deg, var(--fg), var(--fg-dim));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand .dot {
  width: 10px; height: 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow), 0 0 14px var(--accent-glow);
  animation: pulse 2.4s var(--ease-out) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.92); }
}

.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--fg-dim);
  font-family: var(--mono);
  font-size: 12px;
}
.meta button,
.meta .navlink {
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  font-size: 14px;
  transition: color 0.18s var(--ease-out),
              border-color 0.18s var(--ease-out),
              background 0.18s var(--ease-out),
              transform 0.12s var(--ease-out);
}
.meta button:hover,
.meta .navlink:hover {
  color: var(--accent);
  border-color: var(--border-strong);
  background: var(--bg-glass-strong);
}
.meta button:active,
.meta .navlink:active { transform: scale(0.96); }

.meta .navlink .badge {
  display: none;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}
.meta .navlink .badge:not(:empty) { display: inline-block; }

#model {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  font-size: 11px;
  letter-spacing: 0.04em;
}

/* ============================================================================
   Main / messages
   ============================================================================ */

main {
  overflow-y: auto;
  padding: 28px clamp(14px, 5vw, 60px);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 760px;
  margin: 0 auto 20px;
  animation: appear 0.28s var(--ease-out);
}
@keyframes appear {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.msg .role {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin-bottom: 8px;
  font-weight: 600;
}
.msg.user .role { color: var(--user); }
.msg.assistant .role { color: var(--accent); }
.msg.tool .role { color: var(--tool); }

.msg .body {
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Assistant bubble — soft glass card */
.msg.assistant .body {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow-1);
}

/* User bubble — right-aligned, accent tint */
.msg.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.msg.user .role { align-self: flex-end; }
.msg.user .body {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-sm) var(--radius-lg) var(--radius-lg);
  padding: 12px 16px;
  max-width: 85%;
  box-shadow: var(--shadow-2);
}

/* Tool & RAG cards — glassy */
.tool-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: var(--mono);
  font-size: 13px;
  margin: 8px 0;
  overflow: hidden;
}
.tool-card summary {
  cursor: pointer;
  padding: 10px 14px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--tool);
  user-select: none;
}
.tool-card summary::-webkit-details-marker { display: none; }
.tool-card summary::before {
  content: "›";
  color: var(--fg-faint);
  font-size: 18px;
  transition: transform 0.2s var(--ease-out);
  display: inline-block;
}
.tool-card[open] summary::before { transform: rotate(90deg); }
.tool-card .body {
  padding: 0 14px 12px;
  color: var(--fg-dim);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.tool-card .status {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-faint);
  letter-spacing: 0.04em;
}
.tool-card.ok .status { color: var(--ok); }
.tool-card.err .status { color: var(--error); }

.rag-card {
  max-width: 760px;
  margin: 0 auto 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-1);
}
.rag-head {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin-bottom: 8px;
  font-weight: 600;
}
.rag-list { list-style: none; padding: 0; margin: 0; }
.rag-list li {
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.rag-list li:first-child { border-top: 0; }
.rag-source { color: var(--accent); font-family: var(--mono); font-size: 11px; }
.rag-path { color: var(--fg); font-family: var(--mono); font-size: 11px; }
.rag-score { color: var(--fg-faint); font-family: var(--mono); font-size: 10px; margin-left: 6px; }
.rag-snippet { color: var(--fg-dim); font-style: italic; padding-top: 4px; font-size: 12px; }

.cursor::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ============================================================================
   Composer / footer — Liquid Glass
   ============================================================================ */

footer {
  border-top: 1px solid var(--border);
  background: var(--bg-glass-strong);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  padding: 14px clamp(14px, 5vw, 60px) max(14px, var(--safe-bottom));
}

#composer {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#input {
  flex: 1;
  resize: none;
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-family: var(--sans);
  font-size: 16px;     /* iOS: ≥16px prevents zoom-on-focus */
  line-height: 1.45;
  min-height: 48px;
  max-height: 240px;
  outline: none;
  box-shadow: var(--shadow-1);
  transition: border-color 0.18s var(--ease-out),
              box-shadow 0.18s var(--ease-out);
}
#input::placeholder { color: var(--fg-faint); }
#input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow), var(--shadow-1);
}

#send {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  border: 0;
  border-radius: 999px;
  width: 48px;
  height: 48px;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-2);
  transition: filter 0.15s var(--ease-out),
              transform 0.12s var(--ease-spring),
              opacity 0.15s var(--ease-out);
}
#send:hover { filter: brightness(1.08); }
#send:active { transform: scale(0.92); }
#send:disabled {
  background: var(--bg-3);
  color: var(--fg-faint);
  cursor: not-allowed;
  box-shadow: none;
}

.hint {
  text-align: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--fg-faint);
  font-family: var(--mono);
  min-height: 14px;
  letter-spacing: 0.04em;
}

/* ============================================================================
   Dialog — modal sheet
   ============================================================================ */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--bg-2);
  color: var(--fg);
  padding: 0;
  max-width: 480px;
  width: min(92vw, 480px);
  box-shadow: var(--shadow-3);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
dialog form { padding: 24px 26px 22px; }
dialog h2 {
  margin: 0 0 8px;
  font-size: 17px;
  letter-spacing: -0.01em;
  font-weight: 600;
}
dialog p { color: var(--fg-dim); font-size: 13px; margin: 0 0 16px; }
dialog code {
  font-family: var(--mono);
  background: var(--bg-3);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12px;
}
dialog input {
  width: 100%;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  font-family: var(--mono);
  font-size: 14px;
  margin-bottom: 14px;
  outline: none;
  transition: border-color 0.18s var(--ease-out),
              box-shadow 0.18s var(--ease-out);
}
dialog input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}
dialog button {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px;
  transition: filter 0.15s var(--ease-out), transform 0.12s var(--ease-spring);
}
dialog button:hover { filter: brightness(1.08); }
dialog button:active { transform: scale(0.96); }

/* ============================================================================
   Mobile breakpoints
   ============================================================================ */

@media (max-width: 640px) {
  main { padding: 18px 14px 8px; }
  footer { padding: 10px 12px max(12px, var(--safe-bottom)); }
  header { padding: max(8px, var(--safe-top)) 14px 8px; }
  .brand .name { display: none; } /* dot only — saves space on mobile */
  .meta { gap: 6px; }
  .meta button,
  .meta .navlink {
    padding: 6px 10px;
    min-height: 38px;            /* easier touch target */
    font-size: 16px;
  }
  #model { font-size: 10px; padding: 3px 8px; }
  .msg.assistant .body { padding: 12px 14px; border-radius: var(--radius); }
  .msg.user .body { max-width: 92%; }
  #input { font-size: 16px; min-height: 46px; }
  #send { width: 46px; height: 46px; }
}

@media (max-width: 380px) {
  .meta button,
  .meta .navlink { padding: 5px 8px; }
  #model { display: none; } /* free room for nav icons */
}

/* Reduced-motion: kill background animations and transitions */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
