:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1b2430;
  --muted: #5d6b7c;
  --border: #dde3ea;
  --primary: #1f4e79;
  --primary-text: #ffffff;
  --ok: #1e7a46;
  --ok-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fdf0d8;
  --danger: #b3261e;
  --danger-bg: #fbe4e2;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --surface: #1a212b;
    --text: #e6ebf1;
    --muted: #93a1b2;
    --border: #2c3644;
    --primary: #5b9bd5;
    --primary-text: #0d1620;
    --ok: #6fd39a;
    --ok-bg: #173325;
    --warn: #f0b955;
    --warn-bg: #3a2c12;
    --danger: #f28b82;
    --danger-bg: #3d1d1b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.75rem 0 .75rem; }

/* Navigation */
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-text);
}
header a { color: inherit; text-decoration: none; }
.brand { font-weight: 700; }
header nav { display: flex; gap: .25rem; overflow-x: auto; }
header nav a { padding: .3rem .6rem; border-radius: 6px; white-space: nowrap; opacity: .85; }
header nav a[aria-current="page"] { background: rgb(255 255 255 / .18); opacity: 1; }
header nav .nav-link {
  font: inherit; color: inherit; background: none; border: 0; padding: .3rem .6rem;
  border-radius: 6px; opacity: .85; white-space: nowrap; cursor: pointer;
}
header nav .nav-link:hover, header nav a:hover { opacity: 1; background: rgb(255 255 255 / .12); }

main { max-width: 760px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

/* Surfaces */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.head h1 { margin: 0; }
.empty { color: var(--muted); }
.sub { color: var(--muted); font-size: .875rem; }

/* Forms */
.form { display: grid; gap: .85rem; }
.form.narrow { max-width: 360px; margin: 3rem auto; }
label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { min-height: 4.5rem; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
label.check { display: flex; align-items: center; gap: .5rem; color: var(--text); }
label.check input { width: auto; }
.preview { margin: 0; font-weight: 600; min-height: 1.4em; }
.error-text { margin: 0; padding: .6rem .8rem; border-radius: 8px; background: var(--danger-bg); color: var(--danger); }
.divider { text-align: center; margin: .25rem 0 0; }
.compose { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.card.form p { margin: 0; }

/* Flight / ground toggle */
.seg { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.seg legend { font-size: .9rem; color: var(--muted); margin-bottom: .3rem; padding: 0; }
.seg label { display: block; color: var(--text); }
.seg input { position: absolute; opacity: 0; width: 1px; }
.seg span {
  display: block; text-align: center; padding: .6rem; border: 1px solid var(--border);
  background: var(--bg); cursor: pointer;
}
.seg label:first-of-type span { border-radius: 8px 0 0 8px; }
.seg label:last-of-type span { border-radius: 0 8px 8px 0; border-left: 0; }
.seg input:checked + span { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Buttons */
button, .button {
  font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer;
}
button:disabled { opacity: .6; cursor: default; }
.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.big { width: 100%; padding: .9rem; font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }
.small { padding: .3rem .6rem; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.list li + li { border-top: 1px solid var(--border); }
.list li > a, .list li > div {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .75rem 1rem; color: inherit; text-decoration: none;
}
.list li > a:hover { background: var(--bg); }
.right { text-align: right; white-space: nowrap; }
.checklist label { display: flex; align-items: center; gap: .75rem; padding: .7rem 1rem; color: var(--text); }
.checklist input { width: auto; }
.checklist .grow { flex: 1; }

/* Status badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); color: var(--muted); }
.badge.paid { background: var(--ok-bg); color: var(--ok); }
.badge.open, .badge.unbilled { background: var(--warn-bg); color: var(--warn); }
.badge.overdue { background: var(--danger-bg); color: var(--danger); }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.stat {
  display: grid; gap: .15rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: inherit; text-decoration: none;
}
.stat span { color: var(--muted); font-size: .85rem; }
.stat strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stat.alert strong { color: var(--danger); }

/* Totals and key/value rows */
.kv { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; }
.kv span:first-child { color: var(--muted); }
.kv.total { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--border); margin-top: .35rem; padding-top: .6rem; }
.tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.tabs a { padding: .35rem .8rem; border-radius: 999px; text-decoration: none; border: 1px solid var(--border); color: var(--text); }
.tabs a[aria-current="page"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .55rem .75rem; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: .8rem; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
tbody tr + tr td { border-top: 1px solid var(--border); }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

#toast {
  position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 2rem); padding: .7rem 1.1rem; border-radius: 8px;
  background: var(--text); color: var(--bg); box-shadow: 0 4px 16px rgb(0 0 0 / .2); z-index: 20;
}
#toast.error { background: var(--danger); color: #fff; }

@media (max-width: 480px) {
  header nav { width: 100%; }
  .stat strong { font-size: 1.2rem; }
}
