/* Talkmaple design system. Plain CSS, no build step. Tokens first, then primitives, then components. */
:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;

  --bg: #f5f7fb;
  --bg-elev: #ffffff;
  --bg-sunken: #eef1f6;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  --brand: #2563eb;
  --brand-2: #1d4ed8;
  --brand-soft: #dbeafe;
  --brand-text: #ffffff;
  --accent: #7c3aed;

  --ok: #16a34a;   --ok-soft: #dcfce7;
  --warn: #d97706; --warn-soft: #fef3c7;
  --bad: #dc2626;  --bad-soft: #fee2e2;
  --info: #0891b2; --info-soft: #cffafe;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 8px 24px -12px rgb(15 23 42 / .18);
  --shadow-sm: 0 1px 2px rgb(15 23 42 / .06);
  --sidebar-w: 248px;
  --topbar-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --bg-elev: #111827; --bg-sunken: #0f172a;
    --text: #e5e7eb; --text-2: #9ca3af; --text-3: #6b7280;
    --line: #1f2937; --line-strong: #374151;
    --brand: #3b82f6; --brand-2: #2563eb; --brand-soft: #1e3a8a;
    --ok-soft: #052e16; --warn-soft: #422006; --bad-soft: #450a0a; --info-soft: #083344;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 32px -12px rgb(0 0 0 / .6);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --bg-elev: #111827; --bg-sunken: #0f172a;
  --text: #e5e7eb; --text-2: #9ca3af; --text-3: #6b7280;
  --line: #1f2937; --line-strong: #374151;
  --brand: #3b82f6; --brand-2: #2563eb; --brand-soft: #1e3a8a;
  --ok-soft: #052e16; --warn-soft: #422006; --bad-soft: #450a0a; --info-soft: #083344;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 32px -12px rgb(0 0 0 / .6);
}

/* ---------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .35em; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; } h4 { font-size: 13px; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0 0 .75em; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
pre { background: var(--bg-sunken); padding: 12px; border-radius: var(--radius-sm); overflow: auto; white-space: pre-wrap; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); } .dim { color: var(--text-3); } .small { font-size: 12.5px; } .xs { font-size: 11.5px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; } .center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; } .mt-s { margin-top: 8px; } .mb-s { margin-bottom: 8px; }
.w-full { width: 100%; } .grow { flex: 1 1 auto; } .nowrap { white-space: nowrap; }

/* ---------- app shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--bg-elev); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 14px 12px; gap: 6px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--accent)); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px; flex: none; }
.brand .name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand .org { font-size: 12px; color: var(--text-2); }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); margin: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-2); }
:root[data-theme="dark"] .nav a.active, [data-theme="dark"] .nav a.active { color: #bfdbfe; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav .count { margin-left: auto; font-size: 11px; background: var(--bg-sunken); border-radius: 999px; padding: 1px 8px; color: var(--text-2); }
.sidebar .bottom { margin-top: auto; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 28px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; }
.topbar h1 { font-size: 18px; margin: 0; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); animation: pulse 1.6s infinite; display: inline-block; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ---------- cards, tiles */
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card .card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card .card-h h2, .card .card-h h3 { margin: 0; }
.card .card-b { padding: 18px; }
.card.pad { padding: 18px; }
.tile { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px; }
.tile .label { color: var(--text-2); font-size: 12.5px; }
.tile .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.tile .delta { font-size: 12px; color: var(--text-3); }
.tile .delta.up { color: var(--ok); } .tile .delta.down { color: var(--bad); }
.empty { padding: 36px 18px; text-align: center; color: var(--text-2); }
.empty .icon { font-size: 28px; margin-bottom: 6px; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--bg-elev); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; line-height: 1.2; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--bg-sunken); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg-sunken); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.lg { padding: 11px 18px; font-size: 15px; }
.btn svg { width: 16px; height: 16px; }
.btn.icon { padding: 7px; }

/* ---------- forms */
label.field, .field > label { display: block; font-size: 12.5px; font-weight: 550; color: var(--text-2); margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.field .error { font-size: 12px; color: var(--bad); margin-top: 5px; }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="url"], input[type="number"], input[type="date"], input[type="time"], input[type="search"], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg-elev); color: var(--text); font: inherit; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
input.input-error, select.input-error, textarea.input-error { border-color: var(--bad); }
textarea { min-height: 110px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.check input { width: 16px; height: 16px; }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 999px; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(16px); }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: 13.5px; margin-bottom: 14px; }
.alert.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--warn); }
.alert.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, transparent); color: var(--bad); }
.alert.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--info); }

/* ---------- tables */
.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tbody tr:hover td { background: var(--bg-sunken); }
table.data tbody tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- badges, chips */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--bg-sunken); color: var(--text-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-2); display: inline-grid; place-items: center; font-weight: 700; font-size: 12.5px; flex: none; }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }

/* ---------- tabs, toolbar, pagination */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"], .toolbar select { width: auto; min-width: 180px; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 12px; font-size: 13px; color: var(--text-2); }

/* ---------- drawer, modal, toast */
.drawer-backdrop { position: fixed; inset: 0; background: rgb(15 23 42 / .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--bg-elev); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 41; display: flex; flex-direction: column; animation: slidein .18s ease-out; }
.drawer .drawer-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer .drawer-b { padding: 20px; overflow-y: auto; flex: 1; }
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; background: rgb(15 23 42 / .35); padding: 16px; }
.modal .box { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); width: min(560px, 100%); padding: 22px; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px; max-width: 420px; animation: slidein .18s ease-out; }
.toast.ok { background: var(--ok); color: #fff; } .toast.bad { background: var(--bad); color: #fff; }

/* ---------- transcript / chat */
.transcript { display: flex; flex-direction: column; gap: 8px; }
.turn { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 13.5px; white-space: pre-wrap; }
.turn.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.turn.assistant { align-self: flex-start; background: var(--bg-sunken); border-bottom-left-radius: 4px; }
.turn .ts { display: block; font-size: 10.5px; opacity: .7; margin-top: 2px; }
.turn.tool { align-self: center; background: transparent; color: var(--text-3); font-size: 12px; font-family: var(--mono); }

/* ---------- kanban */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 14px; overflow-x: auto; align-items: start; }
.kcol { background: var(--bg-sunken); border-radius: var(--radius); padding: 10px; min-height: 240px; }
.kcol h4 { display: flex; justify-content: space-between; margin: 4px 6px 10px; }
.kcard { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow-sm); cursor: grab; }
.kcard.dragging { opacity: .5; }
.kcard .t { font-weight: 600; } .kcard .s { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }

/* ---------- auth pages */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .side { background: linear-gradient(160deg, #0b1020 0%, #1e3a8a 60%, #7c3aed 140%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth .side h1 { font-size: 34px; margin-bottom: 14px; }
.auth .side p { color: #c7d2fe; font-size: 16px; max-width: 460px; }
.auth .side ul { color: #e0e7ff; padding-left: 18px; line-height: 1.9; }
.auth .form { display: grid; place-items: center; padding: 32px; }
.auth .form .box { width: min(420px, 100%); }
.auth .form h2 { font-size: 24px; margin-bottom: 4px; }

/* ---------- charts */
.chart { position: relative; height: 260px; }
.chart.sm { height: 160px; }

/* ---------- responsive */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform .18s; z-index: 45; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .auth { grid-template-columns: 1fr; } .auth .side { display: none; }
  .kanban { grid-template-columns: repeat(5, 240px); }
}
@media (max-width: 600px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* ---------- sidebar user menu */
[x-cloak] { display: none !important; }
.min0 { min-width: 0; }
.user-area { position: relative; padding: 4px 2px 0; }
.user-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--text); font: inherit; cursor: pointer; text-align: left; transition: background .12s, border-color .12s; }
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--bg-sunken); border-color: var(--line); }
.user-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.user-btn .chev { width: 16px; height: 16px; color: var(--text-3); flex: none; transition: transform .15s; }
.user-menu { position: absolute; left: 2px; right: 2px; bottom: calc(100% + 6px); background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; z-index: 30; }
.user-menu-head { display: flex; gap: 10px; align-items: center; padding: 10px 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.user-menu a, .user-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); font: inherit; font-weight: 500; cursor: pointer; text-align: left; text-decoration: none; }
.user-menu a:hover, .user-menu button:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.user-menu a svg, .user-menu button svg { width: 16px; height: 16px; flex: none; opacity: .8; }
.user-menu button.danger { color: var(--bad); }
.user-menu button.danger:hover { background: var(--bad-soft); }
.user-menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
