:root {
  color-scheme: light dark;
  --navy: #0b1f5c;
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --ink: #141b2d;
  --muted: #5b6579;
  --line: #dde2ec;
  --primary: #1a3fa8;
  --on-primary: #ffffff;
  --accent: #1a3fa8;
  --tile: #0b1f5c;
  --on-tile: #ffffff;
  --ok: #0c7a4c;
  --ok-soft: #e2f5ec;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --shadow: 0 1px 2px rgb(11 31 92 / 6%), 0 6px 20px rgb(11 31 92 / 6%);
  --radius: 18px;
  --radius-sm: 12px;
  --bottom-nav: 68px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1120;
    --surface: #161d31;
    --surface-2: #1f2942;
    --ink: #edf0f7;
    --muted: #a3acc0;
    --line: #2a3350;
    --primary: #8aa8ff;
    --on-primary: #0b1430;
    --accent: #8aa8ff;
    --tile: #233a86;
    --on-tile: #ffffff;
    --ok: #5fd6a2;
    --ok-soft: #14352a;
    --bad: #ff9a90;
    --bad-soft: #3f1f1d;
    --warn: #f2c66d;
    --warn-soft: #3a2f16;
    --shadow: none;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body.centered { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }

h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Shell */
.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--navy);
  color: #fff;
}
.topbar img { width: 40px; height: 40px; border-radius: 11px; background: #fff; padding: 3px; }
.topbar strong { display: block; font-size: 1rem; line-height: 1.2; }
.topbar span { display: block; font-size: .8rem; opacity: .8; }

.page {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + var(--bottom-nav) + 24px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 16px;
}
.page.wide { max-width: 1000px; }
.page.prose { padding-bottom: 32px; gap: 10px; }
.page.prose h2 { margin-top: 10px; }

.tabs {
  position: fixed;
  inset: auto 0 0;
  z-index: 3;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px);
}
.tabs a {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 1px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--muted);
  font-size: clamp(.62rem, 2.7vw, .72rem);
  font-weight: 500;
}
.tabs a svg { width: 22px; height: 22px; }
.tabs a[aria-current="page"] { background: var(--surface-2); color: var(--primary); font-weight: 700; }

@media (min-width: 900px) {
  #app.shell {
    display: grid;
    grid-template-columns: 228px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    min-height: 100dvh;
  }
  #app.shell .topbar { grid-column: 1; grid-row: 1; position: static; padding: 20px 16px 12px; }
  #app.shell .page { grid-column: 2; grid-row: 1 / span 2; padding: 28px 28px 40px; }
  #app.shell .tabs {
    grid-column: 1;
    grid-row: 2;
    position: static;
    display: grid;
    align-content: start;
    gap: 4px;
    padding: 4px 12px;
    background: var(--navy);
    border: 0;
  }
  #app.shell .tabs a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; color: rgb(255 255 255 / 75%); font-size: .92rem; }
  #app.shell .tabs a[aria-current="page"] { background: rgb(255 255 255 / 14%); color: #fff; }
}

/* Surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}
.card.narrow { width: 100%; max-width: 420px; padding: 24px; }

.muted { color: var(--muted); font-size: .9rem; }
.notice, .message { padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; overflow-wrap: anywhere; }
.notice { background: var(--warn-soft); color: var(--warn); }
.message.bad { background: var(--bad-soft); color: var(--bad); }
.message.ok { background: var(--ok-soft); color: var(--ok); }

.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.item { display: grid; gap: 6px; padding: 12px 0; border-top: 1px solid var(--line); min-width: 0; overflow-wrap: anywhere; }
.item:first-child { border-top: 0; padding-top: 0; }
.item:last-child { padding-bottom: 0; }
.pre { white-space: pre-wrap; }

.tag { justify-self: start; padding: 2px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }

/* Gates */
.zone { display: grid; gap: 10px; }
.zone h2 { font-size: .95rem; color: var(--muted); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile {
  min-height: 116px;
  border: 0;
  border-radius: var(--radius);
  background: var(--tile);
  color: var(--on-tile);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  padding: 12px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color .15s, transform .1s;
}
/* A gate left alone on its row takes the whole row. */
.tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
.tile:active { transform: scale(.98); }
.tile svg { width: 30px; height: 30px; }
.tile small { font-size: .78rem; font-weight: 400; min-height: 1.2em; }
.tile.busy { opacity: .7; }
.tile.opened { background: #0c7a4c; color: #fff; }
.tile.failed { background: #b42318; color: #fff; }

/* Forms */
form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
label { display: grid; gap: 5px; font-size: .88rem; font-weight: 500; min-width: 0; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 16px;
}
input:focus, select:focus, textarea:focus { background: var(--surface); border-color: var(--line); }
input[type="date"] { padding-inline: 8px; font-size: 14px; }
textarea { min-height: 110px; resize: vertical; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
form.inline { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
fieldset.checks { display: grid; gap: 10px; margin: 0; padding: 0; border: 0; min-width: 0; }
fieldset.checks legend { padding: 0 0 6px; font-size: .88rem; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
label.check input { width: 22px; min-height: 22px; flex: none; accent-color: var(--primary); }

button.btn {
  min-height: 46px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
button.btn:hover { opacity: .88; }
button.btn.quiet { background: transparent; color: var(--ink); border-color: var(--line); }
button.btn.danger { background: transparent; color: var(--bad); border-color: var(--line); }
button.btn.small { min-height: 40px; padding: 7px 12px; font-size: .86rem; }
button:disabled { opacity: .5; cursor: default; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions > button { flex: 1 1 auto; }
a.btn-link {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: .86rem;
  font-weight: 600;
  text-decoration: none;
}

/* Collapsible days and roles */
.day { border-top: 1px solid var(--line); padding-top: 10px; }
.day:first-child { border-top: 0; padding-top: 0; }
.day summary { position: relative; padding: 4px 0 4px 22px; cursor: pointer; font-weight: 600; list-style: none; }
.day summary::-webkit-details-marker { display: none; }
.day summary::before { content: "›"; position: absolute; left: 4px; top: 0; font-size: 1.3rem; line-height: 1.4; transition: transform .15s; }
.day[open] summary::before { transform: rotate(90deg); }
.day summary span { display: block; }
.day summary span:first-child::first-letter { text-transform: uppercase; }
.day summary .muted { font-weight: 400; }
.day[open] summary { margin-bottom: 8px; }

/* Administration */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat {
  display: grid;
  gap: 2px;
  padding: 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.stat strong { font-size: 1.6rem; line-height: 1.1; letter-spacing: -.02em; }
.stat span { font-size: .82rem; color: var(--muted); }
.stat.alert strong { color: var(--bad); }

.segments {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 14px;
}
.segments button {
  flex: 1 0 auto;
  min-height: 40px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 600;
  cursor: pointer;
}
.segments button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
@media (max-width: 420px) {
  .segments button { padding: 6px 3px; font-size: .74rem; }
}
.count { display: inline-block; min-width: 20px; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: .74rem; line-height: 20px; text-align: center; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips button {
  flex: none;
  min-height: 36px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 500;
  cursor: pointer;
}
.chips button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

.panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.user { border-top: 1px solid var(--line); }
.user:first-child { border-top: 0; }
.user summary { display: flex; align-items: center; gap: 12px; padding: 12px 2px; cursor: pointer; list-style: none; }
.user summary::-webkit-details-marker { display: none; }
.user summary::after { content: "›"; flex: none; color: var(--muted); font-size: 1.3rem; line-height: 1; transition: transform .15s; }
.user[open] > summary::after { transform: rotate(90deg); }
.avatar { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); font-size: .85rem; font-weight: 700; }
.who { flex: 1; min-width: 0; }
.who strong, .who span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.who span { color: var(--muted); font-size: .84rem; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.dot.bad { background: var(--bad); }
.user-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 2px 2px 16px; overflow-wrap: anywhere; }
.user-section { display: grid; gap: 8px; padding-top: 12px; border-top: 1px dashed var(--line); }
.user-section > h3 { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.subs { margin-left: 8px; padding-left: 10px; border-left: 2px solid var(--line); }

@media (min-width: 720px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Finance */
.picker-field { display: grid; gap: 6px; }
.combo { position: relative; }
.combo input { padding-right: 44px; }
.combo-toggle { position: absolute; inset: 0 0 0 auto; width: 44px; border: 0; background: transparent; color: var(--muted); font-size: 1rem; cursor: pointer; }
.picker { display: grid; gap: 4px; max-height: 280px; overflow-y: auto; }
.picker button { display: grid; gap: 1px; padding: 8px 10px; text-align: left; background: var(--surface-2); border: 0; border-radius: var(--radius-sm); cursor: pointer; overflow-wrap: anywhere; }
.picker small, .picked small { display: block; color: var(--muted); font-size: .8rem; }
.picked { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-sm); overflow-wrap: anywhere; }
.picked > span:first-child { flex: 1 1 180px; min-width: 0; }
.statement table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.statement th, .statement td { padding: 8px 4px; text-align: left; border-bottom: 1px solid var(--line); }
.statement td:last-child, .statement th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.statement td small { display: block; color: var(--muted); font-size: .8rem; }
.statement tr.voided td { opacity: .6; }
.statement tr.voided strong, .statement tr.voided td:last-child { text-decoration: line-through; }
.statement tr.total td { font-weight: 700; border-bottom: 2px solid var(--ink); }
.statement tr.net td { font-size: 1.1rem; font-weight: 700; border: 0; }
.money { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.item.voided strong, .item.voided .money { text-decoration: line-through; opacity: .6; }

@media print {
  body { background: #fff; color: #000; }
  .topbar, .tabs, .segments, .no-print { display: none !important; }
  #app.shell { display: block; }
  .page, #app.shell .page { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
}

/* Account */
.profile { grid-template-columns: auto minmax(0, 1fr); align-items: center; }
.profile .who span { color: var(--muted); font-size: .9rem; white-space: normal; }
.avatar.large { width: 60px; height: 60px; background: var(--navy); color: #fff; font-size: 1.15rem; }
.chips-static { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.account-list { gap: 0; padding: 4px 16px; }
.account-row { border-top: 1px solid var(--line); }
.account-row:first-child { border-top: 0; }
.account-row summary { display: flex; align-items: center; gap: 12px; padding: 14px 0; cursor: pointer; list-style: none; }
.account-row summary::-webkit-details-marker { display: none; }
.account-row summary::after { content: "›"; flex: none; color: var(--muted); font-size: 1.3rem; line-height: 1; transition: transform .15s; }
.account-row[open] > summary::after { transform: rotate(90deg); }
.account-row .who span { white-space: normal; }
.row-icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--primary); }
.row-icon svg { width: 22px; height: 22px; }
.account-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 0 0 16px; overflow-wrap: anywhere; }
.center { text-align: center; }

/* Install */
.steps { display: grid; gap: 8px; margin: 0; padding-left: 20px; font-size: .92rem; }
.login-install { border: 0; padding: 0; }
.login-install summary { padding-left: 22px; color: var(--muted); font-size: .9rem; font-weight: 500; }

/* Sign-in */
.login-brand { text-align: center; display: grid; gap: 6px; justify-items: center; }
.login-brand img { width: 148px; height: 148px; padding: 8px; border-radius: 28px; background: #fff; }
