/* ============================================================
   Base — design tokens, reset, page shell, header, shared
   form controls, source cards, scrollbars, drawer overlay.
   Loaded on every page.
   ============================================================ */

:root {
  --bg:            #F6F4EF;
  --surface:       #FFFFFF;
  --surface-alt:   #FBFAF6;
  --ink:           #16181C;
  --ink-2:         #3A3E46;
  --muted:         #6B7280;
  --muted-2:       #9AA0AA;
  --line:          #E7E4DC;
  --line-strong:   #D6D2C8;
  --accent:        oklch(0.62 0.14 45);
  --accent-ink:    oklch(0.38 0.09 45);
  --accent-soft:   oklch(0.96 0.025 55);
  --danger:        oklch(0.55 0.18 25);
  --danger-soft:   oklch(0.96 0.03 25);
  --info:          oklch(0.55 0.11 245);
  --info-soft:     oklch(0.97 0.02 245);
  --success:       oklch(0.50 0.12 155);
  --success-soft:  oklch(0.96 0.03 155);
  --violet:        oklch(0.50 0.14 295);
  --violet-soft:   oklch(0.97 0.02 295);
  --radius:        10px;
  --radius-sm:     7px;
  --radius-lg:     14px;
  --shadow-sm:     0 1px 0 rgba(20,20,30,0.04);
  --shadow-md:     0 1px 2px rgba(20,20,30,0.05), 0 8px 24px -16px rgba(20,20,30,0.18);
  --mono:          "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans:          "Inter Tight", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --header-h:      56px;
  --bp-mobile:     768px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Header ---------- */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 28px;
  height: var(--header-h);
  flex-shrink: 0;
}
header .title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
header .title::before {
  content: "";
  width: 18px; height: 18px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), oklch(0.72 0.12 65));
  display: inline-block;
  flex-shrink: 0;
}

nav { display: flex; gap: 2px; height: 100%; }
nav a {
  color: var(--muted);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  display: flex;
  align-items: center;
  position: relative;
  transition: color .15s ease;
}
nav a::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: -1px;
  height: 2px;
  background: transparent;
  border-radius: 2px;
}
nav a.active { color: var(--ink); }
nav a.active::after { background: var(--ink); }
nav a:hover { color: var(--ink); }

.user-chip {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 0;
}
.user-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-chip-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  transition: border-color .15s ease, background .15s ease;
  white-space: nowrap;
}
.user-chip-link:hover {
  border-color: var(--line-strong);
  background: var(--surface-alt);
}

/* ---------- Layout shell ---------- */
.container {
  display: flex;
  gap: 16px;
  width: 100%;
  padding: 16px 20px 20px;
  flex: 1;
  overflow: hidden;
}
.main-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  min-width: 0;
}

/* ---------- Source cards (shared: chat sources sidebar + search results) ---------- */
.source-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px;
  transition: border-color .15s ease, box-shadow .15s ease, transform .05s;
}
.source-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.source-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.source-card .title {
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: -0.005em;
  color: var(--ink);
  line-height: 1.35;
}
.source-card .score {
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--ink);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}
.source-meta {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.source-meta span {
  font-size: 11px;
  font-family: var(--mono);
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  color: var(--muted);
}
.chunk-content {
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.55;
  margin-bottom: 10px;
  border-left: 2px solid var(--line-strong);
  padding: 2px 0 2px 12px;
}
.doc-link {
  font-size: 12px;
  color: var(--accent-ink);
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.doc-link::after { content: "→"; transition: transform .15s ease; }
.doc-link:hover::after { transform: translateX(2px); }

.inline-citation {
  color: var(--accent-ink);
  text-decoration: none;
  font-size: 0.92em;
  padding: 0 3px;
  border-bottom: 1px dotted currentColor;
  white-space: nowrap;
}
.inline-citation:hover {
  background: var(--accent-soft);
  border-bottom-style: solid;
}

/* ---------- Shared form controls ---------- */
form input[type="text"] {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
form input[type="text"]:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(22,24,28,0.06);
}
form input[type="text"]::placeholder { color: var(--muted-2); }

form button {
  padding: 11px 22px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .05s;
  letter-spacing: 0.01em;
}
form button:hover { background: #000; }
form button:active { transform: translateY(1px); }
form button:disabled { background: var(--muted-2); cursor: not-allowed; }

form button.stop-mode {
  padding: 11px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
form button.stop-mode .stop-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 2px;
}

/* ---------- Scrollbars ---------- */
.conversation::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.thread-sidebar::-webkit-scrollbar,
.thread-list::-webkit-scrollbar,
.search-sidebar::-webkit-scrollbar,
.search-results::-webkit-scrollbar { width: 8px; }
.conversation::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track,
.thread-sidebar::-webkit-scrollbar-track,
.thread-list::-webkit-scrollbar-track,
.search-sidebar::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track { background: transparent; }
.conversation::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb,
.thread-sidebar::-webkit-scrollbar-thumb,
.thread-list::-webkit-scrollbar-thumb,
.search-sidebar::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 8px;
}
.conversation::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

/* ---------- Drawer overlay (used by chat on mobile) ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 28, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 40;
}
body.drawer-open { overflow: hidden; }
body.drawer-open .drawer-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Mobile (≤ 768px) ---------- */
@media (max-width: 768px) {
  header {
    padding: 0 12px;
    gap: 12px;
  }
  nav { gap: 0; }
  nav a { padding: 0 10px; }

  .user-chip { gap: 6px; font-size: 12px; }
  .user-chip-link { padding: 5px 8px; }

  .container {
    padding: 10px;
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .user-chip-name { display: none; }
  .user-chip-link.is-secondary { display: none; }
}
