/* Billkeep web app — layout and components.
   Tokens come from base.css, which mirrors lib/app/theme.dart. Rules the app
   holds to and this sheet keeps: no outlines on cards, chips or fields (a soft
   shadow instead), 26px corners, pill buttons, colour never the only carrier of
   status, and tabular figures everywhere because the screen is a column of
   money. */

/* Shell ------------------------------------------------------------------- */
/* The frame people expect from a dashboard: a fixed sidebar that scrolls on its
   own, a content column with a real maximum width, and a page header that stays
   put while a long list moves under it. */

body.app {
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--sunken);
}

.app-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
@media (max-width: 960px) { .app-shell { grid-template-columns: 1fr; } }

/* Sidebar ----------------------------------------------------------------- */

.side {
  position: sticky; top: 0; align-self: start;
  height: 100vh; height: 100dvh;
  padding: 20px 16px 16px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--card);
  border-right: 1px solid var(--line);
  overflow-y: auto; overscroll-behavior: contain;
}
.side::-webkit-scrollbar { width: 8px; }
.side::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.side .brand { margin: 0 8px 16px; font-size: 1.1rem; }
.side .brand .mark { width: 30px; height: 30px; }

.side-new { width: 100%; margin-bottom: 16px; padding-block: 12px; }
.side-new svg { width: 18px; height: 18px; }

#side-nav { display: grid; gap: 2px; }
.nav-group { display: grid; gap: 2px; }
.nav-label {
  font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); padding: 20px 16px 8px;
}

.side a.tab {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--r-sm);
  color: var(--ink-soft); font-weight: 600; font-size: .95rem;
  transition: background .16s ease, color .16s ease;
}
.side a.tab:hover { background: var(--sunken); color: var(--ink); text-decoration: none; }
.side a.tab svg { width: 19px; height: 19px; flex: 0 0 auto; opacity: .85; }
.side a.tab.is-active {
  background: color-mix(in srgb, var(--brand) 13%, transparent);
  color: var(--brand-ink); font-weight: 700;
}
.side a.tab.is-active svg { opacity: 1; }
/* A marker on the edge, so "which page am I on" is not carried by colour alone. */
.side a.tab.is-active::before {
  content: ""; position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--brand);
}

.side .spacer { flex: 1 1 auto; min-height: 20px; }

.side-foot { display: grid; gap: 8px; padding-top: 16px; border-top: 1px solid var(--line); }

.side-account {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: var(--r-sm);
  color: var(--ink); min-width: 0;
  transition: background .16s ease;
}
.side-account:hover { background: var(--sunken); text-decoration: none; }
.side-account-text { display: grid; min-width: 0; line-height: 1.3; }
.side-account-text strong {
  font-size: .88rem; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-account-text span { font-size: .76rem; color: var(--muted); }
.side-account-go { width: 16px; height: 16px; color: var(--muted); flex: 0 0 auto; margin-left: auto; }

/* The appearance control sits with the account, which is where the rest of the
   per-person switches live. On a phone the sidebar is gone entirely, so the app
   bar carries its own copy — without one, an app-only user could never change
   theme without going out to the marketing site. */
.side-tools {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 2px 8px;
}
.side-tools-label { font-size: .8rem; color: var(--muted); }
.app-bar .theme-toggle { margin-left: 0; margin-right: 10px; width: 36px; height: 36px; }

/* WhatsApp. On a wide screen the app has the same floating pill as the public
   pages — that corner is empty there, because "New invoice" lives in the
   sidebar. On a phone the corner belongs to the New invoice button and the tab
   bar runs under it, so the pill steps aside and a disc sits in the app bar.
   Signed out, there is no app bar, tab bar or New invoice button, so the
   floating one comes back — somebody stuck at sign-in is who needs it most. */
.app-bar .wa-disc { width: 36px; height: 36px; box-shadow: none; }
.app-bar .wa-disc svg { width: 20px; height: 20px; }
.app-bar a.wa-disc:hover { text-decoration: none; filter: brightness(.95); }
@media (max-width: 960px) { .app:not(.is-locked) .wa-float { display: none; } }

.side-links {
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  padding: 4px 12px 0; font-size: .78rem;
}
.side-links a { color: var(--muted); }
.side-links a:hover { color: var(--brand); }

/* Content column ---------------------------------------------------------- */

.main {
  min-width: 0;
  padding: 0 clamp(16px, 2.6vw, 34px) 120px;
  background: var(--page);
}
/* ⚠ **Clear the tab bar *and* the floating button above it.** The bar is 71px,
   the button sits 76px up and stands 60px tall, so content must clear 136px.
   At 96px the last rows in a list scrolled under "New invoice" — the client
   name, the amount and the Paid pill all disappeared behind it. */
@media (max-width: 960px) { .main { padding-bottom: 160px; } }

/* Everything inside the column shares one measure, so a form, a list and a
   report all start and end on the same two lines. */
#view { width: 100%; max-width: 1080px; margin: 0 auto; }

.avatar {
  width: 38px; height: 38px; border-radius: var(--r-sm); flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 800; font-size: .82rem;
  background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand-ink);
  letter-spacing: .02em;
}
a.avatar:hover { text-decoration: none; }

/* Phone-only bar. The sidebar is gone below 960px, so the brand and the
   account need somewhere to live. */
.app-bar {
  display: none; align-items: center; gap: 12px;
  padding: 12px 0 8px;
}
@media (max-width: 960px) { .app-bar { display: flex; } }
.app-bar .brand { font-size: 1.05rem; }

/* Page header ------------------------------------------------------------- */
/* Every screen emits `.topbar`, so restyling it here rather than touching
   thirteen render functions is what makes them all consistent at once. */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 0 0 20px;
  padding: 18px 0 14px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
}
/* The hairline appears only once something has scrolled under it. */
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: var(--line); opacity: 0;
  transition: opacity .2s ease;
}
body.is-scrolled .topbar::after { opacity: 1; }
@media (max-width: 960px) { .topbar { position: static; backdrop-filter: none; padding-top: 8px; } }

.topbar h1 {
  font-size: clamp(1.4rem, 1.1rem + 1.1vw, 1.9rem);
  margin: 0; letter-spacing: -.03em; min-width: 0;
}
.topbar .grow { flex: 1 1 auto; }

/* Mobile tab bar ---------------------------------------------------------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: none; gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
}
@media (max-width: 960px) { .tabbar { display: flex; } .side { display: none; } }
.tabbar a {
  flex: 1 1 0; display: grid; justify-items: center; gap: 3px;
  padding: 8px 4px; border-radius: var(--r-sm); color: var(--muted);
  font-size: .7rem; font-weight: 700; letter-spacing: -.01em;
  transition: color .16s ease, background .16s ease;
}
.tabbar a.is-active { color: var(--brand-ink); background: color-mix(in srgb, var(--brand) 12%, transparent); }
.tabbar a:hover { text-decoration: none; }
.tabbar svg { width: 21px; height: 21px; }

/* The front door --------------------------------------------------------- */
/* No account, no app — the same gate the Android version puts up. The shell's
   navigation is hidden while it is showing, because there is nowhere to go. */

body.is-locked .side,
body.is-locked .tabbar,
body.is-locked .app-bar { display: none; }
body.is-locked .app-shell { grid-template-columns: 1fr; }
body.is-locked .main { padding-top: 0; }

.gate {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px);
  gap: clamp(30px, 5vw, 64px); align-items: center;
  min-height: 100vh; min-height: 100dvh;
  max-width: 1040px; margin: 0 auto; padding: 40px 0;
}
@media (max-width: 900px) {
  .gate { grid-template-columns: 1fr; min-height: 0; padding: 28px 0 60px; align-items: start; }
}

.gate-intro h1 {
  font-size: clamp(1.9rem, 1.3rem + 2.4vw, 2.9rem);
  letter-spacing: -.035em; margin-bottom: .35em;
}
.gate-intro .lede { margin-bottom: 26px; }
.gate-intro .ticks li { font-size: .97rem; }

/* Loading ----------------------------------------------------------------- */

.skeleton { display: grid; gap: 12px; padding-top: 24px; }
.sk {
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, var(--sunken) 25%, var(--card) 37%, var(--sunken) 63%);
  background-size: 400% 100%;
  animation: sk-slide 1.4s ease-in-out infinite;
}
.sk-title { height: 34px; width: min(280px, 60%); border-radius: var(--r-sm); }
.sk-panel { height: 150px; }
.sk-row { height: 74px; }
@keyframes sk-slide {
  from { background-position: 100% 50%; }
  to { background-position: 0 50%; }
}
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }

/* Money position ---------------------------------------------------------- */

.position {
  position: relative; overflow: hidden;
  background: linear-gradient(148deg, var(--panel-a), var(--panel-b));
  color: #fff; border-radius: var(--r-xl); padding: 26px 28px;
  box-shadow: var(--shadow-lg); margin-bottom: 18px;
}
.position::after {
  content: ""; position: absolute; width: 58%; aspect-ratio: 1; right: -10%; top: -36%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, .18), transparent);
  pointer-events: none;
}
.position > * { position: relative; z-index: 1; }
.position .k { font-size: .74rem; letter-spacing: .1em; text-transform: uppercase; opacity: .84; font-weight: 800; }
.position .big { font-size: clamp(2.1rem, 1.4rem + 3vw, 3.1rem); font-weight: 800; letter-spacing: -.04em; margin: 8px 0 20px; }
.position .split2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
/* Darkened, not lightened: a white tint over this gradient raises the ground
   under white text to about 3.4:1. */
.position .sub { background: rgba(16, 7, 52, .24); border-radius: var(--r-md); padding: 12px 16px; }
.position .sub .v { font-size: 1.18rem; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }

/* Toolbar ----------------------------------------------------------------- */
/* Search, filters and sort belong on one band rather than three stacked rows,
   which is what a list screen looks like everywhere else. */

.toolbar {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px;
  background: var(--card); border-radius: var(--r-lg);
  padding: 16px; box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.toolbar-top { display: flex; gap: 12px; align-items: center; min-width: 0; }
@media (max-width: 560px) {
  /* Search and the secondary action stop competing for one row. */
  .toolbar-top { flex-wrap: wrap; }
  .toolbar-top .btn { width: 100%; }
}
.toolbar-top .field { margin: 0; flex: 1 1 auto; min-width: 0; }
.toolbar-bottom {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  flex-wrap: wrap; min-width: 0;
}
.toolbar .count { font-size: .84rem; color: var(--muted); font-weight: 600; white-space: nowrap; }

.search-field { position: relative; }
.search-field svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--muted); pointer-events: none;
}
/* ⚠ **Both classes, or the icon sits on the text.** `.field input` below sets
   the padding shorthand at the same weight and 120 lines later, so it wiped
   this reservation and the placeholder started 14px in — under an icon whose
   right edge is at 32px. Measured at 18px of overlap at every width. */
.field.search-field input { padding-left: 42px; }

.select-quiet {
  font: inherit; color: var(--ink); background: var(--sunken);
  border: 0; border-radius: var(--r-pill); padding: 8px 16px;
  font-size: .9rem; font-weight: 600; cursor: pointer; width: auto;
}

/* Cards and rows ---------------------------------------------------------- */

/* ⚠ `minmax(0, 1fr)`, not the implicit `auto`. A grid track sized `auto` is
   floored at its widest item's min-content width, and a row card holding a long
   account name pushed the whole column past the viewport — a 390px phone laid
   out at 429px, scrolling sideways on every screen built from these. */
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.row-card {
  display: flex; align-items: center; gap: 16px; width: 100%;
  background: var(--card); border: 0; border-radius: var(--r-lg);
  padding: 16px 20px; box-shadow: var(--shadow-sm);
  font: inherit; color: var(--ink); text-align: left; cursor: pointer;
  transition: transform .12s var(--ease-in), box-shadow .2s ease, background .2s ease;
}
.row-card:hover {
  box-shadow: var(--shadow-md); text-decoration: none;
  background: color-mix(in srgb, var(--brand) 3%, var(--card));
}
.row-card:active { transform: scale(.995); }
.row-card .who { flex: 1 1 auto; min-width: 0; }
.row-card .who strong {
  display: block; font-size: 1rem; letter-spacing: -.015em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-card .who span { color: var(--muted); font-size: .86rem; }
.row-card .amount { text-align: right; flex: 0 0 auto; }
.row-card .amount strong { display: block; font-size: 1.04rem; letter-spacing: -.02em; }
.mono { font-variant-numeric: tabular-nums; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: var(--r-pill);
  font-size: .74rem; font-weight: 800; letter-spacing: .01em;
  background: var(--sunken); color: var(--muted);
  white-space: nowrap;
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: var(--r-pill); background: currentColor; flex: 0 0 auto; }
/* Status colours are fills. As a label on a tint of themselves they fall to
   about 2.5:1, so the text takes the ink pair instead. */
.pill.paid { color: var(--paid-ink); background: color-mix(in srgb, var(--paid) 16%, transparent); }
.pill.late { color: var(--late-ink); background: color-mix(in srgb, var(--late) 16%, transparent); }
.pill.draft { color: var(--draft-ink); background: color-mix(in srgb, var(--draft) 20%, transparent); }
.pill.sent { color: var(--brand-ink); background: color-mix(in srgb, var(--brand) 14%, transparent); }
.pill.void { color: var(--muted); text-decoration: line-through; }

.row-go { color: var(--muted); font-size: 1.3rem; line-height: 1; flex: 0 0 auto; }
.setup-nudge { background: color-mix(in srgb, var(--brand) 8%, var(--card)); }

/* Filters ----------------------------------------------------------------- */

.chips {
  display: flex; gap: 4px; overflow-x: auto; padding: 4px;
  scrollbar-width: none; margin: 0;
  background: var(--sunken); border-radius: var(--r-pill);
  /* Without this the row of chips sets the page width instead of scrolling
     inside itself, and a phone ends up 180px wider than the screen. */
  min-width: 0; max-width: 100%; flex: 1 1 auto;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 16px; border-radius: var(--r-pill); font: inherit; font-size: .88rem;
  font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: background .18s ease, color .18s ease;
}
.chip:hover { color: var(--ink); }
.chip.is-on { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }

/* Empty states ------------------------------------------------------------ */

.empty {
  background: var(--card); border-radius: var(--r-lg); padding: 48px 26px;
  text-align: center; box-shadow: var(--shadow-sm);
}
.empty-art {
  width: 66px; height: 66px; border-radius: 20px; margin: 0 auto 18px;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: var(--brand-ink);
}
.empty-art svg { width: 30px; height: 30px; }
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--muted); margin: 0 auto 20px; max-width: 46ch; }

.fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 30;
  box-shadow: var(--shadow-brand);
}
/* On a desktop the sidebar already carries the primary action, so a floating
   one is a second button for the same job. */
@media (min-width: 961px) { .fab { display: none; } }
@media (max-width: 960px) { .fab { bottom: calc(76px + env(safe-area-inset-bottom)); } }

/* Card headings ----------------------------------------------------------- */
/* Screens put an <h3> at the top of a card and prose under it. Spacing that
   pair here means thirteen render functions do not each pick their own. */

.card > h3 { margin-bottom: .5em; letter-spacing: -.02em; }
.card > h3 + p { margin-top: -.2em; }
.card.form > h3 { margin-bottom: 0; }

/* Section headings inside a screen ---------------------------------------- */

.section-title {
  display: flex; align-items: center; gap: 12px;
  margin: 26px 0 12px; color: var(--muted);
  font-size: .74rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
}
.section-title::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--line); }

/* Forms ------------------------------------------------------------------- */

.form { display: grid; gap: 16px; }
.form .field { margin: 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 620px) { .form-row { grid-template-columns: 1fr; } }
.field label { font-weight: 700; font-size: .88rem; letter-spacing: -.01em; }
.field .hint { font-size: .82rem; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; color: var(--ink); background: var(--sunken);
  border: 0; border-radius: var(--r-sm); padding: 12px 14px; width: 100%;
  font-variant-numeric: tabular-nums;
  transition: box-shadow .16s ease, background .16s ease;
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: .8; }
.field input:hover, .field select:hover, .field textarea:hover {
  background: color-mix(in srgb, var(--brand) 5%, var(--sunken));
}
/* An inset ring rather than an outline, so a focused field does not grow and
   shove the row beside it. */
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: none; box-shadow: inset 0 0 0 2px var(--brand);
  background: var(--card);
}
.field input[type="date"] { min-height: 46px; }
.field .error { color: var(--late-ink); font-size: .84rem; font-weight: 600; }
.switch { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.switch input { width: 44px; height: 26px; accent-color: var(--brand); flex: 0 0 auto; }

/* Line editor ------------------------------------------------------------- */

.line {
  background: var(--card); border-radius: var(--r-lg); padding: 16px;
  box-shadow: var(--shadow-sm); display: grid; gap: 10px;
}
.line .top { display: flex; gap: 10px; align-items: flex-start; }
/* The description sits outside a `.field`, so it never picked up the field look
   and rendered as the browser's own grey box beside two styled inputs. */
.line .top input {
  flex: 1 1 auto; min-width: 0;
  font: inherit; color: var(--ink); background: var(--sunken);
  border: 0; border-radius: var(--r-sm); padding: 12px 14px;
  transition: box-shadow .16s ease, background .16s ease;
}
.line .top input::placeholder { color: var(--muted); opacity: .8; }
.line .top input:hover { background: color-mix(in srgb, var(--brand) 5%, var(--sunken)); }
.line .top input:focus-visible {
  outline: none; box-shadow: inset 0 0 0 2px var(--brand); background: var(--card);
}

/* Tax on a line, one tap away rather than behind the tune button. */
.chip-btn {
  border: 0; background: var(--sunken); color: var(--muted); font: inherit;
  font-size: .86rem; font-weight: 700; border-radius: 999px; padding: 0 14px;
  height: 40px; cursor: pointer; white-space: nowrap; flex: 0 0 auto;
}
.chip-btn:hover { color: var(--ink); }
.chip-btn.is-on { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand-ink); }
.totals-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Whose records these are, above every screen until somebody decides. */
.sync-alert {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin: 0 0 16px; padding: 14px 16px; border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--late-ink) 14%, var(--card)); color: var(--ink);
}
.sync-alert strong { display: block; }
.sync-alert .grow { flex: 1 1 240px; }

/* `.icon-link` and `.inline` moved to base.css: the sign-in panel needs them
   and the public page loads that sheet only. */

/* A person or a business. */
.kind-choice { display: flex; gap: 8px; }
.kind-choice label {
  flex: 1 1 0; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 12px; border-radius: var(--r-sm); background: var(--sunken);
  cursor: pointer; font-weight: 600;
}
/* The radios sit inside a `.field`, whose input rule gives every input full
   width and padding: the circle took the row and pushed "A person" onto two
   lines. */
.kind-choice label { white-space: nowrap; }
.kind-choice input {
  width: auto; padding: 0; margin: 0; background: none; flex: 0 0 auto;
  accent-color: var(--brand);
}
.line .qty { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
.line .extras {
  display: grid; gap: 10px; padding-top: 12px; margin-top: 2px;
  border-top: 1px dashed var(--line);
}
.line .tot { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }

.icon-btn {
  border: 0; background: var(--sunken); color: var(--muted);
  width: 40px; height: 40px; border-radius: var(--r-sm); cursor: pointer;
  display: grid; place-items: center; flex: 0 0 auto;
  transition: background .16s ease, color .16s ease;
}
.icon-btn.is-on { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand-ink); }
.icon-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--brand) 10%, var(--sunken)); }
.icon-btn svg { width: 18px; height: 18px; }

.totals-box {
  background: var(--card); border-radius: var(--r-lg); padding: 18px 20px;
  box-shadow: var(--shadow-sm); display: grid; gap: 8px;
}
.totals-box .t { display: flex; justify-content: space-between; gap: 16px; font-variant-numeric: tabular-nums; font-size: .95rem; }
.totals-box .t.grand {
  font-size: 1.25rem; font-weight: 800; letter-spacing: -.03em;
  padding-top: 12px; margin-top: 4px; border-top: 1px solid var(--line);
}
.totals-box .t span:first-child { color: var(--muted); }
.totals-box .t.grand span:first-child { color: var(--ink); }

/* Sheets and dialogs ------------------------------------------------------ */

dialog.sheet {
  border: 0; padding: 0; background: transparent;
  max-width: 560px; width: calc(100% - 28px);
  color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(12, 8, 26, .55); backdrop-filter: blur(3px); }
dialog.sheet .sheet-body {
  background: var(--card); border-radius: var(--r-xl); padding: 26px;
  box-shadow: var(--shadow-lg); max-height: min(86vh, 900px); overflow: auto;
}
dialog.sheet h2 { font-size: 1.3rem; letter-spacing: -.03em; }
dialog.sheet .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
dialog.sheet[open] { animation: sheet-in .22s var(--ease-in); }
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(10px) scale(.99); }
  to { opacity: 1; transform: none; }
}
/* On a phone it comes up from the bottom, which is where a thumb is. */
@media (max-width: 620px) {
  dialog.sheet { margin: auto auto 0; width: 100%; max-width: none; }
  dialog.sheet .sheet-body {
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding-bottom: calc(26px + env(safe-area-inset-bottom));
  }
  dialog.sheet[open] { animation: sheet-up .24s var(--ease-in); }
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--page); padding: 12px 20px;
  border-radius: var(--r-pill); box-shadow: var(--shadow-md); z-index: 60;
  font-weight: 600; font-size: .94rem; max-width: min(90vw, 520px);
  animation: toast-in .22s var(--ease-in);
}
.toast.bad { background: var(--late-ink); color: #fff; }
@media (max-width: 960px) { .toast { bottom: calc(88px + env(safe-area-inset-bottom)); } }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* Reports ----------------------------------------------------------------- */

.stat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
@media (max-width: 700px) { .stat-row { grid-template-columns: 1fr; } }

/* The document ------------------------------------------------------------ */
.doc {
  background: #fff; color: #14121c; border-radius: var(--r-lg);
  padding: 40px; box-shadow: var(--shadow-md); max-width: 820px;
  font-variant-numeric: tabular-nums;
}
.doc h2, .doc h3 { color: #14121c; }
.doc .doc-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.doc .doc-title { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.doc .muted2 { color: #6a6480; }
.doc table { width: 100%; border-collapse: collapse; margin: 26px 0 0; min-width: 0; }
.doc th, .doc td { padding: 9px 8px; border-bottom: 1px solid #e9e4f4; font-size: .92rem; text-align: left; }
.doc th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: #6a6480; }
.doc td.num, .doc th.num { text-align: right; }
.doc .doc-totals { margin-left: auto; width: min(320px, 100%); margin-top: 18px; }
.doc .doc-totals .t { display: flex; justify-content: space-between; padding: 5px 8px; }
.doc .doc-totals .t.grand { font-weight: 800; font-size: 1.1rem; border-top: 2px solid #14121c; margin-top: 6px; padding-top: 10px; }
.doc .pay {
  margin-top: 26px; padding: 16px 18px; border-radius: 14px;
  background: #f4f0ff; display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
}
.doc .pay a { font-weight: 700; }
.doc .qr { flex: 0 0 auto; background: #fff; padding: 6px; border-radius: 8px; line-height: 0; }
.doc .qr svg { display: block; width: 108px; height: 108px; }
.doc-logo { max-height: 64px; max-width: 220px; margin-bottom: 14px; }
.logo-preview {
  max-height: 48px; max-width: 140px; background: var(--sunken);
  border-radius: var(--r-sm); padding: 8px;
}
.sync-status { display: block; margin-top: 6px; font-size: .78rem; }
.sync-status.bad { color: var(--late); }
.doc .mark { margin-top: 30px; text-align: center; color: #8a83a3; font-size: .78rem; }
.doc-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }

/* Simple and Pro -----------------------------------------------------------

   Two shapes of one app. The choice is a pair of large targets rather than a
   switch, because "Simple / Pro" is not an on and an off — both are a real
   answer, and a switch would make one of them read as the broken one. */

.mode-choices {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 16px;
}
@media (max-width: 620px) { .mode-choices { grid-template-columns: minmax(0, 1fr); } }

.mode-choice {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 15px 16px;
  border: 2px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease, transform .12s var(--ease-in);
}
.mode-choice:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.mode-choice:active { transform: scale(.99); }
.mode-choice strong { font-size: 1rem; letter-spacing: -.015em; }
.mode-choice span { font-size: .84rem; color: var(--muted); }
.mode-choice.is-on {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 7%, var(--card));
}
/* The chosen one says so in words as well as in colour — a border is the only
   signal otherwise, and that is the one thing a colour-blind reader cannot use. */
.mode-choice.is-on strong::after {
  content: " · on";
  color: var(--brand-ink);
  font-weight: 800;
}

/* The sidebar's mode switch. A real switch rather than a link, because the
   thing it does is binary and somebody has to be able to see which way it is
   set without reading a sentence. */
.mode-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--brand) 26%, transparent);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--brand) 8%, var(--card));
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .12s var(--ease-in);
}
.mode-pill:hover { background: color-mix(in srgb, var(--brand) 14%, var(--card)); }
.mode-pill:active { transform: scale(.99); }
.mode-pill-dot {
  width: 8px; height: 8px; flex: 0 0 auto;
  border-radius: var(--r-pill);
  background: var(--muted);
}
.mode-pill.is-pro { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 15%, var(--card)); }
.mode-pill.is-pro .mode-pill-dot { background: var(--paid); }
.mode-pill-text { display: grid; gap: 1px; min-width: 0; flex: 1 1 auto; }
.mode-pill-text strong { font-size: .88rem; letter-spacing: -.01em; }
.mode-pill-text span { font-size: .74rem; color: var(--muted); }
.mode-pill-switch {
  width: 34px; height: 20px; flex: 0 0 auto;
  border-radius: var(--r-pill);
  background: var(--line);
  position: relative;
  transition: background .18s ease;
}
.mode-pill-switch i {
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: var(--r-pill);
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: transform .18s var(--ease-in);
}
.mode-pill.is-pro .mode-pill-switch { background: var(--brand); }
.mode-pill.is-pro .mode-pill-switch i { transform: translateX(14px); }
@media (prefers-reduced-motion: reduce) {
  .mode-pill, .mode-pill-switch, .mode-pill-switch i { transition: none; }
}

/* The strip a Pro screen wears when Simple mode is on. */
.mode-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 13px 16px;
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--brand) 10%, var(--card));
  border: 1px solid color-mix(in srgb, var(--brand) 24%, transparent);
}
.mode-strip.is-warn {
  background: color-mix(in srgb, var(--draft) 14%, var(--card));
  border-color: color-mix(in srgb, var(--draft) 42%, transparent);
}
.mode-strip > div { display: grid; gap: 2px; min-width: 0; flex: 1 1 260px; }
.mode-strip strong { font-size: .94rem; }
.mode-strip span { font-size: .85rem; color: var(--muted); }

.nudge {
  margin-top: 18px;
  background: color-mix(in srgb, var(--brand) 6%, var(--card));
  border: 1px solid color-mix(in srgb, var(--brand) 20%, transparent);
}

/* The books ---------------------------------------------------------------

   Two families of table live here and they are not the same thing.

   `.report-table` sits inside `.doc`, which is paper: white in both themes,
   because a profit and loss is printed or handed over and paper does not have
   a dark mode. It inherits `.doc table` and only adds the row kinds a financial
   statement needs — a section heading, a subtotal, a total, a grand total.

   `.ledger-table` on its own is a screen table (the journal entry, the
   reconciliation) and follows the app's tokens like everything else. */

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.ledger-table th, .ledger-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: .92rem;
  vertical-align: top;
}
.ledger-table thead th {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 700;
}
.ledger-table td.num, .ledger-table th.num { text-align: right; white-space: nowrap; }
.ledger-table tfoot th {
  border-bottom: none;
  border-top: 2px solid var(--ink);
  font-weight: 800;
}
.ledger-table tbody tr:last-child td { border-bottom: none; }

/* Inside the document the hairlines are the paper ones, not the theme's. */
.report-doc .ledger-table th, .report-doc .ledger-table td { border-bottom-color: #e9e4f4; }
.report-doc .ledger-table thead th { color: #6a6480; }
.report-doc .ledger-table tfoot th { border-top-color: #14121c; }

/* A statement reads top to bottom in four weights: the heading over a group,
   the accounts in it, the group's own total, and the one figure the whole page
   exists to give. Anything less and a reader has to add up the page themselves
   to find out which line is the answer. */
.report-table tr.section th {
  padding-top: 22px;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6a6480;
  font-weight: 800;
  border-bottom: 1px solid #e9e4f4;
}
.report-table tr.section .muted2 { text-transform: none; letter-spacing: 0; font-weight: 600; }
.report-table tr.section:first-child th { padding-top: 4px; }
.report-table tr.subtotal td { font-weight: 700; border-top: 1px solid #e9e4f4; }
.report-table tr.total td {
  font-weight: 800;
  border-top: 2px solid #cfc6e6;
  border-bottom: none;
  padding-top: 12px;
}
.report-table tr.grand td {
  font-weight: 800;
  font-size: 1.12rem;
  border-top: 2px solid #14121c;
  border-bottom: none;
  padding-top: 14px;
}
.report-doc { margin-top: 18px; }

/* The period controls sit above the paper, not on it — they are the reader's
   controls, and printing them would put a row of buttons on a filed report. */
.report-periods { margin-bottom: 10px; }
.report-range {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.report-range label {
  display: grid;
  gap: 4px;
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
}
.report-range input {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  min-height: 42px;
}
.report-range input:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* Chart of accounts. One card per class, so the five classes read as five
   things rather than one long list of sixty accounts. */
.account-group { margin-bottom: 16px; }
.account-group .row-card { cursor: pointer; }
.account-group .amount { text-align: right; white-space: nowrap; }

.journal-row .amount { text-align: right; display: grid; gap: 2px; white-space: nowrap; }

/* A journal line is account, debit, credit, remove — in that order, because
   that is the order every accounting package has used since paper. */
.journal-line {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.journal-line select, .journal-line input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  min-height: 44px;
}
.journal-line select:focus-visible, .journal-line input:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
@media (max-width: 620px) {
  /* The remove button keeps its own row rather than squeezing three controls
     into a phone's width and making every one of them unusable. */
  .journal-line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .journal-line select { grid-column: 1 / -1; }
  .journal-line .icon-btn { grid-column: 1 / -1; justify-self: end; }
}

/* Reconciliation. */
.reconcile-head { margin-bottom: 16px; }
.reconcile-table td:first-child, .reconcile-table th:first-child { width: 44px; }
.reconcile-table input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brand); }
.reconcile-table tbody tr:hover { background: var(--sunken); }

/* The one figure a reconciliation is for: zero, or not. */
.ok { color: var(--paid-ink); }

@media (max-width: 620px) {
  .report-doc { padding: 22px 18px; }
  .ledger-table th, .ledger-table td { padding: 8px 4px; font-size: .86rem; }
  .report-table tr.grand td { font-size: 1rem; }
}

/* The document's tax block ---------------------------------------------------

   ⚠ A tax authority wants the tax stated as its own statement, not implied by
   a column. A UAE tax invoice — the format the Android renderer was measured
   against — prints the taxable amount and the tax charged **per rate** under
   their own headings. That is the part somebody transcribes onto a return, and
   hunting for it inside a totals column is how it gets transcribed wrong. Zero
   rates are printed too: a zero-rated sale still has to be declared as one. */
.doc .tax-summary {
  margin-top: 26px;
  border: 1px solid #e9e4f4;
  border-radius: 12px;
  padding: 16px 18px;
  max-width: 460px;
}
.doc .tax-summary-title {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6a6480;
  font-weight: 800;
}
.doc .tax-summary table { margin-top: 8px; }
.doc .tax-summary th, .doc .tax-summary td { padding: 6px 0; font-size: .88rem; }
.doc .tax-summary tfoot th { border-bottom: none; border-top: 1px solid #14121c; font-weight: 800; }

/* A wide tax invoice can carry ten columns. It scrolls inside its own box
   rather than setting the width of the page around it. */
.doc-table-scroll { overflow-x: auto; }
.doc-table-scroll table { min-width: 0; }

/* The stamp. A word in the corner, never a watermark across the page: this
   document goes to the owner's paying customer, and defacing it would embarrass
   them rather than tell them anything. */
.doc.has-stamp { position: relative; }
.doc.has-stamp::after {
  content: attr(data-stamp);
  position: absolute;
  top: 26px;
  right: 30px;
  padding: 5px 14px;
  border: 2px solid currentColor;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #8a83a3;
  pointer-events: none;
}
.doc.has-stamp[data-stamp="Paid"]::after { color: #0C7A5A; }
.doc.has-stamp[data-stamp="Overdue"]::after { color: #C42340; }
.doc.has-stamp[data-stamp="Cancelled"]::after { color: #8a83a3; text-decoration: line-through; }
@media (max-width: 620px) {
  .doc.has-stamp::after { top: 14px; right: 14px; font-size: .7rem; }
}

/* The first run -------------------------------------------------------------
   The wizard is a sheet rather than a route: every answer is written at the
   end, so there is no half-finished state a refresh could land in. */

dialog.setup-sheet { max-width: 520px; }
.setup-body { display: grid; gap: 18px; }

.setup-head { display: flex; align-items: center; gap: 12px; }
.setup-dots { display: flex; gap: 6px; flex: 1 1 auto; }
.setup-dots i {
  width: 7px; height: 7px; border-radius: 999px; background: var(--line);
  transition: background .2s, width .2s;
}
.setup-dots i.is-on { background: var(--brand); width: 20px; }

/* A fixed floor, so Next does not walk up and down the screen between a step
   with two fields on it and one with a chip for every currency. */
.setup-step { display: grid; gap: 16px; min-height: 320px; align-content: start; }

.setup-intro { display: grid; gap: 6px; }
.setup-emoji { font-size: 2.4rem; line-height: 1; }
.setup-intro h2 { font-size: 1.45rem; letter-spacing: -.03em; margin: 0; }
.setup-intro p { margin: 0; }
.setup-sub { font-size: .88rem; font-weight: 700; margin: 0; }

/* Wraps rather than scrolls: forty-two currencies in a one-line strip is a
   list somebody has to drag through to find their own. */
.setup-chips { display: flex; flex-wrap: wrap; gap: 8px; max-height: 210px; overflow: auto; }

.setup-logo { display: grid; gap: 14px; justify-items: center; text-align: center; }
.setup-avatar { width: 84px; height: 84px; border-radius: var(--r-lg); font-size: 1.6rem; }
.setup-logo .logo-preview { max-height: 84px; max-width: 200px; }

.setup-preview { display: grid; gap: 10px; }
.setup-letterhead { display: flex; align-items: center; gap: 12px; }
.setup-letterhead .grow { flex: 1 1 auto; min-width: 0; display: grid; }
.setup-letterhead strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.setup-letterhead .logo-preview.sm { max-height: 40px; max-width: 96px; padding: 4px; }
.setup-preview .t {
  display: flex; justify-content: space-between; gap: 16px;
  font-variant-numeric: tabular-nums; font-size: .95rem;
}
.setup-preview .t span:first-child { color: var(--muted); }
.setup-preview .t.grand {
  border-top: 1px solid var(--line); padding-top: 10px; margin-top: 2px;
  font-weight: 800; font-size: 1.1rem;
}
.setup-preview .t.grand span:first-child { color: var(--ink); }

.setup-foot { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.setup-foot [data-back] { margin-right: auto; }
/* `.btn` sets `display: inline-flex`, which beats the browser's own rule for
   `hidden` — the same reason `.icon-link[hidden]` has to say it out loud. */
.setup-foot [hidden] { display: none; }
.setup-foot [data-next] { min-width: 140px; justify-content: center; }

@media (max-width: 620px) {
  .setup-step { min-height: 0; }
  .setup-chips { max-height: none; }
  .setup-foot [data-next] { flex: 1 1 auto; }
}

@page { margin: 14mm; }

@media print {
  .side, .tabbar, .topbar, .app-bar, .doc-actions, .fab, .wa-float, .toast, .toolbar,
  .report-periods, .report-range { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .app-shell { display: block; }
  .doc { box-shadow: none; border-radius: 0; padding: 0; max-width: none; color: #000; }
  /* A table row split across a page break is how a line item ends up printed
     twice, half at the bottom and half at the top. */
  .doc tr, .doc .pay, .doc .doc-totals, .doc .tax-summary { break-inside: avoid; page-break-inside: avoid; }
  /* On paper there is nowhere to scroll to, so the box must not clip. */
  .doc-table-scroll { overflow: visible; }
  .doc thead { display: table-header-group; }
  .card, .position, .row-card, .toolbar { box-shadow: none; }
  #view { max-width: none; }
  a[href]::after { content: ''; }
}

/* Sign-in moved to base.css — the same panel is used by /sign-in on the
   public site, and two copies of it would drift. */
