:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #17202a;
  --muted: #5f6c7b;
  --line: #dde3ea;
  --accent: #1f4e8c;
  --accent-ink: #ffffff;
  --accent-soft: #e5edf8;
  --danger: #c0392b;
  --danger-soft: #fbe9e7;
  --ok: #1d7f49;
  --radius: 10px;
  --font: Figtree, "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151b;
    --surface: #1a2028;
    --text: #e7ecf1;
    --muted: #97a3b0;
    --line: #2c3541;
    --accent: #6ea8ec;
    --accent-ink: #0b1622;
    --accent-soft: #1c2b3f;
    --danger: #ef7468;
    --danger-soft: #3a201d;
    --ok: #55c98a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0; }
p { margin: 0 0 8px; }
a { color: inherit; }
.muted { color: var(--muted); }
.hidden, [hidden] { display: none !important; }
.only-mobile { display: none; }

.ico { display: inline-flex; flex: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  text-decoration: none; color: var(--muted); font-weight: 600;
}
.nav a:hover { background: var(--bg); }
.nav a.on { color: var(--accent); background: var(--accent-soft); }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.run-badge {
  background: var(--danger); color: #fff; text-decoration: none;
  font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 99px; white-space: nowrap;
}
.pill { font-size: 12px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); padding: 3px 9px; border-radius: 99px; text-decoration: none; white-space: nowrap; }

main { max-width: 920px; margin: 0 auto; padding: 20px 16px 48px; }
main.view-detail { max-width: 1000px; }
.splash { padding: 80px 20px; text-align: center; color: var(--muted); }
.signin { max-width: 340px; margin: 12vh auto; padding: 32px 24px; text-align: center; display: grid; gap: 10px; justify-items: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.empty { padding: 28px 20px; text-align: center; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: 600 14px var(--font); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg); color: var(--accent); }
:is(.btn, .icon-btn, a, select, input, textarea, .entry, .chip, .swatch, .run-main):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=tel], input[type=email], input[type=number], input[type=date], input[type=datetime-local], textarea, select {
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: 15px var(--font);
}
textarea { resize: vertical; line-height: 1.4; }
input:disabled, select:disabled { opacity: .6; }
.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.span-2 { grid-column: 1 / -1; }
.notice { grid-column: 1 / -1; background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; margin: 0; }
.warn { color: var(--danger); font-size: 13px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.grey { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
h2 .badge { margin-left: 8px; vertical-align: middle; }
.badge.status-draft { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.status-paid { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }

/* ---------- timer ---------- */
.startbar { display: grid; grid-template-columns: 1fr 150px 170px auto; gap: 8px; padding: 12px; margin-bottom: 18px; }
.start-desc { font-size: 16px !important; }
.start-btn { min-height: 40px; padding: 0 18px; }

.running { margin-bottom: 18px; display: grid; gap: 8px; }
.running:empty { display: none; }
.running .section-title { margin: 0; color: var(--danger); }
.run-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 14px; border-left: 4px solid var(--muted); }
.run-main { flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left; background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; border-radius: 6px; }
.run-desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.run-time { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.log-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.summary { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); }
.summary strong { color: var(--text); font-variant-numeric: tabular-nums; }
.log { display: grid; gap: 12px; }
.day-head { display: flex; justify-content: space-between; padding: 9px 14px; font-weight: 700; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.day-total { font-variant-numeric: tabular-nums; color: var(--text); }
.entry { display: grid; grid-template-columns: 9px minmax(0, 1fr) auto 76px 38px; align-items: center; gap: 12px; padding: 7px 6px 7px 14px; cursor: pointer; }
.entry + .entry { border-top: 1px solid var(--line); }
.entry:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.entry-desc { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; font-size: 13px; color: var(--muted); }
.entry-range { font-size: 13px; color: var(--muted); white-space: nowrap; }
.entry-dur { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.more-btn { justify-self: center; }

/* ---------- clients ---------- */
.client { padding: 14px 16px; display: grid; gap: 12px; }
.client.archived { opacity: .65; }
.client-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.unbilled { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 8px 12px; background: var(--bg); border-radius: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 11px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--text); font: 500 14px var(--font); cursor: pointer; }
.chip:hover { border-color: var(--muted); }
.chip.archived { opacity: .6; }
.chip.add { border-style: dashed; color: var(--muted); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--text); }

/* ---------- invoices ---------- */
.inv-list { overflow: hidden; }
.inv-row { display: grid; grid-template-columns: 56px minmax(0, 1fr) 92px 74px 104px 62px; align-items: center; gap: 12px; padding: 11px 16px; text-decoration: none; }
.inv-row + .inv-row { border-top: 1px solid var(--line); }
.inv-row:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.inv-num { font-weight: 700; }
.inv-client { font-weight: 600; display: grid; }
.inv-period { font-weight: 400; font-size: 13px; }
.inv-amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.inv-hours, .inv-date { font-variant-numeric: tabular-nums; font-size: 14px; }
.inv-summary { background: var(--bg); border-radius: 8px; padding: 10px 12px; display: grid; gap: 4px; }
.inv-summary-main { display: flex; justify-content: space-between; gap: 6px 16px; flex-wrap: wrap; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 99px; padding: 4px 11px; font: 600 13px var(--font); cursor: pointer; }
.chip-btn:hover { color: var(--accent); border-color: var(--accent); }
.inv-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.inv-toolbar-title { font-weight: 700; font-size: 17px; margin-right: auto; }
.inv-toolbar .sel { width: auto; }

/* ---------- settings ---------- */
.settings { padding: 16px; }
.settings h2 { margin-bottom: 4px; }
.settings .form-grid { margin-top: 12px; }
.logo-box { display: grid; gap: 8px; justify-items: start; }
.logo-box img { max-width: 100%; max-height: 64px; background: #fff; border-radius: 6px; padding: 4px; }

/* ---------- dialogs ---------- */
.dlg { border: 0; padding: 0; border-radius: 14px; width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dlg::backdrop { background: rgba(10, 16, 24, .5); }
.dlg-small { width: min(400px, calc(100vw - 20px)); }
.dlg-form { display: flex; flex-direction: column; max-height: calc(100dvh - 20px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 4px 18px; }
.dlg-head h2 { font-size: 18px; }
.dlg-body { padding: 10px 18px 16px; overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.dlg-foot-left { margin-right: auto; }
.dur-preview { font-weight: 600; font-variant-numeric: tabular-nums; }
.dur-preview.bad { color: var(--danger); }
.confirm-text { margin: 0; }

#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 24px));
  background: #17202a; color: #fff; padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 1000;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- printed pages (always light, regardless of theme) ---------- */
.paper-wrap { overflow: hidden; }
.paper { width: 8.5in; margin: 0 auto; color: #111; font: 10.5pt/1.42 var(--font); }
.sheet { background: #fff; padding: 0.5in 0; margin-bottom: 20px; box-shadow: 0 1px 4px rgba(0, 0, 0, .18); }
.sheet-invoice { min-height: 11in; }
.p-pad { padding-left: 0.4in; padding-right: 0.4in; }
.p-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.3in; }
.p-logo { height: 0.7in; max-width: 3.4in; object-fit: contain; object-position: left top; }
.p-logo-text { font-size: 20pt; font-weight: 700; }
.p-biz { text-align: right; }
.p-title { font-size: 30pt; line-height: 1; margin-bottom: 0.2in; white-space: nowrap; }
.p-strong { font-weight: 700; }
.p-gap { height: 1.42em; }
.p-rule { border-top: 1.5px solid #dedede; margin: 0.22in 0 0.16in; }
.p-meta { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.3in; margin-bottom: 0.18in; }
.p-label { color: #8a9499; letter-spacing: .01em; }
.p-facts { border-collapse: collapse; }
.p-facts th { text-align: right; font-weight: 700; padding: 2.5px 10px 2.5px 16px; white-space: nowrap; }
.p-facts td { text-align: left; padding: 2.5px 80px 2.5px 4px; white-space: nowrap; }
.p-facts .p-shade th, .p-facts .p-shade td { background: #f3f4f4; font-weight: 700; padding-top: 4px; padding-bottom: 4px; }
.p-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.p-table thead tr { background: #444; }
.p-table th { color: #fff; font-weight: 700; text-align: left; padding: 9px 10px; }
.p-table td { padding: 9px 10px; vertical-align: top; border-bottom: 1px solid #e3e3e3; }
.p-table :is(th, td):first-child { padding-left: 0.4in; }
.p-table :is(th, td):last-child { padding-right: 0.4in; }
.p-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.p-table .nowrap { white-space: nowrap; }
.p-items td { padding-top: 13px; padding-bottom: 13px; border-bottom: 2px solid #dedede; }
.p-items th:nth-child(1) { width: 40%; }
.p-items th:nth-child(2) { width: 16%; }
.p-items th:nth-child(3) { width: 22%; }
.p-items th:nth-child(4) { width: 22%; }
.p-sub { color: #777; font-size: 9pt; margin-top: 2px; }
.p-entries { font-size: 9.5pt; }
.p-entries td { padding-top: 6px; padding-bottom: 6px; }
.p-proj { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.p-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.p-totals { margin: 0.2in 0 0 auto; width: 3.6in; box-sizing: content-box; }
.p-total-row { display: flex; justify-content: space-between; gap: 20px; padding: 3px 0; }
.p-total-row span:first-child { flex: 1; text-align: right; }
.p-total-row span:last-child { min-width: 1.1in; text-align: right; font-variant-numeric: tabular-nums; }
.p-total-rule { border-top: 2px solid #dedede; margin: 8px 0; }
.p-notes { margin-top: 0.4in; }

/* ---------- phone ---------- */
@media (max-width: 720px) {
  .only-mobile { display: inline; }
  .only-desktop { display: none !important; }
  .topbar { gap: 10px; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    justify-content: space-around; gap: 0;
  }
  .nav a { flex: 1; flex-direction: column; gap: 1px; padding: 6px 4px; font-size: 11px; }
  main { padding: 14px 10px calc(84px + env(safe-area-inset-bottom)); }
  .startbar { grid-template-columns: 1fr 1fr auto; }
  .start-desc { grid-column: 1 / -1; }
  .entry { grid-template-columns: 9px minmax(0, 1fr) auto 38px; gap: 10px; padding-left: 12px; }
  .run-time { font-size: 19px; }
  .run-card { gap: 8px; }
  .run-meta { flex-wrap: wrap; white-space: normal; gap: 0 6px; }
  .summary { gap: 2px 14px; font-size: 14px; }
  .stop-btn { padding: 0 10px; }
  .inv-row { grid-template-columns: 48px minmax(0, 1fr) auto; row-gap: 2px; }
  .inv-date, .inv-hours { display: none; }
  .inv-row .badge { grid-column: 2; justify-self: start; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 19px; }
  input[type=text], input[type=tel], input[type=email], input[type=number], input[type=date], input[type=datetime-local], textarea, select { font-size: 16px; }
}

/* ---------- print: only the invoice pages ---------- */
@media print {
  html, body { background: #fff !important; }
  .no-print, .topbar, .nav, #toast, dialog { display: none !important; }
  main, main.view-detail { max-width: none; margin: 0; padding: 0; }
  .paper-wrap { overflow: visible; }
  .paper { width: auto; margin: 0; zoom: 1 !important; }
  .sheet { box-shadow: none; margin: 0; padding: 0; min-height: 0; }
  .sheet-invoice { break-after: page; }
  .p-table thead { display: table-header-group; }
  .p-table tr { break-inside: avoid; }
  .p-totals { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
