:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #1f7a4d;
  --accent-soft: #e4f3ea;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bar-a: #1f7a4d;
  --bar-b: #f0a020;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b212a;
    --text: #e7eaf0;
    --muted: #98a2b3;
    --line: #2c3440;
    --accent: #4cc38a;
    --accent-soft: #173326;
    --danger: #ff8a7a;
    --danger-soft: #3a1c19;
    --warn: #f0c060;
    --warn-soft: #3a2f12;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.top nav a { padding: 6px 10px; border-radius: 8px; color: var(--text); }
.top nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.logout { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .value { font-size: 26px; font-weight: 700; line-height: 1.2; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile.attention { border-color: var(--bar-b); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.approved { background: var(--accent-soft); color: var(--accent); }
.badge.rejected, .badge.voided { background: var(--danger-soft); color: var(--danger); }

form.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
input, select, button, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { cursor: pointer; font-weight: 600; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 400; }

.pager { display: flex; gap: 12px; align-items: center; margin-top: 14px; color: var(--muted); }

.receipt { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(300px, 420px); gap: 16px; align-items: start; }
@media (max-width: 800px) { .receipt { grid-template-columns: 1fr; } }
.photo img { width: 100%; max-height: 80vh; object-fit: contain; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.photo .empty { padding: 40px; text-align: center; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.choices label { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.choices label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field input, .field select, .field textarea { width: 100%; }
textarea { resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
tr.ours td { background: var(--accent-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.note { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.error { background: var(--danger-soft); color: var(--danger); }
.note.ok { background: var(--accent-soft); color: var(--accent); }

.login { max-width: 360px; margin: 12vh auto 0; }

.chart { width: 100%; height: auto; }
.chart .a { fill: var(--bar-a); }
.chart .b { fill: var(--bar-b); }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.legend .a { background: var(--bar-a); }
.legend .b { background: var(--bar-b); }

.msg { padding: 8px 12px; border-radius: 10px; margin-bottom: 8px; max-width: 640px; overflow-wrap: anywhere; }
.msg.in { background: var(--bg); border: 1px solid var(--line); }
.msg.out { background: var(--accent-soft); margin-left: 40px; }
.msg .meta { font-size: 12px; color: var(--muted); }
