:root {
  --brand: #cc2620;
  --brand-dark: #a81d18;
  --brand-tint: rgba(204, 38, 32, .10);
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e3e7ed;
  --text: #1a1f28;
  --muted: #6b7686;
  --ok: #1f9d55;
  --warn: #c77700;
  --err: #cc2620;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --panel: #171c24;
    --panel-2: #1e242e;
    --line: #2a323e;
    --text: #e7ecf3;
    --muted: #93a0b3;
    --ok: #35c98a;
    --warn: #f0b13d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------- logo */
.logo-img { height: 30px; width: auto; display: block; }
@media (prefers-color-scheme: dark) {
  /* The wordmark is black artwork; give it a light plate so it stays legible. */
  .logo-plate { background: #fff; padding: 5px 10px; border-radius: 7px; }
}

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 30px 28px;
}
.login-card .logo-plate { display: inline-block; margin-bottom: 20px; }
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ------------------------------------------------------------------ shell */
.shell { display: flex; flex-direction: column; min-height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.topbar .spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.nav { display: flex; gap: 2px; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 51px; z-index: 39; overflow-x: auto; }
.nav button {
  background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted);
  font: inherit; font-weight: 550; padding: 11px 14px; cursor: pointer; white-space: nowrap;
}
.nav button:hover { color: var(--text); }
.nav button.active { color: var(--brand); border-bottom-color: var(--brand); }

main { flex: 1; padding: 20px; max-width: 1560px; width: 100%; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { font-size: 18px; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

/* ----------------------------------------------------------------- panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.panel-pad { padding: 16px; }
.panel h3 { font-size: 14px; margin-bottom: 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 14px; padding: 14px 16px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; flex: 1 1 190px; min-width: 0; }
.field.grow-0 { flex: 0 0 auto; }
.field > label, .field > span { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 650; }
.field small { color: var(--muted); font-size: 11.5px; }
label.field { cursor: default; }

input[type=text], input[type=email], input[type=search], input[type=password], input[type=number],
input[type=datetime-local], select, textarea {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font: inherit; width: 100%; min-width: 0;
}
@media (prefers-color-scheme: dark) { input, select, textarea { background: var(--panel-2); } }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-tint); border-color: var(--brand); }
input::placeholder { color: var(--muted); }

.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; margin: 5px 0; }
.checkline input { accent-color: var(--brand); width: 15px; height: 15px; }

.preset-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 12.5px; cursor: pointer; }
.chip:hover { color: var(--text); border-color: var(--brand); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
/* A faded red reads as broken; a disabled primary should just look inert. */
.btn.primary:disabled { background: var(--panel-2); border-color: var(--line); color: var(--muted); opacity: 1; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.danger { color: var(--err); border-color: rgba(204, 38, 32, .35); }
.btn.danger:hover:not(:disabled) { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ----------------------------------------------------------------- badges */
.badge { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge-ok { color: var(--ok); border-color: rgba(31, 157, 85, .4); background: rgba(31, 157, 85, .1); }
.badge-err { color: var(--err); border-color: rgba(204, 38, 32, .4); background: var(--brand-tint); }
.pill { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 11px; text-align: center; }
.muted { color: var(--muted); }

.notice { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13px; border: 1px solid rgba(199, 119, 0, .4); background: rgba(199, 119, 0, .09); }
.notice.error { border-color: rgba(204, 38, 32, .4); background: var(--brand-tint); }

/* ------------------------------------------------------------------ stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 650; }
.stat .value { font-size: 23px; font-weight: 680; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat.accent .value { color: var(--brand); }

.meter { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 10px; }
.meter > i { display: block; height: 100%; background: var(--brand); }
.meter > i.ok { background: var(--ok); }
.meter > i.warn { background: var(--warn); }

.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 84px 1fr 130px; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-row .track { height: 16px; background: var(--panel-2); border-radius: 4px; overflow: hidden; display: flex; }
.bar-row .track i { display: block; height: 100%; }
.bar-row .track i.archived { background: var(--ok); }
.bar-row .track i.pending { background: var(--brand); opacity: .75; }
.bar-row .num { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; padding: 10px 12px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .45px; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable.asc::after { content: ' ▲'; }
th.sortable.desc::after { content: ' ▼'; }
.col-check { width: 38px; }
.col-actions { width: 78px; }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.selected { background: var(--brand-tint); }
td.file { font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.who { display: flex; flex-direction: column; line-height: 1.3; }
.who .name { font-weight: 550; }
.who .number { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tag { font-size: 10.5px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); margin-left: 5px; }
.tag.answered { color: var(--ok); border-color: rgba(31, 157, 85, .4); }
.tag.noanswer { color: var(--warn); border-color: rgba(199, 119, 0, .4); }
.tag.archived { color: var(--ok); border-color: rgba(31, 157, 85, .4); background: rgba(31, 157, 85, .09); }

.empty { padding: 48px 20px; text-align: center; }
.empty .big { font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.spinner { width: 24px; height: 24px; margin: 0 auto 12px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; padding: 11px 16px; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.divider { width: 1px; height: 22px; background: var(--line); }

/* ----------------------------------------------------------------- player */
.player {
  position: fixed; left: 20px; right: 20px; bottom: 16px; z-index: 45; display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  box-shadow: var(--shadow); max-width: 1520px; margin: 0 auto;
}
.player-name { font-size: 12px; font-family: ui-monospace, Menlo, monospace; color: var(--muted); flex: 0 1 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player audio { flex: 1; height: 34px; }

/* ----------------------------------------------------------------- modals */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(10, 14, 20, .5); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 540px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { max-width: 780px; }
.modal > header, .modal > footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; }
.modal > header { border-bottom: 1px solid var(--line); }
.modal > header h2 { font-size: 15px; }
.modal > footer { border-top: 1px solid var(--line); justify-content: flex-end; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

.secret-box { background: var(--panel-2); border: 1px dashed var(--brand); border-radius: 8px; padding: 12px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; }

/* ----------------------------------------------------------------- drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 94vw); z-index: 70; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.drawer > header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 14px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.job { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--panel-2); }
.job h4 { margin: 0 0 4px; font-size: 13px; }
.job .meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 9px 0 7px; }
.bar > i { display: block; height: 100%; background: var(--brand); transition: width .25s ease; }
.job.done .bar > i { background: var(--ok); }
.job.failed .bar > i, .job.cancelled .bar > i { background: var(--err); }
.job .log { max-height: 150px; overflow-y: auto; font-size: 11.5px; font-family: ui-monospace, Menlo, monospace; color: var(--muted); margin-top: 8px; display: flex; flex-direction: column; gap: 2px; }
.job .log .error { color: var(--err); }
.job .log .skip { color: var(--warn); }

/* ----------------------------------------------------------------- toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--brand); border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 380px; font-size: 13px; }
.toast.error { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }

/* ------------------------------------------------------------------ cards */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--panel); }
.card header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.card header h4 { font-size: 14px; }
.card .desc { font-size: 12.5px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; word-break: break-all; }

@media (max-width: 760px) {
  .bar-row { grid-template-columns: 66px 1fr; }
  .bar-row .num { grid-column: 2; text-align: left; }
  .nav { top: 51px; }
}
