:root {
  --ink: #0b1f17;
  --ink-soft: #1f4030;
  --accent: #0e8043;
  --accent-dark: #075c30;
  --bg: #f5f7f4;
  --card: #ffffff;
  --border: #e1e7e1;
  --text: #14251b;
  --muted: #5b6b62;
  --brass: #b8860b;
  --error: #c0392b;
  --radius: 12px;
  /* Surfaces that were hardcoded colors before dark mode existed — kept as
     their own variables (rather than reusing --card/--bg) because they're
     visually distinct from a plain card even within one theme (an input's
     slightly-off-white vs. a card's pure white, say). */
  --input-bg: #fbfcfe;
  --input-readonly-bg: #eef1f7;
  --hover-bg: #eaeee9;
  --shadow-soft: rgba(11,31,23,0.04);
  --shadow-strong: rgba(11,31,23,0.05);
  --font-display: 'Sora', -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-body: 'Inter', -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Legacy aliases kept so nothing that still references the old names breaks. */
  --navy: var(--ink);
  --navy-light: var(--ink-soft);
}

/* Dark theme — toggled by adding data-theme="dark" to <html> (see the
   inline script in index.html's <head>, and js/theme.js for the toggle
   button). The sidebar/lock-screen/auth-brand-panel already use --ink,
   a fixed dark color in both themes, so they're left alone here; only
   the surfaces that were light in the base theme need an override. */
:root[data-theme="dark"] {
  --bg: #101512;
  --card: #1a2119;
  --border: #2c352a;
  --text: #eaf0ea;
  --muted: #97a397;
  --input-bg: #212a1f;
  --input-readonly-bg: #262f24;
  --hover-bg: #29332a;
  --shadow-soft: rgba(0,0,0,0.25);
  --shadow-strong: rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  transition: background 0.15s ease, color 0.15s ease;
}

h1, h2, .brand-name, .section-title, .auth-tagline, .stat-card .value {
  font-family: var(--font-display);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}
.app-shell.hidden { display: none; }

/* Mobile-only top bar (hamburger + brand) and the backdrop behind the
   sidebar drawer it opens — both hidden entirely on desktop/tablet, where
   the sidebar is just always there. See the 720px media query for what
   turns them on and what the drawer itself looks like. */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  z-index: 1300;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--ink);
  box-shadow: 0 1px 2px var(--shadow-soft);
}
.mobile-menu-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.mobile-menu-btn:active { background: var(--ink-soft); }
.mobile-menu-btn span { display: block; width: 20px; height: 2px; background: currentColor; border-radius: 1px; }
.mobile-topbar-title { color: #eef3ef; font-family: var(--font-display); font-weight: 700; font-size: 15px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: rgba(0,0,0,0.45);
}
.sidebar-backdrop.open { display: block; }

/* Full-screen placeholder shown only for the brief moment between first
   paint and init() (in cloud.js) deciding what to show — see the note
   next to #appShell in index.html. Same background as the app itself so
   there's no color flash, just a blank beat before the real UI appears. */
.boot-loader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.boot-loader.hidden { display: none; }
.boot-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: boot-spin 0.7s linear infinite;
}
@keyframes boot-spin { to { transform: rotate(360deg); } }

/* Success tick shown in the subscribe overlay once payment is confirmed */
.subscribe-success-check {
  width: 56px;
  height: 56px;
  margin: 4px auto 14px;
  border-radius: 50%;
  background: #2e9e5b;
  color: #fff;
  font-size: 28px;
  line-height: 56px;
  text-align: center;
  animation: subscribe-check-pop 0.35s ease-out;
}
@keyframes subscribe-check-pop {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 220px;
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  flex-shrink: 0;
}

.brand { text-align: center; margin-bottom: 28px; }

/* Only ever visible inside the mobile drawer (720px media query gives it
   display:flex) — on desktop, where the sidebar is permanent, there's
   nothing to close. */
.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #a9baaf;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.sidebar-close-btn:active { background: var(--ink-soft); color: #fff; }

.logo-box {
  width: 176px;
  height: 56px;
  margin: 0 auto 10px;
  border-radius: 10px;
  background: #fff;
  padding: 6px 10px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.logo-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.logo-placeholder {
  position: absolute;
  font-size: 12px;
  letter-spacing: 1px;
  color: #7c88a6;
  display: none;
}

.logo-preview-box {
  width: 84px;
  height: 84px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--bg);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.logo-preview-box img { width: 100%; height: 100%; object-fit: contain; display: block; }
.logo-preview-box .logo-placeholder { position: absolute; font-size: 11px; color: var(--muted); display: block; }
.logo-preview-box.has-logo .logo-placeholder { display: none; }
.logo-preview-box:not(.has-logo) img { display: none; }

/* Document-color swatches, extracted from the uploaded logo (Settings) */
.color-swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 0 0 1px var(--border);
  transition: transform 0.1s ease;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 0 3px var(--accent-dark); }

/* Shown by JS only when logo.png fails to load */
.logo-box.no-logo img { display: none; }
.logo-box.no-logo .logo-placeholder { display: block; }

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  color: #eef3ef;
}

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-btn {
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  color: #a9baaf;
  text-align: left;
  padding: 10px 12px 10px 13px;
  border-radius: 0 6px 6px 0;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.nav-btn:hover { background: var(--ink-soft); color: #fff; }
.nav-btn.active { background: var(--ink-soft); color: #fff; border-left-color: var(--accent); font-weight: 600; }

.sidebar-footer {
  font-size: 11px;
  color: #6b7591;
  text-align: center;
}

/* ---------------- Theme toggle ---------------- */
.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  background: transparent;
  border: 1px solid var(--ink-soft);
  color: #cfe0d4;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease;
}
.theme-toggle-btn:hover { background: var(--ink-soft); }

/* Sits in the sidebar (dark background in both themes) on the main app,
   but as a small floating icon button on the auth screen instead, since
   that overlay has no sidebar to live in. */
.auth-theme-toggle-btn {
  position: absolute;
  top: 16px;
  right: 64px;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 50%;
  font-size: 16px;
  z-index: 1001;
  background: none;
  color: var(--muted);
}
.auth-theme-toggle-btn:hover { background: var(--border); color: var(--text); }

/* ---------------- Main ---------------- */
.main { flex: 1; padding: 40px 48px; max-width: 960px; margin: 0 auto; width: 100%; }

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

h1 { font-size: 23px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }

.doc-type-tabs {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.tab {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.tab.active { background: var(--ink); color: #fff; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 1px 2px var(--shadow-soft), 0 8px 24px var(--shadow-strong);
}

.card-row {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

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

label { font-size: 12px; color: var(--muted); font-weight: 600; }

input[type=text], input[type=number], input[type=date], textarea, select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}
input[readonly] { background: var(--input-readonly-bg); color: var(--muted); }

.section-title {
  font-size: 14px;
  margin: 22px 0 10px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.items-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.items-table th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.items-table td { padding: 4px 8px; }
.items-table input { width: 100%; }

.remove-row {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 16px;
}

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.12s ease, transform 0.05s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--hover-bg); }

/* Premium / subscribe actions get the brass accent, not the everyday green,
   so the "you're on the free tier, upgrade" moment reads distinctly. */
#subscribeNowBtn, #subscribeSidebarBtn {
  background: var(--brass);
}
#subscribeNowBtn:hover, #subscribeSidebarBtn:hover {
  background: #93690a;
}

.totals-panel {
  margin-top: 18px;
  max-width: 320px;
  margin-left: auto;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 5px 0;
}
.totals-row.grand {
  border-top: 1px dashed var(--border);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 17px;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text);
}

.inline-input { display: flex; gap: 6px; }
.inline-input input { width: 90px; }
.inline-input select { width: 70px; }

textarea { width: 100%; resize: vertical; }

.actions-row { margin-top: 20px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

.records-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.records-table th, .records-table td {
  text-align: left;
  padding: 8px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.records-table th { color: var(--muted); text-transform: uppercase; font-size: 11px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(11,31,23,0.04);
}
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--accent); }
.stat-card.accent-inactive::before { background: var(--error); }
.stat-card .label { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.stat-card .value { font-size: 24px; font-weight: 700; color: var(--text); }

.status-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status-pill.paid { background: #e1f5e8; color: var(--accent-dark); }
.status-pill.partial { background: #fdf3dc; color: var(--brass); }
.plan-option { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; cursor: pointer; background: var(--card); }
.plan-option:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(14,128,67,0.15); }
#subscribePlanRow { display: flex; gap: 8px; margin-bottom: 12px; }
#subscribePlanRow.hidden { display: none; }
.status-pill.unpaid { background: #fdeceb; color: var(--error); }

.row-actions { display: flex; gap: 6px; }
.btn-mini {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}
.btn-mini:hover { background: var(--hover-bg); }

code {
  background: var(--input-readonly-bg);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ---------------- Lock screen ---------------- */
.lock-overlay {
  position: fixed;
  inset: 0;
  background: var(--navy);
  /* Above the mobile sidebar drawer (1500) and its backdrop (1400) — this
     (and .auth-overlay, below) has to win if the drawer happens to be
     open when Sign In, Subscribe, or the lock screen itself appears,
     otherwise the drawer would sit on top of it, unreachable. */
  z-index: 1800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-overlay.hidden { display: none; }
.hidden { display: none !important; }
.items-table.no-pricing .price-col { display: none; }

.lock-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}

.lock-logo-box {
  width: 200px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 10px;
  background: #fff;
  padding: 6px 12px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.lock-logo-box img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lock-logo-box .logo-placeholder { position: absolute; font-size: 11px; color: var(--muted); display: none; }
.lock-logo-box.no-logo img { display: none; }
.lock-logo-box.no-logo .logo-placeholder { display: block; }

.lock-card h2 { margin: 0 0 4px; font-size: 18px; }
.lock-card input {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.lock-card .btn-primary { margin-top: 14px; }
.lock-error { color: var(--error); font-size: 12px; min-height: 16px; margin-top: 10px; }
.success-check {
  width: 64px; height: 64px; line-height: 64px; border-radius: 50%;
  background: var(--accent-dark); color: #fff; font-size: 30px; font-weight: bold;
  margin: 0 auto 16px; text-align: center;
}

/* ---------------- Auth screen (sign in / sign up) ---------------- */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1800; /* see the note on .lock-overlay's z-index */
  display: flex;
}
.auth-overlay.hidden { display: none; }
.auth-close-btn {
  position: absolute;
  top: 16px; right: 20px;
  background: none; border: none;
  font-size: 28px; line-height: 1;
  color: var(--muted);
  cursor: pointer;
  z-index: 1001;
}
.auth-close-btn:hover { color: var(--text); }

.auth-brand-panel {
  flex: 1 1 44%;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px 56px;
  min-width: 0;
}
.auth-logo-badge {
  background: #fff;
  border-radius: 10px;
  padding: 14px 18px;
  display: inline-block;
  width: fit-content;
}
.auth-logo-badge img { display: block; height: 44px; width: auto; }
.auth-tagline {
  margin: 20px 0 8px;
  max-width: 360px;
  color: #fff;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.5;
}
.auth-pricing {
  margin: 0 0 32px;
  max-width: 360px;
  color: #b9ecc9;
  font-size: 16px;
  line-height: 1.5;
}
.auth-doc-art { width: 220px; height: auto; }

.auth-form-panel {
  flex: 1 1 56%;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.auth-form-inner { width: 100%; max-width: 320px; text-align: center; }
.auth-form-inner input {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.auth-form-inner h2 { margin: 0 0 4px; font-size: 20px; }
.auth-form-inner .btn-primary { margin-top: 16px; }

@media (max-width: 760px) {
  .auth-overlay { flex-direction: column; }
  .auth-brand-panel { flex: 0 0 auto; padding: 32px 28px; }
  .auth-logo-badge img { height: 34px; }
  .auth-tagline { font-size: 17px; margin-bottom: 6px; }
  .auth-pricing { margin-bottom: 20px; font-size: 15px; }
  .auth-doc-art { width: 120px; }
  .auth-form-panel { flex: 1 1 auto; }
}

/* Mobile top bar + off-canvas sidebar drawer. Below 720px the sidebar
   (nav, sign in/out, install app, theme toggle — everything) stops being
   squeezed into a cramped horizontal strip at the top of the screen and
   becomes a proper slide-out panel instead, opened via a menu button in a
   slim top bar. Markup is unchanged (index.html) other than the new top
   bar + backdrop; the toggle itself is js/mobile-nav.js. */
@media (max-width: 720px) {
  .mobile-topbar { display: flex; }

  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: min(280px, 82vw);
    z-index: 1500;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-btn { display: flex; align-items: center; justify-content: center; }
  .brand { margin-bottom: 24px; }
  .sidebar-footer button { width: 100% !important; }

  .main { padding: 76px 16px 20px; max-width: 100%; }
  .card { padding: 18px; }
  .totals-panel { max-width: 100%; margin-left: 0; }

  /* The Line Items table (New Document) was readable only by scrolling it
     sideways on a phone — description, qty, price and total all squeezed
     into fixed-width columns with 14px inputs. Below this width it's no
     longer a table visually: each item becomes its own stacked card, one
     labeled field per line, full width and full size to actually read and
     tap. The underlying markup is unchanged (desktop keeps the table),
     this only changes how it's drawn — data-label on each <td> (set in
     renderItemsTable(), js/app.js) supplies the labels shown here. */
  .items-table thead { display: none; }
  .items-table, .items-table tbody, .items-table tr { display: block; width: 100%; }
  .items-table tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px 12px;
    margin-bottom: 12px;
    background: var(--card);
  }
  .items-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  .items-table td:last-child { border-bottom: none; justify-content: flex-end; padding-top: 12px; }
  .items-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--muted);
  }
  .items-table td input {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    text-align: right;
    font-size: 15px;
  }
  .items-table td:first-child input { text-align: left; }
  .items-table .row-total { font-size: 15px; font-weight: 700; color: var(--text); }
  .items-table .remove-row { font-size: 22px; padding: 2px 10px; }

  /* Items table aside, inputs across the whole form were the standard
     14px — fine on desktop, a little small to comfortably tap/read on a
     phone. Bumping them slightly here (not globally) keeps desktop as-is. */
  input[type=text], input[type=number], input[type=date], textarea, select {
    font-size: 15px;
    padding: 10px;
  }
  /* Discount/VAT fields in the totals panel had fixed 90px/70px widths,
     sized for the desktop's smaller font — too tight at the larger mobile
     font-size above. There's room to spare now that .totals-panel itself
     goes full-width on mobile (rule above), so widen them slightly. */
  .inline-input input { width: 110px; }
  .inline-input select { width: 90px; }

  /* The Records table had the same sideways-scroll problem as Line Items
     — 8 columns, one of them holding up to 4 action buttons (Export, Edit,
     WhatsApp, Convert) crammed into a single cell. Scoped to this table
     specifically (not .records-table generally) since the Dashboard's and
     Settings' uses of that class are plain 3–7 column read-only tables
     where horizontal scroll is still a reasonable, standard pattern —
     this one has real per-row actions, which is what actually needed it. */
  #view-records:not(.records-list-mode) .records-table thead { display: none; }
  #view-records:not(.records-list-mode) .records-table, #view-records:not(.records-list-mode) .records-table tbody, #view-records:not(.records-list-mode) .records-table tr {
    display: block; width: 100%;
  }
  #view-records:not(.records-list-mode) .records-table tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px 12px;
    margin-bottom: 12px;
    background: var(--card);
  }
  #view-records:not(.records-list-mode) .records-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
  }
  #view-records:not(.records-list-mode) .records-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--muted);
  }
  /* The raw exported filename isn't something anyone needs to read on a
     phone screen — it's still right there via the Export button. */
  #view-records:not(.records-list-mode) .records-table td.file-col { display: none; }
  #view-records:not(.records-list-mode) .records-table td.row-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    border-bottom: none;
    padding-top: 12px;
  }
  #view-records:not(.records-list-mode) .records-table td.row-actions::before { display: none; }
  #view-records:not(.records-list-mode) .records-table .btn-mini { flex: 1 1 auto; text-align: center; padding: 8px 10px; }

  /* List mode: compact table, scrolls sideways, drops the bulky columns */
  #view-records.records-list-mode .records-table th:nth-child(2),
  #view-records.records-list-mode .records-table td:nth-child(2),
  #view-records.records-list-mode .records-table th:nth-child(6),
  #view-records.records-list-mode .records-table td:nth-child(6),
  #view-records.records-list-mode .records-table th:nth-child(7),
  #view-records.records-list-mode .records-table td:nth-child(7) { display: none; }
  #view-records.records-list-mode .records-table th,
  #view-records.records-list-mode .records-table td { white-space: nowrap; padding: 10px 8px; font-size: 12.5px; }
  #view-records.records-list-mode .records-table td[colspan] { display: table-cell; }
  #view-records.records-list-mode .row-actions .btn-mini { padding: 5px 8px; margin: 0 4px 4px 0; }
  .records-view-toggle { display: inline-flex; }
}

.records-view-toggle {
  display: none; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: 0 0 12px 8px; vertical-align: top;
}
.records-view-toggle button {
  border: none; background: var(--card); color: var(--muted); font-size: 13px; font-weight: 600;
  padding: 9px 14px; cursor: pointer; font-family: inherit;
}
.records-view-toggle button:not(:last-child) { border-right: 1px solid var(--border); }
.records-view-toggle button.active { background: var(--accent); color: #fff; }


/* ---- Extras: renewal banner, Customers, Reports ---- */
.renew-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: #fff7e0; border: 1px solid #f0d98c; color: #6b5200;
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; font-size: 14px; font-weight: 500;
}
.renew-banner.error { background: #fdeceb; border-color: #f3c6c2; color: var(--error); }
.renew-banner.hidden { display: none; }
.extras-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.extras-toolbar input[type=text] { flex: 1; min-width: 200px; max-width: 320px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.filter-select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; background: var(--card); color: var(--text); }
.rep-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.rep-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.rep-legend i.inv, .rep-bar.inv { background: var(--navy-light, #4a6fa5); }
.rep-legend i.col, .rep-bar.col { background: var(--accent); }
.rep-chart { display: flex; align-items: flex-end; gap: 10px; height: 180px; }
.rep-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.rep-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.rep-bar { width: 38%; max-width: 22px; min-height: 2px; border-radius: 3px 3px 0 0; }
.rep-label { font-size: 11px; color: var(--muted); margin-top: 6px; white-space: nowrap; }
.status-pill.unpaid { background: #fdeceb; color: var(--error); }

@media (max-width: 720px) {
  .extras-toolbar > * { width: 100%; max-width: none !important; min-width: 0 !important; }
  .renew-banner { flex-direction: column; align-items: stretch; }
  .renew-banner button { width: 100%; }
  .stack-table thead { display: none; }
  .stack-table, .stack-table tbody, .stack-table tr { display: block; width: 100%; }
  .stack-table tr { border: 1px solid var(--border); border-radius: 10px; padding: 4px 12px; margin-bottom: 12px; background: var(--card); }
  .stack-table td { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 13px; border-bottom: 1px solid var(--border); text-align: right; }
  .stack-table td::before { content: attr(data-label); flex: 0 0 auto; font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); text-align: left; }
  .stack-table td[colspan] { display: block; text-align: left; }
  .stack-table td[colspan]::before { content: none; }
  .stack-table td.row-actions { justify-content: flex-start; flex-wrap: wrap; border-bottom: none; padding-top: 12px; }
  .stack-table td.row-actions::before { display: none; }
  .stack-table .btn-mini { flex: 1 1 auto; text-align: center; padding: 8px 10px; }
}


/* ---- Document style picker ---- */
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.template-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  background: var(--card); border: 2px solid var(--border); border-radius: 12px; padding: 10px;
  cursor: pointer; font-family: inherit; color: var(--text);
}
.template-tile b { font-size: 14px; margin-top: 6px; }
.template-tile small { font-size: 11px; color: var(--muted); line-height: 1.3; }
.template-tile.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,128,67,0.14); }
.tpl-thumb { position: relative; display: block; width: 100%; aspect-ratio: 3/4; background: #fff; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.tpl-thumb i { position: absolute; display: block; border-radius: 2px; background: #d9dedb; }
.tpl-thumb .t-title { height: 5px; background: var(--tpl, #0e8043); }
.tpl-thumb .t-head { left: 10%; right: 10%; height: 8px; background: var(--tpl, #0e8043); }
.tpl-thumb .t-row { left: 10%; right: 10%; height: 4px; }
.tpl-thumb .t-row:nth-of-type(3) { top: 62%; } .tpl-thumb .t-row:nth-of-type(4) { top: 72%; }
.tpl-classic .t-title { top: 10%; right: 10%; width: 35%; }
.tpl-classic .t-head { top: 48%; }
.tpl-minimal .t-title { top: 12%; right: 10%; width: 30%; height: 3px; }
.tpl-minimal .t-head { top: 48%; height: 2px; }
.tpl-bold .t-title { top: 0; left: 0; right: 0; width: 100%; height: 26%; border-radius: 0; }
.tpl-bold .t-head { top: 48%; }
.tpl-letterhead .t-title { top: 12%; left: 30%; right: 30%; width: 40%; height: 4px; }
.tpl-letterhead .t-head { top: 48%; }
@media (max-width: 720px) { .template-grid { grid-template-columns: repeat(2, 1fr); } }

.tpl-sidebar .t-title { top: 0; left: 0; right: 0; width: 100%; height: 38%; border-radius: 0; }
.tpl-sidebar .t-side { top: 8%; left: 8%; width: 14%; height: 46%; background: #2a2a2a; border-radius: 0; }
.tpl-sidebar .t-head { top: 60%; background: #2a2a2a; }
.tpl-sidebar .t-row:nth-of-type(4) { top: 72%; } .tpl-sidebar .t-row:nth-of-type(5) { top: 80%; }
.tpl-banner .t-title { top: 0; left: 0; right: 0; width: 100%; height: 24%; border-radius: 0; }
.tpl-banner .t-head { top: 44%; height: 2px; background: #222; }
.tpl-banner .t-foot { bottom: 0; left: 0; right: 0; height: 16%; background: linear-gradient(90deg, #e3ebe6 62%, var(--tpl, #0e8043) 62%); border-radius: 0; }
.design-request-box {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-top: 18px; padding: 14px 16px; border: 1px dashed var(--border); border-radius: 12px; background: var(--card);
}
.design-request-box b { font-size: 14px; }
@media (max-width: 720px) { .design-request-box { flex-direction: column; align-items: stretch; } .design-request-box .btn-primary { width: 100%; } }


/* ---- Settings: tabbed, roomier layout ---- */
#view-settings { max-width: 920px; }
.settings-tabs {
  display: inline-flex; gap: 4px; padding: 5px; margin-bottom: 18px; max-width: 100%;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow-x: auto;
}
.settings-tab {
  border: none; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px;
  padding: 10px 20px; border-radius: 10px; cursor: pointer; white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { background: var(--ink); color: #fff; }
.settings-status { font-size: 13px; font-weight: 500; color: var(--accent); margin: 0 0 14px; min-height: 0; }
.settings-status:empty { display: none; }

.settings-panel { display: none; }
.settings-panel.active { display: block; }

.settings-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; margin-bottom: 22px;
  box-shadow: 0 1px 2px var(--shadow-soft), 0 8px 24px var(--shadow-strong);
}
.settings-card.hidden { display: none; }
.settings-card-head { margin-bottom: 22px; }
.settings-card-head h3 { font-size: 17px; margin: 0; color: var(--text); }
.settings-card-head p { font-size: 13px; color: var(--muted); line-height: 1.55; margin: 6px 0 0; max-width: 640px; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 22px; }
.settings-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.settings-grid .field { min-width: 0; gap: 8px; }
.settings-grid .field.span-2 { grid-column: 1 / -1; }
.settings-grid input, .settings-grid textarea, .settings-grid select { width: 100%; padding: 12px; font-size: 14px; box-sizing: border-box; }
.settings-card input[type=password] { padding: 12px; }
.settings-card textarea { resize: vertical; }

.logo-row { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.logo-actions { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 220px; }
.style-controls { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-end; margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--border); }
.settings-card .template-grid { gap: 16px; }
.settings-card .actions-row { margin-top: 24px; }
.settings-card .design-request-box { margin-top: 26px; }

.settings-savebar {
  position: sticky; bottom: 14px; z-index: 5; display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 14px 18px; background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 8px 28px var(--shadow-strong);
}

@media (max-width: 720px) {
  .settings-tabs { display: flex; width: 100%; box-sizing: border-box; }
  .settings-tab { flex: 1; padding: 10px 12px; font-size: 13px; }
  .settings-card { padding: 20px; margin-bottom: 18px; }
  .settings-grid, .settings-grid.three { grid-template-columns: 1fr; gap: 16px; }
  .logo-row { gap: 18px; }
  .settings-savebar { bottom: 8px; }
  .settings-savebar .btn-primary, .settings-savebar .btn-secondary { flex: 1; }
  .style-controls > * { flex: 1 1 100%; }
  .style-controls .field { width: 100%; }
}


/* ---- First-time setup wizard ---- */
.setup-banner { background: #e8f1fb; border-color: #bcd4f0; color: #1d4e89; }
.btn-link { background: none; border: none; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; padding: 10px 4px; text-decoration: underline; }
.btn-link:hover { color: var(--text); }
.onboard-card {
  background: var(--card); border-radius: 20px; width: min(860px, 94vw); max-height: 92vh; overflow-y: auto;
  padding: 28px 30px 20px; box-shadow: 0 24px 80px rgba(0,0,0,0.35);
}
.onboard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.onboard-kicker { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; }
.onboard-head h2 { margin: 4px 0 0; font-size: 24px; }
.onboard-dots { display: flex; gap: 6px; padding-top: 6px; }
.onboard-dots i { width: 28px; height: 6px; border-radius: 3px; background: var(--border); display: block; }
.onboard-dots i.on { background: var(--accent); }
.onboard-body { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 28px; align-items: start; }
.onboard-form { display: flex; flex-direction: column; gap: 16px; }
.onboard-form .field { min-width: 0; gap: 8px; }
.onboard-form input[type=text], .onboard-form input[type=number], .onboard-form textarea { width: 100%; padding: 12px; box-sizing: border-box; font-size: 14px; }
.onboard-form input[type=file] { width: 100%; }
.onboard-step.hidden { display: none; }
.onboard-templates { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.onboard-templates .template-tile { padding: 8px; }
.onboard-templates .template-tile small { display: none; }
.onboard-preview { position: sticky; top: 0; background: #eef1ef; border-radius: 14px; padding: 16px; }
.onboard-preview-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 10px; }
.ob-doc { background: #fff; border-radius: 8px; padding: 14px; box-shadow: 0 2px 10px rgba(0,0,0,0.12); display: flex; flex-direction: column; gap: 10px; color: #222; }
.ob-sec { border-radius: 6px; padding: 8px; border: 2px solid transparent; transition: border-color 0.15s, background 0.15s; }
.ob-sec.hl { border-color: var(--accent); background: rgba(14,128,67,0.07); }
.ob-header { display: flex; gap: 10px; align-items: flex-start; }
.ob-logo { width: 38px; height: 38px; border-radius: 8px; background: #e3e7e4; flex: none; background-size: contain; background-repeat: no-repeat; background-position: center; }
.ob-company { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.ob-company b { font-size: 13px; }
.ob-company span { font-size: 10.5px; color: #666; overflow-wrap: anywhere; }
.ob-company span.placeholder, .ob-pay span.placeholder { color: #aaa; font-style: italic; }
.ob-title { font-size: 12px; font-weight: 800; letter-spacing: 0.04em; }
.ob-table { display: flex; flex-direction: column; gap: 6px; padding: 0 8px; }
.ob-table i { height: 7px; border-radius: 3px; background: #e5e9e6; display: block; }
.ob-table i:first-child { background: var(--ob-accent, #0e8043); }
.ob-totals { text-align: right; font-size: 11px; color: #555; }
.ob-pay small { display: block; font-size: 9.5px; font-weight: 700; text-transform: uppercase; color: #777; margin-bottom: 2px; }
.ob-pay span { font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ob-style { font-size: 11px; font-weight: 600; color: #555; text-align: center; }
.onboard-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); }
@media (max-width: 720px) {
  .onboard-card { padding: 20px 18px 16px; border-radius: 16px; }
  .onboard-head h2 { font-size: 20px; }
  .onboard-body { grid-template-columns: 1fr; gap: 18px; }
  .onboard-preview { position: static; order: -1; }
  .onboard-templates { grid-template-columns: repeat(3, 1fr); }
  .onboard-foot { flex-wrap: wrap; }
  .onboard-foot > div { flex: 1; }
  .onboard-foot .btn-primary, .onboard-foot .btn-secondary { flex: 1; }
}

.onboard-form .field > label { display:block; margin-bottom: 2px; }
.onboard-form { gap: 18px; }
.onboard-form .field { display:flex; flex-direction:column; gap:8px; }

.btn-mini.btn-danger { color:#b3261e; border-color:#e6b8b4; }
.btn-mini.btn-danger:hover { background:#fdecea; }
