/* =========================================================
   NTPM — global styles (v2 design pass)

   Toned down from the v1 first pass:
   - No rotations on chemical-code badges or the form-record number
   - No staggered fade-in animations on every section
   - No "sticker" offset shadows on buttons
   - Italic display only for intentional accents
   - Paper grain dialed back; respects dark theme
   - Desktop layout uses a persistent left sidebar nav
   ========================================================= */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --paper-grain:
    radial-gradient(circle at 1px 1px, rgba(24, 20, 16, 0.04) 1px, transparent 0);
}
[data-theme="dark"] {
  --paper-grain:
    radial-gradient(circle at 1px 1px, rgba(232, 230, 224, 0.05) 1px, transparent 0);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper-grain:
      radial-gradient(circle at 1px 1px, rgba(232, 230, 224, 0.05) 1px, transparent 0);
  }
}

html {
  height: 100%;
  background: var(--bone);
}
body {
  background: var(--bone);
  color: var(--ink);
  font-family: var(--font-body);
  font-feature-settings: 'ss01', 'cv11';
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100svh;
}

/* Subtle paper grain, dialed back. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  background-image: var(--paper-grain);
  background-size: 4px 4px;
  mix-blend-mode: multiply;
  opacity: 0.4;
}
[data-theme="dark"] body::before {
  mix-blend-mode: screen;
  opacity: 0.3;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body::before {
    mix-blend-mode: screen;
    opacity: 0.3;
  }
}

/* =========================================================
   App shell
   - Mobile: single column, top header, content
   - Desktop (>=1024px): persistent sidebar + content area
   ========================================================= */

.app {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
  min-height: 100svh;
}

/* Sidebar — hidden on mobile */
.sidebar {
  display: none;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;          /* prevents grid blow-out */
  min-height: 100vh;
  min-height: 100svh;
  background: var(--paper);
}

/* Mobile top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px var(--gutter);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.page {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
}
/* Wide variant for list/dashboard pages that benefit from horizontal space */
.page--wide { max-width: var(--content-wide); }

footer.regulatory {
  padding: 28px var(--gutter) 36px;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--mist-deep);
  line-height: 1.7;
}

/* =========================================================
   Installed app / PWA shell
   ========================================================= */
.is-standalone,
.is-standalone body {
  background: var(--paper);
  background-image: var(--paper-grain);
  background-size: 4px 4px;
}
.is-standalone body {
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: rgba(216, 152, 52, 0.18);
}
.is-standalone .app,
.is-standalone .main {
  min-height: 100dvh;
}
.is-standalone .main {
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
.is-standalone .topbar {
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  padding-bottom: 14px;
}
.is-standalone footer.regulatory {
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}
.is-standalone body.home-page {
  overflow: hidden;
}
.is-standalone body.home-page::before {
  display: none;
}
.is-standalone body.home-page .app,
.is-standalone body.home-page .main {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.is-standalone body.home-page .main {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background-color: var(--paper);
  background-image: var(--paper-grain);
  background-size: 4px 4px;
}
.is-standalone body.home-page .topbar,
.is-standalone body.home-page footer.regulatory {
  background-color: var(--paper);
  background-image: var(--paper-grain);
  background-size: 4px 4px;
}
.is-standalone body.home-page .page--home {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.is-standalone body.home-page .page--home section.field {
  padding-top: 20px;
  padding-bottom: 20px;
}
.is-standalone body.home-page footer.regulatory {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0;
  padding-top: 18px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}
@supports (-webkit-touch-callout: none) {
  body {
    min-height: -webkit-fill-available;
  }
  .is-standalone body {
    min-height: -webkit-fill-available;
  }
  .is-standalone body.home-page .app,
  .is-standalone body.home-page .main {
    height: -webkit-fill-available;
  }
}
@media (display-mode: standalone), (display-mode: fullscreen) {
  html,
  body {
    background: var(--paper);
  }
}

/* ---- Desktop layout ---- */
@media (min-width: 1024px) {
  body { background: var(--bone); }

  .app {
    grid-template-columns: var(--sidebar-w) 1fr;
    max-width: 1480px;
    margin: 0 auto;
    border-left: 1px solid var(--rule);
    border-right: 1px solid var(--rule);
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bone);
    padding: 24px 18px;
    border-right: 1px solid var(--rule);
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    overflow-y: auto;
  }

  .main {
    border-left: none;
    border-right: none;
  }

  .topbar { display: none; }

  .page {
    padding: 0 var(--gutter-lg);
  }
}

/* =========================================================
   Wordmark
   ========================================================= */
.wordmark {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-variation-settings: 'opsz' 144, 'SOFT' 30;
  font-size: 26px;
  letter-spacing: -0.035em;
  line-height: 1;
  color: var(--forest);
  text-decoration: none;
}
.wordmark .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--amber);
  border-radius: 50%;
  margin-bottom: 2px;
}
.wordmark .full {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--mist-deep);
  font-weight: 400;
  margin-left: 4px;
}

/* =========================================================
   Sidebar nav
   ========================================================= */
.sidebar-meta {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  margin-top: 28px;
  gap: 2px;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 15px;
  color: var(--ink);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.sidebar-nav a:hover {
  background: var(--bone-warm);
  color: var(--forest);
}
.sidebar-nav a.is-active {
  border-left-color: var(--amber);
  color: var(--forest);
  background: var(--bone-warm);
}
.sidebar-nav a .nav-glyph {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--mist-deep);
  width: 18px;
  text-align: center;
}
.sidebar-nav a.is-active .nav-glyph { color: var(--amber); }
.nav-badge {
  margin-left: auto;
  background: var(--amber);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  letter-spacing: 0.04em;
  line-height: 1.4;
}

.sidebar-cta {
  margin-top: 24px;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* =========================================================
   Theme toggle
   ========================================================= */
.theme-toggle {
  appearance: none;
  background: transparent;
  border: 1px solid var(--rule-strong);
  color: var(--ink-soft);
  cursor: pointer;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 0;
  transition: all 0.1s;
}
.theme-toggle:hover {
  border-color: var(--ink);
  color: var(--ink);
}

/* =========================================================
   Sections
   ========================================================= */
section.field {
  padding: 24px var(--gutter);
  border-bottom: 1px solid var(--rule);
}
@media (min-width: 1024px) {
  section.field {
    padding: 28px var(--gutter-lg);
  }
}

.field-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--mist-deep);
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.field-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 24, 'SOFT' 30;
  font-size: 26px;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink);
}
.field-meta {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 4px;
  letter-spacing: -0.005em;
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--amber);
  color: var(--ink);
  border: none;
  padding: 14px 18px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  letter-spacing: -0.005em;
  border-radius: 2px;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.btn:hover { background: var(--amber-deep); color: var(--paper); }
.btn:active { transform: translateY(1px); }
.btn .arrow {
  font-size: 14px;
  line-height: 1;
}

.btn--ghost {
  background: transparent;
  color: var(--forest);
  border: 1px solid var(--forest);
  padding: 13px 17px;
}
.btn--ghost:hover {
  background: var(--leaf-soft);
  color: var(--forest);
}

a { color: var(--forest); }
a:hover { color: var(--amber-deep); }

/* =========================================================
   Stat tiles
   ========================================================= */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.tile {
  padding: 22px 16px;
  text-align: center;
  border-right: 1px solid var(--rule);
  color: inherit;
  text-decoration: none;
}
.tile:last-child { border-right: none; }
.tile .num {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 72, 'SOFT' 30;
  font-size: 40px;
  color: var(--forest);
  line-height: 1;
  letter-spacing: -0.04em;
}
.tile .label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
  margin-top: 6px;
}
.home-primary-action {
  width: 100%;
  max-width: 360px;
}

/* =========================================================
   Empty state
   ========================================================= */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-soft);
}
.empty p {
  font-size: 15px;
  max-width: 320px;
  margin: 0 auto 20px;
  line-height: 1.5;
}

/* =========================================================
   Lists
   ========================================================= */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px var(--gutter);
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
  transition: background 0.1s;
}
@media (min-width: 1024px) {
  .list-item {
    padding: 16px var(--gutter-lg);
  }
}
.list-item:hover { background: var(--bone-warm); }
.list-item .primary {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 24, 'SOFT' 30;
  font-size: 18px;
  letter-spacing: -0.018em;
  color: var(--forest);
  line-height: 1.15;
}
.list-item .secondary {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-top: 4px;
}
.list-item .arrow {
  color: var(--mist-deep);
  font-size: 14px;
}

/* =========================================================
   Forms
   ========================================================= */
.form-row { margin-bottom: 18px; }
.form-row--3col {
  display: grid;
  grid-template-columns: 2fr 0.8fr 1.2fr;
  gap: 12px;
  align-items: end;
}
.form-row--3col > div { margin-bottom: 0; }

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--mist-deep);
  margin-bottom: 4px;
  font-weight: 400;
}

.form-input,
.form-textarea {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--rule-strong);
  padding: 11px 0 9px;
  font-family: var(--font-body);
  font-size: 17px;
  color: var(--ink);
  border-radius: 0;
  transition: border-color 0.12s;
  letter-spacing: -0.005em;
  font-variant-numeric: tabular-nums;
}
.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-bottom-color: var(--forest);
}
.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--mist-deep);
  font-family: var(--font-body);
  font-size: 16px;
  font-style: normal;
}
.form-textarea {
  border: 1px solid var(--rule-strong);
  padding: 12px;
  font-size: 16px;
  resize: vertical;
  min-height: 96px;
  background: var(--paper);
}
.form-textarea:focus {
  border-color: var(--forest);
}

.form-help {
  display: block;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
  letter-spacing: -0.005em;
}

.form-error {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--alert);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

/* =========================================================
   Chips (cadence, areas, target pests)
   ========================================================= */
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  min-height: 40px;
  letter-spacing: -0.005em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] {
  background: var(--forest);
  color: var(--paper);
  border-color: var(--forest);
}

/* Styled-radio chips (for cadence, area, pest checkboxes) */
.chip-radio { cursor: pointer; user-select: none; }
.chip-radio input { display: none; }
.chips .chip-radio:has(input:checked) {
  background: var(--forest);
  color: var(--paper);
  border-color: var(--forest);
}

/* =========================================================
   Search
   ========================================================= */
.search {
  position: relative;
  margin-top: 14px;
}
.search input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 12px 14px 12px 40px;
  background: var(--bone-warm);
  border: 1px solid var(--rule-strong);
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  border-radius: 2px;
  letter-spacing: -0.005em;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="%23A89F8A" stroke-width="1.6" stroke-linecap="round"><circle cx="7" cy="7" r="5"/><line x1="14" y1="14" x2="10.5" y2="10.5"/></svg>');
  background-repeat: no-repeat;
  background-position: 14px center;
  background-size: 16px 16px;
}
.search input:focus {
  outline: none;
  border-color: var(--forest);
  background-color: var(--paper);
}
[data-theme="dark"] .search input {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="%236F6857" stroke-width="1.6" stroke-linecap="round"><circle cx="7" cy="7" r="5"/><line x1="14" y1="14" x2="10.5" y2="10.5"/></svg>');
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .search input {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="%236F6857" stroke-width="1.6" stroke-linecap="round"><circle cx="7" cy="7" r="5"/><line x1="14" y1="14" x2="10.5" y2="10.5"/></svg>');
  }
}

/* =========================================================
   Flash messages
   ========================================================= */
.flashes { display: flex; flex-direction: column; }
.flash {
  padding: 12px var(--gutter);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 10px;
}
@media (min-width: 1024px) {
  .flash { padding: 12px var(--gutter-lg); }
}
.flash::before { content: '✓'; font-family: var(--font-display); font-size: 13px; }
.flash-ok { background: var(--leaf-soft); color: var(--forest-deep); }
.flash-error { background: rgba(181, 58, 43, 0.14); color: var(--alert); }
.flash-error::before { content: '!'; }

/* =========================================================
   Customer hero
   ========================================================= */
.customer .name {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 60, 'SOFT' 40;
  font-size: 34px;
  letter-spacing: -0.025em;
  line-height: 1.0;
  color: var(--forest);
}
.customer .addr {
  color: var(--ink-soft);
  font-size: 14px;
  margin-top: 6px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

/* =========================================================
   Back link
   ========================================================= */
.back-link {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.back-link:hover { color: var(--forest); }

/* =========================================================
   Form-record number plate (toned down — no rotation)
   ========================================================= */
.form-no {
  margin: 18px var(--gutter) 0;
  padding: 12px 16px;
  background: var(--bone-warm);
  border: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink);
  border-left: 3px solid var(--leaf);
}
@media (min-width: 1024px) {
  .form-no { margin: 18px var(--gutter-lg) 0; }
}
.form-no .field-record {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.form-no .field-record small {
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.14em;
}
.form-no .number-block {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.form-no .number-block .label {
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.14em;
}
.form-no .number {
  font-family: var(--font-display);
  font-weight: 600;
  font-style: italic;
  font-variation-settings: 'opsz' 14, 'SOFT' 50;
  font-size: 22px;
  letter-spacing: 0;
  color: var(--alert);
  text-transform: none;
}

/* =========================================================
   Chemical lines (toned down — no rotation, no offset shadow)
   ========================================================= */
.lines { display: flex; flex-direction: column; }
.line {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--rule);
  align-items: start;
}
.line:first-child { padding-top: 4px; }
.line:last-child { border-bottom: none; }

.code {
  font-family: var(--font-display);
  font-weight: 600;
  font-variation-settings: 'opsz' 60, 'SOFT' 30;
  font-size: 30px;
  line-height: 1;
  color: var(--forest);
  background: var(--bone-warm);
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule-strong);
  flex-shrink: 0;
  letter-spacing: -0.04em;
  border-radius: 2px;
}

.line-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 2px;
  min-width: 0;
}
.line-product {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 24, 'SOFT' 30;
  font-size: 19px;
  letter-spacing: -0.018em;
  line-height: 1.15;
  color: var(--ink);
}
.line-meta {
  font-size: 12px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.line-meta .sep { color: var(--mist-deep); }
.line-amt {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 24, 'SOFT' 30;
  font-size: 20px;
  color: var(--ink);
  text-align: right;
  line-height: 1.1;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.line-edit {
  margin-top: 12px;
  padding: 12px;
  background: var(--bone);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.line-edit-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 8px;
}
.line-edit-row:last-child { margin-bottom: 0; }
.line-edit label { display: block; }
.line-edit .form-input,
.line-edit select.form-input {
  background: var(--paper);
  font-size: 15px;
  padding: 9px 10px;
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.line-edit .form-input:focus,
.line-edit select.form-input:focus {
  border-color: var(--forest);
}
.line-edit select.form-input {
  -webkit-appearance: none;
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path d="M0 0l5 6 5-6z" fill="%231F1A12"/></svg>');
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

@media (min-width: 1024px) {
  .line-edit-row { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}

.line-remove {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--alert);
  font-family: var(--font-body);
  font-size: 18px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  border-radius: 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: all 0.12s;
}
.line-remove:hover {
  background: var(--alert);
  color: var(--paper);
  border-color: var(--alert);
}

/* =========================================================
   Add-line + chemical picker
   ========================================================= */
.add-line {
  margin-top: 16px;
  width: 100%;
  background: transparent;
  border: 1px dashed var(--rule-strong);
  padding: 14px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  color: var(--leaf);
  cursor: pointer;
  text-align: center;
  transition: all 0.12s;
  border-radius: 2px;
}
.add-line:hover {
  border-color: var(--leaf);
  border-style: solid;
  color: var(--forest);
  background: var(--leaf-soft);
}

.picker { margin-top: 14px; }
.picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
}
@media (min-width: 600px) {
  .picker-grid { grid-template-columns: repeat(6, 1fr); }
}
@media (min-width: 1024px) {
  .picker-grid { grid-template-columns: repeat(8, 1fr); }
}
.picker-tile {
  -webkit-appearance: none;
  appearance: none;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  padding: 10px 6px;
  cursor: pointer;
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: background 0.1s, border-color 0.1s;
  min-height: 64px;
  text-align: center;
}
.picker-tile:hover {
  background: var(--bone-warm);
  border-color: var(--forest);
}
.picker-code {
  font-family: var(--font-display);
  font-weight: 600;
  font-variation-settings: 'opsz' 36, 'SOFT' 30;
  font-size: 20px;
  color: var(--forest);
  letter-spacing: -0.04em;
  line-height: 1;
}
.picker-name {
  font-family: var(--font-body);
  font-size: 10px;
  color: var(--ink-soft);
  line-height: 1.2;
  letter-spacing: -0.005em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  max-height: 24px;
}

/* =========================================================
   Money block
   ========================================================= */
.money {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  font-size: 15px;
}
.money .row { display: contents; }
.money .label {
  color: var(--ink-soft);
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.08em;
  align-self: center;
}
.money .val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 500;
  font-size: 16px;
}
.money .total-row {
  grid-column: 1 / -1;
  border-top: 2px solid var(--ink);
  margin-top: 10px;
  padding-top: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
}
.money .total-row .label {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 36, 'SOFT' 30;
  font-size: 22px;
  text-transform: none;
  letter-spacing: -0.025em;
  color: var(--ink);
}
.money .total-row .val {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 72, 'SOFT' 30;
  font-size: 32px;
  color: var(--forest);
  letter-spacing: -0.035em;
}

/* =========================================================
   CTA wrap
   ========================================================= */
.cta-wrap {
  padding: 22px var(--gutter) 28px;
  background: var(--bone-warm);
  border-top: 1px solid var(--rule);
}
@media (min-width: 1024px) {
  .cta-wrap {
    padding: 24px var(--gutter-lg) 32px;
  }
}

/* =========================================================
   Link buttons
   ========================================================= */
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--leaf);
  cursor: pointer;
  margin-left: auto;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--forest); }
.field-label .link-btn { margin-left: auto; }

/* =========================================================
   Selection + focus
   ========================================================= */
::selection { background: var(--amber); color: var(--ink); }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--forest);
  outline-offset: 2px;
}

/* =========================================================
   Signature pads
   ========================================================= */
.sig-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-top: 14px;
}
@media (min-width: 720px) {
  .sig-grid { grid-template-columns: 1fr 1fr; gap: 22px; }
}

.sig { display: flex; flex-direction: column; gap: 8px; }
.sig-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.sig-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--mist-deep);
}
.sig-clear {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: none;
  min-height: 44px;
  padding: 0 2px 0 18px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--leaf);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.sig-clear:hover { color: var(--forest); }

.sig-pad {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  height: 190px;
  overflow: hidden;
  touch-action: none;          /* keep finger drags from scrolling the page */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.sig-pad::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: 18px;
  right: 18px;
  bottom: 46px;
  border-bottom: 1px solid var(--rule);
  pointer-events: none;
}
.sig-pad canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}
.sig-existing {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  background: transparent;
}
.sig-empty {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 16px;
  color: var(--mist-deep);
  pointer-events: none;
}
@media (max-width: 480px) {
  .sig-pad { height: 210px; }
}

/* =========================================================
   Send / Print / Download CTAs on the show page
   ========================================================= */
.cta-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--mist);
  color: var(--ink-soft);
}
.btn[disabled]:hover {
  background: var(--mist);
  color: var(--ink-soft);
}
.sent-stamp {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mist-deep);
  text-align: center;
  margin-top: 4px;
}

/* =========================================================
   Print stylesheet — fallback for raw Ctrl+P on the show page.
   The "Print" button injects an iframe with the PDF-layout HTML
   and prints that, which yields a much nicer paper output than
   the screen layout. This block keeps Ctrl+P from looking awful.
   ========================================================= */
@media print {
  @page { margin: 0.6in; }
  body { background: #ffffff !important; color: #000 !important; }
  body::before { display: none !important; }
  .sidebar, .topbar, .no-print, .flashes, footer.regulatory { display: none !important; }
  .app, .main, .page { display: block !important; max-width: none !important; margin: 0 !important; padding: 0 !important; border: none !important; }
  section.field { padding: 10px 0 !important; border-bottom: 1px solid #ddd !important; break-inside: avoid; }
  a { color: inherit !important; text-decoration: none !important; }
}

/* =========================================================
   Quick-add (new client + start visit on /visits/new)
   Mobile: stacked. Desktop: name | phone | submit on one row.
   ========================================================= */
.quick-add-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.quick-add-submit { width: 100%; }
@media (min-width: 720px) {
  .quick-add-grid {
    grid-template-columns: 2fr 1.2fr auto;
    align-items: end;
    gap: 18px;
  }
  .quick-add-submit { width: auto; }
}

/* =========================================================
   Schedule — slot rows + overdue/today highlighting
   ========================================================= */
.slot { padding: 0; border-bottom: 1px solid var(--rule); }
.slot-cell {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px var(--gutter);
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 0.1s;
}
@media (min-width: 1024px) {
  .slot-cell { padding: 16px var(--gutter-lg); }
}
.slot-cell:hover { background: var(--bone-warm); }
.slot-cell .primary {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 24, 'SOFT' 30;
  font-size: 18px;
  letter-spacing: -0.018em;
  color: var(--forest);
  line-height: 1.15;
}
.slot-cell .secondary {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-top: 4px;
}
.slot-due {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}

.sched-overdue { border-left: 3px solid var(--alert); }
.sched-overdue .field-label { color: var(--alert); }
.sched-overdue .slot-due { color: var(--alert); font-weight: 600; }

.sched-today { border-left: 3px solid var(--amber); }
.sched-today .field-label { color: var(--amber-deep); }
.sched-today .slot-due { color: var(--amber-deep); font-weight: 600; }

/* =========================================================
   Invoice status — pills + inline status text in lists
   ========================================================= */
.status-block {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  padding: 4px 10px;
  border-radius: 2px;
  border: 1px solid;
}
.status-meta { color: var(--ink-soft); font-size: 14px; line-height: 1.4; }

.status-pill,
.status-draft,
.status-sent,
.status-paid,
.status-exported,
.status-void { font-weight: 600; }

.status-draft   { color: var(--ink-soft);    border-color: var(--rule-strong); background: var(--bone-warm); }
.status-sent    { color: var(--amber-deep);  border-color: var(--amber);       background: rgba(216, 152, 52, 0.10); }
.status-paid    { color: var(--forest);      border-color: var(--leaf);        background: var(--leaf-soft); }
.status-exported{ color: var(--forest-deep); border-color: var(--forest);      background: var(--leaf-soft); }
.status-void    { color: var(--alert);       border-color: var(--alert);       background: rgba(181, 58, 43, 0.08); }

/* For inline use inside .secondary text. */
.list-item .secondary .status-draft,
.list-item .secondary .status-sent,
.list-item .secondary .status-paid,
.list-item .secondary .status-exported,
.list-item .secondary .status-void {
  border: none; padding: 0; background: none; font-size: inherit;
}

/* Chip filters with an active state (used on /invoices) */
.chip.is-active,
.chip[aria-pressed="true"] {
  background: var(--forest);
  color: var(--paper);
  border-color: var(--forest);
}
.chip.is-active:hover { background: var(--forest-deep); }

/* =========================================================
   HTMX loading states — subtle but unmistakable
   ========================================================= */
.htmx-request {
  opacity: 0.55;
  pointer-events: none;
  cursor: wait;
  transition: opacity 0.12s ease-out;
}
/* Picker tiles: a brief amber outline while the request lands so the
   tap registers visually before the line row appears. */
.picker-tile.htmx-request {
  border-color: var(--amber);
  background: var(--bone-warm);
}
/* Search input: an inline pulse on the right while results are fetching. */
.search input.htmx-request {
  opacity: 1;                 /* keep the input legible while typing */
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="%23A89F8A" stroke-width="1.6" stroke-linecap="round"><circle cx="7" cy="7" r="5"/><line x1="14" y1="14" x2="10.5" y2="10.5"/></svg>'),
                    linear-gradient(90deg, transparent 0%, var(--amber) 50%, transparent 100%);
  background-position: 14px center, right;
  background-size: 16px 16px, 40% 2px;
  background-repeat: no-repeat;
}

/* Top-edge progress strip. Shows during any HTMX request so the user
   knows the truck-cell hop is in flight. */
body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--amber);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.18s ease-out, opacity 0.25s ease-out;
  opacity: 0;
  z-index: 9999;
  pointer-events: none;
}
body.htmx-request::after {
  transform: scaleX(0.85);
  opacity: 1;
  transition: transform 1.2s cubic-bezier(0.1, 0.7, 0.2, 0.95), opacity 0.1s;
}

/* =========================================================
   Alpine.js — hide before init
   ========================================================= */
[x-cloak] { display: none !important; }

/* =========================================================
   Archive — pill, banner, danger-zone section, danger button
   ========================================================= */
.archived-tag {
  display: inline-block;
  vertical-align: middle;
  margin-left: 10px;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--bone-warm);
  border: 1px solid var(--rule);
  border-radius: 2px;
  line-height: 1.4;
}

.archived-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--bone-warm);
  border-left: 3px solid var(--ink-soft);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink);
  line-height: 1.45;
}
.archived-banner .link-btn {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--forest);
}

.danger-zone {
  border-top: 1px dashed var(--rule);
  margin-top: 12px;
  padding-top: 22px;
}
.danger-zone .field-label { color: #8b3a2e; }

.btn--danger {
  background: transparent;
  color: #8b3a2e;
  border: 1px solid #8b3a2e;
  padding: 13px 17px;
}
.btn--danger:hover {
  background: #8b3a2e;
  color: var(--paper);
}
.btn--danger .arrow { color: inherit; }
