:root {
  --bg: #0d0f14;
  --panel: #151821;
  --panel-2: #1c2030;
  --line: #262b3b;
  --text: #eef0f6;
  --muted: #8b92a8;
  --accent: #ff5a36;
  --accent-2: #ff8a3d;
  --ok: #34d399;
  --err: #f87171;
  --radius: 14px;
  --sidebar: 248px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6fa; --panel: #ffffff; --panel-2: #f0f2f7; --line: #e2e5ee;
    --text: #12141c; --muted: #5d6478; color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select { font: inherit; color: inherit; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100%; }
.sidebar {
  width: var(--sidebar); flex: none; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 22px 36px 0;
}
.topbar h1 { font: 700 26px/1.2 "Space Grotesk", Inter, sans-serif; margin: 0; letter-spacing: -.01em; }
.view { padding: 24px 36px 48px; max-width: 1100px; width: 100%; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.brand-mark svg { fill: #fff; stroke: none; width: 18px; height: 18px; }
.brand-name { font: 700 18px "Space Grotesk", Inter, sans-serif; letter-spacing: -.01em; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
             color: var(--muted); padding: 18px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--muted); font-weight: 500; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); }
.nav-item.active svg { color: var(--accent); }
.nav-item .tag { margin-left: auto; }

.menu-btn { display: none; background: none; border: 0; padding: 6px; cursor: pointer; }
.scrim { display: none; }

/* ---------- components ---------- */
.tag {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.tag.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent);
            background: color-mix(in srgb, var(--ok) 10%, transparent); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px;
}
.lead { color: var(--muted); margin: 0 0 24px; max-width: 60ch; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.tool-card {
  display: flex; flex-direction: column; gap: 10px; padding: 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  transition: transform .15s, border-color .15s;
}
a.tool-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.tool-card.soon { opacity: .6; cursor: default; }
.tool-card .icon {
  width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
.tool-card h3 { margin: 4px 0 0; font-size: 17px; }
.tool-card p { margin: 0; color: var(--muted); font-size: 14px; }
.tool-card .row { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 6px; }
.tool-card .go { font-size: 13px; font-weight: 600; color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 10px; border: 0; cursor: pointer; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  transition: filter .15s, opacity .15s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }

.input-row { display: flex; gap: 10px; }
.input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); outline: none;
}
.input:focus, .select:focus { border-color: var(--accent); }
.select { padding: 10px 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); outline: none; }

.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 16px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-top: 14px;
         background: color-mix(in srgb, var(--err) 12%, transparent); color: var(--err);
         border: 1px solid color-mix(in srgb, var(--err) 30%, transparent); }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent;
           border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.progress > div { height: 100%; width: 0; border-radius: inherit; transition: width .3s;
                  background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.progress.indeterminate > div { width: 35% !important; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.foot { font-size: 12px; color: var(--muted); padding: 0 36px 28px; margin-top: auto; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 500; }

/* ---------- boot / signed-out states ---------- */
body.booting .shell, body.booting .login { visibility: hidden; }
.login { display: none; }
body.signed-out .shell { display: none; }
body.signed-out .login {
  display: grid; place-items: center; min-height: 100%; padding: 24px 16px;
  background: radial-gradient(60% 50% at 50% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 30px 28px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-brand { padding: 0 0 6px; }
.login-card h1 { font: 700 24px "Space Grotesk", Inter, sans-serif; margin: 0 0 4px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field .input { color: var(--text); font-weight: 400; font-size: 15px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.notice { padding: 12px 14px; border-radius: 10px; font-size: 14px; color: var(--ok);
          background: color-mix(in srgb, var(--ok) 10%, transparent);
          border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); }
.alert { margin-top: 0; }
form .alert { margin-top: 2px; }
.card form, form.card { display: flex; flex-direction: column; gap: 14px; }
.card.narrow { max-width: 460px; }
.card-title { margin: 0; font-size: 17px; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn.sm svg { width: 16px; height: 16px; }
.btn.danger { background: color-mix(in srgb, var(--err) 14%, transparent); color: var(--err);
              border: 1px solid color-mix(in srgb, var(--err) 30%, transparent); }
.icon-btn { background: none; border: 0; padding: 7px; border-radius: 8px; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.textarea { resize: vertical; min-height: 84px; line-height: 1.5; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; width: 100%; }

/* ---------- user box ---------- */
.user-box { display: flex; align-items: center; gap: 4px; border-top: 1px solid var(--line); padding-top: 12px; }
.user-chip { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 9px; }
.user-chip:hover, .user-chip.active { background: var(--panel-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center;
          font-weight: 700; font-size: 14px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.who { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.who b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: var(--muted); font-size: 12px; }

/* ---------- users admin ---------- */
.users-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.users-layout > .card:first-child { display: flex; flex-direction: column; gap: 12px; }
.table { display: flex; flex-direction: column; }
.tr { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tr:first-child { border-top: 0; }
.tr .grow { flex: 1; min-width: 120px; display: flex; align-items: center; gap: 8px; }

/* ---------- youtube tool ---------- */
.yt-stack { display: flex; flex-direction: column; gap: 22px; }
.yt-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.yt-bar .btn { margin-left: auto; }
.count { font-size: 13px; color: var(--muted); }
.count.over { color: var(--err); font-weight: 600; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 17px; }
.section-head .muted { font-size: 14px; margin-left: 6px; }
.section-head .actions { display: flex; gap: 8px; }
.dl-list { display: flex; flex-direction: column; gap: 8px; }
.dl-item { display: grid; grid-template-columns: 112px 1fr auto; gap: 14px; align-items: center;
           background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 10px 10px; }
.dl-thumb { aspect-ratio: 16/9; border-radius: 7px; overflow: hidden; background: var(--panel-2); }
.dl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dl-thumb.empty img { visibility: hidden; }
.dl-body { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.dl-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-status { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.dl-item.is-error .dl-status { color: var(--err); }
.dl-item.is-done .msg::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.dl-actions { display: flex; align-items: center; gap: 4px; }
.dl-item .progress { height: 6px; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
  .menu-btn { display: block; }
  .topbar { padding: 16px 16px 0; }
  .topbar h1 { font-size: 21px; }
  .view { padding: 18px 16px 32px; }
  .foot { padding: 0 16px 24px; }
  .input-row { flex-direction: column; }
  .users-layout { grid-template-columns: 1fr; }
  .yt-bar .btn { margin-left: 0; width: 100%; }
  .dl-item { grid-template-columns: 72px 1fr; }
  .dl-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .dl-actions:empty { display: none; }
}

/* ---------- youtube: auto-download states ---------- */
.dl-status .msg { min-width: 0; }
.dl-status .warn { color: #d97706; }
.dl-status .again { color: var(--accent); font-weight: 600; white-space: nowrap; }
.dl-status .again:hover { text-decoration: underline; }
.dl-item.is-queued { opacity: .75; }
.progress.waiting > div { width: 0 !important; }
.yt-bar .check { color: var(--muted); font-weight: 500; white-space: nowrap; }

/* ---------- logo ---------- */
.brand { padding: 2px 8px 20px; }
.logo-img { display: block; height: auto; width: 172px; max-width: 100%; }
.login-brand { justify-content: center; padding: 0 0 8px; }
.login-brand .logo-img { width: 210px; }

/* ---------- admin: server status ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 8px; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-value { font: 700 24px "Space Grotesk", Inter, sans-serif; }
.stat-sub { font-size: 12.5px; color: var(--muted); }
.meter { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.meter > div { height: 100%; border-radius: inherit; transition: width .4s; background: var(--ok); }
.meter.warn > div { background: #f59e0b; }
.meter.bad > div { background: var(--err); }
.bad-text { color: var(--err); }
.status-layout { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 14px; }
.status-layout > .card { display: flex; flex-direction: column; gap: 10px; }
.status-list { display: flex; flex-direction: column; }
.status-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.status-row:first-child { border-top: 0; }
.status-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.status-row .grow b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-row .grow small { color: var(--muted); font-size: 12.5px; }
@media (max-width: 860px) {
  .stat-grid, .status-layout { grid-template-columns: 1fr; }
}

/* ---------- transcripts library ---------- */
.view:has(.lib), .view:has(.tx) { max-width: 1280px; }
.lib { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.lib-side { padding: 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 16px; }
.lib-side-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
                  padding: 12px 10px 6px; display: flex; align-items: center; justify-content: space-between; }
.lib-side-label:first-child { padding-top: 4px; }
.lib-nav { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; border: 0;
           background: none; color: var(--text); font-weight: 500; text-align: left; cursor: pointer; }
.lib-nav:hover { background: var(--panel-2); }
.lib-nav.active { background: var(--panel-2); font-weight: 600; }
.lib-nav.active svg { color: var(--accent); }
.lib-nav .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-nav .n { margin-left: auto; font-size: 12px; color: var(--muted); }
.icon-btn.sm { padding: 3px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.hint.pad { padding: 4px 10px; }

.lib-main { padding: 0; overflow: hidden; }
.lib-head { display: flex; align-items: center; gap: 14px; padding: 18px 20px; flex-wrap: wrap; }
.lib-head h2 { margin: 0; font: 700 22px "Space Grotesk", Inter, sans-serif; flex: 1; min-width: 160px; }
.lib-search { position: relative; width: min(320px, 100%); }
.lib-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 17px; height: 17px; }
.lib-search .input { padding-left: 36px; width: 100%; }
.lib-folder-actions { display: flex; gap: 6px; }
.bulk { display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: color-mix(in srgb, var(--accent) 8%, var(--panel));
        border-top: 1px solid var(--line); font-size: 14px; font-weight: 600; flex-wrap: wrap; }
.select.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.lib-main > .alert { margin: 0 20px 12px; }
.lib-table .tr { display: grid; grid-template-columns: 44px minmax(0,1fr) 170px 90px 110px 110px; align-items: center;
                 gap: 8px; padding: 0 16px; min-height: 56px; border-top: 1px solid var(--line); }
.lib-table .th { min-height: 42px; font-size: 13px; font-weight: 600; color: var(--muted); }
.lib-table .row-item:hover { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.lib-table .cb { display: grid; place-items: center; }
.lib-table .cb input { width: 17px; height: 17px; accent-color: var(--accent); }
.lib-table .c-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-table a.c-name:hover { color: var(--accent); }
.lib-table .c-name .tag { margin-left: 6px; font-weight: 500; }
.lib-table .c-date, .lib-table .c-dur, .lib-table .c-by { font-size: 14px; color: var(--muted); }
.lib-table .c-act { display: flex; justify-content: flex-end; gap: 4px; }
.lib-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: center; }
.lib-foot:empty { display: none; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); }

.menu { position: absolute; z-index: 50; min-width: 200px; background: var(--panel); border: 1px solid var(--line);
        border-radius: 10px; padding: 6px; box-shadow: 0 12px 32px rgba(0,0,0,.18); display: flex; flex-direction: column; }
.menu a, .menu button { text-align: left; padding: 8px 10px; border-radius: 7px; border: 0; background: none; font-size: 14px; cursor: pointer; color: var(--text); }
.menu a:hover, .menu button:hover { background: var(--panel-2); }
.menu-sub { padding: 6px 10px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.bad-text { color: var(--err) !important; }

/* one transcript */
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 500; margin-bottom: 14px; }
.back-link:hover { color: var(--text); }
.back-link svg { width: 18px; height: 18px; }
.tx { display: grid; grid-template-columns: minmax(0,1fr) 320px; gap: 16px; align-items: start; }
.tx-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13.5px; color: var(--muted); padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.tx-text { padding-top: 6px; -webkit-user-select: text; user-select: text; }
.tx-text p { margin: 14px 0; line-height: 1.7; font-size: 16px; display: grid; grid-template-columns: 64px 1fr; gap: 10px; }
.tx-text .ts { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 3px; }
.tx-side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 16px; }
.tx-side .seg { width: 100%; display: flex; }
.tx-side .seg button { flex: 1; }
.devices { margin-top: 16px; }
.devices .tr { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.devices .grow { flex: 1; display: flex; flex-direction: column; }
@media (max-width: 1100px) {
  .lib-table .tr { grid-template-columns: 40px minmax(0,1fr) 120px 80px 90px; }
  .lib-table .c-by { display: none; }
}
@media (max-width: 860px) {
  .lib, .tx { grid-template-columns: 1fr; }
  .lib-side, .tx-side { position: static; }
  .lib-table .tr { grid-template-columns: 36px minmax(0,1fr) 80px; }
  .lib-table .c-date, .lib-table .c-by { display: none; }
  .lib-table .c-act { grid-column: 3; }
  .lib-table .c-dur { display: none; }
}
