:root {
  --field: oklch(0.985 0.002 255);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.965 0.006 255);
  --ink: oklch(0.22 0.012 255);
  --muted: oklch(0.43 0.018 255);
  --line: oklch(0.88 0.008 255);
  --line-strong: oklch(0.76 0.014 255);
  --red: oklch(0.53 0.205 28);
  --red-dark: oklch(0.43 0.18 28);
  --red-soft: oklch(0.96 0.025 28);
  --green: oklch(0.49 0.12 153);
  --green-soft: oklch(0.96 0.03 153);
  --amber-soft: oklch(0.95 0.045 82);
  --blue-soft: oklch(0.95 0.025 245);
  --danger-soft: oklch(0.95 0.04 28);
  --shadow-panel: -12px 0 32px rgb(21 29 39 / 10%);
  --radius: 8px;
  --focus: 0 0 0 3px oklch(0.72 0.13 28 / 45%);
  --z-sticky: 10;
  --z-panel: 30;
  --z-dialog: 50;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--field);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--field); color: var(--ink); font-size: 14px; }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 100; padding: 10px 14px; border-radius: var(--radius); background: var(--ink); color: white; }
.skip-link:focus { top: 12px; }

.login-view { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: linear-gradient(135deg, var(--field), var(--surface-2)); }
.login-panel { width: min(420px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 22px 60px rgb(20 28 38 / 10%); }
.login-brand { display: inline-flex; gap: 10px; align-items: center; }
.login-brand strong, .login-brand small { display: block; }
.login-brand strong { letter-spacing: .025em; }
.login-brand small { margin-top: 1px; color: var(--muted); font-size: 11px; }
.login-copy { margin-top: 42px; }
.login-copy h1 { margin-bottom: 10px; font-size: clamp(25px, 5vw, 31px); }
.login-copy > p:last-child, .login-help { color: var(--muted); line-height: 1.55; }
.eyebrow { margin-bottom: 9px; color: var(--red-dark); font-size: 11px; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }
.login-form { display: grid; gap: 16px; margin-top: 26px; }
.login-form .button { width: 100%; margin-top: 2px; }
.login-error { min-height: 20px; margin: -4px 0 0; color: var(--red-dark); font-size: 12px; line-height: 1.5; }
.login-help { margin: 12px 0 0; padding-top: 18px; border-top: 1px solid var(--line); font-size: 12px; }

.app-shell { display: grid; grid-template: 64px minmax(0, 1fr) / 188px minmax(620px, 1fr); min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 24px 0 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: inline-flex; gap: 10px; align-items: center; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 7px; background: var(--red); color: white; font-size: 18px; font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .025em; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 11px; }
.identity { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.role-badge { padding: 3px 7px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); text-transform: capitalize; }
.logout-button { min-height: 32px; padding: 5px 8px; font-size: 12px; }

.sidebar { padding: 20px 12px; border-right: 1px solid var(--line); background: var(--surface-2); }
.nav-item, .segment-button { width: 100%; border: 0; border-radius: var(--radius); background: transparent; color: var(--ink); text-align: left; }
.nav-item { display: flex; gap: 10px; align-items: center; min-height: 40px; padding: 8px 10px; font-weight: 650; }
.nav-item.is-active { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.nav-glyph { color: var(--red); font-size: 8px; }
.nav-section { margin-top: 28px; }
.nav-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px 10px; color: var(--muted); font-size: 12px; font-weight: 650; }
.segment-list { display: grid; gap: 2px; }
.segment-button { overflow: hidden; padding: 8px 10px; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.segment-button:hover, .segment-button:focus-visible { background: var(--surface); color: var(--ink); }
.segment-empty { padding: 8px 10px; color: var(--muted); font-size: 12px; line-height: 1.5; }

.workspace { min-width: 0; padding: 26px 28px 40px; transition: margin-right 180ms cubic-bezier(.22, 1, .36, 1); }
body.detail-open .workspace { margin-right: 390px; }
.workspace-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 24px; line-height: 1.2; letter-spacing: -.025em; }
.workspace-heading p { margin-bottom: 0; color: var(--muted); }
.button { min-height: 38px; padding: 8px 13px; border: 1px solid transparent; border-radius: var(--radius); font-weight: 650; }
.button-primary { background: var(--red); color: white; }
.button-primary:hover { background: var(--red-dark); }
.button-secondary { border-color: var(--line-strong); background: var(--surface); color: var(--ink); }
.button-secondary:hover { border-color: var(--ink); }
.button-quiet { background: transparent; color: var(--muted); }
.button-quiet:hover { color: var(--ink); background: var(--surface-2); }
.icon-button { display: grid; place-items: center; width: 32px; min-width: 32px; height: 32px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 20px; }
.icon-button:hover { background: var(--surface-2); color: var(--ink); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-top: 24px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.filters label { flex: 1 1 120px; }
.filters .search-field { flex: 2 1 230px; }
label { display: grid; gap: 6px; min-width: 0; }
label > span { color: var(--muted); font-size: 12px; font-weight: 650; }
input, select { width: 100%; min-width: 0; min-height: 38px; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
input::placeholder { color: oklch(0.48 0.014 255); opacity: 1; }
input:hover, select:hover { border-color: var(--muted); }
.filter-actions { display: flex; flex: 0 1 auto; gap: 4px; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; padding: 8px 0 0; }
.filter-chip { padding: 4px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; }

.lead-surface { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; z-index: var(--z-sticky); height: 38px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 700; text-align: left; }
td { height: 52px; max-width: 230px; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { position: relative; transition: background-color 180ms ease-out; }
tbody tr:hover { background: oklch(0.98 0.006 28); }
tbody tr.is-selected { background: var(--red-soft); }
tbody tr.is-selected::after { position: absolute; top: 0; right: 0; bottom: 0; width: 3px; background: var(--red); content: ""; }
.row-button { display: block; width: 100%; overflow: hidden; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.row-button strong, .row-button span { display: block; overflow: hidden; text-overflow: ellipsis; }
.row-button span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.cell-muted { color: var(--muted); }
.status { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; background: var(--blue-soft); font-size: 12px; font-weight: 650; text-transform: capitalize; }
.status[data-status="won"] { background: var(--green-soft); color: oklch(0.37 0.1 153); }
.status[data-status="lost"], .status[data-status="spam"] { background: var(--danger-soft); color: var(--red-dark); }
.status[data-status="quoted"] { background: var(--amber-soft); color: oklch(0.38 0.08 82); }
.tag-stack { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { display: inline-block; max-width: 120px; overflow: hidden; padding: 2px 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.table-state { padding: 44px 24px; color: var(--muted); text-align: center; }
.table-state[hidden] { display: none; }
.state-title { margin-bottom: 5px; color: var(--ink); font-size: 16px; font-weight: 700; }
.skeleton { display: block; height: 12px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2), oklch(0.93 0.006 255), var(--surface-2)); background-size: 220% 100%; animation: skeleton 1.25s linear infinite; }
@keyframes skeleton { to { background-position: -220% 0; } }
.pagination { display: flex; justify-content: center; padding: 12px; }

.detail-panel { position: fixed; z-index: var(--z-panel); top: 64px; right: 0; bottom: 0; width: min(390px, 100vw); overflow-y: auto; border-left: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-panel); transform: translateX(105%); transition: transform 180ms cubic-bezier(.22, 1, .36, 1); }
.detail-panel.is-open { transform: translateX(0); }
.detail-topbar { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.detail-label { color: var(--muted); font-size: 12px; font-weight: 700; }
#detail-content { padding: 20px 18px 36px; }
.detail-name { margin-bottom: 5px; font-size: 20px; }
.detail-meta { color: var(--muted); font-size: 12px; }
.detail-section { padding: 18px 0; border-top: 1px solid var(--line); }
.detail-section:first-of-type { margin-top: 20px; }
.detail-section h3 { margin-bottom: 10px; font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: 110px 1fr; gap: 9px 12px; margin: 0; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.detail-grid a { color: var(--red-dark); text-underline-offset: 2px; }
.summary { line-height: 1.55; white-space: pre-wrap; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tag-editor { display: flex; gap: 8px; }
.tag-editor input { flex: 1; }
.transcript { display: grid; gap: 10px; margin-top: 12px; }
.message { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); line-height: 1.5; white-space: pre-wrap; }
.message[data-role="user"] { background: var(--red-soft); }
.message strong { display: block; margin-bottom: 4px; font-size: 11px; text-transform: capitalize; }

dialog { width: min(440px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); box-shadow: 0 24px 70px rgb(20 28 38 / 24%); }
dialog::backdrop { background: rgb(20 28 38 / 38%); }
dialog form { padding: 20px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin-bottom: 0; font-size: 20px; }
dialog p { margin: 10px 0 18px; color: var(--muted); line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.toast { position: fixed; z-index: calc(var(--z-dialog) + 1); right: 18px; bottom: 18px; max-width: min(380px, calc(100vw - 36px)); padding: 11px 14px; border-radius: var(--radius); background: var(--ink); color: white; box-shadow: 0 12px 32px rgb(20 28 38 / 24%); }

@media (max-width: 900px) {
  .app-shell { grid-template: 64px auto minmax(0, 1fr) / 1fr; }
  .sidebar { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-item { width: auto; min-width: 90px; }
  .nav-section { display: flex; align-items: center; gap: 6px; margin: 0; }
  .nav-heading { padding: 0; }
  .nav-heading > span { display: none; }
  .segment-list { display: flex; }
  .segment-button { width: auto; max-width: 160px; white-space: nowrap; }
  .segment-empty { display: none; }
  .workspace { padding: 22px 18px 36px; }
  body.detail-open .workspace { margin-right: 0; }
}

@media (max-width: 700px) {
  .topbar { padding-inline: 14px; }
  .identity #identity-email { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .workspace-heading { align-items: stretch; }
  .workspace-heading .button { align-self: flex-start; }
  .filters label { flex-basis: calc(50% - 6px); }
  .filters .search-field, .filter-actions { flex-basis: 100%; }
  .filter-actions .button { flex: 1; }
  table, thead, tbody, tr, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  tbody tr { display: grid; grid-template-columns: 1fr 1fr; padding: 13px 12px; border-bottom: 1px solid var(--line); }
  td { display: grid; grid-template-columns: 82px 1fr; max-width: none; height: auto; min-height: 32px; padding: 5px 0; border: 0; }
  td::before { color: var(--muted); font-size: 11px; font-weight: 650; content: attr(data-label); }
  td:nth-child(2), td:nth-child(3), td:nth-child(7) { grid-column: 1 / -1; }
  tbody tr.is-selected::after { left: 0; right: auto; width: 3px; }
}

@media (max-width: 460px) {
  .login-view { padding: 14px; }
  .login-panel { padding: 24px 20px; }
  .brand small, .role-badge { display: none; }
  .workspace-heading { display: grid; }
  .workspace-heading .button { width: 100%; }
  .filters label, .filters .search-field, .filter-actions { flex-basis: 100%; }
  tbody tr { grid-template-columns: 1fr; }
  td, td:nth-child(2), td:nth-child(3), td:nth-child(7) { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
