/* Team Lunch. Colours: navy #122563 and sky #48B2E2, sampled from the company logo.
   Green = paid and red = owes, as in the original sheet. */
:root {
  --navy: #122563;
  --sky: #48B2E2;
  --bar: #122563;
  --on-bar: #FFFFFF;

  --bg: #F3F6FB;
  --surface: #FFFFFF;
  --sunk: #EAF0F7;
  --ink: #0F1A3C;
  --muted: #56628A;
  --line: #D7DFEC;
  --brand: #122563;
  --on-brand: #FFFFFF;
  --accent: #2E9FD6;
  --accent-soft: #E2F3FB;
  --paid: #17834F;
  --paid-soft: #DCF2E6;
  --on-paid: #FFFFFF;
  --owes: #CF3826;
  --owes-soft: #FCE5E1;
  --on-owes: #FFFFFF;
  --focus: #2E9FD6;
  --shadow: 0 1px 2px rgba(18, 37, 99, .06), 0 4px 16px rgba(18, 37, 99, .06);

  --f-head: Rubik, "Segoe UI", system-ui, sans-serif;
  --f-body: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bar: #0D1B4B;
    --bg: #0A1130;
    --surface: #111A3E;
    --sunk: #172350;
    --ink: #E7ECF9;
    --muted: #9DA9CF;
    --line: #26346A;
    --brand: #48B2E2;
    --on-brand: #06102E;
    --accent: #48B2E2;
    --accent-soft: #15315A;
    --paid: #3DC481;
    --paid-soft: #113828;
    --on-paid: #04200F;
    --owes: #FF7B69;
    --owes-soft: #3D1A1D;
    --on-owes: #2B0703;
    --focus: #48B2E2;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--f-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
main.wrap { flex: 1; padding-block: 20px 48px; display: grid; gap: 18px; align-content: start; }
h1, h2, h3 { font-family: var(--f-head); margin: 0; letter-spacing: -.01em; text-wrap: balance; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
a { color: var(--accent); }
.sub { color: var(--muted); font-size: 13.5px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.loading { color: var(--muted); }

/* ---------- top bar ---------- */
.bar {
  background: var(--bar);
  color: var(--on-bar);
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
}
.bar-in {
  max-width: 1080px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font: 700 18px/1 var(--f-head);
}
.mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: #FFFFFF; /* the logo is drawn on white */
  display: block;
  flex: none;
}
.save {
  margin-left: auto;
  font: 500 12px/1 var(--f-body);
  border: 1px solid rgba(255, 255, 255, .3);
  background: transparent;
  color: var(--on-bar);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: default;
}
.save[data-kind="error"] { background: #CF3826; border-color: #CF3826; cursor: pointer; }
.save[data-kind="saved"] { opacity: .8; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.save[hidden] + .who { margin-left: auto; }
.unlocked {
  font: 600 11px/1 var(--f-body);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #9FE3BF;
}
.unlocked::before { content: "● "; }
.mode-tag {
  font: 600 11px/1 var(--f-body);
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--sky);
  color: #06102E;
  padding: 5px 8px;
  border-radius: 6px;
}

/* ---------- buttons ---------- */
.btn {
  font: 600 14px/1 var(--f-body);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.tiny { padding: 5px 8px; font-size: 12px; border-radius: 7px; }
.btn.on-bar { background: transparent; color: var(--on-bar); border-color: rgba(255, 255, 255, .45); }
.btn.on-bar:hover { background: rgba(255, 255, 255, .1); }
.btn.armed, .x.armed { background: var(--owes); border-color: var(--owes); color: var(--on-owes); }
.btn.danger-btn { color: var(--owes); }
.btn:disabled { opacity: .5; cursor: default; }
.linkish { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible, .msg:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- notices ---------- */
.notice {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
}
.notice.error { background: var(--owes-soft); }
.notice > div { min-width: 0; flex: 1 1 280px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.empty { color: var(--muted); margin: 0; }
p.empty.card { padding: 16px 18px; }

/* ---------- home ---------- */
.home-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.home-head .sub { margin: 4px 0 0; font-size: 14px; }
.sec-h { margin-bottom: 10px; }
.owed-card h2 { margin-bottom: 8px; }
.owed { list-style: none; margin: 0; padding: 0; display: grid; }
.owe-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.owe-row:first-child { border-top: 0; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--brand);
  display: grid;
  place-items: center;
  font: 700 15px/1 var(--f-head);
}
.owe-main { display: grid; min-width: 0; }
.owe-main .sub a { color: var(--muted); }
.amt { font-variant-numeric: tabular-nums; font-weight: 700; }
.amt.owes { color: var(--owes); font-size: 16px; }
@media (max-width: 520px) {
  .owe-row { grid-template-columns: auto 1fr auto; }
  .owe-row .btn { grid-column: 2 / -1; justify-self: start; }
}

.days { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.day-card {
  display: grid;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 16px;
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  min-width: 0;
}
.day-card:hover { border-color: var(--accent); }
.dc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.dc-date { font: 600 16px/1.2 var(--f-head); }
.dc-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.dc-total small { font-weight: 500; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: 600 12.5px/1 var(--f-body);
  padding: 6px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.chip.paid { background: var(--paid-soft); color: var(--paid); }
.chip.owes { background: var(--owes-soft); color: var(--owes); }
.history summary {
  cursor: pointer;
  font: 600 16px/1.3 var(--f-head);
  padding: 8px 0;
  color: var(--muted);
}
.history[open] summary { margin-bottom: 8px; }
.days.compact .day-card { box-shadow: none; }

/* ---------- day ---------- */
.day-top { display: flex; }
.back { text-decoration: none; font-weight: 600; }
.day-head { display: grid; gap: 14px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.f { display: grid; gap: 5px; min-width: 0; }
.f.wide { grid-column: span 2; }
@media (max-width: 460px) { .f.wide { grid-column: auto; } }
.f label { font: 500 12.5px/1.2 var(--f-body); color: var(--muted); }
.f input {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}
.f input:disabled { background: transparent; border-color: transparent; padding-left: 0; color: var(--ink); opacity: 1; }
.row-in { display: flex; gap: 8px; }
.row-in input { flex: 1; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.f input.num { text-align: left; }
input.bad { border-color: var(--owes) !important; background: var(--owes-soft) !important; }

.grid-card { display: grid; gap: 12px; }
.grid-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
.grid th, .grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; height: 40px; }
.grid tr > :last-child { border-right: 0; }
.grid tfoot th, .grid tfoot td { border-bottom: 0; }
.grid thead th {
  background: var(--brand);
  color: var(--on-brand);
  font: 600 13px/1.2 var(--f-body);
  text-align: left;
  padding: 0 10px;
  white-space: nowrap;
}
.grid thead th.c-total { text-align: right; }
.grid .c-name {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  min-width: 170px;
  text-align: left;
}
.grid thead .c-name { background: var(--brand); z-index: 2; }
.grid .c-price { min-width: 84px; background: var(--sunk); }
.grid thead .c-price { background: var(--brand); }
.grid .c-person { min-width: 116px; padding: 0 4px 0 0; }
.grid .c-cell { min-width: 96px; }
.grid .c-total { min-width: 84px; text-align: right; padding: 0 10px; font-weight: 600; white-space: nowrap; }
.grid .c-act { width: 1%; padding: 0 6px; background: var(--surface); }
.grid thead .c-act { background: var(--brand); }
.grid input {
  width: 100%;
  height: 39px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0 10px;
  min-width: 0;
}
.grid input:focus { background: var(--accent-soft); outline: 2px solid var(--focus); outline-offset: -2px; }
.grid input:disabled { opacity: 1; color: var(--ink); }
.grid thead input { color: var(--on-brand); font-weight: 600; }
.grid thead input::placeholder { color: var(--on-brand); opacity: .6; }
.grid thead input:focus { background: rgba(255, 255, 255, .14); }
.grid thead input:disabled { color: var(--on-brand); }
.grid .iname { font-weight: 500; }
.ph { display: flex; align-items: center; }
.x {
  flex: none;
  min-width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 0;
  background: transparent;
  color: inherit;
  font: 600 16px/1 var(--f-body);
  cursor: pointer;
  opacity: .7;
  padding: 0 6px;
  white-space: nowrap;
}
.x:hover { opacity: 1; background: var(--owes-soft); color: var(--owes); }
.grid thead .x:hover { background: rgba(255, 255, 255, .16); color: var(--on-brand); }
.x.armed { font-size: 12px; opacity: 1; }
.acts { display: flex; gap: 4px; align-items: center; }
.grid tr.extra th, .grid tr.extra td { color: var(--muted); font-weight: 500; }
.grid tr.extra .c-name { padding: 0 10px; font-weight: 500; }
.grid tr.extra .c-cell { text-align: right; padding: 0 10px; }
.grid tfoot .c-name { padding: 0 10px; font: 700 14px/1 var(--f-body); }
.grid tfoot td { background: var(--surface); }
.grid tfoot .grand { font-size: 15px; }
.tot {
  width: 100%;
  height: 39px;
  border: 0;
  font: 700 14px/1 var(--f-body);
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 0 10px;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
}
.tot[data-status="owes"] { background: var(--owes); color: var(--on-owes); }
.tot[data-status="paid"] { background: var(--paid); color: var(--on-paid); }
.tot[data-status="payer"] { background: var(--paid-soft); color: var(--paid); cursor: default; }
.tot[data-status="none"] { cursor: default; }
.tot:disabled { cursor: default; opacity: 1; }
.empty-grid { margin: 0; color: var(--muted); }
.hint { margin: 0; color: var(--muted); font-size: 13px; }

.share { display: grid; gap: 10px; }
.share-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.msg {
  margin: 0;
  background: var(--sunk);
  border-radius: 10px;
  padding: 12px 14px;
  font: 12.5px/1.5 ui-monospace, Consolas, "Courier New", monospace;
  white-space: pre;
  overflow-x: auto;
  max-height: 360px;
  overflow-y: auto;
}
.danger { display: flex; justify-content: flex-end; }

/* ---------- footer, dialog, toast ---------- */
.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12.5px;
  padding-block: 14px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}
dialog {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  padding: 22px;
  width: min(400px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 17, 48, .55); }
dialog form { display: grid; gap: 12px; }
.form-err { margin: 0; color: var(--owes); font-size: 14px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 14px;
  max-width: calc(100vw - 32px);
  z-index: 50;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}
.toast[data-kind="error"] { background: var(--owes); color: var(--on-owes); }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .day-card, .x { transition: border-color .15s, background-color .15s, filter .15s; }
}
@media (max-width: 520px) {
  h1 { font-size: 22px; }
  .card { padding: 14px; }
  .brand { font-size: 16px; }
}
