/* NVBF Pocket Office: design system and app shell.
   Order: fonts, tokens (light, then dark twice), base, shell, components, map hooks, utilities.
   Components use tokens only. Class names are documented in js/ui.js (header comment). */

/* ---------- Fonts (vendored, OFL) ---------- */

@font-face {
  font-family: "Barlow Condensed";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/barlow-condensed-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Barlow Condensed";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/barlow-condensed-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Barlow Condensed";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/barlow-condensed-latin-700-normal.woff2") format("woff2");
}

/* ---------- Tokens ---------- */

:root {
  --bg: #EEF0EF;
  --surface: #FFFFFF;
  --surface-2: #F6F7F6;
  --ink: #15171A;
  --ink-2: #565D64;
  --line: #D6DAD9;
  --line-strong: #8A9290;
  --accent: #E8650A;
  --accent-ink: #9A3F00;
  --accent-bg: #FDEEE2;
  --btn: #15171A;
  --btn-ink: #FFFFFF;
  --ok: #1E7B45;
  --info: #2457C5;
  --warn: #A15C00;
  --bad: #B42318;
  --on-bad: #FFFFFF;
  --ok-bg: #E4F2E9;
  --info-bg: #E6EDFB;
  --warn-bg: #FBF0DC;
  --bad-bg: #FBE8E6;
  --stripe-2: #FFFFFF;
  --glass: rgb(255 255 255 / 0.88);
  --scrim: rgb(15 17 19 / 0.45);
  --shadow-1: 0 1px 2px rgb(21 23 26 / 0.06);
  --shadow-2: 0 16px 40px rgb(21 23 26 / 0.18), 0 2px 8px rgb(21 23 26 / 0.08);
  --shadow-up: 0 -6px 18px rgb(21 23 26 / 0.07);
  --logo-filter: none;
  color-scheme: light;

  --font-display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius-card: 12px;
  --radius-ctl: 10px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  --col: 640px;
  --col-wide: 960px;
  --screen-pb: 32px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1113;
    --surface: #181B1E;
    --surface-2: #1F2327;
    --ink: #EEF0F2;
    --ink-2: #A0A7AE;
    --line: #2B3035;
    --line-strong: #646C73;
    --accent: #FF8A2A;
    --accent-ink: #FFB27A;
    --accent-bg: #33200F;
    --btn: #EEF0F2;
    --btn-ink: #0F1113;
    --ok: #5CCB8A;
    --info: #86A8FF;
    --warn: #F2B35B;
    --bad: #FF7B72;
    --on-bad: #0F1113;
    --ok-bg: #13291C;
    --info-bg: #17223D;
    --warn-bg: #2C210F;
    --bad-bg: #341715;
    --stripe-2: #181B1E;
    --glass: rgb(24 27 30 / 0.88);
    --scrim: rgb(0 0 0 / 0.6);
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-2: 0 16px 40px rgb(0 0 0 / 0.55), 0 2px 8px rgb(0 0 0 / 0.3);
    --shadow-up: 0 -6px 18px rgb(0 0 0 / 0.35);
    --logo-filter: invert(1);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0F1113;
  --surface: #181B1E;
  --surface-2: #1F2327;
  --ink: #EEF0F2;
  --ink-2: #A0A7AE;
  --line: #2B3035;
  --line-strong: #646C73;
  --accent: #FF8A2A;
  --accent-ink: #FFB27A;
  --accent-bg: #33200F;
  --btn: #EEF0F2;
  --btn-ink: #0F1113;
  --ok: #5CCB8A;
  --info: #86A8FF;
  --warn: #F2B35B;
  --bad: #FF7B72;
  --on-bad: #0F1113;
  --ok-bg: #13291C;
  --info-bg: #17223D;
  --warn-bg: #2C210F;
  --bad-bg: #341715;
  --stripe-2: #181B1E;
  --glass: rgb(24 27 30 / 0.88);
  --scrim: rgb(0 0 0 / 0.6);
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-2: 0 16px 40px rgb(0 0 0 / 0.55), 0 2px 8px rgb(0 0 0 / 0.3);
  --shadow-up: 0 -6px 18px rgb(0 0 0 / 0.35);
  --logo-filter: invert(1);
  color-scheme: dark;
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, ul, ol, dl, figure {
  margin: 0;
}

ul, ol {
  padding: 0;
  list-style: none;
}

img {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent-ink);
}

[hidden] {
  display: none !important;
}

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

.icon {
  flex: none;
  display: inline-block;
  vertical-align: middle;
}

/* ---------- Boot splash and noscript (static in index.html) ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: var(--bg);
  text-align: center;
}

.boot.is-leaving {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.boot__logo {
  display: block;
  height: 30px;
  width: auto;
  filter: var(--logo-filter);
}

.boot__stripe {
  display: block;
  width: 84px;
  height: 4px;
  background: repeating-linear-gradient(45deg, var(--accent) 0 7px, var(--stripe-2) 7px 14px);
}

.boot__text {
  color: var(--ink-2);
  font-size: 15px;
}

.boot__slow {
  max-width: 30ch;
  color: var(--ink-2);
  font-size: 14px;
  opacity: 0;
  animation: fade-in 0.3s ease 8s forwards;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  color: var(--ink);
  text-align: center;
  font-weight: 600;
}

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

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.appbar {
  flex: none;
  position: relative;
  z-index: 10;
  background: var(--surface);
  padding-top: env(safe-area-inset-top, 0px);
}

/* Signature detail: barricade stripe under the bar */
.appbar::after {
  content: "";
  display: block;
  height: 4px;
  background: repeating-linear-gradient(45deg, var(--accent) 0 7px, var(--stripe-2) 7px 14px);
}

.appbar__inner {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 0 var(--gutter-r) 0 var(--gutter-l);
}

.appbar__brand {
  flex: none;
  display: flex;
  align-items: center;
  height: 28px;
  padding-right: 12px;
  margin-right: 12px;
  border-right: 1px solid var(--line);
}

.appbar__logo {
  display: block;
  height: 22px;
  width: auto;
  filter: var(--logo-filter);
}

.appbar__bar {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.appbar__back {
  margin-left: -10px;
}

.appbar__title {
  flex: 1 1 auto;
  min-width: 0;
  font: 600 24px/1.1 var(--font-display);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appbar__action {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: -6px;
}

.appbar__action:empty {
  display: none;
}

.appbar.has-back .appbar__brand {
  display: none;
}

.app--bare .appbar__brand {
  border-right: 0;
}

.main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 16px var(--gutter-r) 0 var(--gutter-l);
}

.main:has(.sticky-actions) {
  scroll-padding-bottom: 96px;
}

.banners {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: var(--col);
  margin: 0 auto 16px;
}

.banners:empty {
  display: none;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: var(--col);
  margin: 0 auto;
  padding-bottom: var(--screen-pb);
}

.screen--wide {
  max-width: var(--col-wide);
}

/* Shown only when a screen takes a moment to load (no spinner) */
.screen-wait {
  padding: 48px 0;
  color: var(--ink-2);
  text-align: center;
  animation: fade-in 0.3s ease;
}

.main:has(.screen--wide) .banners {
  max-width: var(--col-wide);
}

/* Bottom tab bar (phone) */
.tabbar {
  flex: none;
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 0 var(--gutter-r) calc(8px + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
}

.tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  max-width: 168px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 2px 2px;
  margin: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font: 600 12px/1.1 var(--font-body);
  letter-spacing: 0.01em;
  cursor: pointer;
  touch-action: manipulation;
}

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

.tab[aria-current="page"] {
  color: var(--ink);
}

.tab[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 50%;
  width: 44px;
  height: 3px;
  margin-left: -22px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}

.tab:focus-visible {
  outline-offset: -4px;
  border-radius: var(--radius-ctl);
}

body.keyboard-open .tabbar {
  display: none;
}

/* "Update ready" bar sits above the tab bar */
.update-bar {
  flex: none;
  position: relative;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 10px var(--gutter-r) 10px var(--gutter-l);
  border: 0;
  background: var(--btn);
  color: var(--btn-ink);
  font: 400 15px/1.3 var(--font-body);
  cursor: pointer;
  animation: slide-up 0.25s var(--ease);
}

.update-bar strong {
  font-weight: 700;
}

.update-bar:disabled {
  cursor: progress;
  opacity: 0.85;
}

/* Tablet portrait: keep the bar's logo and title over the centered column */
@media (min-width: 680px) and (max-width: 899px) {
  .appbar__inner {
    max-width: calc(var(--col) + 32px);
    margin: 0 auto;
  }

  .app:has(.screen--wide) .appbar__inner {
    max-width: calc(var(--col-wide) + 32px);
  }
}

/* Desktop: logo top-left, tab bar becomes a left rail, content column centered */
@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .appbar {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .appbar__inner {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    min-height: 64px;
    padding: 0;
  }

  .appbar__brand,
  .appbar.has-back .appbar__brand {
    display: flex;
    height: auto;
    padding: 0 24px;
    margin: 0;
    border-right: 0;
  }

  .appbar__logo {
    height: 26px;
  }

  .appbar__bar {
    width: 100%;
    max-width: calc(var(--col) + 48px);
    margin: 0 auto;
    padding: 0 24px;
  }

  .app:has(.screen--wide) .appbar__bar {
    max-width: calc(var(--col-wide) + 48px);
  }

  .appbar__title {
    font-size: 28px;
  }

  .main {
    grid-column: 2;
    grid-row: 2;
    padding: 28px 24px 0;
    scrollbar-gutter: stable both-edges;
  }

  .update-bar {
    grid-column: 2;
    grid-row: 3;
  }

  .app--bare .main {
    grid-column: 1 / -1;
  }

  .tabbar,
  body.keyboard-open .tabbar {
    grid-column: 1;
    grid-row: 2 / 4;
    display: flex;
    flex-direction: column;
    gap: 4px;
    justify-content: flex-start;
    padding: 20px 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .tab {
    flex: none;
    max-width: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-height: 48px;
    padding: 0 14px;
    border-radius: var(--radius-ctl);
    font-size: 16px;
  }

  .tab[aria-current="page"] {
    background: var(--surface-2);
  }

  .tab[aria-current="page"]::before {
    top: 12px;
    bottom: 12px;
    left: 0;
    width: 3px;
    height: auto;
    margin: 0;
    border-radius: 0 3px 3px 0;
  }

  @media (hover: hover) {
    .tab:hover {
      color: var(--ink);
      background: var(--surface-2);
    }
  }
}

/* ---------- Buttons ---------- */

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-bd: var(--line-strong);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  margin: 0;
  padding: 0 18px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-ctl);
  font: 600 16px/1.2 var(--font-body);
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s, transform 0.06s;
}

.btn__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn--primary {
  --btn-bg: var(--btn);
  --btn-fg: var(--btn-ink);
  --btn-bd: var(--btn);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-bd: transparent;
  padding: 0 12px;
}

.btn--danger {
  --btn-bg: var(--bad-bg);
  --btn-fg: var(--bad);
  --btn-bd: var(--bad-bg);
}

.btn--danger.btn--solid {
  --btn-bg: var(--bad);
  --btn-fg: var(--on-bad);
  --btn-bd: var(--bad);
}

.btn--full {
  display: flex;
  width: 100%;
}

.btn--sm {
  min-height: 44px;
  padding: 0 14px;
  font-size: 15px;
}

.btn--ghost.btn--sm {
  padding: 0 10px;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
  opacity: 0.86;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.btn[aria-busy="true"] {
  cursor: progress;
  opacity: 0.75;
}

@media (hover: hover) {
  .btn--secondary:hover:not(:disabled),
  .btn--ghost:hover:not(:disabled) {
    background: var(--surface-2);
  }
  .btn--primary:hover:not(:disabled) {
    opacity: 0.9;
  }
}

.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-ctl);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn--filled {
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

.icon-btn:active:not(:disabled) {
  background: var(--surface-2);
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

@media (hover: hover) {
  .icon-btn:hover:not(:disabled) {
    background: var(--surface-2);
  }
}

/* Small busy indicator inside a button (only while a task runs) */
.btn-spin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}

/* ---------- Fields and inputs ---------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field__label {
  font: 600 14px/1.3 var(--font-body);
  color: var(--ink);
}

.field__hint {
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink-2);
}

.field__error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--bad);
}

.field__error .icon {
  margin-top: 1px;
}

.input {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-ctl);
  font: 400 16px/1.3 var(--font-body);
  appearance: none;
  -webkit-appearance: none;
}

.input::placeholder {
  color: var(--ink-2);
  opacity: 0.75;
}

.input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.input[aria-invalid="true"],
.input-wrap:has(.input[aria-invalid="true"]) {
  border-color: var(--bad);
}

.input[readonly] {
  background: var(--surface-2);
}

.input--num {
  font-variant-numeric: tabular-nums;
}

textarea.input {
  min-height: 96px;
  padding: 12px 14px;
  line-height: 1.45;
  resize: vertical;
}

/* Input with "$" prefix or "ft" suffix */
.input-wrap {
  display: flex;
  align-items: center;
  min-height: 48px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-ctl);
  cursor: text;
}

.input-wrap > .input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 46px;
  border: 0;
  border-radius: var(--radius-ctl);
  background: transparent;
}

.input-wrap > .input:focus-visible {
  outline: none;
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.input-wrap__prefix,
.input-wrap__suffix {
  flex: none;
  color: var(--ink-2);
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.input-wrap__prefix {
  padding-left: 14px;
}

.input-wrap__prefix + .input {
  padding-left: 4px;
}

.input-wrap__suffix {
  padding-right: 14px;
}

.input:has(+ .input-wrap__suffix) {
  padding-right: 6px;
}

/* Stepper: - 2 + */
.stepper {
  display: inline-flex;
  align-items: stretch;
  height: 48px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-ctl);
  overflow: hidden;
}

.field > .stepper {
  align-self: flex-start;
}

.stepper__btn {
  flex: none;
  width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

.stepper__btn:active:not(:disabled) {
  background: var(--line);
}

.stepper__btn:disabled {
  cursor: not-allowed;
  color: var(--ink-2);
  opacity: 0.45;
}

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

.stepper__value {
  flex: 1 1 68px;
  width: 68px;
  min-width: 44px;
  margin: 0;
  padding: 0 4px;
  border: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  text-align: center;
  font: 600 24px/1 var(--font-display);
  font-variant-numeric: tabular-nums;
  appearance: none;
  -webkit-appearance: none;
}

/* Segmented control */
.seg {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-ctl);
}

.seg__opt {
  flex: 1 1 0;
  min-width: 0;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  font: 600 15px/1.2 var(--font-body);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, color 0.15s;
}

.seg__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seg__opt[aria-checked="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--line);
}

.seg__count {
  flex: none;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--line);
  color: var(--ink);
  font: 700 12px/22px var(--font-body);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.seg__opt[aria-checked="true"] .seg__count {
  background: var(--btn);
  color: var(--btn-ink);
}

.seg__opt:focus-visible {
  outline-offset: -2px;
}

/* Four or more options with counts: count on top, label below */
.seg--stacked .seg__opt {
  flex-direction: column;
  gap: 2px;
  min-height: 58px;
  padding: 6px 4px;
}

.seg--stacked .seg__label {
  font-size: 13px;
}

.seg--stacked .seg__count,
.seg--stacked .seg__opt[aria-checked="true"] .seg__count {
  order: -1;
  min-width: 0;
  height: auto;
  padding: 0;
  background: none;
  color: inherit;
  font: 700 22px/1 var(--font-display);
}

/* ---------- Chips (status pills) ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px 0 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--line);
  font: 600 13px/1 var(--font-display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
}

.chip::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.chip--out,
.chip--paid,
.chip--won {
  background: var(--ok-bg);
  color: var(--ok);
  box-shadow: none;
}

.chip--booked,
.chip--sent {
  background: var(--info-bg);
  color: var(--info);
  box-shadow: none;
}

.chip--draft {
  background: var(--warn-bg);
  color: var(--warn);
  box-shadow: none;
}

.chip--overdue {
  background: var(--bad-bg);
  color: var(--bad);
  box-shadow: none;
}

.chip--accent {
  background: var(--accent-bg);
  color: var(--accent-ink);
  box-shadow: none;
}

/* ---------- Cards, sections, lists ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow-1);
  min-width: 0;
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  padding: 0 2px;
}

.section__head:has(.btn, .icon-btn) {
  margin: -8px 0 -6px;
}

.section__title {
  font: 600 12px/1.3 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.section__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.section__head .btn--ghost {
  margin-right: -10px;
  color: var(--accent-ink);
}

.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.list-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 16px;
  background: var(--surface);
}

.list-row + .list-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 1px;
  background: var(--line);
}

.list-row__main {
  flex: 1 1 auto;
  min-width: 0;
}

.list-row__tap {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

/* The tap target stretches over the whole row */
.list-row__tap::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
}

.list-row__tap:focus-visible {
  outline: none;
}

.list-row__tap:focus-visible::after {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
  border-radius: var(--radius-card);
}

.list-row--tap:active {
  background: var(--surface-2);
}

@media (hover: hover) {
  .list-row--tap:hover {
    background: var(--surface-2);
  }
}

.list-row__title {
  display: block;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row__sub {
  display: -webkit-box;
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink-2);
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.list-row__side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  max-width: 50%;
}

.list-row__meta {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  white-space: nowrap;
}

.list-row__right {
  position: relative;
  z-index: 1;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.list-row__chev {
  flex: none;
  margin-right: -6px;
  color: var(--ink-2);
}

/* Key / value rows */
.kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  min-width: 0;
}

.kv + .kv {
  border-top: 1px solid var(--line);
}

.kv__k {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--ink-2);
  font-size: 15px;
}

.kv__v {
  flex: 0 1 auto;
  min-width: 0;
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.card > .kv:first-child {
  padding-top: 0;
}

.card > .kv:last-child {
  padding-bottom: 0;
}

/* Money total: the one bold place on a screen */
.total {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 16px 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.total::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: var(--accent);
}

.total__label {
  font: 600 12px/1.3 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.total__value {
  font: 700 40px/1.05 var(--font-display);
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.total__sub {
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink-2);
}

.total__lines {
  margin-top: 12px;
  border-top: 1px solid var(--line);
}

.total__lines > .kv:last-child {
  padding-bottom: 0;
}

/* Meter: e.g. panels out vs panels owned */
.meter {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meter__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.meter__label {
  font-weight: 600;
}

.meter__value {
  font: 600 20px/1.1 var(--font-display);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meter__track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
}

.meter__fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  border-radius: 999px;
  background: var(--accent);
}

.meter--over .meter__fill {
  background: var(--bad);
}

.meter__sub {
  font-size: 14px;
  color: var(--ink-2);
}

/* ---------- Banners ---------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-card);
  background: var(--info-bg);
  color: var(--ink);
}

.banner__icon {
  flex: none;
  margin-top: 1px;
  color: var(--info);
}

.banner--ok {
  background: var(--ok-bg);
}

.banner--ok .banner__icon {
  color: var(--ok);
}

.banner--warn {
  background: var(--warn-bg);
}

.banner--warn .banner__icon {
  color: var(--warn);
}

.banner--bad {
  background: var(--bad-bg);
}

.banner--bad .banner__icon {
  color: var(--bad);
}

.banner__body {
  flex: 1 1 auto;
  min-width: 0;
}

.banner__title {
  display: block;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.banner__text {
  font-size: 14px;
  line-height: 1.45;
}

.banner__title + .banner__text {
  margin-top: 2px;
}

.banner__text .icon {
  margin: -3px 1px 0;
}

.banner__action {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.banner__action .btn {
  min-height: 40px;
  padding: 0 14px;
  font-size: 15px;
}

/* ---------- Empty state and error card ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 20px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
  text-align: center;
}

.empty__art {
  display: block;
  width: 120px;
  height: 120px;
  margin-bottom: 8px;
}

.empty__title {
  font: 600 24px/1.15 var(--font-display);
  letter-spacing: 0.01em;
  color: var(--ink);
}

.empty__text {
  max-width: 34ch;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.45;
}

.empty__action {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.empty__detail {
  max-width: 40ch;
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

/* Line drawings: ink + one orange accent */
.art-disc {
  fill: var(--bg);
}

.art-ink,
.art-accent,
.art-soft {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.art-ink {
  stroke: var(--ink);
}

.art-soft {
  stroke: var(--ink-2);
  stroke-width: 1.5;
}

.art-accent {
  stroke: var(--accent);
}

.art-bold {
  stroke-width: 3.5;
}

.art-mesh {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.1;
  opacity: 0.75;
}

.art-paper {
  fill: var(--surface);
}

.art-accent-fill {
  fill: var(--accent);
  stroke: none;
}

/* ---------- Sticky action bar (bottom of a screen, above the tab bar) ---------- */

.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  margin: 8px calc(-1 * var(--gutter-r)) calc(-1 * var(--screen-pb)) calc(-1 * var(--gutter-l));
  padding: 12px var(--gutter-r) 12px var(--gutter-l);
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow-up);
}

.sticky-actions > .btn {
  flex: 1 1 0;
  min-width: 0;
}

.sticky-actions > .icon-btn {
  width: 48px;
  height: 48px;
}

/* Once the column no longer fills the screen, the bar becomes a tray on the column */
@media (min-width: 680px) {
  .sticky-actions {
    margin-left: 0;
    margin-right: 0;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
  }
}

/* ---------- Overlays: bottom sheet, dialog, toast ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.overlay__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  animation: fade-in 0.2s ease;
}

.overlay.is-closing .overlay__scrim {
  animation: fade-out 0.18s ease forwards;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--kb, 0px); /* set by ui.js while the keyboard is up */
  display: flex;
  flex-direction: column;
  max-height: calc(var(--vvh, 100%) - 40px - env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  box-shadow: var(--shadow-2);
  padding-bottom: var(--sheet-pb, env(safe-area-inset-bottom, 0px));
  animation: sheet-in 0.26s var(--ease);
  outline: none;
}

.overlay.is-closing .sheet {
  animation: sheet-out 0.2s ease forwards;
}

.sheet__grab {
  flex: none;
  touch-action: none;
  cursor: grab;
}

.sheet__handle {
  width: 40px;
  height: 5px;
  margin: 8px auto 0;
  border-radius: 3px;
  background: var(--line-strong);
  opacity: 0.6;
}

.sheet__head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 2px calc(var(--gutter-r) - 8px) 2px var(--gutter-l);
}

.sheet__title {
  flex: 1 1 auto;
  min-width: 0;
  font: 600 24px/1.15 var(--font-display);
  letter-spacing: 0.01em;
}

.sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px var(--gutter-r) 20px var(--gutter-l);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet__actions {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 12px var(--gutter-r) 12px var(--gutter-l);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.sheet__actions > .btn {
  flex: 1 1 0;
  min-width: 0;
}

.sheet__actions--stack {
  flex-direction: column;
}

@media (min-width: 900px) {
  .sheet {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(560px, calc(100% - 48px));
    max-height: min(720px, calc(100% - 96px));
    border-radius: var(--radius-card);
    padding-bottom: 0;
    transform: translate(-50%, -50%);
    animation: pop-in-centered 0.2s var(--ease);
  }

  .overlay.is-closing .sheet {
    animation: fade-out 0.15s ease forwards;
  }

  .sheet__grab .sheet__handle {
    display: none;
  }

  .sheet__head {
    padding-top: 12px;
    padding-left: 24px;
    padding-right: 16px;
  }

  .sheet__body {
    padding-left: 24px;
    padding-right: 24px;
  }

  .sheet__actions {
    padding: 16px 24px;
    border-radius: 0 0 var(--radius-card) var(--radius-card);
  }
}

.overlay--center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px var(--gutter-r) 24px var(--gutter-l);
}

.dialog {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 22px 20px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-2);
  animation: pop-in 0.2s var(--ease);
  outline: none;
}

.overlay.is-closing .dialog {
  animation: fade-out 0.15s ease forwards;
}

.dialog__title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

.dialog__text {
  margin-top: 8px;
  color: var(--ink-2);
  line-height: 1.45;
}

.dialog__actions {
  display: flex;
  gap: 8px;
  margin-top: 22px;
}

.dialog__actions > .btn {
  flex: 1 1 0;
  min-width: 0;
}

.toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 24px;
  z-index: 90;
  display: flex;
  justify-content: center;
  padding: 0 var(--gutter-r) 0 var(--gutter-l);
  pointer-events: none;
  transition: bottom 0.2s var(--ease);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 480px;
  min-height: 48px;
  padding: 12px 18px 12px 14px;
  border-radius: var(--radius-card);
  background: var(--btn);
  color: var(--btn-ink);
  box-shadow: var(--shadow-2);
  font-weight: 600;
  line-height: 1.35;
  animation: toast-in 0.22s var(--ease);
}

.toast--error {
  background: var(--bad);
  color: var(--on-bad);
}

.toast.is-leaving {
  animation: fade-out 0.2s ease forwards;
}

/* Copy fallback sheet */
.copy-text {
  min-height: 180px;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.copy-help {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--warn);
  font-weight: 600;
  font-size: 15px;
}

/* ---------- Map hooks (used by map.js and screens) ---------- */

.map {
  position: relative;
  height: 340px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface-2);
  overflow: hidden;
  isolation: isolate;
}

.map--tall {
  height: min(62vh, 560px);
}

.map .leaflet-container,
.leaflet-container.map {
  width: 100%;
  height: 100%;
  font: 12px/1.4 var(--font-body);
  background: var(--surface-2);
}

.leaflet-container .leaflet-control-attribution {
  background: var(--glass);
  color: var(--ink-2);
  font-size: 11px;
  line-height: 1.5;
}

.leaflet-container .leaflet-control-attribution a {
  color: var(--ink);
}

.leaflet-bar {
  border: 1px solid var(--line-strong) !important;
  border-radius: var(--radius-ctl) !important;
  box-shadow: var(--shadow-1) !important;
  overflow: hidden;
}

.leaflet-bar a,
.leaflet-touch .leaflet-bar a {
  width: 44px;
  height: 44px;
  line-height: 44px;
  background: var(--surface);
  color: var(--ink);
  border-bottom-color: var(--line);
}

.leaflet-bar a:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.fence-line {
  stroke: var(--accent);
}

.fence-vertex {
  stroke: var(--surface);
  fill: var(--accent);
}

.leaflet-tooltip.seg-label {
  padding: 2px 7px;
  border: 0;
  border-radius: 6px;
  background: var(--btn);
  color: var(--btn-ink);
  box-shadow: none;
  font: 600 12px/1.4 var(--font-body);
  font-variant-numeric: tabular-nums;
}

.leaflet-tooltip.seg-label::before {
  display: none;
}

.map-pin {
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: var(--shadow-2);
  transform: rotate(-45deg);
}

.map-pin--out {
  background: var(--ok);
}

.map-pin--booked {
  background: var(--info);
}

.map-pin--done {
  background: var(--ink-2);
}

/* Floating tools over a map (undo, clear, locate) */
.map-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-tools .icon-btn {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-1);
}

/* Readout chip over a map (e.g. "412 ft") */
.map-readout {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 1000;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--glass);
  color: var(--ink);
  box-shadow: var(--shadow-1);
  font: 700 20px/1.1 var(--font-display);
  font-variant-numeric: tabular-nums;
}

/* Designed message over a map that cannot show pictures */
.map-overlay {
  position: absolute;
  inset: 0;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px;
  background: var(--surface-2);
  color: var(--ink);
  text-align: center;
}

.map-overlay__title {
  font: 600 20px/1.2 var(--font-display);
}

.map-overlay__text {
  max-width: 32ch;
  color: var(--ink-2);
  font-size: 14px;
}

/* ---------- Utilities ---------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.stack--tight {
  gap: 8px;
}

.stack--loose {
  gap: 24px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.row--between {
  justify-content: space-between;
}

.row--end {
  justify-content: flex-end;
}

.row--nowrap {
  flex-wrap: nowrap;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

.title-xl {
  font: 600 28px/1.1 var(--font-display);
  letter-spacing: 0.01em;
}

.title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

.num {
  font-variant-numeric: tabular-nums;
}

.big-num {
  font: 600 28px/1.1 var(--font-display);
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--ink-2);
}

.small {
  font-size: 14px;
  line-height: 1.4;
}

.tiny {
  font-size: 12px;
  line-height: 1.4;
}

.label {
  font: 600 12px/1.3 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.accent-text {
  color: var(--accent-ink);
}

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

.divider {
  height: 1px;
  margin: 4px 0;
  border: 0;
  background: var(--line);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Motion ---------- */

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes sheet-out {
  from { transform: translateY(var(--drag, 0px)); }
  to { transform: translateY(100%); }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes pop-in-centered {
  from { opacity: 0; transform: translate(-50%, -48%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .btn-spin {
    animation: none;
    border-right-color: currentColor;
    opacity: 0.6;
  }
}
