:root {
  --bg: #f6f7f6;
  --surface: #ffffff;
  --surface-2: #f0f2f1;
  --border: #dfe3e1;
  --text: #17201d;
  --muted: #5f6b67;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3f0;
  --rec: #dc2626;
  --rec-soft: #fde8e8;
  --warn: #b45309;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --s1: #0f766e; --s2: #7c3aed; --s3: #c2410c; --s4: #2563eb;
  --s5: #be185d; --s6: #4d7c0f; --s7: #a16207; --s8: #0e7490;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1413;
    --surface: #161d1b;
    --surface-2: #1d2624;
    --border: #2b3633;
    --text: #e7eeec;
    --muted: #97a5a1;
    --accent: #2dd4bf;
    --accent-ink: #062623;
    --accent-soft: #123330;
    --rec: #f87171;
    --rec-soft: #3a1a1a;
    --warn: #fbbf24;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --s1: #2dd4bf; --s2: #a78bfa; --s3: #fb923c; --s4: #60a5fa;
    --s5: #f472b6; --s6: #a3e635; --s7: #facc15; --s8: #22d3ee;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0f1413;
    --surface: #161d1b;
    --surface-2: #1d2624;
    --border: #2b3633;
    --text: #e7eeec;
    --muted: #97a5a1;
    --accent: #2dd4bf;
    --accent-ink: #062623;
    --accent-soft: #123330;
    --rec: #f87171;
    --rec-soft: #3a1a1a;
    --warn: #fbbf24;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --s1: #2dd4bf; --s2: #a78bfa; --s3: #fb923c; --s4: #60a5fa;
    --s5: #f472b6; --s6: #a3e635; --s7: #facc15; --s8: #22d3ee;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 20; height: 56px;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.status {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); padding: 4px 10px; border-radius: 99px; background: var(--surface-2);
  max-width: 55vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: #16a34a; }
.dot.busy { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.err { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px;
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.status + .icon-btn { margin-left: 4px; }
.mobile-only { display: none; }

/* Layout */
.layout { display: grid; grid-template-columns: 264px 1fr; min-height: calc(100% - 56px); }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow: auto;
}
.side-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 8px 2px; }
.session-list { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.session-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px;
  padding: 8px 10px; border-radius: 10px; cursor: pointer; border: 0; background: transparent; text-align: left; width: 100%;
}
.session-item:hover { background: var(--surface-2); }
.session-item.active { background: var(--accent-soft); }
.session-item .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .d { grid-column: 1; font-size: 12px; color: var(--muted); }
.session-item .del { grid-row: 1 / span 2; grid-column: 2; opacity: 0; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.session-item:hover .del, .session-item:focus-within .del { opacity: 1; }
.session-item .del:hover { color: var(--danger); background: var(--surface); }
.side-foot { font-size: 12px; color: var(--muted); padding: 8px; border-top: 1px solid var(--border); }
.empty-list { font-size: 13px; color: var(--muted); padding: 8px 10px; }
.scrim { display: none; }

.main { padding: 24px; max-width: 980px; width: 100%; margin: 0 auto; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 14px;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; text-align: left; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Setup */
.setup { padding: 24px; margin-bottom: 20px; }
.setup h2 { margin: 0 0 6px; font-size: 20px; }
.setup-rows { display: flex; flex-direction: column; gap: 14px; margin: 20px 0; }
.setup-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.setup-row .size { font-size: 13px; color: var(--muted); }
.setup-row .bar { grid-column: 1 / -1; }
.setup-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }

/* Session head */
.session-head { margin-bottom: 16px; }
.title {
  width: 100%; border: 0; background: transparent; font-size: 26px; font-weight: 700; letter-spacing: -.02em;
  padding: 4px 0; outline: none; border-bottom: 2px solid transparent;
}
.title:focus { border-bottom-color: var(--accent); }
.meta { font-size: 13px; color: var(--muted); }

/* Recorder */
.recorder { display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center; padding: 18px 20px; }
.rec {
  width: 76px; height: 76px; border-radius: 50%; border: 3px solid var(--rec-soft); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; transition: transform .1s;
  box-shadow: 0 0 0 1px var(--border);
}
.rec:hover { transform: scale(1.04); }
.rec:active { transform: scale(.97); }
.rec:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.rec-core { width: 38px; height: 38px; border-radius: 50%; background: var(--rec); transition: all .2s; }
.rec.recording { border-color: var(--rec); animation: ring 1.6s infinite; }
.rec.recording .rec-core { width: 26px; height: 26px; border-radius: 6px; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .35); } 70% { box-shadow: 0 0 0 14px rgba(220, 38, 38, 0); } 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); } }
.timer { font: 600 30px/1.1 var(--mono); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.meter { width: 100%; max-width: 300px; height: 28px; display: block; margin: 6px 0 2px; }
.rec-state { font-size: 13px; color: var(--muted); }
.rec-state.live { color: var(--rec); font-weight: 600; }
.rec-side { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.rec-buttons { display: flex; gap: 8px; }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 22px 0 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tab { border: 0; background: none; padding: 6px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 230px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.menu button:hover { background: var(--surface-2); }
.menu button:disabled { opacity: .4; cursor: not-allowed; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 4px; }
.menu .menu-label { font-size: 12px; color: var(--muted); padding: 6px 10px 2px; }
.menu.floating { position: fixed; right: auto; top: auto; }
.menu input { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); margin: 4px 0; }

.player { margin-bottom: 12px; }
.player audio { width: 100%; height: 40px; }

.jobbar {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center;
  padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); margin-bottom: 12px; font-size: 14px;
}
.jobbar .bar { grid-column: 1 / -1; background: var(--surface); }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Transcript */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 24px 24px; min-height: 280px; }
.turn { padding: 14px 0 4px; }
.turn + .turn { border-top: 1px solid var(--surface-2); }
.turn-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  font-weight: 700; font-size: 13px; padding: 2px 10px 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--sc, var(--text));
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--sc, var(--muted)); }
.chip:hover { outline: 1px solid var(--sc, var(--border)); }
.ts { font: 12px var(--mono); color: var(--muted); border: 0; background: none; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.ts:hover { background: var(--surface-2); color: var(--accent); }
.ts:disabled { cursor: default; background: none; color: var(--muted); }
.turn-text { font-size: 16px; line-height: 1.65; }
.seg { outline: none; border-radius: 4px; transition: background .15s; }
.seg:hover { background: var(--surface-2); }
.seg:focus { background: var(--accent-soft); }
.seg.new { animation: fadein .5s; }
.seg.playing { background: var(--accent-soft); }
@keyframes fadein { from { opacity: 0; } }
.listening { color: var(--muted); font-style: italic; padding: 12px 0; display: flex; gap: 8px; align-items: center; }
.listening .dots span { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); margin: 0 1px; animation: blink 1.2s infinite; }
.listening .dots span:nth-child(2) { animation-delay: .2s; }
.listening .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty b { color: var(--text); display: block; font-size: 17px; margin-bottom: 4px; }

/* Summary */
.summary { font-size: 15.5px; }
.summary h2 { font-size: 17px; margin: 22px 0 8px; }
.summary h2:first-child { margin-top: 12px; }
.summary ul { margin: 0; padding-left: 22px; }
.summary li { margin: 4px 0; }
.summary li.task { list-style: none; margin-left: -22px; display: flex; gap: 8px; }
.summary li.task input { margin-top: 5px; accent-color: var(--accent); }
.summary textarea { width: 100%; min-height: 380px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-2); font: 14px/1.6 var(--mono); margin-top: 12px; }
.summary-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.summary .note { font-size: 13px; color: var(--muted); margin-top: 16px; }
.streaming::after { content: "▍"; color: var(--accent); animation: blink 1s infinite; }

/* Dialog */
.dialog { border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(10, 15, 14, .45); }
.dialog form { padding: 22px 24px; max-height: calc(100vh - 48px); overflow: auto; }
.dialog h2 { margin: 0 0 12px; font-size: 20px; }
fieldset { border: 0; border-top: 1px solid var(--border); margin: 0; padding: 14px 0 6px; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 0 8px 0 0; }
fieldset > label:not(.check) { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 14px; }
fieldset select, fieldset input[type=number], fieldset input[type=url] {
  height: 38px; border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; background: var(--surface-2); font-weight: 400;
}
fieldset input[type=range] { accent-color: var(--accent); }
.range-labels { display: flex; justify-content: space-between; font-weight: 400; }
.storage-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* Mobile */
@media (max-width: 820px) {
  .mobile-only { display: grid; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; width: 280px; height: auto; z-index: 40;
    transform: translateX(-100%); transition: transform .2s;
  }
  body.side-open .sidebar { transform: none; }
  body.side-open .scrim { display: block; position: fixed; inset: 56px 0 0; background: rgba(0,0,0,.35); z-index: 35; }
  .main { padding: 16px; }
  .recorder { grid-template-columns: auto 1fr; }
  .rec-side { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .panel { padding: 4px 16px 16px; }
  .title { font-size: 22px; }
  .status { max-width: 45vw; }
}
@media print {
  .top, .sidebar, .recorder, .toolbar, .player, .jobbar { display: none !important; }
  .layout { display: block; }
  .panel { border: 0; padding: 0; }
  .summary[hidden], .transcript[hidden] { display: block !important; }
}

/* Pop-out mini recorder (always on top) */
body.pip { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; height: 100vh; overflow: hidden; }
.pip-row { display: flex; align-items: center; gap: 12px; }
.pip .rec { width: 52px; height: 52px; border-width: 2px; flex: none; }
.pip .rec-core { width: 24px; height: 24px; }
.pip .rec.recording .rec-core { width: 17px; height: 17px; border-radius: 4px; }
.pip-info { flex: 1; min-width: 0; }
.pip .timer { font-family: var(--mono); font-weight: 600; font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pip .meter { height: 20px; margin: 4px 0 0; max-width: none; }
.pip-state { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pip-state.live { color: var(--rec); font-weight: 600; }
.pip-lines {
  flex: 1; overflow: auto; font-size: 13.5px; line-height: 1.5; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
}
.pip-lines p { margin: 0 0 6px; }
.pip-lines b { color: var(--sc, var(--text)); font-size: 12px; margin-right: 4px; }
.pip-lines .muted { font-style: italic; }
