:root {
  --bg: #0b0c0f;
  --surface: #14161b;
  --surface-2: #1b1e25;
  --border: #262a33;
  --border-strong: #353a46;
  --text: #e8eaed;
  --muted: #8a8f9a;
  --accent: #5ea0ff;
  --accent-soft: rgba(94, 160, 255, 0.15);
  --user-bubble: #1d2230;
  --assistant-bubble: #15171d;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

body {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, #5ea0ff, #a855f7);
}

.brand-name {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-sub {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
}

#nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

#nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  font-size: 11px;
  padding: 0 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.auth-bar #auth-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-bar a {
  color: var(--muted);
  text-decoration: none;
}

.auth-bar a:hover {
  color: var(--accent);
}

body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-form {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form .brand {
  padding: 0;
  margin-bottom: 4px;
}

.login-form h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.login-form input {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
  outline: none;
}

.login-form input:focus {
  border-color: var(--accent);
}

.login-form button {
  margin-top: 4px;
  background: var(--accent);
  color: #0b0c0f;
  border: none;
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.login-form button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.login-error {
  color: var(--err);
  font-size: 12px;
  min-height: 1em;
}

main {
  overflow: auto;
  padding: 28px 32px 60px;
  max-width: 1400px;
}

.page h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 20px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.count-pill {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  background: var(--surface-2);
  border-radius: 999px;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.stat-card .label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}

.card h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 12px;
}

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.plain-list li {
  padding: 8px 0;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.plain-list li:first-child {
  border-top: none;
}

.plain-list a {
  color: var(--text);
  text-decoration: none;
}

.plain-list a:hover {
  color: var(--accent);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 16px;
  min-height: 70vh;
}

.split .thread,
.split .detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  overflow: auto;
  max-height: calc(100vh - 120px);
}

.placeholder {
  color: var(--muted);
  text-align: center;
  padding: 40px 12px;
  font-size: 13px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: calc(100vh - 120px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  z-index: 1;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: var(--surface-2);
}

tbody tr.selected {
  background: var(--accent-soft);
}

.list-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: calc(100vh - 120px);
}

.conv-row {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-row:hover {
  background: var(--surface-2);
}

.conv-row.selected {
  background: var(--accent-soft);
}

.conv-row .row-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.conv-row .who {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.conv-row .who.anon {
  font-weight: 400;
  font-style: italic;
  color: var(--muted);
}

.conv-row .title {
  font-weight: 400;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.conv-row .meta {
  color: var(--muted);
  font-size: 11px;
  display: flex;
  gap: 8px;
}

.conv-row .preview {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.thread-header .title {
  font-weight: 600;
  font-size: 15px;
}

.thread-header .meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 18px;
}

.msg .bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  max-width: 100%;
}

.msg.user .bubble {
  background: var(--user-bubble);
  border-color: var(--border-strong);
}

.msg .who {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.msg .footer {
  color: var(--muted);
  font-size: 11px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.content-block {
  margin-top: 8px;
}

.content-block:first-child {
  margin-top: 0;
}

details.think {
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

details.think > summary {
  cursor: pointer;
  color: var(--muted);
  font-family: var(--sans);
}

details.think > div {
  margin-top: 6px;
  white-space: pre-wrap;
}

.tool-call {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
}

.tool-call .tool-head {
  display: flex;
  gap: 8px;
  align-items: center;
  font-family: var(--mono);
  font-size: 12px;
}

.tool-call .tool-name {
  color: var(--accent);
  font-weight: 600;
}

.tool-call pre {
  margin: 6px 0 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow: auto;
}

.tool-call details {
  margin-top: 6px;
}

.tool-call details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}

.text-block {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-card .name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.lead-card .kv {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 4px 10px;
  font-size: 13px;
}

.lead-card .kv dt {
  color: var(--muted);
}

.lead-card .kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
}

.chip.warn {
  border-color: #6b4a10;
  color: var(--warn);
}

.cv-preview {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 8px 10px;
  max-height: 120px;
  overflow: hidden;
  position: relative;
  white-space: pre-wrap;
  word-break: break-word;
}

.cv-preview.expanded {
  max-height: none;
}

.cv-toggle {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font: inherit;
  cursor: pointer;
  font-size: 12px;
  align-self: flex-start;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.search-box input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-hit {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.search-hit:hover {
  border-color: var(--border-strong);
}

.search-hit .head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.search-hit mark {
  background: #3a2f00;
  color: #fde68a;
  padding: 0 2px;
  border-radius: 2px;
}

.search-hit .snippet {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 8px 10px;
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.ok {
  color: var(--ok);
}

.dim {
  color: var(--muted);
}

a {
  color: var(--accent);
}

.detail h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 18px 0 6px;
}

.detail h3:first-child {
  margin-top: 0;
}

.detail .kv {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 4px 10px;
  font-size: 13px;
}

.detail .kv dt {
  color: var(--muted);
}

.detail .kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ---- mobile sidebar + layout ---- */

#menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 30;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

#menu-toggle:hover {
  color: var(--accent);
}

#sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 19;
  opacity: 0;
  transition: opacity 180ms ease;
}

@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
  }

  main {
    padding: 60px 14px 80px;
    max-width: 100%;
  }

  #menu-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    max-width: 80vw;
    height: 100vh;
    height: 100dvh;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.4);
  }

  body[data-sidebar="open"] .sidebar {
    transform: translateX(0);
  }

  body[data-sidebar="open"] #sidebar-scrim {
    display: block;
    opacity: 1;
  }

  body[data-sidebar="open"] #menu-toggle {
    left: 272px;
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    z-index: 25;
  }

  .page h1 {
    font-size: 20px;
    margin-top: 4px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .split {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .split .thread,
  .split .detail,
  .table-wrap,
  .list-wrap {
    max-height: none;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-card .value {
    font-size: 22px;
  }

  thead th,
  th,
  td {
    padding: 8px 10px;
  }

  .lead-card .kv,
  .detail .kv {
    grid-template-columns: 72px 1fr;
  }

  .search-box {
    flex-direction: column;
    align-items: stretch;
  }
}
