:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16191d;
  --muted: #5d6673;
  --faint: #8a929d;
  --accent: #1f3a5f;
  --accent-text: #ffffff;
  --accent-soft: #e8eef6;
  --ok: #1d6b45;
  --ok-soft: #e4f3ea;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --bad: #a3261b;
  --bad-soft: #fbe7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215;
    --surface: #161a1f;
    --surface-2: #1d2228;
    --border: #2a3038;
    --text: #e8ebef;
    --muted: #a3acb8;
    --faint: #737d89;
    --accent: #8fb4e6;
    --accent-text: #0f1215;
    --accent-soft: #1d2a3a;
    --ok: #6fcf9b;
    --ok-soft: #16291f;
    --warn: #e7b65a;
    --warn-soft: #2c2414;
    --bad: #f0857a;
    --bad-soft: #2f1a18;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: none; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Sign in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.signin-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 28px; height: 28px; }
.signin-card p { margin: 8px 0 20px; color: var(--muted); }
.signin-card form { display: grid; gap: 12px; }

/* Shell */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .company { color: var(--muted); }
.topbar .spacer { flex: 1; }
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 57px); }
nav.side { padding: 16px 12px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
nav.side button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--muted); text-align: left; cursor: pointer; }
nav.side button:hover { background: var(--surface-2); color: var(--text); }
nav.side button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav.side .count { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-size: 12px; text-align: center; }
main { padding: 24px; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
section + section { margin-top: 28px; }
section > h2 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }

/* Cards and rows */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 10px; }
.card-body { padding: 16px; }
.card-row { display: flex; align-items: flex-start; gap: 16px; }
.card-row .grow { flex: 1; min-width: 0; }
.title { font-weight: 600; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; margin-top: 4px; }
.message { margin-top: 12px; padding: 12px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.message .label { display: block; font-size: 12px; color: var(--faint); margin-bottom: 4px; }
.empty { padding: 28px; text-align: center; color: var(--faint); border: 1px dashed var(--border); border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--faint); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Status pills */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.confirm { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.confirm-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
input[type="text"], input[type="password"], select, textarea { width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
textarea { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, nav.side button:focus-visible, tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 180px 1fr; gap: 10px; align-items: end; }
.inline-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.error { color: var(--bad); font-size: 13px; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }

/* Detail panel */
.detail { display: grid; gap: 16px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.back { margin-bottom: 12px; }

/* Money */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { padding: 16px; }
.stat .label { font-size: 12px; color: var(--faint); }
.stat .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 4px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; display: flex; margin-top: 14px; }
.bar span { display: block; height: 100%; }
.bar .spent { background: var(--accent); }
.bar .reserved { background: var(--warn); }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; padding: 12px 16px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: 0 8px 24px rgba(0,0,0,.18); font-size: 13px; z-index: 20; }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .topbar .company { display: none; }
  .layout { grid-template-columns: 1fr; }
  nav.side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px 12px; }
  nav.side button { width: auto; }
  main { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-row { flex-direction: column; }
  .form-grid, .kv { grid-template-columns: 1fr; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .hide-sm { display: none; }
}

/* Spacing fixes found in the browser check */
.stats .card + .card { margin-top: 0; }
.card-body > .actions { margin-top: 14px; }
.bar { margin: 14px 0 28px; }
