@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=Inter:wght@400;500;600;700&display=swap');

/* =========== DESIGN TOKENS =========== */
:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --ink: #0A0E1A;
  --ink-muted: #4A5568;
  --ink-placeholder: #8A8B8F;
  --accent: #1E3A5F;
  --accent-soft: #3A5A85;
  --highlight: #D4B896;
  --highlight-soft: rgba(212, 184, 150, 0.35);
  --highlight-tint: rgba(212, 184, 150, 0.15);
  --border: #D8D4CA;
  --rule: #BDB8A8;
  --success: #2E6B4F;
  --warn: #A8701C;
  --danger: #8B1E1E;
  --highlight-60: rgba(212, 184, 150, 0.35);
  --bg-soft: #EDEAE3;
  --ph: var(--ink-placeholder);
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
}

/* =========== APP SHELL =========== */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
}

.app-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  /* Kept fixed (not sticky): the editor offsets .app-main by --app-header-h,
     which JS keeps in sync with this header's measured height. */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  min-height: 54px;
}
.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand-mark { font-size: 24px; color: var(--accent); display: inline-flex; align-items: center; }
.brand-mark svg { display: block; }
.brand h1, .brand .fi-brand-word { font-family: var(--font-body); font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand-page { font-size: 13px; font-weight: 500; color: var(--ink-muted); letter-spacing: 0; }
/* Unified PL nav — identical pills to Home / Invoices / Kit / Crew / Profile. */
.pl-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pl-nav a { border: 1px solid var(--border); border-radius: 20px; padding: 4px 13px; font-size: 12.5px; font-weight: 500; color: var(--ink-muted); white-space: nowrap; transition: all .12s; text-decoration: none; }
.pl-nav a:hover { border-color: var(--accent-soft); color: var(--accent); }
.pl-nav a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.header-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-left: auto; }
/* The editor's action toolbar is dense; below this width give it the room and
   drop the cross-nav pills (still reachable via the account menu / other pages). */
/* Mobile nav collapse — match canonical (home/invoices): keep the first 3 pills
   (Home / Invoices / Invoice Editor) on tablet instead of hiding the whole nav. */
@media (max-width: 720px) { .app-header .pl-nav a:nth-child(n+4) { display: none; } }

/* Pro pill in header button — only shown on Free */
.header-pro-pill {
  display: none;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 10px;
  line-height: 1.3;
}
body.is-free .header-pro-pill { display: inline-block; }

/* =========== USER AVATAR DROPDOWN (app header) =========== */
.user-menu { position: relative; display: inline-flex; align-items: center; gap: 6px; }
.user-menu .user-btn {
  width: 30px; height: 30px;
  border: none;
  border-radius: 50%;
  padding: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  overflow: hidden;
  transition: opacity 0.15s;
}
.user-menu .user-btn:hover { opacity: 0.85; }
.user-menu .user-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(30,58,95,0.18); }
.user-menu .user-avatar {
  width: 100%; height: 100%;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  overflow: hidden;
  flex-shrink: 0;
}
.user-menu .user-avatar img { width: 100%; height: 100%; object-fit: cover; }
/* Chevron dropped — account control now matches the 30px circle used site-wide. */
.user-menu .user-chev { display: none; }
.user-menu .user-pro-dot {
  display: none;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 10px;
  margin-right: 2px;
}
body.is-pro .user-menu .user-pro-dot { display: inline-block; }
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 240px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 16px 48px rgba(10,14,26,0.14), 0 2px 6px rgba(10,14,26,0.06);
  z-index: 200;
  display: none;
  animation: user-dd-in 0.14s ease-out;
}
@keyframes user-dd-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.user-menu.open .user-dropdown { display: block; }
.user-dropdown-head {
  padding: 10px 10px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.user-dropdown-head strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-dropdown-head span {
  display: block;
  font-size: 11.5px;
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-dropdown a, .user-dropdown button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--bg-soft); color: var(--accent); }
.user-dropdown a svg, .user-dropdown button svg { color: var(--ink-muted); flex-shrink: 0; }
.user-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}
.user-dropdown .sign-out { color: var(--danger); }
.user-dropdown .sign-out svg { color: var(--danger); }

/* =========== SHARE DROPDOWN (Email · PDF · Print) — mirrors the account menu =========== */
.share-menu { position: relative; display: inline-flex; align-items: center; }
.share-btn .user-chev { color: var(--ink-muted); display: inline-flex; }
.share-dropdown { right: 0; left: auto; width: 200px; }
.share-menu.open .share-dropdown { display: block; }

/* Compact undo/redo cluster in the header */
.hdr-history { display: inline-flex; align-items: center; gap: 2px; }

/* Header buttons relocated INTO the account menu — kept in the DOM only as hidden,
   still-clickable triggers (the account-menu items fire .click() on these). */
.hidden-action { display: none !important; }

/* Email send option cards */
.email-send-options { margin: 8px 0 4px; }
.email-send-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 0 0 10px;
}
.email-option-cards { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.email-option-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
button.email-option-card:hover {
  border-color: var(--accent-soft);
  background: var(--bg-soft);
}
button.email-option-card:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(30,58,95,0.18);
  border-color: var(--accent-soft);
}
.email-option-card--disabled {
  opacity: 0.55;
  pointer-events: none;
  background: var(--bg-soft);
}
.email-option-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.email-option-card strong { display: block; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 2px; }
.email-option-card span { font-size: 12px; color: var(--ink-muted); line-height: 1.4; }
.email-send-note {
  font-size: 12px;
  color: var(--ink-muted);
  margin: 0;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: 8px;
  border-left: 2px solid var(--border);
}

/* =========== KNOW YOUR WORTH — KIT RATE MODAL =========== */
#kit-rate-worth { color: var(--accent); white-space: nowrap; }
.kit-rate-options { display: flex; flex-direction: column; gap: 8px; }
.kit-rate-option {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.kit-rate-option:hover { border-color: var(--accent-soft); background: var(--bg-soft); }
.kit-rate-option:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(30,58,95,0.18);
  border-color: var(--accent-soft);
}
.kit-rate-option-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.kit-rate-option-desc { font-size: 12px; color: var(--ink-muted); line-height: 1.4; }
.kit-rate-total { font-weight: 600; color: var(--accent); }
.kit-rate-foot { justify-content: flex-start; }
.kit-rate-skip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-muted);
  cursor: pointer;
}
.kit-rate-skip input { cursor: pointer; }

/* =========== BUTTON SYSTEM =========== */
.btn {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
.btn:hover {
  background: var(--bg-soft);
  border-color: var(--accent-soft);
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.18);
  border-color: var(--accent-soft);
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-icon { padding: 5px 7px; line-height: 0; }
.btn-icon:disabled { pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: #fff;
}
.btn-primary:focus-visible {
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.25);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-muted);
}
.btn-ghost:hover { background: var(--bg-soft); color: var(--ink); border-color: transparent; }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 11px 20px; font-size: 14px; border-radius: 9px; }

.tb-icon { font-size: 1.25em; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
#save-invoice-btn .save-pencil { font-size: 1em; line-height: 1; display: inline-block; }
#save-invoice-btn.btn-dirty {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
#save-invoice-btn.btn-dirty:hover { background: var(--accent-soft); border-color: var(--accent-soft); }
#save-invoice-btn.btn-saved {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.app-main {
  /* Clear the fixed header. Adaptive: JS keeps --app-header-h in sync with the header's
     real height so a wrapped header (narrow window / browser zoom) never covers content. */
  padding-top: var(--app-header-h, 60px);
}
.app-top-grid {
  display: grid;
  grid-template-columns: minmax(380px, 1.05fr) minmax(460px, 1.15fr);
  gap: 0;
}
.form-pane { padding: 20px; background: #fff; overflow-x: hidden; }
.form-pane-bottom {
  border-top: 1px solid var(--border);
}
.preview-pane {
  padding: 20px;
  background: #EDEAE3;
  border-left: 1px solid var(--border);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
  background: var(--surface);
}
fieldset legend {
  padding: 0 6px;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; align-items: end; }
.row label { display: flex; flex-direction: column; font-size: 12px; color: #555; gap: 3px; }
fieldset label { display: flex; flex-direction: column; font-size: 12px; color: #555; gap: 3px; margin-bottom: 8px; }
fieldset label small { color: #999; font-weight: normal; font-size: 11px; }

input[type="text"], input[type="date"], input[type="number"], textarea, select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--ink);
  min-width: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea { font-family: inherit; resize: vertical; }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.14);
}

input::placeholder, textarea::placeholder {
  color: var(--ink-placeholder);
}

button {
  font-family: inherit;
  font-weight: 500;
  transition: opacity 0.15s ease, background 0.15s ease;
}
button:hover {
  opacity: 0.92;
}

.template-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}
.seg-label { font-weight: 600; font-size: 13px; color: #555; }
.seg label { cursor: pointer; margin-right: 14px; font-size: 13px; }

.section-group { margin-bottom: 14px; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.section-head h4 { margin: 0; font-size: 13px; color: #444; }
.head-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; row-gap: 4px; }
.head-actions select { font-size: 12px; padding: 4px 6px; }

.kit-cat-divider {
  display: flex; align-items: center; gap: 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5A6478;
  padding: 6px 4px 2px;
  border-top: 1px solid var(--border);
  margin-top: 3px;
}
.kit-cat-divider svg { flex-shrink: 0; opacity: 0.75; }
.kit-cat-divider:first-child { border-top: none; margin-top: 0; padding-top: 2px; }
/* Alternating tint per category SECTION in the kit editor list (not per row) —
   long mixed-category kits were hard to scan; every other category block sits on
   a soft wash so section boundaries read at a glance. */
.kit-sec-alt { background: rgba(30,58,95,0.045); }
.kit-cat-divider.kit-sec-alt { border-radius: 8px 8px 0 0; }
.row.kit-sec-alt, [data-rows] > .kit-sec-alt { border-radius: 0; }
[data-rows] > .kit-sec-alt:has(+ :not(.kit-sec-alt)) { border-radius: 0 0 8px 8px; }
.kit-cat-divider .cat-drag-handle { opacity: 0; cursor: grab; font-size: 12px; color: var(--ink-muted); flex-shrink: 0; transition: opacity 0.15s; touch-action: none; }
.kit-cat-divider:hover .cat-drag-handle { opacity: 0.6; }
.kit-cat-divider.cat-dragging { opacity: 0.4; }
.kit-cat-divider.cat-drag-over { border-top: 2px solid var(--accent); }
.rows > .row-item {
  display: grid;
  grid-template-columns: 18px 2.4fr 0.45fr 0.75fr 1.15fr 28px 28px;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.rows > .row-item.kit-row {
  /* 9 grid children now: grip, details, qty, amount, notes, category, the
     assign/status toggle (🏷), dup, rm — one 28px track per icon button. A
     missing track here is what caused rm to wrap onto its own implicit row. */
  grid-template-columns: 18px 2.4fr 0.45fr 0.75fr 1.15fr auto 28px 28px 28px;
  /* Kit rows can now be two lines tall (description + assign/status sub-row),
     so top-align the rest of the row instead of centering against that height —
     same fix labor rows already use for their benchmark-hint sub-row. */
  align-items: start;
}
.rows > .row-item.kit-row > input,
.rows > .row-item.kit-row > select,
.rows > .row-item.kit-row > button,
.rows > .row-item.kit-row > .row-drag-handle { margin-top: 5px; }
.row-drag-handle {
  color: var(--ink-faint, #ccc);
  font-size: 14px;
  cursor: grab;
  line-height: 1;
  user-select: none;
  opacity: 0;
  transition: opacity 0.15s;
  text-align: center;
  /* Let touch drags on the grip move the row instead of scrolling the page. */
  touch-action: none;
}
.rows > .row-item:hover .row-drag-handle { opacity: 1; }
.row-drag-handle:active { cursor: grabbing; }
.row-dragging { opacity: 0.4; }
.row-drag-over { outline: 2px solid var(--accent); outline-offset: -1px; border-radius: 4px; }
.rows > .row-item input { font-size: 12px; padding: 5px 7px; }
.rows > .row-item.labor-row { align-items: start; }
.rows > .row-item.labor-row input,
.rows > .row-item.labor-row button,
.rows > .row-item.labor-row .row-drag-handle { margin-top: 5px; }
.details-col { display: flex; flex-direction: column; min-width: 0; gap: 3px; }
.details-col > input { width: 100%; box-sizing: border-box; }
.row-bm-hint { font-size: 11px; line-height: 1.3; padding: 0 2px 2px; }
.row-bm-hint em { font-style: normal; font-weight: 600; }
.row-bm-hint.bm-green em { color: #16a34a; }
.row-bm-hint.bm-amber em { color: #b45309; }
.row-bm-hint.bm-red em { color: #dc2626; }
.kit-assign-row { display: flex; gap: 4px; margin-top: 3px; }
.kit-assign-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-soft);
  color: var(--ink-muted);
}
.kit-assign-input:focus { outline: none; border-color: var(--accent); color: var(--ink); }
.kit-status-select {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 3px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-soft);
  color: var(--ink-muted);
  cursor: pointer;
  max-width: 82px;
}
.kit-status-select:hover { border-color: var(--ink-muted); }
.kit-status-select:focus { outline: none; border-color: var(--accent); color: var(--ink); }
.bm-fuzzy { font-size: 10px; color: var(--ink-faint, #8A8F98); margin-left: 2px; }
.bm-range { font-size: 10px; color: var(--ink-faint, #8A8F98); margin-left: 2px; }
.kit-cat-select {
  font-size: 11px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-soft);
  color: var(--ink-muted);
  cursor: pointer;
  white-space: nowrap;
  max-width: 130px;
}
.kit-cat-select:hover { border-color: var(--ink-muted); }
.kit-cat-select:focus { outline: none; border-color: var(--accent); color: var(--ink); }
.rows .rm-btn,
.rows .dup-btn,
.kit-catalog-row .rm-btn,
.kit-catalog-row .dup-btn {
  border-radius: 4px;
  cursor: pointer;
  padding: 3px 0;
  font-size: 14px;
}
.rows .rm-btn,
.kit-catalog-row .rm-btn {
  background: rgba(139, 30, 30, 0.06);
  border: 1px solid rgba(139, 30, 30, 0.2);
  color: var(--accent);
}
.rows .dup-btn,
.kit-catalog-row .dup-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--ink-muted);
}
.rows .dup-btn:hover,
.kit-catalog-row .dup-btn:hover {
  color: var(--accent);
  border-color: var(--accent-soft);
}

/* =========== PANELS =========== */
.settings-panel, .recents-panel {
  position: fixed;
  top: 0; right: 0;
  width: 420px;
  height: 100vh;
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(10, 14, 26, 0.08);
  z-index: 200;
  padding: 20px 22px;
  overflow-y: auto;
  animation: panel-slide-in 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes panel-slide-in {
  from { transform: translateX(12px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: -20px;
  background: #fff;
  padding-top: 20px;
  margin: -20px -22px 16px;
  padding-left: 22px;
  padding-right: 22px;
  z-index: 2;
}
.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.panel-head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
/* Pinned, conspicuous Save in the sticky Business Info header */
.settings-save-top {
  font-weight: 600;
  padding: 8px 14px;
  box-shadow: 0 2px 8px rgba(30, 58, 95, 0.25);
  white-space: nowrap;
}
.muted { color: #888; font-size: 12px; }
.section-hint {
  color: var(--ink-muted, #6a6a66);
  font-size: 12px;
  line-height: 1.5;
  margin: 6px 0 10px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--accent, #2E6B4F) 4%, transparent);
  border-left: 2px solid color-mix(in srgb, var(--accent, #2E6B4F) 35%, transparent);
  border-radius: 0 6px 6px 0;
}
.section-hint strong { color: var(--ink, #222); font-weight: 600; }
.kit-summary-line { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--ink); }
.kit-summary-pills { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 4px; }
.kit-summary-pill { font-size: 11px; padding: 3px 8px; background: var(--highlight-tint); border: 1px solid var(--highlight); border-radius: 20px; color: var(--ink-muted); }
.theme-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.theme-preset-btn {
  padding: 5px 10px; font-size: 12px; border: 1px solid var(--border);
  border-radius: 4px; background: var(--surface); cursor: pointer;
  font-family: var(--font-body); color: var(--ink);
  transition: background 0.15s, border-color 0.15s;
}
.theme-preset-btn:hover { background: var(--bg-soft); border-color: var(--accent); }
.theme-preset-btn.active-theme { background: var(--accent); color: #fff; border-color: var(--accent); }
.custom-slot-wrap { display: flex; align-items: center; gap: 2px; }
.custom-slot-del { padding: 4px 6px; font-size: 11px; background: transparent; border: 1px solid transparent; border-radius: 4px; cursor: pointer; color: var(--ink-muted); line-height: 1; }
.custom-slot-del:hover { background: #fee2e2; border-color: #f87171; color: #dc2626; }
.theme-status { font-size: 11px; color: var(--ink-muted); margin: 4px 0 0; min-height: 16px; }
input[type="color"] {
  width: 100%; height: 36px; padding: 2px 4px;
  border: 1px solid var(--border); border-radius: 4px; cursor: pointer;
}
.settings-footer {
  position: sticky;
  bottom: 0;
  background: #fff;
  padding: 10px 0;
  display: flex;
  gap: 8px;
  border-top: 1px solid #eee;
  margin-top: 14px;
}

#recents-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
#recents-list li {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
#recents-list li:hover { background: var(--bg-soft); border-color: var(--accent-soft); }
#recents-list li:active { transform: translateY(0.5px); }
#recents-list li .r-head { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; color: var(--ink); }
#recents-list li .r-sub { font-size: 11px; color: var(--ink-muted); margin-top: 4px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.r-discount-tag { font-size: 10px; font-weight: 600; background: rgba(139,30,30,0.07); color: var(--danger); border: 1px solid rgba(139,30,30,0.18); border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.r-delete-btn {
  margin-left: auto;
  padding: 2px 7px;
  font-size: 11px;
  opacity: 0;
  background: rgba(139, 30, 30, 0.06);
  border-color: rgba(139, 30, 30, 0.2);
  color: var(--danger);
  transition: opacity 0.15s ease;
}
#recents-list li:hover .r-delete-btn { opacity: 1; }
.r-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62%; }
.r-rename-btn {
  padding: 2px 7px;
  font-size: 11px;
  opacity: 0;
  color: var(--ink-muted);
  transition: opacity 0.15s ease;
}
#recents-list li:hover .r-rename-btn { opacity: 1; }

#kit-catalog-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.kit-catalog-row {
  display: grid;
  grid-template-columns: 90px 1fr 70px 28px 28px;
  gap: 4px;
  align-items: center;
}
.kit-catalog-row input, .kit-catalog-row select { font-size: 12px; padding: 4px 6px; }

/* Helper text for kit guidance (form + settings) */
.kit-helper-crew-link {
  display: inline-flex; align-items: center; gap: 3px;
  color: var(--accent); font-weight: 600; text-decoration: none;
}
.kit-helper-crew-link:hover { text-decoration: underline; }
.kit-helper-crew-link svg { flex-shrink: 0; }
.kit-helper {
  color: var(--ink-muted);
  font-size: 0.72rem;
  font-style: normal;
  line-height: 1.5;
  margin: 3px 0 10px 0;
}

.kit-bulk-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.kit-bulk-buttons .btn { font-size: 11px; padding: 5px 10px; }

.welcome-banner {
  background: var(--highlight-tint);
  border: 1px solid var(--highlight-soft);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
}
.welcome-banner strong { color: var(--accent); }

/* Status badges (recents list + preview header) */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  vertical-align: middle;
  margin-left: 4px;
}
.status-draft { background: var(--border); color: var(--ink-muted); }
.status-sent { background: rgba(168, 112, 28, 0.15); color: var(--warn); }
.status-viewed { background: rgba(46, 107, 79, 0.12); color: var(--success); }
.status-paid { background: rgba(46, 107, 79, 0.18); color: var(--success); }
.status-deposit-paid { background: rgba(46, 107, 79, 0.12); color: var(--success); }
.status-overdue { background: rgba(139, 30, 30, 0.12); color: var(--danger); }
.status-soft-hold { background: rgba(138, 90, 18, 0.14); color: var(--warn); }
.status-locked-in { background: rgba(30, 58, 95, 0.14); color: var(--accent); }
.status-pro-bono { background: rgba(107, 87, 32, 0.14); color: #6B5720; }

/* Clauses under payment footer (due date, late fee, meal penalty) */
.invoice.coverage .cv-clauses {
  margin-top: 6px;
  font-size: 10px;
  color: #555;
  white-space: pre-line;
  line-height: 1.5;
  border-top: 1px solid #e5e5e0;
  padding-top: 6px;
}

/* Toast hint */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  right: auto;
  bottom: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1a1a1a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transform: translateX(-50%) translateY(-12px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 4000;
  max-width: 340px;
}
.toast-msg { flex: 1; min-width: 0; }
.toast-close {
  background: none;
  border: none;
  padding: 0 2px;
  font-size: 12px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  flex-shrink: 0;
}
.toast-close:hover { color: #fff; }
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }

/* =========== SITE-WIDE ANNOUNCEMENT BANNER =========== */
.announcement-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.4;
  padding: 8px 16px;
  color: var(--accent);
  background: rgba(30, 58, 95, 0.07);
  border-bottom: 1px solid rgba(30, 58, 95, 0.16);
}
.announcement-banner-text { flex: 1; min-width: 0; }
.announcement-banner-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.announcement-banner-link:hover { text-decoration: underline; }
.announcement-banner-close {
  background: none;
  border: none;
  padding: 0 2px;
  font-size: 12px;
  line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.announcement-banner-close:hover { color: var(--ink); }

/* =========== REUSABLE CONTEXTUAL CHIP (see renderContextualChip in app.js) =========== */
.contextual-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  line-height: 1.4;
}
.contextual-chip-body { flex: 1; min-width: 0; }
.contextual-chip-close {
  background: none;
  border: none;
  padding: 0 2px;
  font-size: 12px;
  line-height: 1;
  color: inherit;
  opacity: 0.65;
  cursor: pointer;
  flex-shrink: 0;
}
.contextual-chip-close:hover { opacity: 1; }
.contextual-chip-green   { background: rgba(46, 107, 79, 0.12); border-color: rgba(46, 107, 79, 0.35); color: #1D4A34; }
.contextual-chip-amber   { background: rgba(168, 112, 28, 0.14); border-color: rgba(168, 112, 28, 0.4); color: #6B4611; }
.contextual-chip-red     { background: rgba(139, 30, 30, 0.12); border-color: rgba(139, 30, 30, 0.4); color: #6B1717; }
.contextual-chip-neutral { background: rgba(120, 120, 120, 0.08); border-color: rgba(120, 120, 120, 0.28); color: var(--ink-muted); }

/* =========== PREVIEW WRAPPER =========== */
.preview-shell {
  position: relative;
  background: var(--surface);
  margin: 0 auto;
  max-width: 816px; /* 8.5in at 96dpi */
  min-height: 600px;
  padding: 32px 36px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Desktop only (matches the .app-top-grid two-column breakpoint — mobile below 901px keeps
   its own separate, intentional single-column layout untouched, see the max-width:900px
   block below). ROOT-CAUSE FIX for the page-break marker drifting on resize: lock the preview
   to its true intrinsic print width (816px = 8.5in @ 96dpi) with a real `width` (not just
   max-width), so the on-screen text reflows EXACTLY as it will in the real PDF at every
   window size — the fluid .app-top-grid right column can no longer squeeze it narrower.
   When the available column is narrower than 816px, #preview-scale-wrap (JS, see
   updatePreviewScale() in app.js) visually shrinks the whole shell with a CSS
   transform:scale() instead of letting it reflow — the intrinsic 816px layout box (and thus
   text wrapping, and thus updatePageBreaks()'s marker math) never changes with window width. */
@media (min-width: 901px) {
  .preview-shell {
    width: 816px;
    transform-origin: top left;
  }
}

/* =========== PAGE BREAK MARKERS =========== */
.page-break-marker {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}
.page-break-marker::before,
.page-break-marker::after {
  content: '';
  flex: 1;
  border-top: 1.5px dashed rgba(160, 140, 120, 0.55);
}
/* Page label reads like a real page header: a small, subtle, sentence-case "Page N" tucked at
   the TOP-LEFT of the new page (just below the break line, aligned with the content) — not a
   pill floating on the line or in the gutter. The dashed line stays continuous. Preview-only. */
.page-break-marker .pbm-label {
  position: absolute;
  left: 2px;               /* in the paper's left white margin — no content there, no overlap */
  right: auto;
  top: 0;
  transform: translateY(3px);  /* just below the break line, top-left of the new page */
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: none;    /* "Page 2", not "PAGE 2" */
  color: #A89A86;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  white-space: nowrap;
}
@media print { .page-break-marker { display: none !important; } }

/* =========== Page break avoidance (applies in both print and PDF capture) =========== */
#invoice-preview tr,
#invoice-preview .cv-kit-subcat-row,
#invoice-preview .cv-kit-subcat-group,
#invoice-preview .cv-total-row,
#invoice-preview .cv-subtotal-row,
#invoice-preview .cv-discount-row,
#invoice-preview .cv-deposit-row,
#invoice-preview .cv-deposit-credit-row,
#invoice-preview .cv-balance-row {
  break-inside: avoid;
  page-break-inside: avoid;
}
#invoice-preview .cv-totals-block {
  break-inside: avoid;
  page-break-inside: avoid;
  break-before: avoid;
  page-break-before: avoid;
}
#invoice-preview .cv-payment-block,
#invoice-preview .cv-details-grid {
  break-inside: avoid;
  page-break-inside: avoid;
  break-before: avoid;
  page-break-before: avoid;
}
#invoice-preview .cv-clauses,
#invoice-preview .cv-w9-note {
  break-inside: avoid;
  page-break-inside: avoid;
}

/* =========== Preview line-item table column sizing =========== */
.invoice table { table-layout: fixed; }
.invoice table th.col-details { text-align: left; width: 40%; }
.invoice table th.col-notes  { text-align: left; width: 36%; font-size: 9px; }
.invoice table th.col-amount { text-align: right !important; width: 24%; }
.invoice table td.amt { text-align: right; font-variant-numeric: tabular-nums; }
.invoice table td.notes-col { font-size: 10px; color: var(--ink-muted); vertical-align: top; line-height: 1.4; }

/* =========== TEMPLATE A: COVERAGE INVOICE (refined palette) =========== */
.invoice.coverage {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink);
  line-height: 1.5;
}
.invoice.coverage .cv-inv-num {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11px;
  margin-top: 16px;
  margin-bottom: 10px;
  letter-spacing: 1px;
  color: var(--ink-muted);
  text-transform: uppercase;
}
.invoice.coverage .cv-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.invoice.coverage .cv-title,
.invoice .preview-title,
.invoice .invoice-header-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--ink);
}
.invoice.coverage .cv-biz {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 400;
  font-style: italic;
  line-height: 1.2;
  margin-bottom: 10px;
  color: var(--ink);
}
.invoice.coverage .cv-addr { font-size: 11px; white-space: pre-line; margin-bottom: 2px; color: var(--ink-muted); }
.invoice.coverage .cv-phone { font-size: 11px; margin-bottom: 8px; color: var(--ink-muted); }
.invoice.coverage .cv-date {
  color: var(--accent);
  font-weight: 600;
  margin: 8px 0;
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
}

.invoice.coverage .cv-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 14px;
  padding: 11px 0;
}
.invoice.coverage .cv-label,
.invoice .preview-section-heading {
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-size: 10px;
  text-decoration: none;
}
.invoice.coverage .cv-attn { font-size: 11px; font-weight: 700; color: var(--ink); margin-bottom: 4px; letter-spacing: 0.02em; }
.invoice.coverage .cv-scope { white-space: pre-line; font-size: 11px; color: var(--ink); }
.invoice.coverage .cv-deliverables { font-size: 11px; }
.cv-deliverables p, .cv-deliverables div,
.cv-scope-roles p, .cv-scope-roles div { margin: 0; line-height: 1.5; }
.cv-deliv-group { margin-bottom: 9px; }
.cv-deliv-group:last-child { margin-bottom: 0; }
.cv-deliv-head { font-weight: 600; color: var(--ink); line-height: 1.4; }
.cv-deliv-item { color: var(--ink-muted); padding-left: 10px; line-height: 1.5; position: relative; }
.cv-deliv-item::before { content: '—'; position: absolute; left: 0; color: var(--rule); font-weight: 400; }

.invoice.coverage table { width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 14px; }
.invoice.coverage thead th {
  text-align: left;
  background: transparent;
  padding: 8px 10px;
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--ink);
  color: var(--ink);
}
.invoice.coverage tbody td { padding: 4px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.invoice.coverage tbody td:nth-child(2) { font-variant-numeric: tabular-nums; }
.invoice.coverage tr.cv-section-row td {
  background: var(--bg-soft);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 7px 10px;
}
.invoice.coverage tr.cv-section-divider td {
  padding: 0;
  height: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
}
.invoice.coverage tr.cv-kit-subcat-row td {
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--highlight);
  padding: 8px 10px 1px;
  border-bottom: none;
  background: transparent;
  line-height: 1;
}
/* NOTE: was `tr.cv-kit-subcat-row:first-child` — broke once each category header started
   being wrapped in its own dedicated <tbody> for the page-break orphan fix (every group's
   header is a structural :first-child of ITS tbody now, not just the very first header in the
   whole table). cv-kit-subcat-row-first is applied explicitly in JS to only the true first
   header in the table; see renderCoverage() in app.js. */
.invoice.coverage tr.cv-kit-subcat-row-first td { padding-top: 2px; }
.invoice.coverage tr.cv-total-row td {
  background: var(--highlight-soft);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  padding: 10px 18px;
  /* No top divider — the TOTAL flows on as the anchor of the grouped totals block. */
  border-top: none;
  border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.invoice.coverage .cv-payment-block {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
}
.invoice.coverage .cv-pay-head,
.invoice .payment-footer-heading {
  color: var(--accent);
  font-weight: 600;
  font-size: 1rem;
  margin-top: 8px;
  margin-bottom: 4px;
  letter-spacing: 0.01em;
}
.invoice.coverage .cv-pay-detail {
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
  display: inline-block;
  padding-bottom: 2px;
}
.invoice.coverage .cv-pay-note,
.invoice .payment-footer-body {
  white-space: pre-line;
  margin-top: 6px;
  font-size: 0.9rem;
  color: var(--ink-muted);
  line-height: 1.5;
}
.invoice.coverage .cv-clauses {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  font-size: 10px;
  color: var(--ink-muted);
  white-space: pre-line;
  line-height: 1.5;
}
.cv-w9-note {
  margin-top: 6px;
  font-size: 9.5px;
  color: var(--ink-muted);
  opacity: 0.75;
  font-style: italic;
}
.cv-pay-zelle-line {
  margin-top: 8px;
  display: block;
  line-height: 1.4;
}
.cv-pay-head-inline {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.82rem;
}
.cv-pay-detail-inline {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 500;
  border-bottom: 1px solid var(--accent);
  padding-bottom: 1px;
}

/* Subtle inline pencil-edit icons next to preview title + subtitle */
.edit-icon {
  display: inline-block;
  margin-left: 8px;
  opacity: 0.4;
  cursor: pointer;
  transition: opacity 0.15s ease, color 0.15s ease;
  font-size: 0.8em;
  color: var(--ink-muted);
  user-select: none;
}
.edit-icon:hover { opacity: 1; color: var(--accent); }
.preview-title:hover .edit-icon,
.preview-subtitle:hover .edit-icon { opacity: 1; }

/* Tax info lines under business address */
.invoice .cv-tax,
.invoice .q-tax {
  font-size: 11px;
  color: var(--ink-muted);
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}

/* Banking info block in payment footer */
.invoice .cv-pay-divider {
  height: 1px;
  background: var(--rule);
  margin: 10px 0;
}
.invoice .cv-pay-banking {
  white-space: pre-line;
  font-size: 11px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
  line-height: 1.6;
}
.invoice .cv-pay-preferred {
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin: 4px 0;
}

/* SSN row */
.ssn-row { display: flex; gap: 6px; align-items: center; }
.ssn-row input { flex: 1; }

/* Payment method radios */
.payment-method-radios { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.payment-method-radios label { display: flex; flex-direction: row !important; gap: 6px; font-size: 13px; font-weight: 500; cursor: pointer; align-items: center; }

/* Wire fields */
.wire-fields { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px dashed var(--border); margin-top: 8px; }

/* Per-invoice tax inject toggle */
.meta-tax-inject { margin: 10px 0; padding: 8px 12px; background: var(--bg-soft); border-radius: 6px; }

/* Placeholder ghost text in preview */
.invoice .ph { color: var(--ph); font-style: italic; font-weight: 400; }

/* Empty row in table scaffold */
.invoice.coverage tr.cv-empty-row td,
.invoice.quote tr.q-item td span.ph { padding: 20px 10px; text-align: left; }

/* Totals block = one cohesive "money math" group, set apart from the line items above by a
   single dark rule, with NO dividers between its own rows (subtotal / discount / total) so the
   eye reads it as one cluster — the State-46 look, kept with the bold. A soft champagne tint
   binds subtotal + discount; the TOTAL row (below) is the stronger champagne anchor. */
.invoice.coverage tr.cv-subtotal-row td,
.invoice.quote tr.q-subtotal-row td {
  padding: 6px 10px 5px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: rgba(212, 184, 150, 0.12);
  border-top: 1.5px solid var(--ink);   /* the one rule dividing totals from line items */
  border-bottom: none;
}
/* Discount = the visible concession, bold, red amount — grouped flush with the subtotal above
   and the total below (no internal dividers). */
.invoice.coverage tr.cv-discount-row td,
.invoice.quote tr.q-discount-row td {
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: rgba(212, 184, 150, 0.12);
  border: none;
}
.invoice.coverage tr.cv-discount-row td:last-child,
.invoice.quote tr.q-discount-row td:last-child {
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 800;
}

/* Deposit / balance rows — same champagne as TOTAL but lighter */
.invoice.coverage tr.cv-deposit-row td,
.invoice.quote tr.q-deposit-row td,
.invoice .deposit-row td {
  background: rgba(212, 184, 150, 0.25);
  font-weight: 500;
  font-size: 11px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.invoice.coverage tr.cv-balance-row td,
.invoice.quote tr.q-balance-row td,
.invoice .balance-row td {
  background: rgba(212, 184, 150, 0.18);
  font-weight: 500;
  font-size: 11px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.invoice.coverage tr.cv-deposit-row td:first-child,
.invoice.quote tr.q-deposit-row td:first-child,
.invoice .deposit-row .label,
.invoice .balance-row .label { color: var(--accent); font-weight: 500; }

/* Closing-invoice tag near the invoice number */
.invoice.coverage .cv-closing-tag {
  font-family: var(--font-mono, monospace);
  font-size: 10px;
  letter-spacing: 0.6px;
  color: var(--accent);
  text-transform: uppercase;
  margin: -10px 0 18px;
  padding: 4px 8px;
  display: inline-block;
  background: rgba(212, 184, 150, 0.18);
  border: 1px solid rgba(212, 184, 150, 0.5);
  border-radius: 3px;
}

/* Deposit-received credit row */
.invoice.coverage tr.cv-deposit-credit-row td,
.invoice.quote tr.q-deposit-credit-row td {
  padding: 7px 20px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  border-bottom: 1px solid rgba(46, 107, 79, 0.15);
}
.invoice.coverage tr.cv-deposit-credit-row td:last-child,
.invoice.quote tr.q-deposit-credit-row td:last-child { color: var(--ink-muted); font-weight: 500; }

/* Deposit paid on original invoice — green tint to signal collected */
.invoice.coverage tr.cv-deposit-paid td,
.invoice.quote tr.q-deposit-paid td {
  background: rgba(46, 107, 79, 0.07);
  color: var(--success);
  font-weight: 600;
  font-size: 12px;
  border-top: 1px solid rgba(46, 107, 79, 0.18);
  border-bottom: 1px solid rgba(46, 107, 79, 0.18);
}
.invoice.coverage tr.cv-deposit-paid td:last-child,
.invoice.quote tr.q-deposit-paid td:last-child { color: var(--success); }

/* Balance Due total row — navy bg, white text */
.invoice.coverage tr.cv-balance-due-row td,
.invoice.quote tr.q-balance-due-row td {
  background: var(--accent) !important;
  color: #fff !important;
  border-top: none;
  border-bottom: none;
}

/* Meta deposit form block */
.meta-deposit {
  margin-top: 12px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: #fafaf5;
}
.deposit-toggle, .deposit-nonrefundable {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
}
.deposit-toggle input[type="checkbox"],
.deposit-nonrefundable input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}
.deposit-fields { margin-top: 10px; }
.deposit-fields .row { margin-bottom: 6px; }
.deposit-fields .muted { color: #888; font-size: 11px; }
.deposit-paid-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.deposit-paid-badge { font-size: 12px; font-weight: 600; color: var(--success); }
.btn-link-sm { background: none; border: none; padding: 0; font: inherit; font-size: 11px; font-weight: 500; color: var(--ink-muted); cursor: pointer; text-decoration: underline; }
.btn-link-sm:hover { color: var(--danger); }

/* Checkbox row */
.checkbox-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px;
  font-size: 12px;
  color: var(--ink);
}
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }

/* Deposit block styling */
.deposit-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.deposit-block > .checkbox-row { margin-bottom: 8px; }

/* =========== TEMPLATE B: PRODUCTION QUOTE (refined palette) =========== */
.invoice.quote {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink);
  line-height: 1.5;
}
.invoice.quote .q-inv-num {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 1px;
  margin-top: 28px;
  margin-bottom: 18px;
  color: var(--ink-muted);
  text-transform: uppercase;
}
.invoice.quote .q-hero {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 24px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}
.invoice.quote .q-logo { display: none; }
.invoice.quote .q-title-row { display: flex; align-items: baseline; gap: 8px; }
.invoice.quote .q-brand-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--ink);
}
.invoice.quote .q-biz { font-size: 11px; margin-top: 10px; white-space: pre-line; color: var(--ink-muted); }
.invoice.quote .q-recipient { font-size: 11px; white-space: pre-line; color: var(--ink); }
.invoice.quote .q-date {
  color: var(--accent);
  font-weight: 600;
  margin: 14px 0 8px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
}
.invoice.quote .q-scope-label {
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
  font-size: 10px;
  text-decoration: none;
}
.invoice.quote .q-scope-body { color: var(--ink); }
.invoice.quote .q-scope-body { white-space: pre-line; color: var(--ink); font-size: 11px; margin-bottom: 22px; }

.invoice.quote .q-header-bar {
  background: var(--ink);
  color: #fff;
  padding: 14px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: 0.15em;
  font-size: 13px;
  text-transform: uppercase;
}

.invoice.quote table { width: 100%; border-collapse: collapse; font-size: 11px; }
.invoice.quote thead th {
  background: var(--bg);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 2px solid var(--ink);
}
.invoice.quote tbody td { padding: 4px 10px; border-bottom: 1px solid var(--border); vertical-align: top; background: #fff; }
.invoice.quote tbody td:nth-child(3) { font-variant-numeric: tabular-nums; }
.invoice.quote tr.q-section td {
  background: var(--bg-soft);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.invoice.quote tr.q-item td { background: #fff; }
.invoice.quote tr.q-total td {
  background: var(--highlight-soft);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.invoice.quote tr.q-spacer td {
  background: transparent;
  height: 12px;
  padding: 0;
  border: none;
}

/* =========== PRINT =========== */
@media print {
  .app-header, .form-pane, .settings-panel, .recents-panel, #appearance-panel { display: none !important; }
  .app-top-grid { display: block; }
  .preview-pane { padding: 0; background: #fff; border-left: none; }
  .preview-shell { box-shadow: none; max-width: 100%; min-height: auto; padding: 24px 36px; }
  body { background: #fff; }

  /* Keep rows and key blocks intact — no mid-element cuts */
  #invoice-preview tr,
  #invoice-preview .cv-kit-subcat-row,
  #invoice-preview .cv-kit-subcat-group,
  #invoice-preview .cv-section-divider,
  #invoice-preview .cv-total-row,
  #invoice-preview .cv-subtotal-row,
  #invoice-preview .cv-discount-row,
  #invoice-preview .cv-deposit-row,
  #invoice-preview .cv-deposit-credit-row,
  #invoice-preview .cv-balance-row,
  #invoice-preview .cv-payment-block,
  #invoice-preview .cv-details-grid,
  #invoice-preview .cv-clauses,
  #invoice-preview .q-scope-block,
  #invoice-preview .q-deliverable-block {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  /* Never orphan the payment/totals block from the line items above */
  #invoice-preview .cv-payment-block,
  #invoice-preview .cv-details-grid {
    break-before: avoid;
    page-break-before: avoid;
  }
  /* Keep table headers repeating across pages */
  #invoice-preview thead {
    display: table-header-group;
  }
}

/* =========== UTILITY =========== */
[hidden] { display: none !important; }

/* Mobile */
@media (max-width: 900px) {
  .app-main { padding-top: var(--app-header-h, 118px); }
  .app-top-grid { grid-template-columns: 1fr; }
  .preview-pane { min-height: 60vh; border-left: none; border-top: 1px solid var(--border); }
  .rows > .row-item { grid-template-columns: 18px 1fr 0.4fr 0.6fr 0.9fr 32px 32px; }
  .rows > .row-item.kit-row { grid-template-columns: 18px 1fr 0.4fr 0.6fr 0.9fr auto 32px 32px 32px; }
  .settings-panel, .recents-panel { width: 100%; max-width: 100vw; padding: 16px; }
  .panel-head { margin: -16px -16px 14px; padding: 16px; top: -16px; }
  .app-header { padding: 8px 12px; }
  .brand h1, .brand .fi-brand-word { font-size: 16px; }
  .header-actions .btn { padding: 6px 10px; font-size: 12px; }
}
@media (max-width: 500px) {
  .app-header { gap: 6px; }
  .header-actions { gap: 4px; }
  .header-actions .btn { padding: 6px 9px; font-size: 11.5px; }
  .brand h1, .brand .fi-brand-word { font-size: 15px; }
  .modal-head { padding: 16px 18px 10px; }
  .modal-head h2 { font-size: 20px; }
  .modal-body, .modal-foot, .modal-sub { padding-left: 18px; padding-right: 18px; }
  .paywall-body { padding: 20px 18px 4px; }
  .paywall-price { margin-left: -18px; margin-right: -18px; padding: 14px 18px; }
}

/* ============================================================================
   MOBILE (phones, ≤ 600px). Desktop (> 600px) is untouched by everything here.
   A real single-column phone experience: swipeable action bar, comfortable
   full-width form, and a preview that fits the screen instead of overflowing.
   ============================================================================ */
@media (max-width: 600px) {
  /* <fieldset> has a non-zero UA-default min-width (based on its content's
     min-content size) that a plain <div> doesn't — it refuses to shrink below
     that, which silently forces every fieldset-wrapped form section (Meta,
     Client, Line Items, etc.) wider than the 390px phone viewport instead of
     respecting it. Caught by the mobile kit-row tap-target fix above: bumping
     .rm-btn/.dup-btn to 38px pushed a kit-row's content past the fieldset's
     old (just-barely-fitting) min-content width, tipping it into real
     unreachable horizontal overflow (.form-pane clips with overflow-x:hidden,
     so it wasn't even page-scrollable). min-width:0 is the standard fix —
     lets the fieldset shrink to its container so flex-wrap can do its job. */
  fieldset { min-width: 0; }
  /* Fixed header → one horizontally-swipeable action row (no tall wrap block) */
  .app-header { flex-wrap: nowrap; gap: 8px; padding: 8px 10px; }
  .brand { flex: 0 0 auto; }
  .brand h1, .brand .fi-brand-word { font-size: 0; }           /* hide the wordmark text, keep the logo mark */
  .brand .brand-mark, .brand svg, .brand img { font-size: 20px; }
  .header-actions {
    flex: 1;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding-bottom: 2px;
  }
  .header-actions::-webkit-scrollbar { display: none; }
  .header-actions .btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 12.5px;
    min-height: 40px;               /* comfortable tap target */
  }

  /* Single column, and reorder so ALL the form comes first, preview last. On desktop the
     preview lives inside .app-top-grid (beside the top form) while line-items are a sibling
     below; flattening the grid with display:contents lets us order all three in one flex column:
     top form → line-items/project → preview. */
  .app-main { display: flex; flex-direction: column; }
  .app-top-grid { display: contents; }
  .form-pane-top { order: 1; }
  .form-pane-bottom { order: 2; }
  .preview-pane { order: 3; }
  .form-pane { padding: 14px 14px 40px; }
  .preview-pane { min-height: auto; border-left: none; border-top: 1px solid var(--border); padding: 14px 8px; }

  /* 16px inputs prevent iOS auto-zoom on focus; roomy tap targets */
  .form-pane input, .form-pane select, .form-pane textarea { font-size: 16px; padding: 9px 10px; }
  label { font-size: 12px; }

  /* Stack any two-up field groups (the form uses .row grids for these) */
  .form-pane .row,
  .field-row, .two-col, .grid-2, .form-row {
    grid-template-columns: 1fr !important;
    display: grid;
    gap: 10px;
  }
  /* The "saved clients" select + Save button pair also sits in a flex row — stack it */
  .form-pane .row > * { min-width: 0; }

  /* Line-item editor rows → card layout: name full-width on top, controls on a second row
     (the desktop 7/8-column grid is unusable at phone width). Flex-wrap handles both labor
     rows and kit rows (which have an extra category <select>). */
  .rows > .row-item,
  .rows > .row-item.kit-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border, #e5e5e5);
    border-radius: 10px;
    margin-bottom: 8px;
    background: #fafafa;
  }
  .rows > .row-item > .row-drag-handle { flex: 0 0 auto; opacity: .5; }
  .rows > .row-item > *:nth-child(2) { flex: 1 1 100%; order: 0; }   /* the name/details input */
  .rows > .row-item input { flex: 1 1 70px; min-width: 56px; font-size: 16px; padding: 8px; }
  .rows > .row-item select { flex: 1 1 120px; min-width: 100px; font-size: 14px; }
  /* rm-btn/dup-btn (and the kit-assign-toggle-btn, which reuses .dup-btn's chrome
     per app.js) are 3px-vertical-padding icon buttons sized by their glyph alone on
     desktop (~28px grid track) — on phones with no grid track to size them, they
     shrank to ~10-15px x 25px, well under a comfortable tap target. Give them a
     real square hit area matching this breakpoint's other ~40px controls
     (.btn-sm, .header-actions .btn) without changing their desktop appearance. */
  .rows > .row-item .rm-btn, .rows > .row-item .dup-btn {
    flex: 0 0 auto;
    min-width: 38px;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 16px;
  }

  /* Invoice preview: fit the device width, trim heavy paper padding so it's readable */
  .preview-shell { max-width: 100%; padding: 20px 16px; box-shadow: none; }
  #invoice-preview { font-size: 12px; }

  /* Keep the page-break "PAGE 2" pill INSIDE the paper on phones (no gutter to float into,
     avoids a horizontal-scroll overflow) — sit it just above the line at the right. */
  .page-break-marker .pbm-label { display: none; }  /* line alone marks the break on phones */

  /* Side panels + modals go full-screen for thumb reach */
  .settings-panel, .recents-panel, #appearance-panel, #dashboard-panel {
    width: 100vw; max-width: 100vw; left: 0; right: 0;
  }
  .modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .modal-overlay { padding: 0; }
  .modal-close { width: 40px; height: 40px; }   /* tap target on full-screen modals */

  /* The Share ▾ and account (avatar) dropdowns are positioned absolute against
     .user-menu/.share-menu, which live inside .header-actions — and that bar is
     overflow-x:auto here (horizontally-swipeable action row), which per the CSS
     overflow spec forces its overflow-y to auto too, silently CLIPPING the
     dropdown panel instead of letting it float over the page. Anchor them to the
     viewport instead so they always render in full, right-aligned near the
     header regardless of the trigger's scroll position. --app-header-h is kept
     accurate at every breakpoint by JS (adaptive header height), so this tracks
     the real header edge even as it wraps/reflows on narrow phones. */
  .user-dropdown {
    position: fixed;
    top: calc(var(--app-header-h, 56px) + 6px);
    right: 8px;
    left: auto;
  }

  /* Comfortable tap targets (~40px, matching this app's established mobile
     sizing) for the small buttons used throughout modals/panels/dashboard —
     Save/Cancel in Save-as-Kit/Save-as-Crew, CSV import controls, "Add external
     invoice", etc. Desktop .btn-sm (24px) is untouched outside this query. */
  .btn-sm { min-height: 40px; padding: 9px 14px; font-size: 13px; }

  /* Kit row "assigned to / status" combo + category select: bump to the same
     comfortable sizing as the rest of the mobile row-card controls (they inherit
     .rows > .row-item select's 14px/100px sizing already; this just adds height/
     padding so they're easy to tap, matching .kit-assign-input's row). */
  .kit-assign-row { gap: 6px; }
  .kit-status-select, .kit-cat-select { padding: 8px 6px; max-width: none; flex: 1 1 90px; }
  .kit-assign-input, .kit-status-select { min-height: 38px; }

  /* "Skip this next time" checkbox row in the know-your-worth modal — grow the
     whole label's hit area, not just the tiny native checkbox. */
  .kit-rate-skip { padding: 8px 4px; }
}

/* Extra-small phones (≤ 380px): trim a touch more */
@media (max-width: 380px) {
  .header-actions .btn { padding: 8px 10px; font-size: 12px; }
  .form-pane { padding: 12px 12px 40px; }
  .preview-shell { padding: 16px 12px; }
}

/* Print: drop the fixed header so PDF capture doesn't get clipped */
@media print {
  .app-header { position: static; }
  .app-main { padding-top: 0; }
}

/* Invoice logo */
.invoice-logo { display: block; object-fit: contain; flex-shrink: 0; }
.invoice-logo.size-small { height: 40px; }
.invoice-logo.size-medium { height: 60px; }
.invoice-logo.size-large { height: 80px; }
.cv-header-wrap { margin-bottom: 14px; }
.cv-header-logo-left { display: flex; align-items: flex-start; gap: 16px; }
.cv-header-logo-left .cv-title-block { flex: 1; }
.cv-header-logo-center { display: flex; flex-direction: column; align-items: center; text-align: center; }
.cv-header-logo-center .cv-title-block { text-align: left; margin-top: 8px; }
.cv-header-logo-right { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.cv-header-logo-right .cv-title-block { flex: 1; }

/* Logo upload placeholder shown in preview when no logo is set */
.cv-logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 70px;
  height: 54px;
  flex-shrink: 0;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  color: var(--ink-muted);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.cv-logo-placeholder:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(30,58,95,0.04);
}
@media print {
  .cv-logo-placeholder { display: none !important; }
}

/* Notes sub-line in preview table */
.cv-notes-line, .q-notes-line {
  font-size: 10px;
  color: var(--ink-muted);
  margin-top: 2px;
  line-height: 1.4;
}

/* Logo preview in settings */
.logo-upload-field { display: flex; flex-direction: column; gap: 8px; }
.logo-preview-wrap { display: flex; align-items: center; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.logo-preview-wrap img { max-height: 60px; max-width: 140px; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; padding: 4px; }
.logo-upload-actions { display: flex; gap: 8px; align-items: center; }

/* Payment methods list in footer */
.cv-pay-methods { margin-top: 8px; }
.cv-pay-method-line { font-size: 12px; color: var(--ink); margin-bottom: 3px; }
.cv-pay-method-label { font-weight: 600; color: var(--accent); }

/* Settings brand section */
.settings-brand-section { margin-bottom: 12px; }

/* Helper span */
span.field-helper {
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 400;
  display: block;
  margin-top: 2px;
  line-height: 1.4;
}

/* =========== SAAS: PRO / FREE UI =========== */

/* Pro badge in header */
.pro-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  vertical-align: middle;
}

/* Pro-only tag inline — hidden for Pro users, tasteful indicator for free.
   Visual normalized to match .pl-pro-dot (canonical Pro pill, see home.html). */
.pro-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 10px;
  vertical-align: middle;
}
body.is-pro .pro-tag { display: none; }

/* Pro-only features unlocked globally — inputs stay fully interactive for everyone.
   The inline "PRO" text tags (.pro-tag / .pro-pill) remain as awareness markers. */
body.is-free .pro-only {
  position: relative;
}
body.is-free .pro-only input,
body.is-free .pro-only textarea,
body.is-free .pro-only select,
body.is-free .pro-only button:not(.paywall-trigger) {
  pointer-events: auto;
}
body.is-free .pro-only::after {
  content: none;
}

/* Phone input row: country code + number side by side */
.phone-input-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.phone-country-sel {
  width: 66px;
  flex-shrink: 0;
  font-size: 13px;
}
.phone-input-row input[type="text"] {
  flex: 1;
  min-width: 0;
}

/* Coming soon tag */
.coming-soon-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-soft);
  color: var(--ink-muted);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  border: 1px dashed var(--border);
}

/* Upgrade link in header */
.btn-link-pricing {
  background: var(--accent) !important;
  color: #fff !important;
  text-decoration: none;
  border-color: var(--accent) !important;
  font-weight: 600;
}
.btn-link-pricing:hover { background: var(--accent-soft) !important; border-color: var(--accent-soft) !important; }

/* Pro unlock banner */
.pro-unlock-banner {
  background: var(--highlight-tint);
  border: 1px solid var(--highlight-soft);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-top: 12px;
}
.pro-unlock-banner a { color: var(--accent); text-decoration: underline; }

/* Free usage banner */
.free-usage-banner {
  background: var(--bg-soft);
  border: 1px dashed var(--border);
  color: var(--ink-muted);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 12px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.free-usage-banner a { color: var(--accent); text-decoration: none; font-weight: 600; }
.free-usage-banner a:hover { text-decoration: underline; }

/* =========== BENCHMARK MARKET BAR (per-invoice override + compare) =========== */
.bm-market-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  row-gap: 4px;
  margin-bottom: 8px;
}
.bm-market-bar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
}
.bm-market-bar select {
  font-size: 12px;
  padding: 4px 6px;
  max-width: 100%;
  min-width: 0;
}
#compare-markets-btn { white-space: nowrap; }

/* "Why this number" — the pill/hint market text is a real button: hover shows the
   native title tooltip on desktop, click/tap toggles the inline .bm-math line
   (mobile has no hover). Styled as dotted-underlined text, not a chrome button. */
button.bm-why {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
button.bm-why:hover { text-decoration-style: solid; }
button.bm-why:focus-visible { outline: 1px dotted currentColor; outline-offset: 2px; }
.bm-math {
  display: block;
  font-size: 10.5px;
  color: inherit;
  opacity: 0.8;
  margin-top: 3px;
  line-height: 1.35;
}
.bm-math[hidden] { display: none; }
.row-bm-hint .bm-math { font-size: 10px; color: var(--ink-muted); opacity: 1; }

/* =========== COMPARE MARKETS MODAL =========== */
.market-compare-modal { max-width: 480px; }
.mc-table-wrap { overflow-x: auto; }
.mc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.mc-table th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.mc-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border-soft, var(--border));
  color: var(--ink);
  white-space: nowrap;
}
.mc-table td:first-child { white-space: normal; }
.mc-table tr:last-child td { border-bottom: none; }
.mc-table .mc-num { text-align: right; }
.mc-table .mc-range { color: var(--ink-muted); font-size: 11.5px; }
.mc-table tr.mc-active td { background: var(--bg-soft); }
.mc-table tr.mc-active td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.mc-tag {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(30, 58, 95, 0.08);
  border: 1px solid rgba(30, 58, 95, 0.2);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: 1px;
}
.mc-note {
  font-size: 11px;
  color: var(--ink-muted);
  margin: 10px 0 0;
  line-height: 1.4;
}

/* =========== BENCHMARK PILLS =========== */
.benchmark-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.benchmark-pill {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  line-height: 1.4;
}
.benchmark-pill em { font-style: normal; font-weight: 600; }
.benchmark-pill .muted { color: var(--ink-muted); font-size: 11px; }
.benchmark-green  { background: rgba(46, 107, 79, 0.12); border-color: rgba(46, 107, 79, 0.35); color: #1D4A34; }
.benchmark-amber  { background: rgba(168, 112, 28, 0.14); border-color: rgba(168, 112, 28, 0.4);  color: #6B4611; }
.benchmark-red    { background: rgba(139, 30, 30, 0.12); border-color: rgba(139, 30, 30, 0.4);  color: #6B1717; }
.benchmark-neutral { background: rgba(120, 120, 120, 0.08); border-color: rgba(120, 120, 120, 0.28); color: var(--ink-muted); }

/* =========== STATE FILM INCENTIVE CHIP + MODAL =========== */
/* Sibling of the benchmark market bar: compact, dismissible, informational only.
   Accent-tinted like .mc-tag so it reads as app chrome, never invoice content. */
.incentive-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.4;
  padding: 5px 8px 5px 10px;
  margin-bottom: 8px;
  border-radius: 6px;
  color: var(--accent);
  background: rgba(30, 58, 95, 0.06);
  border: 1px solid rgba(30, 58, 95, 0.18);
}
.incentive-chip-text { flex: 1; min-width: 0; }
.incentive-chip-details {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  white-space: nowrap;
}
.incentive-chip-details:hover { text-decoration-style: solid; }
.incentive-chip-close {
  background: none;
  border: none;
  padding: 0 2px;
  font-size: 12px;
  line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
}
.incentive-chip-close:hover { color: var(--ink); }

.incentive-modal { max-width: 440px; }
.incentive-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 0 0 10px;
  font-size: 12.5px;
}
.incentive-facts dt {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  align-self: baseline;
}
.incentive-facts dd { margin: 0; color: var(--ink); }
.incentive-note { font-size: 12.5px; line-height: 1.5; color: var(--ink); margin: 0 0 10px; }
.incentive-link { margin: 0 0 10px; font-size: 12.5px; }
.incentive-link a { color: var(--accent); font-weight: 600; text-decoration: none; }
.incentive-link a:hover { text-decoration: underline; }
.incentive-disclaimer { font-size: 11px; color: var(--ink-muted); line-height: 1.4; margin: 0; }

/* Locked template radio */
.seg label.locked { opacity: 0.55; }
.seg label.locked::after { content: ' 🔒'; font-size: 10px; }

/* =========== MODALS =========== */
body.modal-open { overflow: hidden; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: modal-fade-in 0.18s ease-out;
}
@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal {
  background: #fff;
  border-radius: 14px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(10, 14, 26, 0.25), 0 0 1px rgba(10, 14, 26, 0.18);
  display: flex;
  flex-direction: column;
  animation: modal-pop-in 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
  font-weight: 400;
}
.modal-close {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 16px;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.modal-close:hover { color: var(--ink); background: var(--bg-soft); }
.modal-close:focus-visible { outline: none; border-color: var(--accent-soft); box-shadow: 0 0 0 3px rgba(30,58,95,0.18); }
.modal-sub {
  padding: 0 24px;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.55;
  margin-top: 8px;
}
.modal-body {
  padding: 16px 24px;
}
.modal-body label { display: block; margin-bottom: 12px; font-size: 12px; font-weight: 500; color: var(--ink-muted); }
.modal-body input, .modal-body textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  margin-top: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.modal-body input:focus, .modal-body textarea:focus {
  outline: none;
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(30,58,95,0.14);
}
.modal-foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* Destructive-action button (shared confirm modal: delete, etc.) */
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: #6e1717; border-color: #6e1717; color: #fff; }
.btn-danger:focus-visible { box-shadow: 0 0 0 3px rgba(139, 30, 30, 0.25); }

/* Gmail-send explainer modal */
.gmail-send-steps {
  margin: 0;
  padding-left: 20px;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.7;
}
.gmail-send-steps li { margin-bottom: 4px; }

/* Role selector */
.role-modal { max-width: 780px; }
.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  padding: 18px 22px;
}
.role-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.role-card:hover { border-color: var(--accent); background: #fff; }
.role-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: #fff; }
.role-pick-badge {
  font-size: 9px; font-weight: 700; letter-spacing: 0.08em; border-radius: 999px;
  padding: 2px 8px; background: var(--bg-soft); color: var(--accent); flex-shrink: 0;
}
.role-card.is-lead .role-pick-badge { background: var(--accent); color: #fff; }
.role-card.locked { opacity: 0.85; }
.role-card.locked:hover { border-color: var(--highlight); background: var(--highlight-tint); }
.role-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.role-card-top strong { font-size: 15px; font-weight: 600; }
.role-card p { margin: 0; font-size: 12px; color: var(--ink-muted); line-height: 1.4; }
.role-card-rate { font-size: 11px; }
.pro-pill {
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

/* Paywall modal */
.paywall-modal { max-width: 520px; }
.paywall-body {
  padding: 24px 28px 8px;
  text-align: center;
}
.paywall-icon {
  color: var(--accent);
  margin: 0 auto 12px;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.paywall-body p {
  font-size: 14px;
  color: var(--ink);
  margin: 6px 0 18px;
  line-height: 1.55;
}
.paywall-list {
  list-style: none;
  padding: 0;
  margin: 16px auto 0;
  max-width: 400px;
  text-align: left;
}
.paywall-list li {
  padding: 8px 0 8px 24px;
  position: relative;
  font-size: 13px;
  color: var(--ink);
  line-height: 1.5;
}
.paywall-list li + li { border-top: 1px dashed color-mix(in srgb, var(--border) 70%, transparent); }
.paywall-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 11px;
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none' stroke='%232E6B4F' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 7.5L5.5 11 12 3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
}
.paywall-price {
  margin: 20px -28px 0;
  padding: 16px 28px;
  background: var(--highlight-tint);
  border-top: 1px solid var(--highlight-soft);
  border-bottom: 1px solid var(--highlight-soft);
  font-size: 14px;
  text-align: center;
}
.paywall-price strong { font-weight: 600; }
.paywall-price .muted { color: var(--ink-muted); font-size: 12px; }
.paywall-secondary {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 6px 10px;
  text-decoration: underline;
}
.paywall-secondary:hover { color: var(--ink); }

/* Email modal */
.email-modal { max-width: 620px; }
.coming-soon-banner {
  background: var(--highlight-tint);
  border: 1px solid var(--highlight-soft);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink);
  margin-top: 10px;
}

/* =========== DASHBOARD =========== */
.dashboard-panel { width: 720px; max-width: 96vw; }
.dashboard-panel #dashboard-body { padding: 0; }
.dashboard-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s;
}
.metric-card:hover { border-color: var(--accent-soft); }
.metric-card.metric-success { background: rgba(46, 107, 79, 0.08); border-color: rgba(46, 107, 79, 0.22); }
.metric-card.metric-danger { background: rgba(139, 30, 30, 0.06); border-color: rgba(139, 30, 30, 0.22); }
.metric-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); font-weight: 600; }
.metric-value { font-size: 24px; font-weight: 400; color: var(--ink); font-family: var(--font-display); letter-spacing: -0.01em; line-height: 1.1; }
.metric-sub { font-size: 11px; color: var(--ink-muted); }
.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.dashboard-table thead th {
  background: var(--bg-soft);
  text-align: left;
  padding: 10px 12px;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
}
.dashboard-table tbody td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.dashboard-table tbody tr:last-child td { border-bottom: none; }
.dashboard-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-soft) 40%, transparent); }
.dashboard-table tbody tr:hover td { background: var(--bg-soft); }
.dashboard-table td.amt, .dashboard-table th.amt { text-align: right; font-variant-numeric: tabular-nums; }
.dashboard-table a { color: var(--accent); text-decoration: none; font-weight: 500; }
.dashboard-table a:hover { text-decoration: underline; }
.dashboard-table-wrap { overflow-x: auto; }

/* =========== EMPTY STATES =========== */
.empty-state {
  text-align: center;
  padding: 40px 24px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
  color: var(--ink);
}
.empty-state p {
  font-size: 13px;
  color: var(--ink-muted);
  margin: 0 0 14px;
  line-height: 1.55;
}
.status-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.status-draft { background: var(--bg-soft); color: var(--ink-muted); }
.status-sent { background: rgba(30, 58, 95, 0.12); color: var(--accent); }
.status-viewed { background: rgba(30, 58, 95, 0.2); color: var(--accent); }
.status-paid { background: rgba(46, 107, 79, 0.2); color: var(--success); }
.status-deposit-paid { background: rgba(46, 107, 79, 0.14); color: var(--success); }
.status-overdue { background: rgba(139, 30, 30, 0.15); color: var(--danger); }
.status-soft-hold { background: rgba(138, 90, 18, 0.16); color: var(--warn); }
.status-locked-in { background: rgba(30, 58, 95, 0.16); color: var(--accent); }
.status-pro-bono { background: rgba(107, 87, 32, 0.16); color: #6B5720; }

/* =========== WATERMARK =========== */
.pdf-watermark {
  font-size: 10px;
  text-align: center;
  color: #8A8B8F;
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px dashed #D8D4CA;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* =========== PRINT WATERMARK — removed; unlocked globally =========== */
@media print {
  body.is-free .invoice::after {
    content: none;
  }
}

/* =========== V76 — COLUMN HEADERS + DEPOSIT + RICH TEXT =========== */

/* Invoice preview column headers */
.cv-col-head {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 8px;
}
.cv-scope-roles { margin-top: 6px; }

/* Deposit row — label on one line, "Non-refundable" as subdued sub-note */
.cv-dep-label { display: block; }
.cv-dep-meta { display: block; font-size: 10px; opacity: 0.6; font-style: italic; }

/* Rich text label */
.richtext-label { display: flex; flex-direction: column; }

/* Rich text wrapper */
.richtext-wrap {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}

/* Toolbar */
.richtext-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1px;
  padding: 3px 6px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.rt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 24px;
  border: none;
  background: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink);
  padding: 0;
  transition: background 0.12s;
}
.rt-btn:hover { background: var(--highlight-tint); }
.rt-sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; }
.rt-color-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 24px;
  position: relative;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.12s;
}
.rt-color-wrap:hover { background: var(--highlight-tint); }
.rt-s-icon { font-size: 13px; font-weight: 400; font-style: normal; pointer-events: none; padding: 0 2px; }
.rt-color-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  pointer-events: none;
  line-height: 1;
  border-bottom: 5px solid #000;
  padding-bottom: 2px;
  display: inline-block;
  margin-top: 5px;
}
.rt-btn svg { display: block; }
.rt-btn-text { width: auto; padding: 0 7px; font-size: 10.5px; font-weight: 500; }
.rt-color {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* Editor content area */
.richtext-editor {
  min-height: 80px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  outline: none;
  background: var(--bg);
}
.richtext-editor p,
.richtext-editor div { margin: 0; }
/* Links inside the note editors + invoice preview/PDF render as clear links. */
.richtext-editor a { color: var(--accent); text-decoration: underline; cursor: pointer; }
.cv-scope-roles a,
.cv-deliverables a { color: var(--accent); text-decoration: underline; }
.richtext-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-muted);
  opacity: 0.5;
  white-space: pre-line;
  pointer-events: none;
}

/* Pro gate — dim B/I/U/Color for free users */
/* Rich-text tools unlocked globally — fully usable, no greyed-out state */
body.is-free .richtext-toolbar .pro-rt-btn { opacity: 1; cursor: pointer; }

/* Camera autocomplete dropdown */
.cam-ac-dropdown { font-family: inherit; }
.cam-ac-row:last-child { border-bottom: none !important; }
/* Non-selectable department header in the grouped (role) autocomplete. Visual
   styling is set inline in buildGroupedDropdown; kept here for discoverability. */
.cam-ac-header { user-select: none; }
.cam-ac-dropdown::-webkit-scrollbar { width: 4px; }
.cam-ac-dropdown::-webkit-scrollbar-track { background: transparent; }
.cam-ac-dropdown::-webkit-scrollbar-thumb { background: #D8D4CA; border-radius: 4px; }

/* =============== ADD EXTERNAL INVOICE =============== */
.dashboard-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 0 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.dashboard-actions-hint { font-size: 12px; line-height: 1.4; }
@media (max-width: 560px) { .dashboard-actions-hint { display: none; } }

.ext-modal { max-width: 600px; }
.ext-choice-grid { display: grid; gap: 12px; }
.ext-choice {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  width: 100%;
  font-family: inherit;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.ext-choice:hover { border-color: var(--accent-soft); background: var(--bg-soft); }
.ext-choice:focus-visible { outline: none; border-color: var(--accent-soft); box-shadow: 0 0 0 3px rgba(30,58,95,0.16); }
.ext-choice-title { font-size: 15px; font-weight: 600; color: var(--ink); }
.ext-choice-desc { font-size: 12.5px; color: var(--ink-muted); line-height: 1.5; }

.ext-dropzone {
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--bg-soft);
}
.ext-dropzone:hover, .ext-dropzone:focus-visible { border-color: var(--accent-soft); background: #fff; outline: none; }
.ext-dropzone.ext-dragover { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(30,58,95,0.12); }
.ext-dropzone-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ext-dropzone-icon { font-size: 26px; }
.ext-dropzone-inner strong { font-size: 15px; color: var(--ink); }
.ext-dropzone-hint { font-size: 11.5px; }
.ext-link-btn { color: var(--accent); text-decoration: underline; cursor: pointer; }
.ext-link-btn:hover { color: var(--accent-soft); }

.ext-uploading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 30px 20px;
  font-size: 14px;
  color: var(--ink-muted);
}
.ext-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ext-spin 0.8s linear infinite;
  flex: none;
}
@keyframes ext-spin { to { transform: rotate(360deg); } }

.ext-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; }
.ext-field { margin-bottom: 8px; }
.ext-field.ext-field-full { grid-column: 1 / -1; }
.ext-field > span { display: block; font-size: 12px; font-weight: 500; color: var(--ink-muted); margin-bottom: 2px; }
.ext-field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  margin-top: 6px;
  background: #fff;
}
.ext-field select:focus { outline: none; border-color: var(--accent-soft); box-shadow: 0 0 0 3px rgba(30,58,95,0.14); }
@media (max-width: 480px) { .ext-form-grid { grid-template-columns: 1fr; } }

.ext-note {
  font-size: 12.5px;
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
}
.ext-note.ext-note-warn {
  background: rgba(139, 30, 30, 0.06);
  color: #8B1E1E;
  border-color: rgba(139, 30, 30, 0.22);
}
.ext-lineitems { margin-top: 4px; margin-bottom: 8px; }
.ext-lineitems-head { font-size: 12px; font-weight: 600; color: var(--ink-muted); margin-bottom: 6px; }
.ext-lineitems ul, #ext-lineitems { list-style: none; margin: 0; padding: 0; }
#ext-lineitems li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
  color: var(--ink);
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
#ext-lineitems li:last-child { border-bottom: none; }
#ext-lineitems .ext-li-amt { color: var(--ink-muted); white-space: nowrap; }

/* CSV import step (client-side parsing — no AI) */
.ext-modal-wide { max-width: 780px; }
.ext-back-link {
  display: inline-block;
  margin: 0 0 12px;
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  font-family: inherit;
}
.ext-csv-map-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin-bottom: 16px; }
@media (max-width: 480px) { .ext-csv-map-grid { grid-template-columns: 1fr; } }
.ext-csv-preview-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.ext-csv-preview-head strong { font-size: 12.5px; color: var(--ink); }
.ext-csv-preview-head .muted { font-size: 11.5px; }
.ext-csv-preview-wrap { max-height: 260px; overflow-y: auto; margin-bottom: 14px; }
.ext-csv-preview-wrap .dashboard-table { font-size: 11.5px; }
.ext-csv-skip-list { margin: 10px 0 0; padding-left: 18px; font-size: 12px; color: var(--ink-muted); max-height: 160px; overflow-y: auto; }
.ext-csv-skip-list li { margin-bottom: 4px; }

/* "External" tag on recents + dashboard rows */
.ext-tag {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  vertical-align: middle;
  margin-left: 6px;
}



/* ── PL-DARK-MODE (#59) — refined palette, uniform across all pages. Token
   overrides only; layout untouched. Auto via prefers-color-scheme, manual
   override via <html data-theme> (auth.js paints it from invgen:theme).
   Documents (invoice preview / call sheet / memos) stay paper. ── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --accent: #8FB0D6;
    --accent-soft: #6E93BE;
    --bg: #0F1116;
    --bg-soft: #171A22;
    --border: #2A2E3A;
    --danger: #E07A7A;
    --highlight: #C9AA6C;
    --highlight-soft: rgba(201,170,108,0.16);
    --highlight-tint: rgba(201,170,108,0.10);
    --ink: #E8E2D2;
    --ink-muted: #A9B4C4;
    --ink-placeholder: #5D6B80;
    --ph: #5D6B80;
    --rule: #2A2E3A;
    --success: #6FD99A;
    --surface: #181B24;
    --warn: #F0C173;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #8FB0D6;
    --accent-soft: #6E93BE;
    --bg: #0F1116;
    --bg-soft: #171A22;
    --border: #2A2E3A;
    --danger: #E07A7A;
    --highlight: #C9AA6C;
    --highlight-soft: rgba(201,170,108,0.16);
    --highlight-tint: rgba(201,170,108,0.10);
    --ink: #E8E2D2;
    --ink-muted: #A9B4C4;
    --ink-placeholder: #5D6B80;
    --ph: #5D6B80;
    --rule: #2A2E3A;
    --success: #6FD99A;
    --surface: #181B24;
    --warn: #F0C173;
}
.preview-shell, .preview-shell * { color-scheme: light; }

/* Dark-only repairs: panels that hardcode light paint go to tokens IN DARK ONLY
   (the light theme keeps its exact current look), and the invoice PREVIEW gets
   its light tokens re-pinned — the paper must never inherit the dark chrome. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .form-pane,
  :root:not([data-theme="light"]) .user-dropdown,
  :root:not([data-theme="light"]) .settings-panel,
  :root:not([data-theme="light"]) .recents-panel,
  :root:not([data-theme="light"]) .settings-head,
  :root:not([data-theme="light"]) .settings-footer,
  :root:not([data-theme="light"]) .modal { background: var(--surface); }
  :root:not([data-theme="light"]) .meta-deposit { background: var(--bg-soft); }
  :root:not([data-theme="light"]) .preview-shell {
    --bg: #F7F5F0; --bg-soft: #EDEAE3; --surface: #FFFFFF;
    --ink: #0A0E1A; --ink-muted: #4A5568; --ink-placeholder: #8A94A6;
    --border: #D8D4CA; --rule: #D8D4CA; --accent: #1E3A5F; --accent-soft: #3A5A85;
    --highlight: #B8922A; --highlight-soft: #F4E9CE; --highlight-tint: #FAF4E4;
  }
}
:root[data-theme="dark"] .form-pane,
:root[data-theme="dark"] .user-dropdown,
:root[data-theme="dark"] .settings-panel,
:root[data-theme="dark"] .recents-panel,
:root[data-theme="dark"] .settings-head,
:root[data-theme="dark"] .settings-footer,
:root[data-theme="dark"] .modal { background: var(--surface); }
:root[data-theme="dark"] .meta-deposit { background: var(--bg-soft); }
:root[data-theme="dark"] .preview-shell {
  --bg: #F7F5F0; --bg-soft: #EDEAE3; --surface: #FFFFFF;
  --ink: #0A0E1A; --ink-muted: #4A5568; --ink-placeholder: #8A94A6;
  --border: #D8D4CA; --rule: #D8D4CA; --accent: #1E3A5F; --accent-soft: #3A5A85;
  --highlight: #B8922A; --highlight-soft: #F4E9CE; --highlight-tint: #FAF4E4;
}

/* PL-DARK-MODE: benchmark pills get dark-tuned tones (their light hexes were
   unreadable green-on-green in dark). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .benchmark-green { color: #7ED0A0; }
  :root:not([data-theme="light"]) .benchmark-amber { color: #DDB55E; }
  :root:not([data-theme="light"]) .benchmark-red { color: #E89090; }
}
:root[data-theme="dark"] .benchmark-green { color: #7ED0A0; }
:root[data-theme="dark"] .benchmark-amber { color: #DDB55E; }
:root[data-theme="dark"] .benchmark-red { color: #E89090; }

/* PL-DARK-TEXT: hardcoded #555/#444 form labels → readable in dark (screen-only; print/PDF exempt) */
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .row label, :root:not([data-theme="light"]) fieldset label { color: var(--ink-muted); }
  :root:not([data-theme="light"]) .seg-label { color: var(--ink-muted); }
  :root:not([data-theme="light"]) .richtext-label { color: var(--ink-muted); }
  :root:not([data-theme="light"]) .section-head h4 { color: var(--ink); }
}
@media screen {
  :root[data-theme="dark"] .row label, :root[data-theme="dark"] fieldset label { color: var(--ink-muted); }
  :root[data-theme="dark"] .seg-label { color: var(--ink-muted); }
  :root[data-theme="dark"] .richtext-label { color: var(--ink-muted); }
  :root[data-theme="dark"] .section-head h4 { color: var(--ink); }
}

/* PL-DARK-RECENTS: recent-invoice cards were hardcoded #fff (unreadable cream-on-white in dark). */
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #recents-list li { background: var(--bg-soft); }
  :root:not([data-theme="light"]) #recents-list li:hover { background: var(--surface); }
}
@media screen {
  :root[data-theme="dark"] #recents-list li { background: var(--bg-soft); }
  :root[data-theme="dark"] #recents-list li:hover { background: var(--surface); }
}

/* PL-DARK-CLOSEDSTATE: surfaces only visible with panels/modals OPEN (closed-state sweep 07-11). */
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .panel-head,
  :root:not([data-theme="light"]) .panel-foot { background: var(--surface); }
  :root:not([data-theme="light"]) .ext-choice { background: var(--bg-soft); }
  :root:not([data-theme="light"]) .ext-dropzone:hover, :root:not([data-theme="light"]) .ext-dropzone:focus-visible,
  :root:not([data-theme="light"]) .ext-dropzone.ext-dragover { background: var(--bg-soft); }
  :root:not([data-theme="light"]) .ext-field select { background: var(--surface); }
}
@media screen {
  :root[data-theme="dark"] .panel-head,
  :root[data-theme="dark"] .panel-foot { background: var(--surface); }
  :root[data-theme="dark"] .ext-choice { background: var(--bg-soft); }
  :root[data-theme="dark"] .ext-dropzone:hover, :root[data-theme="dark"] .ext-dropzone:focus-visible,
  :root[data-theme="dark"] .ext-dropzone.ext-dragover { background: var(--bg-soft); }
  :root[data-theme="dark"] .ext-field select { background: var(--surface); }
}
