:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e4e7ec;
  --brand: #3b5bdb; --ok: #2f9e44; --low: #f08c00; --out: #e03131; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12151c; --card: #1b1f2a; --ink: #e8ebf2; --muted: #9aa3b5; --line: #2b3140; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; padding: 0 16px 48px; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h2 { font-size: 18px; }
.muted, small { color: var(--muted); }
small { font-size: 12px; }

.top { display: flex; justify-content: space-between; align-items: center; max-width: 960px; margin: 0 auto; padding: 14px 0; gap: 12px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; color: var(--ink); }
.top nav { display: flex; gap: 14px; flex-wrap: wrap; }
.top nav a { color: var(--muted); }
main, .timer { max-width: 960px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }

/* timer */
.timer { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; position: sticky; top: 8px; z-index: 5; box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.timer input { flex: 1 1 180px; }
.timer.running { border-color: var(--brand); }
.t-who { flex: 1 1 200px; display: flex; flex-direction: column; font-weight: 600; }
.t-clock { font: 600 26px/1 ui-monospace, Menlo, monospace; direction: ltr; }
.bal { font-weight: 600; color: var(--ok); }
.bal.out { color: var(--out); }

/* inputs + buttons */
input, select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-width: 0; }
input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 9px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.stop { background: var(--out); border-color: var(--out); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--out); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; margin-top: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; margin-top: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.head h2 { margin: 0; }
.search { max-width: 220px; }

/* client list */
.client { display: grid; grid-template-columns: minmax(140px, 1.4fr) 2fr auto 36px; gap: 12px; align-items: center; padding: 10px 6px; border-top: 1px solid var(--line); color: var(--ink); }
.client:hover { background: var(--bg); }
.client .name { font-weight: 600; }
.client .nums { white-space: nowrap; font-size: 14px; }
.client.out .nums b { color: var(--out); }
.client.low .nums b { color: var(--low); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.bar.low i { background: var(--low); }
.bar.out i { background: var(--out); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); vertical-align: middle; }
.badge.warn { color: var(--low); border-color: var(--low); }
.line { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* client page */
.warn-box { background: rgba(240,140,0,.1); color: var(--low); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-weight: 600; }
.bank-sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 10px; }
.bank-sum > div { display: flex; flex-direction: column; }
.bank-sum b { font-size: 22px; }
.bal-out { color: var(--out); } .bal-low { color: var(--low); } .bal-ok { color: var(--ok); }
.entries { width: 100%; border-collapse: collapse; }
.entries td { padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.entries td:first-child { white-space: nowrap; width: 1%; }
.entries td:nth-child(2) { white-space: nowrap; width: 1%; font-weight: 600; }
.entries .acts { text-align: left; white-space: nowrap; width: 1%; }
.entries tr.pending { background: rgba(240,140,0,.08); }
.entries tr.live { background: rgba(59,91,219,.08); }
details { border-top: 1px solid var(--line); padding: 8px 0; }
summary { cursor: pointer; }
.tiers { display: flex; flex-direction: column; gap: 6px; grid-column: 1 / -1; }
.tiers input { width: 90px; }
pre { background: var(--bg); padding: 10px; border-radius: 8px; direction: ltr; overflow-x: auto; user-select: all; }

/* dialogs + toast */
dialog { border: none; border-radius: var(--radius); padding: 0; width: min(480px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dlg { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.dlg p { margin: 0; }
dialog:has(.wide) { width: min(720px, calc(100vw - 32px)); }
.mail-preview { border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 50vh; overflow: auto; background: #fff; color: #222; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; z-index: 50; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--out); color: #fff; }

/* login + public pages */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-card.public { width: min(480px, 100%); }
.login-card .logo { height: 36px; align-self: flex-start; }
.facts { margin: 0; padding-inline-start: 18px; line-height: 1.9; }
.err { color: var(--out); }

@media (max-width: 640px) {
  .client { grid-template-columns: 1fr auto; }
  .client .bar { grid-column: 1 / -1; grid-row: 2; }
  .client .btn { display: none; }
  .bank-sum b { font-size: 18px; }
  .t-clock { font-size: 22px; }
  .entries .acts { display: block; width: auto; text-align: right; }
  .entries td:first-child, .entries td:nth-child(2) { white-space: normal; }
}

/* time values like -2:54 must render left-to-right inside RTL text */
.bank-sum b, .nums b, .bal, .entries td:nth-child(2), .t-clock { direction: ltr; unicode-bidi: isolate; text-align: right; }
