:root {
  --ink: #12231c;
  --ink-soft: #46564e;
  --ink-faint: #7c8b83;
  --page: #eef0ec;
  --surface: #ffffff;
  --line: #dbe0da;
  --line-soft: #eaeee8;
  --jade: #0e7c5a;
  --jade-dim: #e4f1eb;
  --rust: #a83a1c;
  --rust-dim: #fbeae4;
  --amber: #8a6410;
  --amber-dim: #fbf1dc;
  --focus: #0e7c5a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(18, 35, 28, .06), 0 8px 24px -16px rgba(18, 35, 28, .28);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.014em; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.0625rem; }
h3 { font-size: .9375rem; }
p { margin: 0 0 .75rem; }

.num, td.num, th.num, .money, input[type="number"], input[type="date"] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

a { color: var(--jade); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------- app frame */

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--ink);
  color: #cfded6;
  padding: 20px 14px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.brand strong { color: #fff; font-size: 1.0625rem; letter-spacing: -.02em; }
.brand span { font-size: .75rem; color: #86a094; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border-radius: 7px; color: #b9cec4;
  text-decoration: none; font-size: .875rem; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.11); color: #fff; }
.nav-group { font-size: .6875rem; color: #6e8a7d; padding: 10px 10px 4px; font-weight: 600; }
.nav .pip {
  background: var(--rust); color: #fff; border-radius: 20px;
  padding: 1px 7px; font-size: .6875rem; font-weight: 700;
}

.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; }
.sidebar-foot .who { padding: 0 8px 10px; font-size: .8125rem; }
.sidebar-foot .who b { display: block; color: #fff; }
.sidebar-foot .who span { color: #7f9a8d; font-size: .75rem; }

.main { padding: 24px 28px 80px; max-width: 1180px; }

.page-head {
  display: flex; flex-wrap: wrap; gap: 12px 16px;
  align-items: flex-end; justify-content: space-between; margin-bottom: 18px;
}
.page-head .sub { color: var(--ink-faint); font-size: .875rem; margin-top: 2px; }

/* ------------------------------------------------------------- components */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card > header {
  padding: 13px 16px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card > .body { padding: 16px; }
.card > .body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

.stat { padding: 15px 16px; }
.stat .label { font-size: .8125rem; color: var(--ink-faint); }
.stat .value { font-size: 1.5rem; font-weight: 620; letter-spacing: -.02em; margin-top: 3px; }
.stat .foot { font-size: .8125rem; color: var(--ink-soft); margin-top: 4px; }

.balance-hero { padding: 22px 20px; }
.balance-hero .value { font-size: 2.5rem; line-height: 1; letter-spacing: -.03em; }
.owe { color: var(--rust); }
.credit { color: var(--jade); }
.settled { color: var(--ink-soft); }

button, .btn {
  font: inherit; font-weight: 550; cursor: pointer;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  padding: 8px 14px; text-decoration: none; display: inline-flex;
  align-items: center; gap: 7px; line-height: 1.3;
}
button:hover, .btn:hover { border-color: #c4ccc2; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #1c352a; border-color: #1c352a; }
.btn-danger { color: var(--rust); border-color: #e8cfc6; background: #fff; }
.btn-danger:hover { background: var(--rust-dim); }
.btn-sm { padding: 5px 10px; font-size: .8125rem; border-radius: 7px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--line-soft); border-color: transparent; }

label { display: block; font-size: .8125rem; font-weight: 550; margin-bottom: 5px; color: var(--ink-soft); }
input, select, textarea {
  font: inherit; width: 100%; padding: 8px 11px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--jade); outline: none; box-shadow: 0 0 0 3px var(--jade-dim); }
.field { margin-bottom: 13px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: .78125rem; color: var(--ink-faint); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  text-align: left; font-weight: 600; color: var(--ink-faint);
  font-size: .78125rem; padding: 9px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfb; }
.num { text-align: right; }
tfoot td { font-weight: 620; border-top: 1px solid var(--line); border-bottom: 0; background: #fafbfa; }
.table-wrap { overflow-x: auto; }
.table-wrap table { min-width: 520px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.tag-mess { background: var(--jade-dim); color: #0a5b42; }
.tag-general { background: #e7edf6; color: #2b4a76; }
.tag-cook { background: var(--amber-dim); color: var(--amber); }
.tag-pending { background: var(--amber-dim); color: var(--amber); }
.tag-approved { background: var(--jade-dim); color: #0a5b42; }
.tag-rejected { background: var(--rust-dim); color: var(--rust); }
.tag-open { background: var(--jade-dim); color: #0a5b42; }
.tag-closed { background: #e6e9e5; color: var(--ink-soft); }

.empty { padding: 34px 18px; text-align: center; color: var(--ink-faint); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; font-weight: 600; }

.bar { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--jade); }

.split-list { list-style: none; margin: 0; padding: 0; }
.split-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px dashed var(--line-soft); font-size: .875rem;
}
.split-list li:last-child { border-bottom: 0; }
.split-list .k { color: var(--ink-soft); }
.split-list .v { font-variant-numeric: tabular-nums; font-weight: 550; }
.split-list li.total { border-top: 1px solid var(--line); border-bottom: 0; margin-top: 4px; padding-top: 10px; font-weight: 620; }

/* ---------------------------------------------------------------- login */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 80% at 50% 0%, #1b3a2c 0%, var(--ink) 62%);
}
.login-card { width: 100%; max-width: 372px; background: var(--surface); border-radius: 14px; padding: 26px; box-shadow: 0 24px 60px -24px rgba(0,0,0,.5); }
.login-card .mark { font-size: 1.375rem; font-weight: 640; letter-spacing: -.02em; }
.login-card .tagline { color: var(--ink-faint); font-size: .875rem; margin: 4px 0 20px; }

.alert { padding: 10px 13px; border-radius: 8px; font-size: .875rem; margin-bottom: 13px; }
.alert-error { background: var(--rust-dim); color: #7d2b14; }
.alert-info { background: var(--jade-dim); color: #0a5b42; }
.alert-warn { background: var(--amber-dim); color: var(--amber); }

/* ---------------------------------------------------------------- modal */

.modal-root { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 18px; }
.modal-root[hidden] { display: none; }   /* [hidden] alone loses to display:grid */
.modal-root::before { content: ""; position: absolute; inset: 0; background: rgba(18,35,28,.45); }
.modal {
  position: relative; background: var(--surface); border-radius: 12px;
  width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 30px 70px -20px rgba(0,0,0,.45);
}
.modal header { padding: 16px 18px 0; }
.modal .body { padding: 16px 18px; }
.modal footer { padding: 0 18px 18px; display: flex; gap: 9px; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 130%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 9px;
  font-size: .875rem; z-index: 90; max-width: 90vw;
  opacity: 0; pointer-events: none;
  transition: transform .22s ease, opacity .22s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.bad { background: var(--rust); }

/* --------------------------------------------------------------- mobile */

.tabbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px 15px calc(84px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.3125rem; }
  .balance-hero .value { font-size: 2.125rem; }
  .field-row { grid-template-columns: 1fr; }

  /* iOS Safari auto-zooms on any input under 16px — keep all form fields at 16px on phones. */
  input, select, textarea { font-size: 16px; }

  .mobile-head {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--ink); color: #fff; padding: 12px 15px;
    padding-top: calc(12px + env(safe-area-inset-top));
    position: sticky; top: 0; z-index: 40;
  }
  .mobile-head strong { font-size: 1rem; }
  .mobile-head .btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    flex: 1; text-align: center; text-decoration: none; color: var(--ink-faint);
    font-size: .6875rem; font-weight: 600; padding: 5px 2px; border-radius: 8px;
    display: flex; flex-direction: column; gap: 3px; align-items: center;
  }
  .tabbar a[aria-current="page"] { color: var(--jade); background: var(--jade-dim); }
  .tabbar svg { width: 19px; height: 19px; }
}

@media (min-width: 861px) { .mobile-head { display: none; } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  .sidebar, .tabbar, .mobile-head, button, .btn { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
