:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1a2330;
  --muted: #62707f;
  --line: #dde3e9;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --danger: #b42020;
  --warn-bg: #fff7e0;
  --chip: #e8edf2;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(20, 35, 50, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151b;
    --panel: #1a212a;
    --ink: #e6ebf0;
    --muted: #91a0b0;
    --line: #2b3543;
    --chip: #26303c;
    --warn-bg: #3a3420;
    --shadow: 0 2px 10px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* beat display:flex on hidden elements */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 70px; /* room for bottom nav on mobile */
}
main { max-width: 900px; margin: 0 auto; padding: 12px 14px 40px; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h3 small { text-transform: none; letter-spacing: 0; font-weight: normal; }
a { color: var(--brand); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--brand); color: var(--brand-ink);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { color: var(--brand-ink); }

.tabs {
  display: flex; gap: 2px; max-width: 900px; margin: 0 auto; padding: 8px 10px 0;
}
.tab {
  flex: 1; text-align: center; padding: 9px 4px; border-radius: var(--radius) var(--radius) 0 0;
  text-decoration: none; color: var(--muted); background: transparent; font-size: 14px;
}
.tab span { margin-left: 6px; }
.tab.on { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

.view { background: var(--panel); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px;
}
.toolbar label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.spacer { flex: 1; }
.narrow { width: 110px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
input[type="search"] { flex: 1; min-width: 140px; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
label.check { display: flex; align-items: center; gap: 8px; }

.btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); border-radius: 8px; padding: 8px 14px; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.small { padding: 4px 10px; font-size: 13px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }

.group-head {
  display: flex; justify-content: space-between; font-weight: 600; color: var(--muted);
  padding: 14px 4px 6px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px 4px; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--ink); font: inherit;
}
button.row { cursor: pointer; }
button.row:hover { background: var(--chip); }
.row-date { color: var(--muted); font-size: 13px; min-width: 52px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main small, .row small { color: var(--muted); }
.row-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; color: var(--muted); }

.chip {
  background: var(--chip); border-radius: 999px; padding: 2px 10px; font-size: 12px;
  white-space: nowrap; border: 0; color: var(--ink);
}
button.chip { cursor: pointer; font: inherit; font-size: 13px; padding: 6px 12px; }
button.chip:hover { outline: 2px solid var(--brand); }
.chip.code { background: var(--chip); color: var(--brand); font-weight: 600; }
.chip.st-draft { background: #e5efff; color: #1d4ed8; }
.chip.st-reported { background: #e3f4e3; color: #15803d; }
.chip.st-planned { background: #f3e8ff; color: #7e22ce; }
@media (prefers-color-scheme: dark) {
  .chip.st-draft { background: #1d3050; color: #93b4f5; }
  .chip.st-reported { background: #1c3a24; color: #86d996; }
  .chip.st-planned { background: #37244d; color: #cfa9f5; }
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.hint { color: var(--muted); font-size: 13px; }
.warn { background: var(--warn-bg); padding: 8px 12px; border-radius: 8px; font-size: 13px; }

.cards { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.card {
  background: var(--bg); border-radius: var(--radius); padding: 10px 18px; text-align: center;
  display: flex; flex-direction: column; min-width: 90px;
}
.card b { font-size: 18px; }
.card span { color: var(--muted); font-size: 12px; }
.codes { display: flex; flex-wrap: wrap; gap: 6px; }

.tscroll { overflow-x: auto; margin: 10px 0; }
table.mini { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
table.mini td, table.mini th { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: left; }
table.mini td:nth-child(n+2), table.mini th:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; }
table.mini tr.tot td { font-weight: 700; border-top: 2px solid var(--line); }

/* Timesheet week */
.week { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.day { background: var(--bg); border-radius: var(--radius); padding: 8px 10px; }
.day.today { outline: 2px solid var(--brand); }
.day-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.ts-row { border: 0; padding: 6px 2px; cursor: pointer; }
.ts-row.planned { opacity: .75; }

/* Dialogs */
dialog {
  border: 0; border-radius: 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
  background: var(--panel); color: var(--ink); padding: 18px; width: min(560px, calc(100vw - 30px));
  max-height: calc(100vh - 30px); overflow-y: auto;
}
dialog::backdrop { background: rgba(10, 15, 20, .55); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label.check, dialog label.switch { flex-direction: row; align-items: center; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg-foot { display: flex; gap: 8px; margin-top: 12px; align-items: center; }

/* Big GST switch */
.gst-row { display: flex; align-items: center; gap: 16px; background: var(--bg); border-radius: var(--radius); padding: 10px 12px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 16px; }
.switch input { position: absolute; opacity: 0; }
.switch .slider {
  width: 52px; height: 28px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s;
}
.switch .slider::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::after { left: 27px; }
.gst-amt { flex-direction: row !important; align-items: center; gap: 8px; }
.gst-amt input { width: 110px; }

/* OCR auto-fill */
.ocr-status { font-size: 13px; color: var(--brand); align-self: center; }
.ocr-status.busy { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }
input.autofilled { outline: 2px solid var(--brand); }

/* Receipt chips */
.rc-chip {
  display: inline-flex; align-items: center; gap: 8px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; max-width: 100%;
}
.rc-chip img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.rc-icon { font-size: 24px; }
.rc-name { font-size: 12px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-x { border: 0; background: transparent; color: var(--danger); font-size: 18px; cursor: pointer; padding: 0 4px; }

/* Settings */
.settings { max-width: 620px; }
.settings + .settings { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 6px; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin: 6px 0; }
.settings label.check { flex-direction: row; align-items: center; color: var(--ink); }
.settings textarea, .settings input { width: 100%; }
.settings .grid2 label { margin: 0; }
.settings .actions label.btn { flex-direction: row; color: var(--ink); width: auto; }

/* Banner + toasts */
.banner {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--warn-bg); padding: 10px 16px; font-size: 14px;
  max-width: 900px; margin: 8px auto 0; border-radius: var(--radius);
}
#toasts { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); opacity: 1; transition: opacity .4s;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; }

/* Mobile: bottom tab bar */
@media (max-width: 640px) {
  .tabs {
    position: fixed; bottom: 0; left: 0; right: 0; margin: 0; padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--line); z-index: 30;
  }
  .tab { border-radius: 8px; display: flex; flex-direction: column; font-size: 11px; }
  .tab span { margin: 0; }
  .tab.on { box-shadow: none; background: var(--chip); }
  .grid2 { grid-template-columns: 1fr; }
  .row-date { min-width: 44px; }
  .exp-row, .trip-row { flex-wrap: wrap; }
  .exp-row .row-main, .trip-row .row-main { flex: 1 1 60%; }
  .exp-row .row-main b, .trip-row .row-main b { white-space: normal; }
  main { padding: 10px 8px 90px; }
}
