/* ============================================================
   TradesBill PWA App Shell Styles
   ============================================================ */

/* ── App layout ──────────────────────────────────────────────── */
html, body { height: 100%; overflow: hidden; }

#app {
  display: grid;
  height: 100dvh;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  #app {
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: 1fr;
  }
}

/* ── Top bar (mobile only) ───────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  grid-column: 1;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 50;
}

@media (min-width: 768px) {
  .topbar { display: none; }
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  color: #ffffff;
}

.topbar-logo span { color: var(--accent); }

/* Shared logo icon (SVG with orange rect baked in) */
.logo-icon { flex-shrink: 0; display: block; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;

  /* Mobile: fixed overlay */
  position: fixed;
  inset: 0;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform var(--transition-slow);
  width: var(--sidebar-width);
}

.sidebar.open {
  transform: translateX(0);
}

@media (min-width: 768px) {
  .sidebar {
    position: static;
    transform: none;
    grid-column: 1;
    grid-row: 1;
    z-index: auto;
    width: auto;
  }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  min-height: 100dvh;
  background: rgb(0 0 0 / 0.5);
  z-index: 199;
}

.sidebar-overlay.active { display: block; }

@media (min-width: 768px) {
  .sidebar-overlay { display: none !important; }
}

/* Sidebar header */
.sidebar-header {
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.sidebar-logo span { color: var(--accent); }

/* ── Logo upload dropzone ────────────────────────────────────── */
.logo-upload-area {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 120px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  background: var(--bg-surface);
  overflow: hidden;
}

.logo-upload-area:hover {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 5%, transparent);
}

.logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  color: var(--color-text-muted);
  padding: var(--sp-4);
  text-align: center;
  pointer-events: none;
}

.logo-placeholder svg { opacity: 0.4; }

.logo-placeholder span {
  font-size: var(--text-sm);
  font-weight: 600;
}

.logo-placeholder .logo-hint {
  font-size: var(--text-xs);
  font-weight: 400;
  opacity: 0.7;
}

.logo-preview {
  width: 100%;
  height: 120px;
  object-fit: contain;
  object-position: center;
  padding: var(--sp-3);
  display: block;
}

/* Background-removal toggle shown after upload */
.logo-bg-remove-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.logo-bg-remove-row input[type="checkbox"] {
  accent-color: var(--color-accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.logo-bg-remove-row label {
  cursor: pointer;
  user-select: none;
}

/* Sidebar nav */
.sidebar-nav {
  flex: 1;
  padding: var(--sp-3) var(--sp-3);
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: var(--sp-6);
}

.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--sidebar-section-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 var(--sp-3);
  margin-bottom: var(--sp-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--sidebar-text);
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-item-badge {
  margin-left: auto;
  background: var(--error);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Sidebar footer (user + plan) */
.sidebar-footer {
  padding: var(--sp-4);
  border-top: 1px solid var(--sidebar-border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background var(--transition);
}

.user-info:hover { background: var(--sidebar-hover-bg); }

.user-avatar {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-details { min-width: 0; flex: 1; }
.user-name    { font-size: var(--text-sm); font-weight: 600; color: var(--sidebar-text); }
.user-plan    { font-size: var(--text-xs); color: var(--text-muted); }

/* Pro Active banner */
.pro-active-banner {
  align-items: center;
  gap: var(--sp-2);
  background: var(--color-pro-banner-bg);
  color: var(--color-pro-banner-text);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  margin-top: var(--sp-2);
}

/* Sync indicator in sidebar footer */
.sync-status {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-2);
  cursor: default;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}

.sync-dot.syncing { background: var(--warning); animation: pulse 1s ease-in-out infinite; }
.sync-dot.synced  { background: var(--success); }
.sync-dot.error   { background: var(--error); }
.sync-dot.offline { background: var(--text-muted); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Main content area ───────────────────────────────────────── */
#main {
  overflow-y: auto;
  overscroll-behavior-y: contain;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

@media (min-width: 768px) {
  #main {
    grid-column: 2;
    grid-row: 1;
  }
}

/* Page wrapper */
.page {
  flex: 1;
  padding: var(--sp-6) var(--sp-6);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 639px) {
  .page { padding: var(--sp-4) var(--sp-4); }
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ── Dashboard stats ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: var(--sp-6);
}

@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-4) var(--sp-5);
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--sp-2);
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-family: var(--font-mono);
  color: var(--color-text);
}

.stat-value.overdue { color: var(--error); }
.stat-value.paid    { color: var(--success); }

/* ── Invoice list ────────────────────────────────────────────── */
.list-toolbar {
  display: flex;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.list-toolbar .input {
  flex: 1;
  min-width: 200px;
}

.filter-tabs {
  display: flex;
  gap: var(--sp-1);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-1);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }

.filter-tab {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  white-space: nowrap;
}

.filter-tab.active {
  background: var(--color-accent);
  color: #fff;
}

/* ── Greeting ────────────────────────────────────────────────── */
.dash-greeting { flex: 1; min-width: 0; }

.dash-greeting-text {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--color-text);
  margin: 0;
}

.dash-greeting-date {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: var(--sp-1) 0 0;
}

/* ── Invoice rows ────────────────────────────────────────────── */
.invoice-row {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 var(--sp-4);
  gap: var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background var(--transition);
}

.invoice-row:hover { background: var(--color-surface-2); }
.invoice-row:last-child { border-bottom: none; }

.invoice-row-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.invoice-number { font-size: var(--text-sm); font-weight: 700; color: var(--color-text); }
.invoice-client { font-size: var(--text-xs); color: var(--color-text-muted); }
.invoice-date   { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; }

.invoice-amount {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

/* ── Invoice detail / form ───────────────────────────────────── */
.form-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  margin-bottom: var(--sp-4);
}

.form-section-title {
  font-size: var(--text-base);
  font-weight: 700;
  margin-bottom: var(--sp-5);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}

@media (min-width: 640px) {
  .form-grid-2 { grid-template-columns: 1fr 1fr; }
}

/* Line items table */
.line-items-table {
  width: 100%;
  border-collapse: collapse;
}

.line-items-table th {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.line-items-table td {
  padding: var(--sp-2) var(--sp-2);
  border-bottom: 1px solid var(--border-subtle);
}

.line-item-desc  { width: 40%; }
.line-item-qty   { width: 10%; }
.line-item-unit  { width: 10%; }
.line-item-price { width: 15%; }
.line-item-gst   { width: 10%; }
.line-item-total { width: 12%; }
.line-item-del   { width: 3%; }

/* Invoice totals */
.invoice-totals {
  margin-top: var(--sp-4);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-2);
}

.totals-row {
  display: flex;
  gap: var(--sp-8);
  font-size: var(--text-sm);
}

.totals-label { color: var(--text-secondary); min-width: 120px; text-align: right; }
.totals-value { font-family: var(--font-mono); min-width: 100px; text-align: right; font-weight: 600; }
.totals-row.grand { font-size: var(--text-lg); border-top: 2px solid var(--border); padding-top: var(--sp-2); }
.totals-row.grand .totals-value { color: var(--accent); }

/* ── PDF preview panel ───────────────────────────────────────── */
.pdf-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(100vw, 480px);
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 300;
  transform: translateX(100%);
  transition: transform var(--transition-slow);
  box-shadow: var(--shadow-xl);
}

.pdf-panel.open { transform: translateX(0); }

.pdf-panel-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.pdf-panel-title { font-size: var(--text-base); font-weight: 700; }

.pdf-panel-actions {
  display: flex;
  gap: var(--sp-2);
}

.pdf-preview-frame {
  flex: 1;
  border: none;
  background: #525659;
}


/* ── Auth screens ────────────────────────────────────────────── */
.auth-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  background: var(--bg-base);
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--sp-8);
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  font-size: var(--text-3xl);
  font-weight: 900;
  letter-spacing: -0.04em;
  text-align: center;
  margin-bottom: var(--sp-8);
}

.auth-logo span { color: var(--accent); }

.auth-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  text-align: center;
  margin-bottom: var(--sp-2);
}

.auth-sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: var(--sp-8);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-5) 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-google {
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #ddd;
  font-weight: 600;
}

.btn-google:hover { background: #f5f5f5; }

.auth-footer {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--sp-6);
}

.auth-footer a { color: var(--accent); }

/* ── Settings page ───────────────────────────────────────────── */
.settings-nav,
.settings-tabs {
  display: flex;
  gap: var(--sp-1);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-1);
  margin-bottom: var(--sp-6);
  overflow-x: auto;
  scrollbar-width: none;
}

.settings-nav::-webkit-scrollbar,
.settings-tabs::-webkit-scrollbar { display: none; }

.settings-tab {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.settings-tab.active {
  background: var(--color-accent);
  color: #fff;
}

/* ── Settings cards ──────────────────────────────────────────── */
.settings-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.settings-card + .settings-card { margin-top: var(--sp-4); }

.settings-card h3 {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--color-border);
}

.settings-card p { font-size: var(--text-sm); color: var(--color-text-muted); }

.danger-zone { border-color: var(--color-error); }
.danger-zone h3 { color: var(--color-error); border-bottom-color: #fee2e2; }

.danger-action {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.danger-action + .danger-action {
  padding-top: var(--sp-4);
  border-top: 1px solid var(--color-border);
}

/* ── Colour picker ───────────────────────────────────────────── */
.color-picker-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.color-swatch {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  padding: 2px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

.color-swatch::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch::-webkit-color-swatch { border: none; border-radius: 4px; }

/* ── Pro upgrade prompt ──────────────────────────────────────── */
.pro-gate {
  background: var(--bg-surface);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-radius: var(--radius-xl);
  padding: var(--sp-8);
  text-align: center;
  max-width: 400px;
  margin: var(--sp-8) auto;
}

.pro-gate h3 { font-size: var(--text-xl); font-weight: 800; margin-bottom: var(--sp-3); }
.pro-gate p  { color: var(--text-secondary); font-size: var(--text-sm); margin-bottom: var(--sp-6); line-height: 1.65; }

.plan-selector {
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
  margin-bottom: var(--sp-4);
}
.plan-option {
  cursor: pointer;
  flex: 1;
  max-width: 160px;
}
.plan-option input[type="radio"] { display: none; }
.plan-option-body {
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-3) var(--sp-4);
  text-align: center;
  transition: border-color .15s, background .15s;
}
.plan-option input:checked + .plan-option-body {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.plan-option-name { font-weight: 600; font-size: var(--text-sm); margin-bottom: var(--sp-1); }
.plan-option-price { font-size: var(--text-lg); font-weight: 700; }
.plan-option-price span { font-size: var(--text-xs); font-weight: 400; color: var(--text-secondary); }
.plan-badge {
  display: inline-block;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 99px;
  vertical-align: middle;
  margin-left: 4px;
}

/* ── Help page (routed view) ─────────────────────────────────── */
.help-page {
  max-width: 720px;
}

.help-page-tabs {
  display: flex;
  gap: var(--sp-1);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-1);
  margin-bottom: var(--sp-5);
  width: fit-content;
}

.help-page-body {
  min-height: 400px;
}

.help-tab {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.help-tab.active {
  background: var(--color-accent);
  color: #fff;
}

.help-tab:not(.active):hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* ── Search bar ──────────────────────────────────────────────── */
.help-search-bar {
  position: relative;
  margin-bottom: var(--sp-5);
}

.help-search-icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}

.help-search-input {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3) var(--sp-2) calc(var(--sp-3) + 16px + var(--sp-2));
  font-size: var(--text-sm);
  color: var(--color-text);
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.help-search-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.help-search-input::placeholder { color: var(--color-text-faint); }

/* ── Section labels ──────────────────────────────────────────── */
.help-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin: var(--sp-4) 0 var(--sp-2);
}

.help-section-label:first-child { margin-top: 0; }

/* ── Article list ────────────────────────────────────────────── */
.help-article-list {
  list-style: none;
  margin: 0 0 var(--sp-3);
  padding: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.help-article-list li {
  border-bottom: 1px solid var(--color-border);
}

.help-article-list li:last-child { border-bottom: none; }

.help-article-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: none;
  border: none;
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-align: left;
  gap: var(--sp-3);
}

.help-article-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-accent);
}

.help-article-btn svg { flex-shrink: 0; color: var(--color-text-muted); }

/* ── Section groups (details/summary) ───────────────────────── */
.help-section-group { margin-bottom: var(--sp-3); }

.help-section-group > summary {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  padding: var(--sp-2) var(--sp-1);
  border-radius: var(--radius);
  transition: color var(--transition);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  user-select: none;
}

.help-section-group > summary:hover { color: var(--color-accent); }

.help-section-group > summary::before {
  content: '▶';
  font-size: 9px;
  color: var(--color-text-muted);
  transition: transform var(--transition);
  display: inline-block;
}

.help-section-group[open] > summary::before { transform: rotate(90deg); }

/* ── Article two-column layout with TOC ─────────────────────── */
.help-article-layout {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: var(--sp-6);
  align-items: start;
}

.help-toc {
  position: sticky;
  top: var(--sp-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
}

.help-toc-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: var(--sp-3);
  padding-left: var(--sp-2);
}

.help-toc-item {
  display: block;
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  transition: all var(--transition);
  line-height: 1.4;
  margin-bottom: 2px;
}

.help-toc-item:hover {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.help-toc-item.active {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  background: var(--color-accent-soft);
  font-weight: 600;
}

.help-h3 {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-text);
  margin: var(--sp-6) 0 var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--color-border);
  scroll-margin-top: 80px;
}

.help-h3:first-child { margin-top: 0; border-top: none; }

@media (max-width: 767px) {
  .help-article-layout {
    grid-template-columns: 1fr;
  }
  .help-toc {
    position: static;
    order: -1;
  }
}

/* ── Article view ────────────────────────────────────────────── */
.help-back-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  background: none;
  border: none;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--sp-1) 0;
  margin-bottom: var(--sp-4);
  transition: color var(--transition);
}

.help-back-btn:hover { color: var(--color-text); }

.help-article {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  margin-bottom: var(--sp-4);
}

.help-article-section {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-accent-text);
  margin-bottom: var(--sp-2);
}

.help-article-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 var(--sp-4);
  line-height: 1.3;
}

.help-article-body {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.75;
}

.help-article-body p { margin: 0 0 var(--sp-3); }
.help-article-body p:last-child { margin-bottom: 0; }

.help-feedback {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--sp-3) 0;
  flex-wrap: wrap;
}

.help-feedback-btn {
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition);
}

.help-feedback-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.help-feedback-thanks {
  color: var(--color-success);
  font-weight: 600;
}

/* ── Search empty / ask AI ───────────────────────────────────── */
.help-empty {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.help-ask-ai-btn {
  display: block;
  margin: var(--sp-3) auto 0;
  background: none;
  border: none;
  font-size: var(--text-sm);
  color: var(--color-accent);
  cursor: pointer;
  font-weight: 500;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  transition: background var(--transition);
}

.help-ask-ai-btn:hover { background: var(--color-accent-soft); }

/* ── AI chat tab ─────────────────────────────────────────────── */
.help-ai-messages {
  min-height: 200px;
  max-height: 420px;
  overflow-y: auto;
  padding: var(--sp-2) 0 var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.help-ai-welcome {
  text-align: center;
  padding: var(--sp-6) 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.help-ai-icon { font-size: 2rem; margin-bottom: var(--sp-3); }

.help-ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: center;
  margin-top: var(--sp-4);
}

.help-ai-chip {
  padding: var(--sp-2) var(--sp-3);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition);
}

.help-ai-chip:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.help-ai-msg { display: flex; }
.help-ai-msg.user { justify-content: flex-end; }

.help-ai-bubble {
  max-width: 80%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.65;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.help-ai-msg.user .help-ai-bubble {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent-text);
}

.help-ai-msg.thinking .help-ai-bubble {
  color: var(--color-text-muted);
  font-style: italic;
}

.help-ai-footer {
  padding-top: var(--sp-4);
  border-top: 1px solid var(--color-border);
}

.help-ai-input-row {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-end;
}

.help-ai-input {
  flex: 1;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  resize: none;
  outline: none;
  font-family: var(--font-sans);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.help-ai-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.help-ai-input::placeholder { color: var(--color-text-faint); }

.help-ai-send-btn {
  padding: var(--sp-2) var(--sp-3);
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.help-ai-send-btn:hover { background: var(--color-accent-hover); }

.help-ai-usage {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--sp-2);
  text-align: right;
}

.help-ai-offline,
.help-ai-limit {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-align: center;
}

/* ============================================================
   Invoice & Detail Views — CSS for all class names used in
   invoices.js HTML templates.
   ============================================================ */

/* ── Content padding ─────────────────────────────────────────── */
#view-container {
  padding: var(--sp-6);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

@media (max-width: 639px) {
  #view-container { padding: var(--sp-4); }
}

/* ── View header (all views) ─────────────────────────────────── */
.view-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
}

.view-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
}

.view-header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.back-btn { flex-shrink: 0; }

/* ── Invoice list ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.filter-pills {
  display: flex;
  gap: var(--sp-1);
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.filter-pills::-webkit-scrollbar { display: none; }

.filter-pill {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.filter-pill:hover { background: var(--bg-elevated); color: var(--text-primary); }
.filter-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.invoice-list {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.invoice-row-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}

.invoice-type-tag {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 500;
  margin-left: var(--sp-2);
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: var(--radius-full);
}

/* ── Invoice form (.form-card, .form-row-2, .form-group) ─────── */
.form-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding-bottom: var(--sp-8);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}

@media (min-width: 600px) {
  .form-row-2 { grid-template-columns: 1fr 1fr; }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

/* ── Line items section ──────────────────────────────────────── */
.line-items-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
}

.line-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.line-items-header > span {
  font-weight: 700;
  font-size: var(--text-base);
}

/* Scrollable wrapper for narrow screens */
#line-items-list,
.line-items-head-row {
  min-width: 0;
}

.line-items-scroll-wrap {
  overflow-x: auto;
}

/* 7-column grid: desc | qty | unit | price | gst | amount | delete */
.line-items-head-row,
.line-item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 76px 90px 96px 80px 32px;
  gap: var(--sp-2);
  align-items: start;
}

/* Compact padding for inputs inside line-item cells — global .input uses 12px/16px which
   leaves almost no text room inside the narrow fixed-width columns */
.line-item-row .input,
.line-item-row .select {
  padding: var(--sp-1) var(--sp-2);
}

.line-items-head-row {
  padding: var(--sp-2) 0 var(--sp-3);
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--sp-1);
}

.line-items-head-row > span {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.line-items-head-row > span:nth-child(n+2) { text-align: center; }
.line-items-head-row > span:nth-child(6)   { text-align: right; }
.line-items-head-row > span:nth-child(7)   { visibility: hidden; }

.line-item-row {
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.line-item-row:last-child { border-bottom: none; }

.line-item-desc {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
  width: 100%;
}

.li-notes {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  padding-top: var(--sp-1);
}

.li-qty, .li-unit, .li-price { text-align: center; }
.li-gst  { font-size: var(--text-sm); }

/* Wrapper divs: centre-align their input on desktop */
.li-qty-wrap, .li-unit-wrap, .li-price-wrap, .li-gst-wrap { align-items: center; }

.li-amount {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
  text-align: right;
  padding-top: var(--sp-3);
  white-space: nowrap;
}

.line-item-delete {
  color: var(--text-muted);
  justify-self: center;
}

.line-item-delete:hover {
  color: var(--error) !important;
  background: color-mix(in srgb, var(--error) 10%, transparent) !important;
}

/* Overflow scroll on mobile so head row + list scroll together */
@media (max-width: 639px) {
  .line-items-section {
    overflow-x: auto;
  }

  .line-items-head-row,
  .line-item-row {
    min-width: 620px;
  }
}

/* ── Invoice totals ──────────────────────────────────────────── */
.inv-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-2);
  padding-top: var(--sp-5);
}

.inv-total-row {
  display: flex;
  gap: var(--sp-6);
  font-size: var(--text-sm);
  min-width: 260px;
}

.inv-total-row > span:first-child {
  flex: 1;
  color: var(--text-secondary);
  text-align: right;
}

.inv-total-row > span:last-child {
  font-family: var(--font-mono);
  font-weight: 600;
  min-width: 90px;
  text-align: right;
}

.inv-total-grand {
  font-weight: 700;
  padding-top: var(--sp-3);
  margin-top: var(--sp-1);
  border-top: 2px solid var(--border);
}

.inv-total-grand > span:first-child { color: var(--text-primary); }
.inv-total-grand > span:last-child  { color: var(--accent); font-size: var(--text-base); }
.inv-total-balance > span:last-child { color: var(--error); }

/* ── Invoice detail card ─────────────────────────────────────── */
.detail-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.detail-type { font-size: var(--text-sm); font-weight: 600; color: var(--text-secondary); }
.detail-date,
.detail-due  { font-size: var(--text-sm); color: var(--text-muted); }

.detail-section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--sp-2);
  display: block;
}

.detail-client {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
  font-size: var(--text-sm);
  line-height: 1.7;
}

.detail-client strong {
  font-size: var(--text-base);
  font-weight: 700;
  display: block;
  margin-bottom: var(--sp-1);
}

.detail-client > div { color: var(--text-secondary); }

.detail-notes {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--text-secondary);
}

.detail-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border-subtle);
}

.line-notes {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
  font-style: italic;
}

/* ── Payment history ─────────────────────────────────────────── */
.payments-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
}

.payment-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.payment-row:last-child { border-bottom: none; padding-bottom: 0; }
.payment-row > span:last-child {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--success);
  white-space: nowrap;
}

/* ── Modal — outer wrapper override ─────────────────────────── */
/* invoices.js uses: <div class="modal" style="display:none/flex">
     <div class="modal-backdrop" />   (click-to-close)
     <div class="modal-box">...</div>
   </div>
   Override design-system where .modal was the inner card.            */
.modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  /* reset design-system card styles */
  background: transparent;
  border: none;
  border-radius: 0;
  max-width: none;
  max-height: none;
  overflow: visible;
  animation: none;
}

.modal > .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.72);
  z-index: 0;
  display: block;
}

.modal-box {
  position: relative;
  z-index: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  padding: var(--sp-6);
  animation: modal-in 200ms ease;
}

.modal-box .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-5);
}

.modal-box .modal-header h3 {
  font-size: var(--text-lg);
  font-weight: 700;
}

/* ── Confirm / typed-confirm modals ─────────────────────────── */
.confirm-modal-box {
  max-width: 420px;
}

.confirm-modal-message {
  margin: 0 0 var(--sp-5);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.confirm-modal-type-hint {
  margin-bottom: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.confirm-modal-input {
  width: 100%;
  margin-bottom: var(--sp-5);
}

.confirm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
}

/* ── Invoice edit tabs ──────────────────────────────────────── */
.inv-tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--sp-4);
}
.inv-tab {
  padding: var(--sp-2) var(--sp-4);
  background: none;
  border: none;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.inv-tab.active {
  background: var(--color-accent);
  color: #fff;
  border-bottom-color: transparent;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* ── Costing card ───────────────────────────────────────────── */
.costing-card { padding: var(--sp-6); }
.costing-global { margin-bottom: var(--sp-6); }
.costing-table-wrap { overflow-x: auto; }
.costing-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.costing-table th {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.costing-table td {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.costing-table .input { max-width: 90px; padding: var(--sp-1) var(--sp-2); }
.costing-desc { color: var(--text-secondary); max-width: 200px; }
.costing-sell { font-weight: 600; text-align: right; white-space: nowrap; }

/* ── Costing summary ────────────────────────────────────────── */
.costing-summary {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}
.costing-summary-row {
  display: flex;
  justify-content: space-between;
  padding: var(--sp-1) 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.costing-summary-row strong { color: var(--text-primary); }
.costing-margin strong { color: var(--accent); font-size: var(--text-base); }

.form-actions {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  margin-top: var(--sp-6);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border-subtle);
}

/* ── Catalog modal rows ──────────────────────────────────────── */
.catalog-pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
}

.catalog-pick-row:hover { background: var(--bg-elevated); }
.catalog-pick-row:last-child { border-bottom: none; }

.catalog-pick-row > span {
  font-family: var(--font-mono);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  color: var(--accent);
}

.catalog-pick-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}

/* ── PDF preview panel ───────────────────────────────────────── */
#pdf-preview-panel {
  position: fixed;
  inset: 0;
  z-index: 500;
  flex-direction: column;
  background: var(--bg-base);
}

.pdf-preview-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.pdf-frame {
  flex: 1;
  border: none;
  background: #525659;
  width: 100%;
}

/* ── Help overlay — stronger backdrop ────────────────────────── */
.help-backdrop { background: rgb(0 0 0 / 0.65); }

/* ── Utility additions ───────────────────────────────────────── */
.text-center { text-align: center; }

/* Dashboard section header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
  margin-top: var(--sp-6);
}

.section-title { font-size: var(--text-lg); font-weight: 700; }

.section-link {
  font-size: var(--text-sm);
  color: var(--accent);
  text-decoration: none;
}

.section-link:hover { text-decoration: underline; }

/* ── Invoice list — column header row ───────────────────────── */

/* 5-column grid: # | Client | Status | Amount | Date */
.invoice-list-header,
.invoice-row {
  display: grid;
  grid-template-columns: 110px 1fr 90px 100px 80px;
  gap: var(--sp-4);
  align-items: center;
  padding: var(--sp-3) var(--sp-5);
}

.invoice-list-header {
  border-bottom: 2px solid var(--border);
  padding-top: var(--sp-3);
  padding-bottom: var(--sp-3);
}

.invoice-list-header > span {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Number + type tag stacked */
.invoice-num-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

/* Tighter row on mobile — drop Date column */
@media (max-width: 599px) {
  .invoice-list-header,
  .invoice-row {
    grid-template-columns: 90px 1fr 80px 90px;
    padding: var(--sp-3) var(--sp-4);
  }

  .invoice-list-header > span:last-child,
  .invoice-row > span:last-child { display: none; }
}

/* ── User account dropdown ───────────────────────────────────── */
.user-dropdown {
  position: absolute;
  bottom: calc(100% + var(--sp-2));
  left: var(--sp-2);
  right: var(--sp-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: 300;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity var(--transition), transform var(--transition);
}

.user-dropdown.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
}

.user-dropdown-item:hover { background: var(--bg-surface); }

.user-dropdown-item--danger { color: var(--error); }
.user-dropdown-item--danger:hover { background: color-mix(in srgb, var(--error) 8%, transparent); }

.user-dropdown-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--sp-1) 0;
}

/* ── Sync status — upgrade nudge style ───────────────────────── */
.sync-status { cursor: default; }

/* ── btn-secondary ───────────────────────────────────────────── */
.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-surface-2);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ── Client list ─────────────────────────────────────────────── */
.client-list {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.client-list-header,
.client-row {
  display: grid;
  grid-template-columns: 1fr 1fr 160px;
  gap: var(--sp-4);
  align-items: center;
  padding: var(--sp-3) var(--sp-5);
}

.client-list-header {
  border-bottom: 2px solid var(--border);
}

.client-list-header > span {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.client-row {
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition);
}

.client-row:last-child { border-bottom: none; }
.client-row:hover { background: var(--bg-surface-2); }

.client-name-cell {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.client-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.03em;
}

.client-name-wrap { min-width: 0; }

.client-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-email {
  font-size: var(--text-sm);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-abn {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Catalog list ────────────────────────────────────────────── */
.catalog-list {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.catalog-list-header,
.catalog-row {
  display: grid;
  grid-template-columns: 1fr 140px 180px;
  gap: var(--sp-4);
  align-items: center;
  padding: var(--sp-3) var(--sp-5);
}

.catalog-list-header {
  border-bottom: 2px solid var(--border);
}

.catalog-list-header > span {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.catalog-row {
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition);
}

.catalog-row:last-child { border-bottom: none; }
.catalog-row:hover { background: var(--bg-surface-2); }

.catalog-name-cell { min-width: 0; }

.catalog-row-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.catalog-row-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.catalog-category-cell { display: flex; align-items: center; }

.catalog-tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--accent-text);
  background: var(--accent-soft);
  padding: 2px var(--sp-2);
  border-radius: var(--radius-sm);
}

.catalog-no-cat {
  font-size: var(--text-sm);
  color: var(--text-faint);
}

.catalog-price-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.catalog-price {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.catalog-gst {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.cat-count-bar {
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding: var(--sp-2) 0 var(--sp-3);
}

/* ── BAS Tax Summary ─────────────────────────────────────────── */

.tax-period-selector {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.tax-period-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.tax-period-pills {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: var(--sp-2);
  padding-bottom: 2px;
}

.tax-period-pills::-webkit-scrollbar { display: none; }

/* BAS key figures — two large highlight cards */
.bas-figures {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.bas-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5) var(--sp-6);
  border-left: 4px solid var(--color-border);
}

.bas-g1 { border-left-color: var(--color-accent); }
.bas-1a { border-left-color: var(--color-success); }

.bas-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--sp-2);
}

.bas-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-text);
  letter-spacing: -0.02em;
  margin-bottom: var(--sp-1);
}

.bas-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Summary stat grid — reuses .stat-card */
.tax-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

@media (min-width: 640px) {
  .bas-figures      { grid-template-columns: repeat(2, 1fr); }
  .tax-summary-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Invoice breakdown table */
.tax-table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--sp-4);
}

.tax-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.tax-table th {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  border-bottom: 2px solid var(--color-border);
  background: var(--color-surface);
  white-space: nowrap;
}

.tax-table th.text-right,
.tax-table td.text-right { text-align: right; }

.tax-table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}

.tax-table tbody tr:last-child td { border-bottom: none; }

.tax-table tbody tr:hover td { background: var(--color-surface-2); }

.tax-total-row td {
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-surface-2);
  border-top: 2px solid var(--color-border);
  font-size: var(--text-sm);
  color: var(--color-text);
}

.inv-num-cell {
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--color-text);
}

/* Disclaimer footer */
.tax-disclaimer {
  font-size: var(--text-xs);
  color: var(--color-warning);
  background: var(--color-warning-bg);
  border: 1px solid color-mix(in srgb, var(--color-warning) 30%, transparent);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-4);
  line-height: 1.6;
}

/* ── PDF Template Picker ─────────────────────────────────────── */
.template-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
}

@media (min-width: 640px) {
  .template-picker { grid-template-columns: repeat(5, 1fr); }
}

@media (min-width: 900px) {
  .template-picker { grid-template-columns: repeat(9, 1fr); }
}

.template-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
}

.template-option input[type="radio"] { display: none; }

.template-thumb {
  display: flex;
  flex-direction: column;
  width: 52px;
  height: 68px;
  border-radius: 3px;
  overflow: hidden;
  border: 2px solid var(--border);
  transition: border-color var(--transition), box-shadow var(--transition);
  background: #fff;
}

.template-option:hover .template-thumb {
  border-color: var(--accent);
}

.template-option input:checked ~ .template-thumb {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.template-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
}

.template-option input:checked ~ .template-label {
  color: var(--accent);
  font-weight: 700;
}

/* Thumbnail anatomy */
.tpl-header {
  display: block;
  width: 100%;
  height: 14px;
  flex-shrink: 0;
}

.tpl-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 4px;
  flex: 1;
}

.tpl-line {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: #d1d5db;
  width: 100%;
}

.tpl-line-wide { background: #e5e7eb; }
.tpl-line-short { width: 60%; }

/* ── Per-template thumbnail colours ──────────────────────────── */

/* 1. Classic Blue */
.template-thumb-classic-blue .tpl-header { background: #1e50a0; }
.template-thumb-classic-blue .tpl-body   { background: #f0f5ff; }
.template-thumb-classic-blue .tpl-line   { background: #93b4e8; }

/* 2. Minimalist Stark */
.template-thumb-minimalist-stark .tpl-header {
  background: #fff;
  border-bottom: 1.5px solid #000;
  height: 12px;
}
.template-thumb-minimalist-stark .tpl-body { background: #fff; }
.template-thumb-minimalist-stark .tpl-line { background: #aaaaaa; }

/* 3. Modern Charcoal */
.template-thumb-modern-charcoal .tpl-header { background: #2d2d32; height: 16px; }
.template-thumb-modern-charcoal .tpl-body   { background: #f0f0f0; }
.template-thumb-modern-charcoal .tpl-line   { background: #aaaaac; }

/* 4. Emerald Trades */
.template-thumb-emerald-trades .tpl-header { background: #047857; }
.template-thumb-emerald-trades .tpl-body   { background: #ecfdf5; }
.template-thumb-emerald-trades .tpl-line   { background: #6ee7b7; }

/* 5. Midnight Slate */
.template-thumb-midnight-slate .tpl-header { background: #0f172a; height: 18px; }
.template-thumb-midnight-slate .tpl-body   { background: #f1f5f9; }
.template-thumb-midnight-slate .tpl-line   { background: #94a3b8; }

/* 6. Warm Terracotta */
.template-thumb-warm-terracotta .tpl-header { background: #b45309; }
.template-thumb-warm-terracotta .tpl-body   { background: #fff7ed; }
.template-thumb-warm-terracotta .tpl-line   { background: #fbbf7a; }

/* 7. Ocean Breeze */
.template-thumb-ocean-breeze .tpl-header { background: #0284c7; }
.template-thumb-ocean-breeze .tpl-body   { background: #e0f2fe; }
.template-thumb-ocean-breeze .tpl-line   { background: #7dd3f5; }

/* 8. Royal Amethyst */
.template-thumb-royal-amethyst .tpl-header { background: #6d28d9; }
.template-thumb-royal-amethyst .tpl-body   { background: #f5f3ff; }
.template-thumb-royal-amethyst .tpl-line   { background: #c4b5fd; }

/* 9. Nordic Minimal */
.template-thumb-nordic-minimal .tpl-header {
  background: #f8f8f8;
  border-bottom: 1px solid #d0d0d0;
  height: 12px;
}
.template-thumb-nordic-minimal .tpl-body { background: #fff; }
.template-thumb-nordic-minimal .tpl-line { background: #c0c0c0; }

/* ── End template picker ─────────────────────────────────────── */

@media (max-width: 599px) {
  .client-list-header,
  .client-row {
    grid-template-columns: 1fr 130px;
    padding: var(--sp-3) var(--sp-4);
  }

  .client-list-header > span:nth-child(2),
  .client-row > .client-email { display: none; }

  .catalog-list-header,
  .catalog-row {
    grid-template-columns: 1fr 120px;
    padding: var(--sp-3) var(--sp-4);
  }

  .catalog-list-header > span:nth-child(2),
  .catalog-row > .catalog-category-cell { display: none; }
}

/* ============================================================
   MOBILE RESPONSIVENESS — 375–430px viewport fixes
   ============================================================ */

/* ── Pattern 1+2: Page header — title row + actions row ──────── */
@media (max-width: 599px) {
  /* Wrap so actions fall to their own row beneath back+title */
  .view-header {
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
  }

  .back-btn {
    flex-shrink: 0;
    order: 1;
  }

  /* Direct buttons in view-header (e.g. Settings Save, Clients New) sit right of title */
  .view-header > .btn {
    order: 3;
    flex-shrink: 0;
  }

  .view-title {
    order: 2;
    flex: 1;
    min-width: 0;
    font-size: clamp(14px, 4vw, 18px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Actions span the full width on their own second row */
  .view-header-actions {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
    gap: var(--sp-2);
    flex-shrink: 0;
  }

  .view-header-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
  }

  /* Primary CTA (Record Payment) gets its own full-width row */
  .view-header-actions .btn-primary {
    flex-basis: 100%;
  }

  .view-header-actions .btn:only-child {
    flex: 1 1 100%;
  }
}

/* ── Pattern 3: Invoice list — tighter grid at 430px ────────── */
@media (max-width: 430px) {
  .invoice-list-header,
  .invoice-row {
    grid-template-columns: 76px 1fr 68px 82px;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
  }
}

/* ── Pattern 3: Client list — tighter columns at 430px ──────── */
@media (max-width: 430px) {
  .client-list-header,
  .client-row {
    grid-template-columns: 1fr 110px;
    padding: var(--sp-2) var(--sp-3);
  }
}

/* ── Pattern 3: Catalog list — tighter columns at 430px ─────── */
@media (max-width: 430px) {
  .catalog-list-header,
  .catalog-row {
    grid-template-columns: 1fr 100px;
    padding: var(--sp-2) var(--sp-3);
  }
}

/* ── Pattern 3: BAS tax table — fixed layout, hide extra cols ── */
@media (max-width: 599px) {
  .tax-table-wrap { overflow-x: visible; }

  .tax-table {
    table-layout: fixed;
    width: 100%;
  }

  .tax-table th:nth-child(1) { width: 20%; }  /* Invoice # */
  .tax-table th:nth-child(2) { width: 30%; }  /* Client    */
  .tax-table th:nth-child(3) { width: 24%; }  /* Date      */
  .tax-table th:nth-child(4) { width: 26%; }  /* Status    */

  /* Hide Subtotal, GST, Total columns */
  .tax-table th:nth-child(5),
  .tax-table td:nth-child(5),
  .tax-table th:nth-child(6),
  .tax-table td:nth-child(6),
  .tax-table th:nth-child(7),
  .tax-table td:nth-child(7) { display: none; }

  /* Shrink cell padding */
  .tax-table th,
  .tax-table td { padding: var(--sp-2) var(--sp-2); font-size: 12px; }
}

/* ── Pattern 3: Line items table — fixed layout mobile ──────── */
@media (max-width: 599px) {
  /* Edit view: class-based widths for the editable grid rows */
  .line-item-desc  { width: 38%; }
  .line-item-qty   { width: 10%; }
  .line-item-unit  { width: 12%; }
  .line-item-price { width: 22%; }
  .line-item-gst   { width: 10%; }
  .line-item-total { display: none; }
  .line-item-del   { width: 8%; }

  /* Detail view: <table> inside .table-wrap — nth-child because th/td have no classes */
  .table-wrap .line-items-table {
    table-layout: fixed;
    width: 100%;
  }
  /* Col 1 Description */
  .table-wrap .line-items-table th:nth-child(1),
  .table-wrap .line-items-table td:nth-child(1) { width: 44%; word-break: break-word; overflow-wrap: anywhere; }
  /* Col 2 Qty */
  .table-wrap .line-items-table th:nth-child(2),
  .table-wrap .line-items-table td:nth-child(2) { width: 10%; }
  /* Col 3 Unit — hide */
  .table-wrap .line-items-table th:nth-child(3),
  .table-wrap .line-items-table td:nth-child(3) { display: none; }
  /* Col 4 Price */
  .table-wrap .line-items-table th:nth-child(4),
  .table-wrap .line-items-table td:nth-child(4) { width: 22%; }
  /* Col 5 GST — hide */
  .table-wrap .line-items-table th:nth-child(5),
  .table-wrap .line-items-table td:nth-child(5) { display: none; }
  /* Col 6 Amount */
  .table-wrap .line-items-table th:nth-child(6),
  .table-wrap .line-items-table td:nth-child(6) { width: 24%; }

  .table-wrap .line-items-table th,
  .table-wrap .line-items-table td { padding: var(--sp-1) var(--sp-1); font-size: 12px; }
}

/* ── Pattern 4: Scroll-hint fade for pill rows ───────────────── */
/* filter-pills and tax-period-pills: already set to nowrap+scroll above */
/* Add fade gradient as last child pseudo via wrapper */
.filter-bar,
.tax-period-selector {
  position: relative;
}

/* Settings tabs: ensure flex-shrink on each tab */
.settings-tab,
.filter-pill { flex-shrink: 0; }

/* ── Pattern 5: Sidebar overlay — full viewport on iOS ──────── */
@media (max-width: 767px) {
  .sidebar {
    height: 100vh;
    min-height: 100dvh;
  }
}

/* ── Pattern 7: BAS stat cards — smaller labels, min-height ─── */
@media (max-width: 599px) {
  .bas-label {
    font-size: 11px;
  }

  .bas-card {
    min-height: 110px;
    padding: var(--sp-4);
  }

  .bas-value {
    font-size: var(--text-2xl);
  }

  .bas-hint {
    font-size: 10px;
  }
}

/* ── Pattern 8: Client detail field hierarchy ────────────────── */
.client-detail-field {
  margin-bottom: 12px;
}

.client-detail-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 2px;
}

.client-detail-value {
  display: block;
  font-size: 15px;
  color: var(--color-text);
  word-break: break-word;
}

/* ── Pattern 9: Branding tab additions ───────────────────────── */
.branding-pro-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.font-selector {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.font-option {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: border-color var(--transition), background var(--transition);
}

.font-option:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.font-option input[type="radio"] { display: none; }

.font-option.selected {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
}

.branding-preview {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  max-width: 380px;
}

.branding-preview-header {
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.branding-preview-logo {
  font-size: var(--text-sm);
  font-weight: 800;
  color: #fff;
  opacity: 0.9;
}

.branding-preview-type {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #fff;
  opacity: 0.85;
  text-transform: uppercase;
}

.branding-preview-body {
  padding: var(--sp-3) var(--sp-4);
}

.branding-preview-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

.branding-preview-meta-item p:first-child {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 2px;
}

.branding-preview-meta-item p:last-child {
  font-size: 11px;
  color: #1a2332;
  font-weight: 500;
}

.branding-preview-table-head {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  padding: var(--sp-1) var(--sp-2);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  margin-bottom: 2px;
  border-radius: 2px;
}

.branding-preview-table-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  padding: var(--sp-1) var(--sp-2);
  font-size: 10px;
  color: #444;
  border-bottom: 1px solid #eee;
}

.branding-preview-total {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-2);
  font-size: 11px;
  font-weight: 700;
}

/* ── Pattern 10: Help article image slots ────────────────────── */
.article-image-slot {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--sp-5) var(--sp-4);
  margin: var(--sp-4) 0;
  text-align: center;
  background: var(--color-surface-2);
}

.article-image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  color: var(--color-text-faint);
}

.article-image-placeholder svg {
  opacity: 0.4;
}

.article-image-placeholder span {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.article-image-slot figcaption {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--sp-2);
  font-style: italic;
}

/* When a real screenshot is loaded, drop the dashed-box styling */
.article-image-slot:has(img) {
  border: none;
  padding: 0;
  background: none;
}

.article-image-slot img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

/* ── Pattern 9: User dropdown additions ─────────────────────── */
/* (no CSS needed — existing .user-dropdown styles cover new items) */

/* ============================================================
   MOBILE UX — Touch targets, gestures, layout improvements
   ============================================================ */

/* ── 1. Eliminate 300ms tap delay on all interactive elements ── */
.btn,
button,
.nav-item,
.invoice-row,
.client-row,
.catalog-row,
.filter-pill,
.filter-tab,
.settings-tab,
.inv-tab,
.help-tab,
.help-article-btn,
.catalog-pick-row,
.user-info,
.user-dropdown-item {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ── 2. Touch target minimums (44×44px) ─────────────────────── */
.btn        { min-height: 44px; }
.btn-sm     { min-height: 36px; }
.btn-icon   { min-height: 44px; min-width: 44px; }

.nav-item   { min-height: 44px; }

.settings-tab,
.filter-tab,
.help-tab,
.inv-tab {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.filter-pill     { min-height: 36px; display: inline-flex; align-items: center; }
.invoice-row     { min-height: 52px; }
.client-row,
.catalog-row     { min-height: 52px; }
.help-article-btn { min-height: 48px; }
.user-info        { min-height: 52px; }

/* ── 3. Prevent iOS auto-zoom on focused inputs (needs 16px) ── */
@media (max-width: 767px) {
  .input,
  .select,
  textarea {
    font-size: 16px;
  }
}

/* ── 4. Safe area bottom padding (iPhone home indicator) ──────── */
@media (max-width: 767px) {
  .page,
  #view-container {
    padding-bottom: calc(var(--sp-6) + env(safe-area-inset-bottom, 0px));
  }
}

/* ── 10. Prevent horizontal scroll ──────────────────────────── */
@media (max-width: 767px) {
  #main {
    overflow-x: clip;
  }

  #view-container,
  .page {
    max-width: 100%;
    overflow-x: clip;
  }

  /* Reduce form section padding so content has more room */
  .form-section,
  .line-items-section,
  .detail-card,
  .settings-card {
    padding: var(--sp-4);
  }

  /* Scale down page/view titles */
  .page-title,
  .view-title {
    font-size: clamp(15px, 4vw, 18px);
  }

  /* Greeting is secondary to the page title — one step smaller */
  .dash-greeting-text {
    font-size: var(--text-lg); /* 18px */
  }

  /* Stat card values — 24px is too dominant on a 430px screen */
  .stat-value {
    font-size: var(--text-lg); /* 18px */
  }

  /* Card/section sub-headings — all views */
  .settings-card h3,
  .detail-card h3,
  .section-title,
  .form-section-title,
  .line-items-header > span {
    font-size: var(--text-sm); /* 14px */
  }

  /* BAS Tax Summary — big G1/1A figures */
  .bas-value {
    font-size: var(--text-lg); /* 18px — was 24px */
  }

  /* BAS label minimum legibility */
  .bas-label {
    font-size: var(--text-xs); /* 12px — was 11px */
  }

  /* Hide the notes sub-field in line items on mobile — secondary info */
  .li-notes-field {
    display: none;
  }

  /* Line item description textarea — auto-expands via JS */
  .line-item-desc .li-desc {
    resize: none;
    min-height: 48px;
    overflow: hidden;
    line-height: 1.4;
  }

  /* Topbar logo text — prevent overflow on very small screens */
  .topbar-logo {
    font-size: var(--text-base);
  }

  /* Ensure totals don't overflow */
  .inv-totals,
  .invoice-totals {
    width: 100%;
    align-items: stretch;
  }

  .inv-total-row {
    min-width: 0;
    width: 100%;
    justify-content: space-between;
  }
}

/* ── 5. Modal → bottom sheet on mobile ──────────────────────── */
@media (max-width: 599px) {
  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-box {
    max-width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 92dvh;
    padding: var(--sp-5) var(--sp-5) calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
    animation: sheet-up 250ms ease;
  }

  @keyframes sheet-up {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
  }
}

/* ── 6. Form actions: full-width stacked on mobile ───────────── */
@media (max-width: 599px) {
  .form-actions {
    flex-direction: column-reverse;
    gap: var(--sp-2);
  }

  .form-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ── 7. Line item wrapper divs (added in invoices.js) ─────────── */
/* Desktop: pass-through — wrapper fills its grid cell */
.li-field-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.li-field-wrap .input,
.li-field-wrap .select {
  width: 100%;
}

/* ── 8. Line items: stacked card layout on mobile ───────────── */
@media (max-width: 599px) {
  .line-items-section     { overflow-x: visible !important; }
  .line-items-scroll-wrap { overflow-x: visible !important; }
  .line-items-head-row    { display: none !important; }

  /* Row layout: description full-width, then numeric row below */
  .line-item-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr auto !important;
    grid-template-rows: auto auto !important;
    min-width: 0 !important;
    position: relative !important;
    padding: var(--sp-3) 40px var(--sp-3) 0 !important;
    gap: var(--sp-2) !important;
    align-items: start !important;
  }

  /* Description: full width across all columns */
  .line-item-row .line-item-desc {
    grid-column: 1 / -1 !important;
    grid-row: 1 !important;
    width: 100% !important;
  }

  /* Delete button: absolute top-right corner */
  .line-item-row .line-item-delete {
    position: absolute !important;
    top: var(--sp-3) !important;
    right: 0 !important;
    width: 32px !important;
    height: 32px !important;
  }

  /* Row 2: Qty | Price | Amount */
  .line-item-row .li-qty-wrap   { grid-column: 1; grid-row: 2; }
  .line-item-row .li-price-wrap { grid-column: 2; grid-row: 2; }
  .line-item-row .li-amount {
    grid-column: 3;
    grid-row: 2;
    text-align: right;
    padding-top: 18px;
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--color-accent);
    white-space: nowrap;
  }

  /* Hide unit and GST on mobile */
  .line-item-row .li-unit-wrap,
  .line-item-row .li-gst-wrap { display: none !important; }

  /* Field labels */
  .li-qty-wrap::before,
  .li-price-wrap::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--sp-1);
  }

  .line-item-row .input,
  .line-item-row .select {
    width: 100%;
    font-size: 16px;
  }
}

/* ── 9. Reduced motion support ──────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
