/* Bills — one stylesheet, no framework.
 *
 * Type: Instrument Sans (self-hosted, variable 400–700) so the app keeps its
 * face offline. Colour: one accent per theme, status colours reserved for
 * status. Every text/background pair below was measured against WCAG AA.
 */

@font-face {
  font-family: 'Instrument Sans';
  src: url('fonts/instrument-sans-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Instrument Sans';
  src: url('fonts/instrument-sans-latin-ext.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  /* includes U+20B1, the peso sign */
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
    U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* neutrals, one hue family (cool slate) */
  --bg: #12130f;
  --surface: #1a1b16;
  --surface-2: #22231c;
  --surface-3: #2b2c24;
  --raised: #2b2c24;
  --track: #22231c;
  --line: #2e3027;
  --line-soft: #24261e;
  --ink: #f2f4ec;
  --ink-2: #cfd3c4;
  --muted: #9aa08e;

  /* one accent, plus status colours that mean one thing each */
  --accent: #9fe870;
  --accent-ink: #9fe870;
  --on-accent: #163300;
  --red: #ff8a80;
  --amber: #f0c05a;
  --green: #45c98a;

  /* category tints for the row icons */
  --c-indigo: #7cb3f5;
  --c-amber: #f0c05a;
  --c-cyan: #6fd0e8;
  --c-rose: #f79ab0;
  --c-violet: #b9a5f5;
  --c-green: #c2e06a;
  --c-teal: #56cfc0;
  --c-slate: #a7ad9c;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-2: 0 14px 40px -18px rgba(0, 0, 0, .75);
  --glow: 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);

  /* The summary hero is dark in both themes. It answers the one question the
     screen exists for, and in light mode it was the palest thing on it. */
  --hero-bg: radial-gradient(22rem 13rem at 100% -10%, rgba(159, 232, 112, .30), transparent 68%),
    linear-gradient(158deg, #1b3a10 0%, #0b2400 100%);
  --hero-ink: #f3f8ee;
  --hero-k: #b6cfa4;
  --hero-fill: #9fe870;
  --hero-track: rgba(255, 255, 255, .16);

  --bar: 60px;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --dur: 180ms;

  color-scheme: dark;
}

/* The palette follows the device unless you pick one in the Actions menu. An
   explicit choice is stored, wins over the device, and is the same token set
   in both cases — hence the repeat. */
:root[data-theme='light'] {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --surface-3: #e7e4dc;
  --raised: #ffffff;
  --track: #eae7e0;
  --line: #e3e1da;
  --line-soft: #ece9e2;
  --ink: #0e0f0c;
  --ink-2: #2b2d27;
  --muted: #5c5f57;
  --accent: #9fe870;
  --accent-ink: #2c6a12;
  --on-accent: #163300;
  --red: #d03238;
  --amber: #8a5a00;
  --green: #054d28;
  --c-indigo: #2c5fa8;
  --c-amber: #8a5a00;
  --c-cyan: #146b8c;
  --c-rose: #a8335f;
  --c-violet: #6a4bb0;
  --c-green: #4a6b12;
  --c-teal: #11695f;
  --c-slate: #5c5f57;
  --shadow-1: 0 1px 2px rgba(38, 33, 22, .10);
  --shadow-2: 0 18px 40px -24px rgba(38, 33, 22, .30);
  --glow: 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
  color-scheme: light;
}

:root[data-theme='dark'] {
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --surface-3: #e7e4dc;
  --raised: #ffffff;
  --track: #eae7e0;
  --line: #e3e1da;
  --line-soft: #ece9e2;
  --ink: #0e0f0c;
  --ink-2: #2b2d27;
  --muted: #5c5f57;
  --accent: #9fe870;
  --accent-ink: #2c6a12;
  --on-accent: #163300;
  --red: #d03238;
  --amber: #8a5a00;
  --green: #054d28;
  --c-indigo: #2c5fa8;
  --c-amber: #8a5a00;
  --c-cyan: #146b8c;
  --c-rose: #a8335f;
  --c-violet: #6a4bb0;
  --c-green: #4a6b12;
  --c-teal: #11695f;
  --c-slate: #5c5f57;
  --shadow-1: 0 1px 2px rgba(38, 33, 22, .10);
  --shadow-2: 0 18px 40px -24px rgba(38, 33, 22, .30);
  --glow: 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
  color-scheme: light;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Instrument Sans', ui-sans-serif, system-ui, -apple-system,
    'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

/* a very faint wash so the flat surfaces have somewhere to sit */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(60rem 40rem at 50% -20%,
    color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%);
  z-index: 0;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.hidden { display: none !important; }

/* The icon sprite is referenced by <use>, never drawn — and `hidden` alone does
   not hide an SVG element, whose UA rule is HTML-only. */
.sprite { display: none; }

.skip-link {
  position: absolute;
  left: 8px;
  top: -56px;
  z-index: 40;
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  transition: top var(--dur) var(--ease);
}

.skip-link:focus { top: 8px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------- shell ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--line-soft);
}

/* the controls belong above the content column, not at the window edges */
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 2px;
  height: var(--bar);
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 8px;
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: -.01em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

.icon-btn:active { transform: scale(.94); }

.icon-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-btn { margin-left: 2px; }

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: var(--surface-2); color: var(--ink); }
}

.shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 14px 0;
}

/* ---------------- summary: one hero, two subordinates ---------------- */

.summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 16px 18px 18px;
  border-radius: var(--r-lg);
  background: var(--hero-bg);
  border: 1px solid rgba(255, 255, 255, .07);
  box-shadow: 0 20px 46px -26px rgba(6, 12, 24, .7), var(--shadow-1);
  color: var(--hero-ink);
}

.hero-k {
  display: block;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--hero-k);
}

.hero-v {
  display: block;
  margin-top: 6px;
  font-size: clamp(30px, 9vw, 40px);
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: 1.05;
  color: var(--hero-ink);
}

.hero-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.hero-note {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--hero-k);
  text-wrap: pretty;
}

.meter {
  width: 110px;
  height: 5px;
  flex: 0 0 auto;
  margin-left: auto;
  border-radius: 99px;
  background: var(--hero-track);
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--hero-fill);
  transition: width 420ms var(--ease);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}

.stat .k {
  display: block;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat .v {
  display: block;
  margin-top: 3px;
  font-size: 16.5px;
  font-weight: 600;
  letter-spacing: -.01em;
}

#overdueCard .v { color: var(--muted); }
#overdueCard.has-value { border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }
#overdueCard.has-value .v { color: var(--red); }

@media (min-width: 760px) {
  .summary { grid-template-columns: 1.45fr 1fr; align-items: stretch; }
  .stats { grid-template-columns: 1fr; }
  .stat { display: flex; flex-direction: column; justify-content: center; }
}

/* ---------------- segmented tabs ---------------- */

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 14px 0 12px;
}

.add-inline {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.add-inline svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.add-inline:active { transform: scale(.98); }

@media (hover: hover) and (pointer: fine) {
  .add-inline:hover { filter: brightness(1.07); }
}

.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0;
  padding: 4px;
  border-radius: 14px;
  background: var(--track);
  border: 1px solid var(--line-soft);
}

.tabs button {
  position: relative;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.tabs button[aria-selected='true'] {
  background: var(--raised);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

@media (hover: hover) and (pointer: fine) {
  .tabs button:hover { color: var(--ink); }
}

/* ---------------- lists ---------------- */

/* informational, not a warning: amber belongs to "due soon" in this app */
.banner.note {
  align-items: flex-start;
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink-2);
  font-weight: 500;
}

.note-close {
  margin-left: auto;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.totals {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
}

.totals li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
}

.totals li:last-child { border-bottom: 0; }

.totals-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.totals-meta {
  font-size: 11.5px;
  color: var(--muted);
}

.totals b {
  font-weight: 650;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.banner.banner-btn {
  width: 100%;
  cursor: pointer;
  text-align: left;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  background: color-mix(in srgb, var(--accent-ink) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--accent-ink) 28%, var(--line));
  color: var(--accent-ink);
}

@media (hover: hover) and (pointer: fine) {
  .banner-btn:hover { background: color-mix(in srgb, var(--accent-ink) 14%, var(--surface)); }
}

.banner {
  display: flex;
  gap: 8px;
  margin: 0 0 10px;
  padding: 11px 13px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--amber) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber) 34%, transparent);
  color: var(--amber);
  font-size: 12.5px;
  font-weight: 500;
  text-wrap: pretty;
}

/* an inline amount editor sits where the figure was */
.amount-input {
  width: 7.4em;
  padding: 2px 7px;
  border: 1px solid color-mix(in srgb, var(--accent-ink) 45%, var(--line));
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -.01em;
  text-align: right;
}

.item-amount { cursor: pointer; }

@media (hover: hover) and (pointer: fine) {
  .item-amount:hover { text-decoration: underline dotted; text-underline-offset: 3px; }
}

/* group heading with its own subtotal */
.group {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 4px 2px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.group:first-child { padding-top: 0; }

.group b {
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  --tile: var(--c-slate);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

@media (hover: hover) and (pointer: fine) {
  .item:hover { border-color: color-mix(in srgb, var(--ink) 16%, var(--line)); }
}

/* category tint, driven by data-cat on the row */
.item[data-cat='creditcard'] { --tile: var(--c-indigo); }
.item[data-cat='utilities'] { --tile: var(--c-amber); }
.item[data-cat='internetphone'] { --tile: var(--c-cyan); }
.item[data-cat='insurance'] { --tile: var(--c-slate); }
.item[data-cat='loan'] { --tile: var(--c-slate); }
.item[data-cat='housing'] { --tile: var(--c-rose); }
.item[data-cat='subscription'] { --tile: var(--c-violet); }
.item[data-cat='food'] { --tile: var(--c-green); }
.item[data-cat='transport'] { --tile: var(--c-teal); }
.item[data-cat='health'] { --tile: var(--c-rose); }

.tile {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: color-mix(in srgb, var(--tile) 15%, transparent);
  color: var(--tile);
}

.ico {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tile .ico { width: 19px; height: 19px; }

.item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.item-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.005em;
}

.item-title .t {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.item-sub span {
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex: 0 0 auto;
  text-align: right;
}

.item-amount {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.item-status {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .02em;
  white-space: nowrap;
  color: var(--muted);
}

.item[data-state='overdue'] .item-amount { color: var(--red); }
.item[data-state='overdue'] .item-status { color: var(--red); }
.item[data-state='soon'] .item-status { color: var(--amber); }
.item[data-state='paid'] .item-title .t {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
.item[data-state='paid'] .item-amount { color: var(--muted); font-weight: 500; }
.item[data-state='paid'] .item-status { color: var(--green); }

/* the tick: 26px of ink inside a 44px thumb target */
.tick {
  position: relative;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 50%;
  border: 1.6px solid color-mix(in srgb, var(--ink) 26%, transparent);
  background: transparent;
  color: transparent;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease),
    color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.tick::after {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 50%;
}

.tick svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Paid is the mark, not a filled disc: no ring, no fill, just the check — and
   it grows into the box the ring used to occupy. */
.tick[aria-pressed='true'] {
  background: transparent;
  border-color: transparent;
  color: var(--green);
}

.tick[aria-pressed='true'] svg {
  width: 19px;
  height: 19px;
  stroke-width: 2.6;
}

.tick:active { transform: scale(.9); }

@media (hover: hover) and (pointer: fine) {
  .tick:hover { border-color: var(--green); }
}

.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--muted);
}

/* ---------------- empty state ---------------- */

.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin: 26px 0 0;
  padding: 30px 18px;
  border-radius: var(--r-lg);
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
  font-size: 13.5px;
  line-height: 1.55;
  text-wrap: pretty;
}

.empty .ico {
  width: 26px;
  height: 26px;
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

.rec-note {
  margin: 0 0 10px;
  padding: 11px 13px;
  border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--line));
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
  text-wrap: pretty;
}

/* ---------------- add bar ----------------
 * A floating button always sits on top of whatever row is at the fold, and in a
 * ledger that row's amount is the thing you came to read. A bottom bar owns its
 * own strip of the viewport instead. */

.addbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 12;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-top: 1px solid var(--line-soft);
}

.addbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 50px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  box-shadow: var(--shadow-2), var(--glow);
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.addbar-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2.4;
}

.addbar-btn:active { transform: scale(.985); }

@media (hover: hover) and (pointer: fine) {
  .addbar-btn:hover { filter: brightness(1.07); }
}

@media (min-width: 760px) {
  .addbar { display: none; }
  .controls { grid-template-columns: 1fr auto; align-items: center; }
  .add-inline { display: flex; }
  body { padding-bottom: 48px; }
}

/* ---------------- sheets ---------------- */

dialog.sheet {
  width: min(520px, calc(100vw - 24px));
  max-height: min(88dvh, 720px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, .6);
  overflow: auto;
  overscroll-behavior: contain;
}

dialog.sheet::backdrop {
  background: rgba(4, 7, 11, .55);
  backdrop-filter: blur(6px);
}

dialog.sheet form,
dialog.sheet .sheet-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 18px calc(16px + env(safe-area-inset-bottom));
}

dialog.sheet h2 {
  margin: 0 0 2px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.015em;
}

dialog.sheet label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

dialog.sheet input[type='text'],
dialog.sheet input[type='number'],
dialog.sheet input[type='date'],
dialog.sheet select,
dialog.sheet textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: max(16px, 15px);   /* under 16px iOS zooms the field on focus */
  letter-spacing: 0;
  text-transform: none;
}

dialog.sheet textarea { min-height: 58px; resize: vertical; }

dialog.sheet input:focus-visible,
dialog.sheet select:focus-visible,
dialog.sheet textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.check {
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
  font-size: 13.5px !important;
  font-weight: 550 !important;
  letter-spacing: 0 !important;
  text-transform: none !important;
  color: var(--ink-2) !important;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.field-row { display: flex; align-items: center; gap: 8px; }

.field-ico {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--accent-ink);
}

.field-ico .ico { width: 20px; height: 20px; }

.hint-btn {
  margin-top: -4px;
  padding: 9px 11px;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 11px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.hint-btn[hidden] { display: none; }


.formerr {
  margin: 0;
  font-size: 12.5px;
  color: var(--red);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.spacer { flex: 1; }

.actions button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease),
    background var(--dur) var(--ease);
}

.actions button:active { transform: scale(.97); }

.primary { background: var(--accent); color: var(--on-accent); }
.ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.ghost.danger { color: var(--red); }
.ghost.danger[hidden] { display: none; }

@media (hover: hover) and (pointer: fine) {
  .primary:hover { filter: brightness(1.08); }
  .ghost:hover { background: var(--surface-2); }
}

.rowbtn {
  width: 100%;
  min-height: 48px;
  padding: 0 4px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14.5px;
  text-align: left;
  cursor: pointer;
}

.rowbtn:last-of-type { border-bottom: 0; }

.themeswitch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 0 4px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14.5px;
  text-align: left;
  cursor: pointer;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 28px;
  border-radius: 99px;
  background: var(--surface-3);
  transition: background var(--dur) var(--ease);
}

.switch .thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}

.themeswitch[aria-checked='true'] .switch { background: var(--accent); }
.themeswitch[aria-checked='true'] .switch .thumb { transform: translateX(18px); background: #fff; }

@media (hover: hover) and (pointer: fine) {
  .rowbtn:hover { color: var(--accent-ink); }
}

dialog.small { width: min(420px, calc(100vw - 24px)); }
dialog.small .sheet-body, dialog.small form { gap: 0; }

.menu-note {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  text-wrap: pretty;
}

@media (max-width: 560px) {
  dialog.sheet {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-bottom: 0;
    max-height: 92dvh;
  }
}

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 11px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-3);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-2);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 760px) {
  .toast { bottom: 28px; }
}

/* ---------------- motion preferences ---------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
