/* Master Admin. No inline styles are used anywhere, because the server's security policy blocks them. */
:root {
  --bg: #f1f4f4; --surface: #ffffff; --fg: #14201f; --muted: #5b6a69; --line: #dbe2e2;
  --accent: #0e7c86; --accent-ink: #ffffff; --accent-soft: #ddf0f1;
  --good: #1d7f48; --good-soft: #def3e6; --warn: #9a6412; --warn-soft: #faefd6; --crit: #b42b2b; --crit-soft: #fbe3e3;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1415; --surface: #152122; --fg: #e6eeee; --muted: #93a5a4; --line: #26383a;
    --accent: #3cc0cc; --accent-ink: #062427; --accent-soft: #14393d;
    --good: #5fd08c; --good-soft: #15341f; --warn: #e5b45a; --warn-soft: #3b2e12; --crit: #f08585; --crit-soft: #3d1a1a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 24px; } h2 { font-size: 15px; } h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.noscript { padding: 24px; }

/* Layout */
.app { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 24px; max-width: 1400px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); }
.side { align-self: start; position: sticky; top: 20px; display: flex; flex-direction: column; gap: 16px; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.logo { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); position: relative; display: inline-block; }
.logo::after { content: ""; position: absolute; inset: 7px; border: 2px solid var(--accent-ink); border-radius: 2px; }
.navgroup { display: flex; flex-direction: column; gap: 2px; }
.navlabel { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 8px 10px 2px; font-weight: 600; }
nav a { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; }
nav a:hover { background: var(--accent-soft); color: var(--fg); }
nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
nav a.locked { opacity: 0.45; pointer-events: none; }
.me { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--muted); }
.me b { color: var(--fg); font-size: 13px; display: block; overflow-wrap: anywhere; }
main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.pagehead { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; }
.pagehead p { margin: 2px 0 0; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 200px; min-width: 0; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.halves { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.halves table { min-width: 0; }

/* Surfaces */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
.panel > h2 { margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi .val { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi .note { font-size: 12px; color: var(--muted); }
.kpi .note.bad { color: var(--crit); font-weight: 600; }
.note { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 18px 4px; }
.banner { border-radius: 10px; padding: 12px 16px; background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }
.banner.bad { background: var(--crit-soft); color: var(--crit); border-color: var(--crit); }
.banner b { color: inherit; }
.banner .row { margin-top: 8px; }

/* Tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.center, th.center { text-align: center; }
td small { display: block; color: var(--muted); }
.who { display: flex; align-items: center; gap: 10px; }
.av { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 600; font-size: 12px; flex: none; }
.done-title { text-decoration: line-through; color: var(--muted); }

/* Controls */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 6px 12px; cursor: pointer; font-weight: 500; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--crit); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="datetime-local"], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; min-width: 0; width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.form .wide { grid-column: 1 / -1; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; min-width: 0; }
.err { color: var(--crit); font-size: 13px; min-height: 18px; margin-top: 8px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { border: 1px solid var(--line); background: var(--surface); padding: 5px 12px; border-radius: 16px; cursor: pointer; font-weight: 500; }
.tab[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 10px; white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.crit { background: var(--crit-soft); color: var(--crit); }
.pill.mute { background: var(--accent-soft); color: var(--accent); }
.switch { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
.switch small { display: block; color: var(--muted); max-width: 60ch; }

/* Invoice editor */
.lines { display: flex; flex-direction: column; gap: 8px; }
.line { display: grid; grid-template-columns: minmax(0, 3fr) 80px 120px 110px 34px; gap: 8px; align-items: center; }
.line .amt { text-align: right; font-variant-numeric: tabular-nums; }
.totals { margin-left: auto; width: min(100%, 280px); display: flex; flex-direction: column; gap: 4px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; gap: 12px; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 1px solid var(--line); padding-top: 6px; }

/* Timeline */
.day { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 4px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; }
.timeline li { padding: 7px 0 7px 12px; position: relative; display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 52px; }
.timeline .detail { color: var(--muted); overflow-wrap: anywhere; }

/* Chart */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .gl { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--accent); }
.chart .bar.last { fill: var(--accent); }
.chart .bar.past { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1; }
.chart .val { fill: var(--fg); font-weight: 600; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login .panel { width: min(100%, 380px); padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { margin-bottom: 4px; }
.secret { font-family: ui-monospace, Menlo, monospace; background: var(--accent-soft); padding: 6px 10px; border-radius: 6px; overflow-wrap: anywhere; user-select: all; }
.qr { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }

/* Modal and toast */
.backdrop { position: fixed; inset: 0; background: rgba(5, 15, 15, 0.55); display: grid; place-items: center; padding: 16px; z-index: 30; overflow-y: auto; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(100%, 640px); display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-weight: 500; z-index: 40; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--crit); color: #fff; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .side { position: static; }
  nav { display: flex; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .navgroup { flex-direction: row; }
  .navlabel { display: none; }
  nav a { white-space: nowrap; }
  .me { flex-direction: row; justify-content: space-between; align-items: center; }
  .two { grid-template-columns: minmax(0, 1fr); }
  .line { grid-template-columns: minmax(0, 1fr) 70px 100px; }
  .line .amt, .line .rm { grid-column: auto; }
}
@media print {
  .app, .toast { display: none; }
  .backdrop { position: static; background: none; padding: 0; display: block; }
  .modal { border: 0; max-height: none; width: 100%; }
  .no-print { display: none !important; }
  body { background: #fff; color: #000; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .tab, nav a { transition: border-color 0.15s, background 0.15s; }
}
