:root {
  --bg: #f5f6f8; --surface: #ffffff; --fg: #1f2328; --muted: #5f6670; --line: #e3e6ea; --hover: #f0f2f5;
  --brand: #185abd; --brand-soft: #e8f0fb; --red: #c4314b; --red-soft: #fbe9ec; --green: #107c41; --green-soft: #e6f4ea;
  --amber: #a35a00; --amber-soft: #fff3e0; --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --surface: #1e2125; --fg: #e6e8eb; --muted: #9aa1aa; --line: #2e3238; --hover: #262a2f;
    --brand: #6ea4f0; --brand-soft: #1d2b40; --red: #f08a9b; --red-soft: #3a2026; --green: #6cc795; --green-soft: #1b3226;
    --amber: #f0b45e; --amber-soft: #3a2c18; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif; font-size: 14px; line-height: 1.5; color: var(--fg); background: var(--bg); direction: rtl; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: Consolas, monospace; font-size: 12px; }

/* ---------- top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar .inner { max-width: 1160px; margin: 0 auto; padding: 0 16px; height: 56px; display: flex; align-items: center; gap: 20px; }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 400; }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav a { padding: 6px 12px; border-radius: 8px; color: var(--fg); white-space: nowrap; }
nav a:hover { background: var(--hover); text-decoration: none; }
nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.whoami { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; white-space: nowrap; }

main { max-width: 1160px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }
.page-head select { width: auto; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card, .grid + .card, .card + .grid { margin-top: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.stats > .card + .card { margin-top: 0; }   /* cards side by side: the gap is the grid's */
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 7px 14px;
       border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: var(--red-soft); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.link { border: none; background: none; color: var(--brand); padding: 2px 6px; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn.link.danger { color: var(--red); }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--surface); width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=text] { max-width: 260px; }
.toolbar select { width: auto; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
tr.off td { color: var(--muted); }
td.nowrap, th.nowrap { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* ---------- pills, bars ---------- */
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; background: var(--hover); color: var(--muted); white-space: nowrap; }
.pill.active { background: var(--green-soft); color: var(--green); }
.pill.pending { background: var(--amber-soft); color: var(--amber); }
.pill.disabled, .pill.no-device, .pill.limit { background: var(--red-soft); color: var(--red); }
.pill.near { background: var(--amber-soft); color: var(--amber); }
.pill.admin { background: var(--brand-soft); color: var(--brand); }
.pill.viewer { background: var(--hover); color: var(--fg); }
.pill.transcriber { background: var(--amber-soft); color: var(--amber); }
.meter { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.meter .track { flex: 1; height: 6px; background: var(--hover); border-radius: 3px; overflow: hidden; min-width: 60px; }
.meter .fill { height: 100%; background: var(--green); border-radius: 3px; }
.meter .fill.near { background: var(--amber); }
.meter .fill.full { background: var(--red); }

/* the monthly history: plain bars, no chart library */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 18px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bars .col { width: 100%; max-width: 34px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .col.zero { background: var(--line); }
.bars .val { font-size: 11px; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }
.bars .lbl { font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; }

/* ---------- login ---------- */
.login { max-width: 400px; margin: 10vh auto 0; }
.login .card { padding: 28px; }
.login h1 { margin-bottom: 4px; }
.login p { margin: 0 0 18px; color: var(--muted); }
.login .code-input { font-size: 24px; letter-spacing: 8px; text-align: center; direction: ltr; font-family: Consolas, monospace; }
.login .btn { width: 100%; justify-content: center; margin-top: 4px; }
.login .remember { margin: 2px 0 14px; font-size: 14px; color: var(--muted); flex-wrap: nowrap; align-items: flex-start; }
.login .remember input { width: auto; margin-top: 3px; flex: none; }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(480px, calc(100vw - 32px)); background: var(--surface); color: var(--fg); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin-bottom: 14px; }
.dlg-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.code-box { font-family: Consolas, monospace; font-size: 30px; letter-spacing: 4px; text-align: center; direction: ltr; background: var(--brand-soft);
            color: var(--brand); border-radius: 10px; padding: 14px; margin: 10px 0; user-select: all; }
textarea.msg { min-height: 120px; resize: vertical; }
.error-box { background: var(--red-soft); color: var(--red); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.warn-box { background: var(--amber-soft); color: var(--amber); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }

/* ---------- user card ---------- */
.back { display: inline-block; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.danger-zone { border-color: var(--red-soft); }
.diff { font-size: 12px; color: var(--muted); }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #2b2f35; color: #fff; padding: 9px 18px; border-radius: 8px;
         box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 100; max-width: calc(100vw - 32px); }
#toast.err { background: var(--red); }

@media (max-width: 640px) {
  .topbar .inner { gap: 10px; height: auto; padding-top: 8px; padding-bottom: 8px; flex-wrap: wrap; }
  nav { order: 3; width: 100%; }
  .whoami { font-size: 12px; }
  main { padding-top: 16px; }
  .hide-sm { display: none; }
}

/* the agent screen's last questions: the steps of a search (task #303) */
ol.steps { margin: 6px 0 0; padding-inline-start: 22px; }
tr.steps-row td { border-top: 0; padding-top: 0; }
ol.steps li { margin: 2px 0; overflow-wrap: anywhere; }
ol.steps li.off { color: var(--red); }

/* the tab of the books in search by meaning: the page the server rebuilds, in a frame */
.vb-frame { display: block; width: 100%; height: calc(100vh - 190px); min-height: 420px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
