:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --bar: #2a78d6;
  --bar-hover: #5598e7;
  --good: #006300;
  --good-wash: rgba(12, 163, 12, 0.12);
  --warning: #9a6700;
  --warning-mark: #fab219;
  --critical: #d03b3b;
  --shadow: 0 8px 30px rgba(11, 11, 11, 0.12);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --bar: #3987e5;
    --bar-hover: #6da7ec;
    --good: #0ca30c;
    --good-wash: rgba(12, 163, 12, 0.16);
    --warning: #fab219;
    --warning-mark: #fab219;
    --critical: #e66767;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); }
body { font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* top bar */
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; height: 56px; }
.brand { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.spacer { flex: 1; }
.sync-status { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.sync-status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: 1px; }
.sync-status.running .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.sync-status.error .dot { background: var(--critical); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* Google Drive connection */
.drive-chip { max-width: 240px; }
.drive-chip span:last-child { overflow: hidden; text-overflow: ellipsis; }
.drive-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.drive-chip.off { color: var(--warning); }
.drive-chip.off .dot { background: var(--warning-mark); }
.google-body { padding: 4px 18px 8px; display: grid; gap: 10px; font-size: 13.5px; }
.google-body ol { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.google-body code { font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; overflow-wrap: anywhere; }
.google-body .copy-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.google-body .account { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.google-body .account strong { display: block; }
.google-body details summary { cursor: pointer; color: var(--ink-2); }
.modal a.btn { text-decoration: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn { width: 30px; height: 30px; display: inline-grid; place-items: center; border-radius: 8px; border: 0; background: transparent; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.on { color: var(--accent); }
svg.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main.wrap { padding-top: 20px; padding-bottom: 120px; }
.filters { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
select, input[type="search"], input[type="text"] { height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); padding: 0 10px; }
select:focus, input:focus, .btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; transition: opacity 0.2s; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile .value small { font-size: 15px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.card-head .count { color: var(--muted); font-size: 13px; }

/* speaker bars */
.bars { padding: 4px 16px 14px; position: relative; }
.bar-row { display: grid; grid-template-columns: 130px minmax(0, 1fr); align-items: center; gap: 12px; height: 32px; border-radius: 6px; }
.bar-row:hover .bar, .bar-row:focus .bar { background: var(--bar-hover); }
.bar-row:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; border-left: 1px solid var(--axis); height: 100%; }
.bar { height: 16px; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; transition: width 0.3s ease; }
.bar-value { font-size: 13px; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-value span { color: var(--muted); margin-left: 6px; }
.empty { color: var(--muted); padding: 18px 16px 22px; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; min-width: 150px; }
.tooltip strong { display: block; font-size: 14px; }
.tooltip .muted { color: var(--ink-2); }

/* attention */
.attention { border-color: color-mix(in srgb, var(--warning-mark) 55%, var(--border)); }
.attention summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; align-items: center; gap: 8px; font-weight: 500; }
.attention summary::-webkit-details-marker { display: none; }
.attention summary .warn-icon { color: var(--warning-mark); }
.attention summary .chev { margin-left: auto; color: var(--muted); transition: transform 0.15s; }
.attention[open] summary .chev { transform: rotate(180deg); }
.attention ul { list-style: none; margin: 0; padding: 0 16px 12px; max-height: 320px; overflow: auto; }
.attention li { padding: 8px 0; border-top: 1px solid var(--grid); display: grid; gap: 2px; }
.attention li .where { font-size: 12.5px; color: var(--ink-2); word-break: break-all; }

/* source folders */
.head-action { margin-left: auto; }
.source-list { list-style: none; margin: 0; padding: 0 16px 8px; }
.source-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--grid); min-width: 0; }
.source-list li:first-child { border-top: 0; }
.source-list .f-icon { color: var(--muted); display: inline-flex; flex: none; }
.source-list .meta { white-space: nowrap; margin-top: 0; }
.link-btn { border: 0; background: none; padding: 0; color: var(--ink); font-weight: 500; cursor: pointer; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.link-btn:hover { color: var(--accent); text-decoration: underline; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.merged-count { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge { font-size: 11.5px; color: var(--ink-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.empty-row { color: var(--muted); padding: 4px 0 10px; }

/* folder preview */
.modal.wide { width: 640px; max-width: 100%; }
.preview-body { overflow: auto; padding: 2px 18px 10px; border-top: 1px solid var(--grid); border-bottom: 1px solid var(--grid); min-height: 120px; max-height: 55vh; }
.pair-list, .issue-list { list-style: none; margin: 0; padding: 0; }
.pair-list li, .issue-list li { padding: 8px 0; border-top: 1px solid var(--grid); }
.pair-list li:first-child, .issue-list li:first-child { border-top: 0; }
.pair-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tracks { display: grid; gap: 2px; margin: 4px 0 2px; }
.track { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: baseline; font-size: 12.5px; }
.track .side { color: var(--muted); font-weight: 600; }
.track .file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track .meta { margin: 0; white-space: nowrap; }
.pair-list .note { color: var(--warning); font-size: 12.5px; margin-top: 2px; }
.preview-body h4 { margin: 14px 0 2px; font-size: 13px; font-weight: 600; color: var(--ink-2); }

/* table */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--surface-2); }
.segmented button { border: 0; background: transparent; height: 26px; padding: 0 10px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.segmented button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.card-head input[type="search"] { margin-left: auto; width: 220px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-top: 1px solid var(--grid); vertical-align: middle; }
th { font-weight: 500; color: var(--muted); font-size: 12.5px; border-top: 0; white-space: nowrap; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--ink); }
th .arrow { font-size: 10px; margin-left: 3px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child { width: 36px; padding-left: 16px; }
td:last-child, th:last-child { padding-right: 16px; }
tr.selected td { background: var(--accent-wash); }
tbody tr:hover td { background: var(--surface-2); }
tbody tr.selected:hover td { background: var(--accent-wash); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; vertical-align: middle; }
.name { font-weight: 500; word-break: break-all; }
.meta { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.meta .warn { color: var(--warning); cursor: help; margin-left: 6px; }
.drive-badge { color: var(--muted); display: inline-flex; cursor: help; }
.pill { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; font-size: 12.5px; cursor: pointer; color: var(--ink-2); white-space: nowrap; }
.pill:hover { border-color: var(--axis); color: var(--ink); }
.pill.paid { background: var(--good-wash); border-color: transparent; color: var(--good); font-weight: 500; }
.more { text-align: center; padding: 12px; border-top: 1px solid var(--grid); }

/* player */
.player { display: flex; align-items: center; gap: 10px; padding: 8px 16px 12px; flex-wrap: wrap; }
.player .now { font-size: 13px; font-weight: 500; min-width: 0; flex: 1 1 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player audio { height: 32px; flex: 1 1 300px; min-width: 200px; }

/* selection bar */
.selbar { position: fixed; left: 16px; right: 16px; bottom: 20px; margin: 0 auto; width: max-content; max-width: calc(100vw - 32px); z-index: 20;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); border-radius: 12px; padding: 8px 8px 8px 16px; }
.selbar .what { font-weight: 500; margin-right: 6px; white-space: nowrap; }

/* toast */
.toast { position: fixed; right: 16px; bottom: 20px; z-index: 30; width: 330px; max-width: calc(100vw - 32px); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 12px; padding: 12px 14px; font-size: 13px; }
.toast .title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.toast .title .close { margin-left: auto; }
.toast .line { color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast .err { color: var(--critical); margin-top: 4px; font-size: 12.5px; max-height: 90px; overflow: auto; }
.progress { height: 4px; border-radius: 2px; background: var(--grid); margin-top: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.3s; }
.toast.with-selbar { bottom: 84px; }

/* modal */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 40; display: grid; place-items: center; padding: 16px;
  grid-template-columns: minmax(0, 1fr); }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); width: 520px; max-width: 100%; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal header { padding: 16px 18px 6px; }
.modal header h3 { margin: 0; font-size: 16px; }
.modal header p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 8px 18px; font-size: 13px; color: var(--ink-2); }
.crumbs button { border: 0; background: transparent; padding: 2px 4px; border-radius: 4px; cursor: pointer; color: var(--accent); }
.crumbs button:hover { background: var(--accent-wash); }
.crumbs .current { color: var(--ink); font-weight: 500; padding: 2px 4px; }
.folder-list { list-style: none; margin: 0; padding: 4px 10px; overflow: auto; min-height: 96px; max-height: 340px; flex: 1 1 auto; border-top: 1px solid var(--grid); border-bottom: 1px solid var(--grid); }
.folder-list li button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; text-align: left; }
.folder-list li button:hover { background: var(--surface-2); }
.folder-list .f-icon { color: var(--muted); flex: none; }
.folder-list .state { color: var(--muted); padding: 16px 8px; }
.paste { display: flex; gap: 8px; padding: 10px 18px 0; }
.paste input { flex: 1; min-width: 0; }
.upload-options { padding: 10px 18px 0; display: grid; gap: 8px; flex: none; }
.modal > header, .modal > .paste, .modal > .crumbs, .modal > footer, .modal > .error { flex: none; }
.modal { overflow: auto; }
.opt-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.opt-row > label { width: 92px; flex: none; color: var(--ink-2); font-size: 13px; }
.opt-row select, .opt-row input[type="text"] { flex: 1; min-width: 0; }
.opt-row label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.opt-row input:disabled { opacity: 0.5; }
.name-example, .name-help { margin: 0 0 0 102px; font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.name-help { color: var(--muted); }
.name-example.bad { color: var(--critical); }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; align-items: center; }
.modal footer .dest { margin-right: auto; color: var(--ink-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal .error { color: var(--critical); font-size: 13px; padding: 6px 18px 0; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 340px; max-width: 100%; display: grid; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 18px; }
.login input { height: 38px; width: 100%; }
.login .btn { height: 38px; justify-content: center; }
.login .error { color: var(--critical); font-size: 13px; margin: 0; }

@media (max-width: 860px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .col-size, .col-drive { display: none; }
}
@media (max-width: 560px) {
  .sync-status { display: none; }
  .drive-chip:not(.off) { max-width: 44px; }
  .drive-chip:not(.off) span:last-child { display: none; }
  .topbar .btn { padding: 0 9px; }
  .bar-row { grid-template-columns: 90px minmax(0, 1fr); }
  .card-head input[type="search"] { width: 100%; margin-left: 0; order: 3; }
  .source-list .meta, .source-list .btn.small .label { display: none; }
  .opt-row > label { width: auto; }
  .name-example, .name-help { margin-left: 0; }
  .folder-list { min-height: 120px; max-height: 30vh; }
  .merged-count { font-size: 12px; }
  .track { grid-template-columns: 18px minmax(0, 1fr); }
  .track .meta { grid-column: 2; white-space: normal; }
  .tile .value { font-size: 22px; }
  /* Rows become two-line cards: name on top, duration + status below. */
  thead { display: none; }
  table, tbody { display: block; }
  tbody tr { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto 38px;
    grid-template-areas: "chk name name play" "chk dur status play"; border-top: 1px solid var(--grid); padding: 6px 0; }
  tbody tr.selected, tbody tr.selected:hover { background: var(--accent-wash); }
  tbody td { border-top: 0; padding: 3px 8px; background: transparent !important; }
  tbody td:nth-child(1) { grid-area: chk; padding-left: 16px; align-self: center; }
  tbody td:nth-child(2) { grid-area: name; }
  tbody td:nth-child(3) { grid-area: dur; text-align: left; align-self: center; color: var(--ink-2); }
  tbody td:nth-child(5) { grid-area: status; }
  tbody td:nth-child(7) { grid-area: play; align-self: center; padding: 0 8px 0 0; }
  .name { word-break: normal; overflow-wrap: anywhere; }
}
