:root {
  --bg: #fafaf8;
  --panel: #ffffff;
  --sidebar: #f3f3f0;
  --fg: #18181b;
  --muted: #6b6b73;
  --faint: #9b9ba3;
  --line: #e6e6e1;
  --line-strong: #d6d6cf;
  --accent: #3b5bdb;
  --accent-fg: #ffffff;
  --accent-soft: #eef1fc;
  --danger: #d6336c;
  --danger-soft: #fdeef3;
  --ok: #2b8a3e;
  --ok-soft: #ebf7ee;
  --warn: #b35c00;
  --warn-soft: #fff4e5;
  --rec: #e03131;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114; --panel: #18181c; --sidebar: #141417; --fg: #ececef; --muted: #a0a0a9; --faint: #6f6f78;
    --line: #26262c; --line-strong: #33333a; --accent: #7c95ff; --accent-fg: #0c0c10; --accent-soft: #1d2340;
    --danger: #ff6b9a; --danger-soft: #3a1825; --ok: #69db7c; --ok-soft: #15301c; --warn: #ffb35c; --warn-soft: #3a2a12;
    --rec: #ff6b6b; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.booting { min-height: 100vh; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 272px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px; font-weight: 650; font-size: 16px; color: var(--fg); }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); padding: 6px 10px 4px; display: flex; justify-content: space-between; align-items: center; }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--fg); font-size: 14.5px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.nav-item:hover { background: rgba(127,127,127,.09); }
.nav-item.active { background: var(--panel); box-shadow: var(--shadow); font-weight: 560; }
.nav-item .count { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.nav-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 0 6px; }
.main { min-width: 0; padding: 28px clamp(16px, 4vw, 48px) 64px; }
.page { max-width: 920px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; font-weight: 680; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.topbar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .shell.menu-open .sidebar { display: flex; position: fixed; inset: 0 25% 0 0; z-index: 50; height: 100%; box-shadow: var(--shadow); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 20; }
  .main { padding: 20px 16px 64px; }
  .page-head h1 { font-size: 22px; }
}

/* ---------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 9px; padding: 8px 14px; font-size: 14px; font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: rgba(127,127,127,.1); }
.btn.lg { padding: 12px 20px; font-size: 15px; border-radius: 11px; }
.btn.block { width: 100%; }
.icon { width: 16px; height: 16px; flex: none; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 560; color: var(--muted); }
.input, textarea.input, select.input { width: 100%; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 9px; padding: 9px 12px; outline: none; transition: border-color .12s, box-shadow .12s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 120px; line-height: 1.55; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.search { position: relative; flex: 1 1 260px; max-width: 360px; }
.search .input { padding-left: 34px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 22px; }

/* ---------- call list */
.calls { display: flex; flex-direction: column; gap: 10px; }
.call-card { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 16px 18px; color: var(--fg); transition: border-color .12s, transform .12s; }
.call-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.call-card h3 { font-size: 16px; font-weight: 620; }
.call-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.call-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--faint); }
.call-summary { grid-column: 1 / -1; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.fail { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.neutral { background: rgba(127,127,127,.12); color: var(--muted); }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.empty { text-align: center; padding: 56px 24px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; color: var(--faint); margin-bottom: 12px; }
.empty h3 { color: var(--fg); font-size: 17px; margin-bottom: 6px; }
.empty p { margin: 0 auto 18px; max-width: 380px; }

/* ---------- new call / recorder */
.mode-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 6px 0 20px; }
.mode { text-align: left; padding: 16px; border: 1.5px solid var(--line-strong); border-radius: 12px; background: var(--panel); cursor: pointer; display: flex; gap: 12px; align-items: flex-start; }
.mode:hover { border-color: var(--faint); }
.mode.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.mode .mi { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.mode strong { display: block; font-size: 14.5px; margin-bottom: 2px; }
.mode span { font-size: 13px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); background: var(--accent-soft); border-radius: 10px; padding: 11px 14px; margin-bottom: 18px; }
.hint b { color: var(--fg); }

.recorder { text-align: center; padding: 40px 24px 32px; }
.rec-state { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--rec); }
.rec-state .pulse { width: 9px; height: 9px; }
.timer { font-size: clamp(48px, 10vw, 72px); font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin: 6px 0 4px; }
.levels { display: flex; justify-content: center; gap: 28px; margin: 18px 0 26px; flex-wrap: wrap; }
.level { width: 210px; }
.level-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.meter { height: 8px; border-radius: 99px; background: rgba(127,127,127,.15); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .08s linear; }
.saved { font-size: 13px; color: var(--muted); margin-top: 14px; }
.stop { background: var(--rec); border-color: var(--rec); color: #fff; }
.stop:hover { filter: brightness(1.05); }
.warnbox { display: flex; gap: 10px; text-align: left; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 11px 14px; font-size: 13.5px; margin: 0 auto 18px; max-width: 520px; }

.dropzone { border: 1.5px dashed var(--line-strong); border-radius: 12px; padding: 32px 18px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .12s, background .12s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { color: var(--fg); }
.progress { height: 6px; border-radius: 99px; background: rgba(127,127,127,.15); overflow: hidden; margin-top: 14px; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- call detail */
.detail-head { margin-bottom: 18px; }
.back { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); margin-bottom: 14px; }
.back:hover { color: var(--fg); }
.title-input { font-size: 26px; font-weight: 680; letter-spacing: -.01em; border: 0; background: none; width: 100%; padding: 2px 0; outline: none; border-bottom: 1.5px solid transparent; }
.title-input:hover { border-bottom-color: var(--line); }
.title-input:focus { border-bottom-color: var(--accent); }
.detail-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; font-size: 13.5px; color: var(--muted); }
.detail-meta select { width: auto; padding: 4px 8px; font-size: 13.5px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 20px 0 22px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 9px 14px; font-weight: 560; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }

.notes h2 { font-size: 12px; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); font-weight: 650; margin: 26px 0 10px; }
.notes h2:first-child { margin-top: 0; }
.notes .summary { font-size: 16px; line-height: 1.65; margin: 0; }
.notes ul { margin: 0; padding-left: 20px; }
.notes li { margin: 0 0 7px; }
.actions { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.action { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: start; padding: 11px 14px; border-top: 1px solid var(--line); }
.action:first-child { border-top: 0; }
.action .check { width: 16px; height: 16px; border: 1.5px solid var(--line-strong); border-radius: 5px; margin-top: 3px; }
.action .who { font-size: 12.5px; color: var(--muted); text-align: right; }
.action .who b { display: block; color: var(--fg); font-weight: 600; }
.muted { color: var(--muted); }
.transcript { white-space: pre-wrap; font-size: 15px; line-height: 1.75; }
audio { width: 100%; margin-top: 4px; }

.processing { text-align: center; padding: 48px 20px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.failbox { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 16px 18px; display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.sent { display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: var(--ok); background: var(--ok-soft); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; font-size: 19px; margin-bottom: 22px; }
.login .brand img { width: 36px; height: 36px; }
.error { color: var(--danger); font-size: 13.5px; margin: 0 0 12px; min-height: 0; }

/* ---------- modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10,10,14,.45); display: grid; place-items: center; padding: 16px; z-index: 100; animation: fade .12s; }
.modal { width: 100%; max-width: 440px; padding: 22px; }
.modal h3 { font-size: 18px; margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }
@keyframes fade { from { opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); color: #fff; }
