/* ═══════════════════════════════════════════════════════════
   EliteInvoice — Design System
═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent:        #0071e3;
  --accent-hover:  #0077ed;
  --accent-dim:    #e8f1fc;
  --bg:            #f5f5f7;
  --surface:       #ffffff;
  --border:        #d2d2d7;
  --border-light:  #e8e8ed;
  --text-primary:  #1d1d1f;
  --text-secondary:#6e6e73;
  --text-tertiary: #aeaeb2;
  --danger:        #ff3b30;
  --success:       #34c759;
  --warning:       #ff9f0a;
  --sidebar-w:     240px;
}
[data-theme="dark"] {
  --bg:#1c1c1e;--surface:#2c2c2e;--border:#3a3a3c;
  --border-light:#2c2c2e;--text-primary:#f5f5f7;
  --text-secondary:#a1a1a6;--text-tertiary:#636366;
}
[data-theme="dark"] .sidebar{background:#111113}
[data-theme="dark"] .hamburger{background:rgba(30,30,32,0.92);border-color:#3a3a3c}
[data-theme="dark"] .hamburger:hover{background:#2c2c2e}
[data-theme="dark"] input,[data-theme="dark"] textarea,[data-theme="dark"] select{background:#2c2c2e;color:#f5f5f7;border-color:#3a3a3c}
[data-theme="dark"] input:focus,[data-theme="dark"] textarea:focus,[data-theme="dark"] .field-input:focus{background:#3a3a3c;border-color:var(--accent)}
[data-theme="dark"] #magicInput{background:#2c2c2e;color:#f5f5f7;border-color:#3a3a3c}
[data-theme="dark"] #magicInput:focus{background:#3a3a3c;border-color:var(--accent);color:#f5f5f7}
[data-theme="dark"] .history-card{background:#2c2c2e;border-color:#3a3a3c}
[data-theme="dark"] .history-card-actions{border-top-color:#3a3a3c}
[data-theme="dark"] .settings-card{background:#2c2c2e;border-color:#3a3a3c}
[data-theme="dark"] .magic-box,[data-theme="dark"] .magic-card{background:#2c2c2e;border-color:#3a3a3c}
[data-theme="dark"] .modal-box{background:#2c2c2e}
[data-theme="dark"] .modal-header{border-bottom-color:#3a3a3c}
[data-theme="dark"] .modal-footer{border-top-color:#3a3a3c}
[data-theme="dark"] .revenue-dashboard{background:linear-gradient(135deg,#1a3a5c 0%,#0d2137 100%)}
[data-theme="dark"] .sidebar-overlay{background:rgba(0,0,0,0.6)}
[data-theme="dark"] #toast{background:#e0e0e5;color:#1c1c1e}
[data-theme="dark"] .invoice-table tbody tr:hover{background:#3a3a3c}
[data-theme="dark"] .invoice-table thead tr{border-bottom-color:#636366}
[data-theme="dark"] .invoice-table tbody tr{border-bottom-color:#3a3a3c}
[data-theme="dark"] .invoice-table td input{color:#f5f5f7}
[data-theme="dark"] .invoice-table td input:focus{background:transparent}
[data-theme="dark"] .invoice-table td.td-total{color:#f5f5f7}
[data-theme="dark"] .totals-row{border-bottom-color:#3a3a3c}
[data-theme="dark"] .totals-grand{border-top-color:#636366}
[data-theme="dark"] .invoice-notes{border-top-color:#3a3a3c}
[data-theme="dark"] .invoice-document{border-color:#3a3a3c}
[data-theme="dark"] .nav-item{color:#a1a1a6}
[data-theme="dark"] .nav-item:hover{background:#2c2c2e;color:#f5f5f7}
[data-theme="dark"] .nav-item.active{background:rgba(0,113,227,0.18);color:#4da3ff} /* overridden by template tinting above 768px */
[data-theme="dark"] .btn-primary{background:#0a84ff}
[data-theme="dark"] .btn-primary:hover{background:#0070d8}
[data-theme="dark"] .btn-secondary{background:#2c2c2e;color:#d1d1d6;border-color:#3a3a3c}
[data-theme="dark"] .btn-secondary:hover{background:#3a3a3c;color:#f5f5f7}
[data-theme="dark"] .btn-ghost{color:#a1a1a6;border-color:#3a3a3c}
[data-theme="dark"] .btn-ghost:hover{background:#2c2c2e;color:#f5f5f7}
[data-theme="dark"] .magic-badge,[data-theme="dark"] .modal-ai-badge{
  background: linear-gradient(110deg, #0d2a4a, #1a1040, #2d1050, #0d2a4a);
  background-size: 250% 250%;
  animation: aiGradientShift 14s ease-in-out infinite 2s;
  color: #a78bfa;
}[data-theme="dark"] .hc-overdue-badge.upcoming{background:#0d2e18;color:#4ade80}
[data-theme="dark"] .hc-overdue-badge.gentle{background:#2e1f00;color:#fbbf24}
[data-theme="dark"] .hc-overdue-badge.friendly{background:#2e1500;color:#fb923c}
[data-theme="dark"] .hc-overdue-badge.firm{background:#2e0a0a;color:#f87171}
[data-theme="dark"] .modal-tone-badge.upcoming{background:#0d2e18;color:#4ade80}
[data-theme="dark"] .modal-tone-badge.gentle{background:#2e1f00;color:#fbbf24}
[data-theme="dark"] .modal-tone-badge.friendly{background:#2e1500;color:#fb923c}
[data-theme="dark"] .modal-tone-badge.firm{background:#2e0a0a;color:#f87171}
[data-theme="dark"] .btn-del-invoice{background:#2e0a0a;color:#f87171;border-color:#3a1010}
[data-theme="dark"] .btn-del-invoice:hover{background:#3d0f0f}
[data-theme="dark"] .btn-draft-email { box-shadow: 0 2px 10px rgba(94,92,230,0.2); }
[data-theme="dark"] .btn-load{background:#1c2e1c;color:#4ade80;border-color:#1a3a1a}
[data-theme="dark"] .btn-load:hover{background:#243824}
[data-theme="dark"] .confirm-box{background:#2c2c2e}
[data-theme="dark"] .confirm-icon{background:#2e0a0a}
[data-theme="dark"] .btn-danger{background:#c0392b}
[data-theme="dark"] .btn-danger:hover{background:#a93226}
[data-theme="dark"] .view-icon{background:rgba(0,113,227,0.15);color:#4da3ff}
.theme-icon-dark{display:none;align-items:center;gap:6px}
.theme-icon-light{display:flex;align-items:center;gap:6px}
[data-theme="dark"] .theme-icon-dark{display:flex}
[data-theme="dark"] .theme-icon-light{display:none}
:root {
  --radius-sm:     12px;
  --radius-md:     16px;
  --radius-lg:     20px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:     0 4px 16px rgba(0,0,0,.09), 0 1px 4px rgba(0,0,0,.06);
  --shadow-lg:     0 8px 32px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.07);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
  --hamburger-clearance: 68px;
}

html { overflow-x: clip; }
html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; min-height: 100vh; }

/* ══════════════════════════════════════════════════
   PAGE WRAPPER
══════════════════════════════════════════════════ */
.page-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: clip;
}
.main-content {
  flex: 1;
  padding: 32px 40px 48px;
  min-width: 0;
  overflow-x: clip;
}

/* ══════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  box-shadow: 1px 0 0 var(--border-light);
  border-radius: 0 24px 24px 0;
  overflow: hidden;
}
.sidebar-brand {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 4px 8px 20px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 12px;
}
.sidebar-brand svg { flex-shrink: 0; margin-top: 2px; }
.sidebar-brand-text { display: flex; flex-direction: column; gap: 2px; }
.sidebar-tagline {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--text-tertiary);
  opacity: 0.8;
  line-height: 1.3;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 450;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg    { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover  { background: var(--bg); color: var(--text-primary); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }

.sidebar-datetime {
  padding: 0 12px 8px;
  font-size: 10.5px;
  color: var(--text-tertiary);
  opacity: 0.72;
  line-height: 1.6;
  letter-spacing: 0.01em;
}
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 12px 12px 4px;
  border-top: 1px solid var(--border-light);
  font-size: 11.5px;
  color: var(--text-tertiary);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: background 0.3s;
}
.status-dot.online  { background: var(--success); }
.status-dot.offline { background: var(--danger); }

/* ══════════════════════════════════════════════════
   VIEW SYSTEM
══════════════════════════════════════════════════ */
.view { display: none; }
#view-invoice.active,#view-history.active,#view-settings.active,#view-templates.active,#view-help.active {
  display: flex; flex-direction: column; align-items: center;
}
#view-invoice.active > *,#view-history.active > *,
#view-settings.active > *,#view-templates.active > *,#view-help.active > * { width:100%;max-width:860px; }

.history-actions{display:flex;gap:8px;align-items:center;flex-wrap:wrap}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.view-title-group{display:flex;align-items:center;gap:14px}
.view-icon{display:flex;align-items:center;justify-content:center;width:46px;height:46px;border-radius:14px;background:var(--accent-dim);color:var(--accent);flex-shrink:0}
.view-header h1{font-size:26px;font-weight:700;letter-spacing:-0.6px;color:var(--text-primary);line-height:1.2}
.subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ══════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════ */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 20px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: -0.1px;
  white-space: nowrap;
}
.btn-primary:hover  { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 7px 16px;
  border-radius: 20px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--bg); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 20px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--bg); color: var(--text-primary); }

.btn-ai {
  background: linear-gradient(110deg, #0071e3, #5e5ce6, #a855f7, #0071e3);
  background-size: 250% 250%;
  animation: aiGradientShift 14s ease-in-out infinite;
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 20px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.2s;
  flex-shrink: 0;
  white-space: nowrap;
  box-shadow: 0 2px 12px rgba(94,92,230,0.35);
}
.btn-ai:hover    { opacity: 0.92; box-shadow: 0 4px 20px rgba(94,92,230,0.5); }
.btn-ai:active   { transform: scale(0.97); }
.btn-ai:disabled { opacity: 0.5; cursor: not-allowed; animation: none; }

.btn-add-row {
  background: transparent;
  color: var(--accent);
  border: 1.5px dashed var(--accent);
  padding: 7px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: background 0.15s;
}
.btn-add-row:hover { background: var(--accent-dim); }

/* ── UPDATE INVOICE BUTTON ── */
.btn-update {
  background: #1a7f37;
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 20px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: -0.1px;
  white-space: nowrap;
}
.btn-update:hover  { background: #1c8a3c; }
.btn-update:active { transform: scale(0.97); }

/* ── CANCEL EDIT BUTTON ── */
.btn-cancel-edit {
  background: transparent;
  color: var(--success);
  border: 1px solid var(--success);
  padding: 7px 16px;
  border-radius: 20px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}
.btn-cancel-edit:hover { background: rgba(26,127,55,0.08); }
[data-theme="dark"] .btn-cancel-edit { color: #4ade80; border-color: #4ade80; }
[data-theme="dark"] .btn-cancel-edit:hover { background: rgba(74,222,128,0.1); }

/* ══════════════════════════════════════════════════
   INVOICE EDITOR — CURRENCY SELECT
══════════════════════════════════════════════════ */
#currencySelect {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-family: var(--font);
  font-size: 13px;
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236e6e73' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ══════════════════════════════════════════════════
   MAGIC CARD
══════════════════════════════════════════════════ */
.magic-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  width: 100%; max-width: 100%;
  position: relative;
  /* Animated gradient border via outline trick */
  border: 1.5px solid transparent;
  background-clip: padding-box;
  outline: 1.5px solid transparent;
}
/* Animated gradient border using ::before pseudo overlay */
.magic-card::before {
  content: '';
  position: absolute;
  inset: -1.5px;
  border-radius: calc(var(--radius-lg) + 1px);
  background: linear-gradient(110deg, #0071e3, #5e5ce6, #a855f7, #06b6d4, #0071e3);
  background-size: 300% 300%;
  animation: aiGradientShift 16s ease-in-out infinite;
  z-index: 0;
  opacity: 0.55;
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  padding: 1.5px;
}
.magic-card > * { position: relative; z-index: 1; }

.magic-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; flex-wrap: wrap; gap: 8px;
}
.magic-badge {
  display: flex; align-items: center; gap: 5px;
  background: linear-gradient(110deg, #dbeafe, #ede9fe, #fce7f3, #dbeafe);
  background-size: 250% 250%;
  animation: aiGradientShift 14s ease-in-out infinite 2s;
  color: #4f46e5;
  font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.3px; padding: 4px 10px; border-radius: 20px;
  text-transform: uppercase;
}
.magic-hint { font-size: 11.5px; color: var(--text-tertiary); }

#magicInput {
  width: 100%;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--bg);
  resize: vertical;
  line-height: 1.55;
  transition: border-color 0.15s;
}
#magicInput:focus { outline: none; border-color: var(--accent); background: var(--bg); }

.magic-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; min-height: 32px; gap: 10px;
}
.magic-status {
  font-size: 12.5px; color: var(--text-secondary);
  display: flex; align-items: center; gap: 6px;
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════
   INVOICE DOCUMENT
══════════════════════════════════════════════════ */
.invoice-document {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 40px 44px 52px;
  box-shadow: var(--shadow-md);
  width: 100%; max-width: 860px;
  margin: 0 auto;
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* Print accent bar — hidden on screen, shown in @media print below */
.invoice-print-bar { display: none; }

/* Edit mode — green border glow */
.invoice-document.is-editing {
  border-color: #1a7f37;
  box-shadow:
    var(--shadow-md),
    0 0 0 2px rgba(26, 127, 55, 0.15);
}

/* Edit mode banner — hidden by default, shown inside .is-editing */
.edit-mode-banner {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 10px 14px;
  background: #f0faf3;
  border: 1px solid #aee8bc;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: #1a7f37;
  font-weight: 500;
}
.invoice-document.is-editing .edit-mode-banner {
  display: flex;
}

.invoice-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 36px; gap: 20px; flex-wrap: wrap;
}
.invoice-brand  { display: flex; align-items: flex-start; gap: 14px; min-width: 0; }
.invoice-logo   { width: auto; height: 60px; object-fit: contain; border-radius: 12px; flex-shrink: 0; }
.invoice-biz-name    { font-size: 17px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.4px; word-break: break-word; }
.invoice-biz-address { font-size: 12px; color: var(--text-secondary); margin-top: 4px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.invoice-biz-contact { font-size: 11.5px; color: var(--text-tertiary); margin-top: 5px; line-height: 1.7; word-break: break-word; }
.invoice-biz-contact a { color: var(--accent); text-decoration: none; }
.invoice-biz-contact a:hover { text-decoration: underline; }

.invoice-meta { text-align: right; flex-shrink: 0; }
.invoice-title-block {
  display: flex; align-items: baseline; gap: 10px;
  justify-content: flex-end; margin-bottom: 14px;
}
.invoice-title-label { font-size: 11px; font-weight: 700; letter-spacing: 2px; color: var(--text-tertiary); text-transform: uppercase; }
.invoice-number      { font-size: 20px; font-weight: 700; color: var(--accent); letter-spacing: -0.5px; }
.invoice-number-input {
  font-size: 20px; font-weight: 700; color: var(--accent);
  letter-spacing: -0.5px; font-family: inherit;
  background: transparent; border: none; border-bottom: 1.5px dashed var(--accent);
  padding: 0 2px 1px; width: 140px; outline: none;
  transition: border-color 0.15s, background 0.15s;
  border-radius: 2px;
}
.invoice-number-input:hover { background: rgba(26,86,219,0.06); }
.invoice-number-input:focus { border-bottom-style: solid; background: rgba(26,86,219,0.08); }

.invoice-dates       { display: flex; flex-direction: column; gap: 6px; }
.date-row {
  display: flex; align-items: center; gap: 10px;
  justify-content: flex-end; font-size: 12.5px; color: var(--text-secondary);
}
.date-input {
  border: 1px solid var(--border-light); border-radius: 10px; padding: 4px 8px;
  font-family: var(--font); font-size: 12.5px; color: var(--text-primary);
  background: var(--bg); max-width: 100%;
}
.date-input:focus { outline: none; border-color: var(--accent); }

.invoice-bill-to { background: var(--bg); border-radius: var(--radius-md); padding: 16px 20px; margin-bottom: 24px; }
.bill-label { font-size: 10px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: 10px; }
.bill-fields { display: flex; gap: 10px; flex-wrap: wrap; }
.bill-input {
  border: none; background: transparent; border-bottom: 1px solid var(--border);
  padding: 4px 2px; font-family: var(--font); font-size: 13.5px; color: var(--text-primary);
  min-width: 0; flex: 1 1 120px; transition: border-color 0.15s;
}
.bill-input:focus     { outline: none; border-bottom-color: var(--accent); }
.bill-input-wide      { flex: 2 1 180px; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; margin-bottom: 0; }
.invoice-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.invoice-table thead tr { border-bottom: 2px solid var(--text-primary); }
.invoice-table th {
  padding: 10px 12px; font-weight: 700; font-size: 11px; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--text-tertiary); text-align: left; white-space: nowrap;
}
.col-desc  { width: 45%; }
.col-qty   { width: 12%; text-align: center; }
.col-price { width: 18%; text-align: right; }
.col-total { width: 18%; text-align: right; }
.col-del   { width: 7%;  text-align: center; }

.invoice-table tbody tr { border-bottom: 1px solid var(--border-light); }
.invoice-table tbody tr:hover { background: var(--bg); }
.invoice-table td { padding: 9px 12px; vertical-align: middle; }
.invoice-table td input {
  width: 100%; border: none; background: transparent; font-family: var(--font);
  font-size: 13.5px; color: var(--text-primary); padding: 2px 0; min-width: 0;
}
.invoice-table td input:focus { outline: none; }
.invoice-table td.td-qty input   { text-align: center; }
.invoice-table td.td-price input { text-align: right; }
.invoice-table td.td-total { text-align: right; font-weight: 500; color: var(--text-primary); }

.del-row-btn {
  background: transparent; border: none; color: var(--text-tertiary); cursor: pointer;
  font-size: 17px; line-height: 1; padding: 2px 6px; border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.del-row-btn:hover { color: var(--danger); background: #fff2f0; }
.table-actions { padding: 12px 0 4px; }

/* ── TOTALS ── */
.totals-block { display: flex; justify-content: flex-end; margin: 20px 0 24px; }
.totals-table { width: 100%; max-width: 300px; display: flex; flex-direction: column; gap: 8px; }
.totals-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13.5px; color: var(--text-secondary); padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
}
.totals-row:last-child { border-bottom: none; }
.totals-grand { font-size: 16px; font-weight: 700; color: var(--text-primary); padding-top: 8px; }
.tax-rate-input {
  width: 44px; border: 1px solid var(--border); border-radius: 8px; padding: 2px 5px;
  font-family: var(--font); font-size: 12.5px; text-align: center; background: var(--bg);
}
.tax-rate-input:focus { outline: none; border-color: var(--accent); }

.invoice-notes { border-top: 1px solid var(--border-light); padding-top: 18px; }
.notes-label { font-size: 10px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: 8px; }
.notes-input {
  width: 100%; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--font); font-size: 13px; color: var(--text-secondary);
  background: var(--bg); resize: vertical; line-height: 1.5;
}
.notes-input:focus { outline: none; border-color: var(--accent); }

/* ══════════════════════════════════════════════════
   REVENUE DASHBOARD CARD
══════════════════════════════════════════════════ */
.revenue-dashboard {
  background: linear-gradient(135deg, #0a2540 0%, #0d3460 55%, #0f4a7a 100%);
  border-radius: var(--radius-lg);
  padding: 2px;
  margin-bottom: 24px;
  box-shadow:
    0 4px 24px rgba(0,113,227,0.22),
    0 1px 6px  rgba(0,113,227,0.12),
    inset 0 1px 0 rgba(255,255,255,0.06);
  max-width: 760px;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.revenue-dashboard::before {
  content: '';
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(0,113,227,0.18) 0%, transparent 70%),
    radial-gradient(ellipse at 80% 20%, rgba(94,92,230,0.14) 0%, transparent 60%);
  pointer-events: none;
  border-radius: inherit;
}
.revenue-dashboard-inner {
  background: linear-gradient(135deg, #0d2d50 0%, #0e3b68 60%, #103f72 100%);
  border-radius: calc(var(--radius-lg) - 2px);
  padding: 22px 26px 20px;
  position: relative; z-index: 1;
}

.revenue-main-stat { margin-bottom: 16px; }
.revenue-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: rgba(255,255,255,0.5);
  margin-bottom: 8px;
}
.revenue-label svg { opacity: 0.6; }

.revenue-amount {
  font-size: 34px; font-weight: 800; letter-spacing: -1.2px;
  color: #ffffff; line-height: 1.1;
  transition: opacity 0.3s;
}
.revenue-amount.updating { opacity: 0.4; }

/* Base currency sub-label */
.revenue-base-label {
  font-size: 11px;
  color: rgba(255,255,255,0.38);
  letter-spacing: 0.3px;
  margin-top: 5px;
  margin-bottom: 10px;
  transition: color 0.3s;
  cursor: default;
}

/* Per-currency chips */
.revenue-multicurrency {
  display: flex; flex-wrap: wrap; gap: 6px;
  min-height: 22px;
}
.rev-currency-chip {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 11.5px; font-weight: 600;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 4px;
}
.chip-converted {
  font-size: 10.5px;
  font-weight: 500;
  color: rgba(255,255,255,0.45);
  padding-left: 2px;
}

/* Stat pills */
.revenue-stats-row { display: flex; gap: 10px; flex-wrap: wrap; }
.revenue-stat-pill {
  flex: 1 1 80px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex; flex-direction: column; gap: 4px;
  transition: background 0.15s;
}
.revenue-stat-pill:hover { background: rgba(255,255,255,0.11); }
.revenue-stat-pill.overdue-pill { border-color: rgba(255,59,48,0.3); }
.revenue-stat-pill.overdue-pill:hover { background: rgba(255,59,48,0.1); }

.revenue-stat-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.6px; color: rgba(255,255,255,0.45);
}
.revenue-stat-value {
  font-size: 17px; font-weight: 700; color: #ffffff; letter-spacing: -0.5px;
}
.overdue-pill .revenue-stat-value            { color: #ff6b6b; }
.overdue-pill .revenue-stat-value.no-overdue { color: #5ddb8a; }

/* ══════════════════════════════════════════════════
   HISTORY LIST
══════════════════════════════════════════════════ */
.history-list { display: flex; flex-direction: column; gap: 12px; max-width: 760px; width: 100%; }

.history-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s; flex-wrap: wrap;
}
.history-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); cursor: pointer; }
.history-card:focus  { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: var(--shadow-md); }

.history-card-info .hc-number { font-size: 14px; font-weight: 700; color: var(--accent); letter-spacing: -0.3px; }
.history-card-info .hc-client { font-size: 13px; color: var(--text-primary); margin-top: 2px; }
.history-card-info .hc-date   { font-size: 11.5px; color: var(--text-tertiary); margin-top: 2px; }

.hc-overdue-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 700; padding: 2px 8px;
  border-radius: 20px; margin-top: 4px; letter-spacing: 0.2px;
}
.hc-overdue-badge.upcoming { background: #e8f8ee; color: #1a7f37; }
.hc-overdue-badge.gentle   { background: #fff8e7; color: #9a6700; }
.hc-overdue-badge.friendly { background: #fff3e0; color: #c45800; }
.hc-overdue-badge.firm     { background: #ffeef0; color: #cf222e; }

.history-card-amount-group {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0;
}
.history-card-amount { font-size: 17px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.4px; }
.hc-converted {
  font-size: 11.5px; font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: -0.2px;
}

.history-card-actions { display: flex; gap: 8px; align-items: center; }

.btn-load {
  background: var(--accent-dim); color: var(--accent); border: none;
  padding: 6px 14px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: var(--font); transition: background 0.15s;
}
.btn-load:hover { background: #d0e5fc; }

.btn-draft-email {
  background: linear-gradient(110deg, #0071e3, #5e5ce6, #a855f7, #0071e3);
  background-size: 250% 250%;
  animation: aiGradientShift 14s ease-in-out infinite 1s;
  color: #fff; border: none; padding: 6px 13px; border-radius: 20px;
  font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: var(--font);
  display: flex; align-items: center; gap: 5px;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.2s; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(94,92,230,0.3);
}
.btn-draft-email:hover  { opacity: 0.92; box-shadow: 0 3px 16px rgba(94,92,230,0.45); }
.btn-draft-email:active { transform: scale(0.97); }

.btn-del-invoice {
  background: #fff0f0; color: #e03131; border: 1px solid #ffc9c9;
  padding: 6px 12px; border-radius: 20px; font-size: 12.5px; cursor: pointer;
  font-family: var(--font); transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-del-invoice:hover { background: #ffe3e3; color: var(--danger); border-color: var(--danger); }

.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text-tertiary);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty-state p { font-size: 14px; }

/* ══════════════════════════════════════════════════
   SETTINGS
══════════════════════════════════════════════════ */
.settings-card {
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: var(--radius-lg); padding: 28px 32px;
  width: 100%; max-width: 580px; box-shadow: var(--shadow-sm);
}
.settings-section-title { font-size: 15px; font-weight: 700; color: var(--text-primary); margin-bottom: 22px; letter-spacing: -0.3px; }
.field-group { margin-bottom: 18px; }
.field-label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary);
  letter-spacing: 0.2px; margin-bottom: 6px; text-transform: uppercase;
}
.field-optional { font-size: 10px; font-weight: 400; color: var(--text-tertiary); text-transform: none; letter-spacing: 0; margin-left: 3px; }
.field-input {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; font-family: var(--font); font-size: 14px; color: var(--text-primary);
  background: var(--bg); transition: border-color 0.15s;
}
.field-input:focus   { outline: none; border-color: var(--accent); background: var(--bg); }
.field-textarea      { resize: vertical; line-height: 1.5; }
.field-row-two       { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.settings-divider { display: flex; align-items: center; gap: 10px; margin: 6px 0 18px; }
.settings-divider::before,
.settings-divider::after { content: ''; flex: 1; height: 1px; background: var(--border-light); }
.settings-divider span { font-size: 11px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.8px; white-space: nowrap; }

/* ── BASE CURRENCY ROW ── */
.base-ccy-row {
  display: flex; gap: 10px; align-items: center;
}
.base-ccy-select {
  flex: 1;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236e6e73' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
.base-ccy-save-btn {
  flex-shrink: 0;
  padding: 9px 20px;
  border-radius: var(--radius-sm);
}
.base-ccy-hint {
  margin-top: 7px;
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.5;
}
.base-ccy-hint a { color: var(--accent); text-decoration: none; }
.base-ccy-hint a:hover { text-decoration: underline; }

/* ── LOGO UPLOAD ── */
.logo-upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius-md); padding: 24px;
  text-align: center; cursor: pointer; transition: border-color 0.2s, background 0.2s;
  display: flex; align-items: center; justify-content: center;
  min-height: 110px; flex-direction: column; gap: 6px;
}
.logo-upload-area:hover { border-color: var(--accent); background: var(--accent-dim); }
#logoPlaceholder { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-secondary); }
#logoPlaceholder span  { font-size: 13px; font-weight: 500; }
#logoPlaceholder small { font-size: 11px; color: var(--text-tertiary); }

.upload-status, .save-status { margin-top: 8px; font-size: 12.5px; min-height: 18px; }
.upload-status.ok, .save-status.ok   { color: var(--success); }
.upload-status.err, .save-status.err { color: var(--danger); }
.settings-save-btn { margin-top: 8px; }

/* ══════════════════════════════════════════════════
   TOAST
══════════════════════════════════════════════════ */
#toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-primary); color: #fff;
  padding: 10px 22px; border-radius: 24px;
  font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999; white-space: normal;
  max-width: calc(100vw - 48px); word-break: break-word; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 767px) {
  #toast { bottom: calc(96px + env(safe-area-inset-bottom) + 12px); }
}

/* ══════════════════════════════════════════════════
   FOOTER
══════════════════════════════════════════════════ */
.app-footer {
  width: 100%;
  padding: 18px 40px 18px calc(var(--sidebar-w) + 40px);
  font-size: 12px; color: var(--text-tertiary);
  border-top: 1px solid var(--border-light); background: var(--surface); text-align: center;
}
.app-footer a { color: var(--accent); text-decoration: none; font-weight: 500; }
.app-footer a:hover { text-decoration: underline; }

/* ══════════════════════════════════════════════════
   AI FOLLOW-UP DRAFTER MODAL
══════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 500; display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.visible { display: flex; }

.modal-card {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 580px; max-height: 90vh;
  overflow-y: auto; display: flex; flex-direction: column;
  animation: modalIn 0.22s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border-light);
  gap: 12px; flex-wrap: wrap;
}
.modal-title-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.modal-ai-badge {
  display: flex; align-items: center; gap: 5px;
  background: linear-gradient(110deg, #dbeafe, #ede9fe, #fce7f3, #dbeafe);
  background-size: 250% 250%;
  animation: aiGradientShift 16s ease-in-out infinite 3s;
  color: #4f46e5; font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.3px; padding: 4px 10px; border-radius: 20px; text-transform: uppercase;
}
.modal-invoice-ref { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.modal-close {
  background: transparent; border: 1px solid var(--border-light); border-radius: 10px;
  padding: 5px; cursor: pointer; color: var(--text-tertiary);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s; flex-shrink: 0;
}
.modal-close:hover { background: var(--bg); color: var(--text-primary); }

.modal-loading {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 52px 24px; font-size: 13.5px; color: var(--text-secondary);
}
.modal-tone-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 5px 13px; border-radius: 20px;
  margin: 18px 24px 4px; letter-spacing: 0.2px; width: fit-content;
}
.modal-tone-badge.upcoming { background: #e8f8ee; color: #1a7f37; }
.modal-tone-badge.gentle   { background: #fff8e7; color: #9a6700; }
.modal-tone-badge.friendly { background: #fff3e0; color: #c45800; }
.modal-tone-badge.firm     { background: #ffeef0; color: #cf222e; }

.modal-result        { padding-bottom: 24px; }
.modal-field-group   { padding: 10px 24px 0; }
.modal-field-label   { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-tertiary); margin-bottom: 6px; }
.modal-subject-input {
  width: 100%; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 9px 12px; font-family: var(--font); font-size: 13.5px; font-weight: 600;
  color: var(--text-primary); background: var(--bg);
}
.modal-body-textarea {
  width: 100%; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 12px 13px; font-family: var(--font); font-size: 13px; color: var(--text-primary);
  background: var(--bg); resize: vertical; line-height: 1.65; min-height: 220px;
}
.modal-actions { display: flex; gap: 10px; padding: 16px 24px 0; flex-wrap: wrap; }
.modal-actions .btn-secondary,
.modal-actions .btn-primary { flex: 1 1 auto; justify-content: center; }

.modal-error {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 40px 24px; text-align: center; color: var(--text-secondary);
}
.modal-error svg{color:var(--danger)}
.modal-error p{font-size:13.5px}
.similar-box {
  max-width: 480px;
  padding: 28px 28px 24px;
}
.similar-icon svg { stroke: var(--accent); }
.similar-matches {
  display: flex; flex-direction: column; gap: 8px;
  margin: 12px 0 8px; width: 100%;
}
.similar-match-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 9px 12px; gap: 12px;
}
.similar-match-info {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0; flex: 1;
}
.similar-match-id     { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.similar-match-client { font-size: 12px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.similar-match-date   { font-size: 11px; color: var(--text-tertiary); }
.similar-match-score {
  font-size: 11px; font-weight: 700; color: var(--accent);
  background: rgba(26,86,219,0.1); padding: 3px 9px;
  border-radius: 99px; flex-shrink: 0; white-space: nowrap;
}
[data-theme="dark"] .similar-match-item  { background: #2c2c2e; border-color: #3a3a3c; }
[data-theme="dark"] .similar-match-score { background: rgba(96,165,250,0.15); }
/* Similar dialog button row — override the generic flex:1 stretching */
.similar-box .confirm-actions {
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}
.similar-box .confirm-actions button {
  flex: 1 1 100%;
  width: 100%;
  justify-content: center;
}
.confirm-box{background:var(--surface);border-radius:var(--radius-lg);padding:32px 28px 24px;width:100%;max-width:360px;box-shadow:var(--shadow-lg);display:flex;flex-direction:column;align-items:center;gap:8px;text-align:center}
.confirm-icon{width:52px;height:52px;border-radius:50%;background:#ffeef0;color:var(--danger);display:flex;align-items:center;justify-content:center;margin-bottom:4px}
.confirm-box h3{font-size:16px;font-weight:700;color:var(--text-primary);margin:0}
.confirm-box p{font-size:13px;color:var(--text-secondary);margin:0}
.confirm-actions{display:flex;gap:10px;margin-top:16px;width:100%}
.confirm-actions button{flex:1;justify-content:center}
.btn-danger{background:var(--danger);color:#fff;border:none;padding:8px 18px;border-radius:20px;font-family:var(--font);font-size:13px;font-weight:600;cursor:pointer;transition:background 0.15s}
.btn-danger:hover{background:#b91c2c}

/* ══════════════════════════════════════════════════
   PRINT
══════════════════════════════════════════════════ */

/* ══ HELP VIEW ══ */
.help-quick-cards{display:grid;grid-template-columns:repeat(2,1fr);gap:12px;width:100%;margin-bottom:28px}
.help-quick-card{display:flex;align-items:center;gap:12px;background:var(--surface);border:1px solid var(--border-light);border-radius:var(--radius-md);padding:14px 16px;box-shadow:var(--shadow-sm);transition:box-shadow 0.15s,transform 0.15s}
.help-quick-card:hover{box-shadow:var(--shadow-md);transform:translateY(-1px)}
.help-quick-icon{width:40px;height:40px;border-radius:12px;display:flex;align-items:center;justify-content:center;flex-shrink:0}
.help-quick-title{font-size:13.5px;font-weight:600;color:var(--text-primary);line-height:1.3}
.help-quick-desc{font-size:12px;color:var(--text-secondary);margin-top:2px;line-height:1.4}
.help-section-title{font-size:11px;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;color:var(--text-tertiary);margin-bottom:12px;padding-left:2px;width:100%}
.help-faq{width:100%;display:flex;flex-direction:column;gap:0;border:1px solid var(--border-light);border-radius:var(--radius-md);overflow:hidden;background:var(--surface);box-shadow:var(--shadow-sm)}
.faq-item{border-bottom:1px solid var(--border-light)}
.faq-item:last-child{border-bottom:none}
.faq-question{width:100%;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:15px 18px;background:transparent;border:none;cursor:pointer;font-family:var(--font);font-size:13.5px;font-weight:500;color:var(--text-primary);text-align:left;transition:background 0.12s}
.faq-question:hover{background:var(--bg)}
.faq-question.open{color:var(--accent)}
.faq-chevron{flex-shrink:0;color:var(--text-tertiary);transition:transform 0.2s ease}
.faq-question.open .faq-chevron{transform:rotate(180deg);color:var(--accent)}
.faq-answer{display:none;padding:0 18px 16px 18px;border-top:1px solid var(--border-light)}
.faq-answer.open{display:block}
.faq-answer p{font-size:13.5px;color:var(--text-secondary);line-height:1.65;margin:12px 0 0}
.faq-answer strong{color:var(--text-primary);font-weight:600}
.faq-answer em{font-style:italic;color:var(--text-primary)}
.faq-answer code{background:var(--bg);border:1px solid var(--border-light);border-radius:4px;padding:1px 6px;font-size:12.5px;font-family:'SF Mono','Fira Code',monospace;color:var(--accent)}
.help-tips{width:100%;display:flex;flex-direction:column;gap:10px}
.help-tip{display:flex;align-items:flex-start;gap:14px;background:var(--surface);border:1px solid var(--border-light);border-radius:var(--radius-md);padding:14px 16px;font-size:13.5px;color:var(--text-secondary);line-height:1.55;box-shadow:var(--shadow-sm)}
.help-tip-num{font-size:11px;font-weight:700;letter-spacing:0.05em;color:var(--accent);background:var(--accent-dim);border-radius:8px;padding:3px 7px;flex-shrink:0;margin-top:1px}
.help-tip strong{color:var(--text-primary)}
[data-theme="dark"] .help-quick-card{background:#2c2c2e;border-color:#3a3a3c}
[data-theme="dark"] .help-faq{background:#2c2c2e;border-color:#3a3a3c}
[data-theme="dark"] .faq-item{border-color:#3a3a3c}
[data-theme="dark"] .faq-question:hover{background:#3a3a3c}
[data-theme="dark"] .faq-answer{border-color:#3a3a3c}
[data-theme="dark"] .faq-answer code{background:#1c1c1e;border-color:#3a3a3c}
[data-theme="dark"] .help-tip{background:#2c2c2e;border-color:#3a3a3c}
[data-theme="dark"] .help-tip-num{background:rgba(0,113,227,0.15);color:#4da3ff}
[data-theme="dark"] .help-quick-icon[style*="background:#e8f4ff"]{background:rgba(0,113,227,0.15)!important;color:#4da3ff!important}
[data-theme="dark"] .help-quick-icon[style*="background:#edfaf1"]{background:rgba(26,127,55,0.15)!important;color:#4ade80!important}
[data-theme="dark"] .help-quick-icon[style*="background:#fff0f0"]{background:rgba(207,34,46,0.15)!important;color:#f87171!important}
[data-theme="dark"] .help-quick-icon[style*="background:#fff3e0"]{background:rgba(230,81,0,0.15)!important;color:#fb923c!important}
[data-theme="dark"] .help-quick-icon[style*="background:#f3e8ff"]{background:rgba(124,58,237,0.15)!important;color:#c084fc!important}
@media (max-width:600px){.help-quick-cards{grid-template-columns:1fr}}

/* ── Help footer cards (disclaimer + contact) ── */
.help-footer-cards {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 28px;
}
.help-disclaimer,
.help-contact {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  line-height: 1.55;
}
.help-disclaimer {
  background: #fffbea;
  border: 1px solid #f5d97a;
}
.help-contact {
  background: var(--surface);
  border: 1px solid var(--border-light);
}
.help-disclaimer-icon,
.help-contact-icon {
  flex-shrink: 0;
  margin-top: 1px;
}
.help-disclaimer-icon { color: #b45309; }
.help-contact-icon    { color: var(--accent); }
.help-disclaimer-title,
.help-contact-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.help-disclaimer-text,
.help-contact-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
}
.help-disclaimer-text strong { color: var(--text-primary); }
.help-contact-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.help-contact-link:hover { text-decoration: underline; }

/* ── Help footer credit card (mobile only) ── */
.help-footer-credit {
  display: none; /* hidden everywhere except mobile — see media query */
}

/* ── Mobile top header (hidden on desktop) ── */
.mobile-header,
.mobile-brand-pill-header,
.mobile-theme-circle,
.mobile-top-row {
  display: none;
}

[data-theme="dark"] .help-disclaimer {
  background: #2a1f00;
  border-color: #7a5c00;
}
[data-theme="dark"] .help-disclaimer-icon { color: #fbbf24; }
[data-theme="dark"] .help-contact { background: #2c2c2e; border-color: #3a3a3c; }

@media print {
  /* ── Page setup ── */
  @page { size: A4; margin: 0; }

  /* ── Force colour rendering ── */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }

  /* ── Override ALL theme variables to pure light ── */
  :root, [data-theme="dark"], [data-theme="light"] {
    --bg:             #f7f9fc !important;
    --surface:        #ffffff !important;
    --border:         #c8d0dc !important;
    --border-light:   #e4e8f0 !important;
    --text-primary:   #0d1117 !important;
    --text-secondary: #3d4a5c !important;
    --text-tertiary:  #6b7a90 !important;
    --accent:         #1a56db !important;
    --accent-dim:     #e8f0fb !important;
  }

  /* ── Hide all UI chrome ── */
  .sidebar, .view-header, .magic-card, .table-actions,
  .no-print, .hamburger, .mobile-brand-pill, .mobile-top-blur, .sidebar-overlay, .app-footer,
  .mobile-tab-bar, .mobile-header, .mobile-brand-pill-header, .mobile-theme-circle, .mobile-top-row,
  #toast, .modal-overlay, .revenue-dashboard,
  .edit-mode-banner, .del-row-btn, .col-del { display: none !important; }
  .page-wrapper::before, .page-wrapper::after { display: none !important; }
  #view-history, #view-settings, #view-templates, #view-help { display: none !important; }

  /* ── Layout reset ── */
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  .page-wrapper { margin-left: 0 !important; display: block !important; }
  .main-content { padding: 0 !important; background: #fff !important; }
  .view         { display: block !important; }

  /* ── Strip all rounded corners ── */
  * { border-radius: 0 !important; }

  /* ── Invoice document wrapper ── */
  .invoice-document {
    position: relative !important;
    border: none !important; box-shadow: none !important;
    border-radius: 0 !important; padding: 0 !important;
    max-width: 100% !important; width: 100% !important;
    margin: 0 !important; background: #fff !important;
    overflow: visible !important;  /* Safari fix: hidden clips content in print */
    min-height: 100vh !important; /* fill full A4 page — no white gap below content */
  }

  /* ── Top accent bar (real DOM element — more reliable than ::before in Safari) ── */
  .invoice-document::before { display: none !important; }
  .invoice-print-bar {
    display: block !important;
    height: 7px !important;
    width: 100% !important; margin: 0 !important; padding: 0 !important;
    background: linear-gradient(90deg, #1a56db 0%, #0ea5e9 60%, #38bdf8 100%) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
    flex-shrink: 0 !important;
  }
  /* Templates with full-bleed header bands — hide the accent bar */
  .tpl-minimal .invoice-print-bar,
  .tpl-bold    .invoice-print-bar,
  .tpl-slate   .invoice-print-bar,
  .tpl-rose    .invoice-print-bar,
  .tpl-midnight .invoice-print-bar,
  .tpl-forest  .invoice-print-bar { display: none !important; }



  /* ── Inner content padding ── */
  .invoice-top, .invoice-bill-to, .table-wrap, .totals-block, .invoice-notes {
    padding-left: 36pt !important; padding-right: 36pt !important;
  }
  .invoice-top    { padding-top: 28pt !important; margin-bottom: 22pt !important; }
  .invoice-notes  { padding-bottom: 36pt !important; }

  /* ── Brand ── */
  .invoice-logo        { max-height: 52px !important; border-radius: 4px !important; }
  .invoice-biz-name    { font-size: 15pt !important; font-weight: 800 !important; color: #0d1117 !important; letter-spacing: -0.3px !important; }
  .invoice-biz-address { font-size: 9pt !important; color: #3d4a5c !important; line-height: 1.55 !important; }
  .invoice-biz-contact { font-size: 9pt !important; color: #6b7a90 !important; line-height: 1.6 !important; }
  .invoice-biz-contact a { color: #1a56db !important; text-decoration: none !important; }
  /* Per-template link colors in print */
  .tpl-bold     .invoice-biz-contact a { color: #93c5fd !important; }
  .tpl-slate    .invoice-biz-contact a { color: #166534 !important; }
  .tpl-ocean    .invoice-biz-contact a { color: #0891b2 !important; }
  .tpl-rose     .invoice-biz-contact a { color: #fecdd3 !important; }
  .tpl-midnight .invoice-biz-contact a { color: #bfdbfe !important; }
  .tpl-forest   .invoice-biz-contact a { color: #bbf7d0 !important; }

  /* ── Invoice number & dates ── */
  .invoice-title-label { font-size: 7.5pt !important; font-weight: 700 !important; letter-spacing: 0.18em !important; color: #6b7a90 !important; text-transform: uppercase !important; }
  .invoice-number      { font-size: 13pt !important; font-weight: 700 !important; color: #1a56db !important; letter-spacing: -0.3px !important; }
  .invoice-number-input {
    font-size: 13pt !important; font-weight: 700 !important; color: #1a56db !important;
    letter-spacing: -0.3px !important; border: none !important;
    background: transparent !important; padding: 0 !important; width: auto !important;
  }
  .date-row            { font-size: 9.5pt !important; color: #3d4a5c !important; }
  .date-input          { border: none !important; background: transparent !important; font-size: 9.5pt !important; color: #0d1117 !important; font-weight: 500 !important; padding: 0 !important; }

  /* ── Bill-to block ── */
  .invoice-bill-to {
    background: #eef3ff !important;
    border-left: 4px solid #1a56db !important;
    border-radius: 0 6px 6px 0 !important;
    padding-top: 11pt !important; padding-bottom: 11pt !important;
    margin-bottom: 22pt !important;
  }
  .bill-label  { font-size: 7.5pt !important; font-weight: 800 !important; letter-spacing: 0.18em !important; text-transform: uppercase !important; color: #1a56db !important; margin-bottom: 7px !important; }
  .bill-input  { border: none !important; background: transparent !important; border-bottom: none !important; font-size: 10pt !important; color: #0d1117 !important; padding: 1px 0 !important; }

  /* ── Table ── */
  .table-wrap { overflow: visible !important; }
  .invoice-table { width: 100% !important; border-collapse: collapse !important; page-break-inside: avoid !important; }
  .invoice-table thead tr { background: #0d1117 !important; border-bottom: none !important; }
  .invoice-table th {
    font-size: 7.5pt !important; font-weight: 700 !important; color: #ffffff !important;
    text-transform: uppercase !important; letter-spacing: 0.08em !important;
    padding: 8pt 10pt !important; background: #0d1117 !important;
  }
  .invoice-table tbody tr:nth-child(even) td { background: #f7f9fc !important; }
  .invoice-table tbody tr:nth-child(odd)  td { background: #ffffff !important; }
  .invoice-table td {
    font-size: 10pt !important; color: #0d1117 !important;
    padding: 7pt 10pt !important; border-bottom: 1px solid #e4e8f0 !important;
  }
  .invoice-table td input { font-size: 10pt !important; color: #0d1117 !important; background: transparent !important; border: none !important; width: 100% !important; padding: 0 !important; }
  .invoice-table td.td-qty input   { text-align: center !important; }
  .invoice-table td.td-price input { text-align: right !important; }
  .invoice-table td.td-total       { text-align: right !important; font-weight: 600 !important; color: #0d1117 !important; }
  .invoice-table tbody tr:last-child td { border-bottom: 2px solid #0d1117 !important; }
  tr { page-break-inside: avoid !important; }

  /* ── Totals ── */
  .totals-block { margin: 0 !important; padding-top: 10pt !important; justify-content: flex-end !important; }
  .totals-table { max-width: 280px !important; }
  .totals-row   { font-size: 10pt !important; color: #3d4a5c !important; padding: 5pt 0 !important; border-bottom: 1px solid #e4e8f0 !important; }
  .totals-row:last-child { border-bottom: none !important; }
  .totals-grand { font-size: 13.5pt !important; font-weight: 800 !important; color: #0d1117 !important; border-top: 2.5px solid #0d1117 !important; padding-top: 7pt !important; background: transparent !important; }
  .tax-rate-input { border: none !important; background: transparent !important; font-size: 10pt !important; color: #0d1117 !important; }

  /* ── Notes ── */
  .invoice-notes { border-top: 1px solid #e4e8f0 !important; padding-top: 14pt !important; margin-top: 14pt !important; }
  .notes-label   { font-size: 7.5pt !important; font-weight: 800 !important; letter-spacing: 0.15em !important; text-transform: uppercase !important; color: #6b7a90 !important; margin-bottom: 5px !important; }
  .notes-input   { border: none !important; background: transparent !important; font-size: 10pt !important; color: #3d4a5c !important; line-height: 1.6 !important; resize: none !important; padding: 0 !important; }

  /* ── Footer gradient bar (after notes) ── */
  .invoice-notes::after {
    content: '' !important; display: block !important;
    margin-top: 24pt !important; height: 4px !important;
    background: linear-gradient(90deg, #1a56db 0%, #0ea5e9 60%, #38bdf8 100%) !important;
    border-radius: 2px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* ── Global resets ── */
  input, textarea, select {
    border: none !important; background: transparent !important;
    color: #0d1117 !important; box-shadow: none !important;
  }
  input[type="date"]::-webkit-calendar-picker-indicator { display: none !important; }
  input[type="date"] { -webkit-appearance: none !important; appearance: none !important; }
}


/* ══════════════════════════════════════════════════
   TEMPLATES VIEW
══════════════════════════════════════════════════ */

.templates-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
}

.template-card {
  background: var(--surface);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.15s;
  position: relative;
}
.template-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.template-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow-md);
}

/* Tick badge */
.template-check {
  display: none;
  position: absolute;
  top: 10px; right: 10px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  align-items: center;
  justify-content: center;
}
.template-card.selected .template-check { display: flex; }

.template-info {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border-light);
}
.template-name {
  font-size: 13.5px; font-weight: 700;
  color: var(--text-primary); margin-bottom: 3px;
}
.template-desc {
  font-size: 12px; color: var(--text-secondary); line-height: 1.45;
}

.templates-note {
  display: flex; align-items: flex-start; gap: 7px;
  font-size: 12px; color: var(--text-tertiary);
  background: var(--bg); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 10px 14px;
  margin-top: 24px; line-height: 1.5; width: 100%;
}

/* ── Template preview thumbnails ── */
.template-preview {
  height: 160px;
  padding: 10px 12px 8px;
  background: #fff;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* Shared preview elements */
.tpl-prev-bar       { height: 5px; border-radius: 2px; background: linear-gradient(90deg,#1a56db,#38bdf8); margin: -10px -12px 7px; }
.tpl-prev-header    { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tpl-prev-biz       { display: flex; gap: 6px; align-items: flex-start; }
.tpl-prev-logo      { width: 18px; height: 18px; border-radius: 3px; background: #d0dff7; flex-shrink: 0; }
.tpl-prev-bizname   { height: 7px; width: 70px; border-radius: 3px; background: #1a56db; margin-bottom: 4px; }
.tpl-prev-bizname.dark  { background: #0d1117; }
.tpl-prev-bizname.light { background: rgba(255,255,255,0.85); }
.tpl-prev-bizname.slate { background: #4a5568; }
.tpl-prev-line      { height: 4px; width: 80px; border-radius: 2px; background: #d1d5db; margin-bottom: 3px; }
.tpl-prev-line.sm   { width: 55px; background: #e5e7eb; }
.tpl-prev-line.light { background: rgba(255,255,255,0.4); }
.tpl-prev-line.slate { background: rgba(255,255,255,0.5); }
.tpl-prev-meta      { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.tpl-prev-invnum    { height: 9px; width: 50px; border-radius: 3px; background: #1a56db; margin-bottom: 4px; }
.tpl-prev-invnum.dark   { background: #0d1117; }
.tpl-prev-invnum.slate  { background: #4a5568; }
.tpl-prev-divider   { height: 1.5px; background: #0d1117; margin: 2px 0; }
.tpl-prev-billtobg  { background: #eef3ff; border-left: 3px solid #1a56db; padding: 5px 7px; border-radius: 0 3px 3px 0; }
.tpl-prev-billtobg.minimal { background: #f9fafb; border-left: 2px solid #9ca3af; }
.tpl-prev-billtobg.bold    { background: #fff7ed; border-left: 3px solid #ea580c; }
.tpl-prev-billtobg.slate   { background: #f0fdf4; border-left: 3px solid #4a5568; }
.tpl-prev-tablehead { height: 10px; background: #0d1117; border-radius: 2px; }
.tpl-prev-tablehead.minimal { background: transparent; border-bottom: 1.5px solid #0d1117; height: 8px; }
.tpl-prev-tablehead.bold    { background: #ea580c; }
.tpl-prev-tablehead.slate   { background: #4a5568; }
.tpl-prev-row       { height: 6px; background: #f3f4f6; border-radius: 2px; }
.tpl-prev-total     { height: 8px; width: 50%; align-self: flex-end; border-radius: 2px; background: #d0dff7; margin-top: 2px; }
.tpl-prev-total.minimal { background: #e5e7eb; }
.tpl-prev-total.bold    { background: #fdba74; }
.tpl-prev-total.slate   { background: #bbf7d0; }

/* Bold header band */
.tpl-prev-header-band {
  display: flex; justify-content: space-between; align-items: center;
  background: #1c1c1e; border-radius: 4px;
  padding: 6px 8px; margin: -10px -12px 7px; gap: 6px;
}
.tpl-prev-logo.light    { background: rgba(255,255,255,0.25); }
.tpl-prev-invnum-bold   { font-size: 9px; font-weight: 800; color: #fff; letter-spacing: 0.1em; flex-shrink: 0; }
.tpl-prev-biz.light     { color: #fff; }

/* Slate two-column top */
.tpl-prev-slate-top {
  background: #f1f5f0; border-radius: 4px;
  padding: 6px 8px; margin: -10px -12px 0; gap: 3px;
  display: flex; flex-direction: column;
}
.tpl-prev-slate-meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  margin-bottom: 4px;
}

/* Dark mode preview backgrounds */
[data-theme="dark"] .template-preview { background: #1c1c1e; }
[data-theme="dark"] .tpl-prev-row     { background: #2c2c2e; }
[data-theme="dark"] .tpl-prev-billtobg { background: rgba(26,86,219,0.12); }
[data-theme="dark"] .tpl-prev-billtobg.minimal { background: #2c2c2e; }
[data-theme="dark"] .tpl-prev-billtobg.bold    { background: rgba(234,88,12,0.12); }
[data-theme="dark"] .tpl-prev-billtobg.slate   { background: rgba(74,85,104,0.15); }
[data-theme="dark"] .tpl-prev-line    { background: #3a3a3c; }
[data-theme="dark"] .tpl-prev-line.sm { background: #2c2c2e; }
[data-theme="dark"] .tpl-prev-slate-top { background: #2c2c2e; }
[data-theme="dark"] .template-info   { border-color: #3a3a3c; }
[data-theme="dark"] .template-card   { background: #2c2c2e; border-color: #3a3a3c; }

/* Responsive */
@media (max-width: 600px) {
  .templates-grid { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════
   INVOICE TEMPLATE OVERRIDES — live editor
   Applied via .tpl-{name} on #invoiceDocument
══════════════════════════════════════════════════ */

/* ── MINIMAL ── */
.tpl-minimal .invoice-number, .tpl-minimal .invoice-number-input { color: var(--text-primary); border-bottom-color: var(--text-primary); }
.tpl-minimal .invoice-biz-name    { color: var(--text-primary); }
.tpl-minimal .invoice-bill-to     { background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.tpl-minimal .bill-label          { color: var(--text-tertiary); }
.tpl-minimal .invoice-table thead tr { border-bottom: 2px solid var(--text-primary); }
.tpl-minimal .invoice-table th    { color: var(--text-primary); }

/* ── BOLD ── */
.tpl-bold .invoice-top {
  background: #1c1c1e;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin: -40px -44px 28px;
  padding: 28px 44px 24px;
}
.tpl-bold .invoice-biz-name    { color: #fff; }
.tpl-bold .invoice-number-input { color: #fb923c; border-bottom-color: rgba(251,146,60,0.5); }
.tpl-bold .invoice-number-input:hover { background: rgba(251,146,60,0.1); }
.tpl-bold .invoice-number-input:focus { background: rgba(251,146,60,0.15); }
.tpl-bold .invoice-biz-address { color: rgba(255,255,255,0.82); }
.tpl-bold .invoice-biz-contact { color: rgba(255,255,255,0.72); }
.tpl-bold .invoice-biz-contact a { color: #93c5fd; }
.tpl-bold .invoice-title-label { color: rgba(255,255,255,0.65); }
.tpl-bold .invoice-number, .tpl-bold .invoice-number-input { color: #fb923c; border-bottom-color: #fb923c; }
.tpl-bold .date-row            { color: rgba(255,255,255,0.85); }
.tpl-bold .date-input          { color: rgba(255,255,255,0.9); background: transparent; border-color: rgba(255,255,255,0.2); }
.tpl-bold .invoice-logo        { filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4)); }
.tpl-bold .invoice-bill-to     { background: #fff7ed; border-left: 4px solid #ea580c; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.tpl-bold .bill-label          { color: #ea580c; }
.tpl-bold .invoice-table thead tr { border-bottom: none; }
.tpl-bold .invoice-table th    { background: #ea580c; color: #fff; padding: 10px 12px; }
.tpl-bold .invoice-table th:first-child { border-radius: 4px 0 0 4px; }
.tpl-bold .invoice-table th:last-child  { border-radius: 0 4px 4px 0; }
.tpl-bold .totals-grand        { color: #ea580c; border-top-color: #ea580c; }

/* ── SLATE ── */
.tpl-slate .invoice-top {
  background: #f1f5f0;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin: -40px -44px 28px;
  padding: 28px 44px 24px;
  border-bottom: 3px solid #4a5568;
}
.tpl-slate .invoice-biz-name    { color: #1a202c; }
.tpl-slate .invoice-biz-address { color: #374151; }
.tpl-slate .invoice-biz-contact { color: #4a5568; }
.tpl-slate .invoice-biz-contact a { color: #166534; }
.tpl-slate .invoice-title-label { color: #4a5568; }
.tpl-slate .invoice-number, .tpl-slate .invoice-number-input { color: #2d6a4f; border-bottom-color: #2d6a4f; }
.tpl-slate .date-row            { color: #4a5568; }
.tpl-slate .invoice-bill-to     { background: #f0fdf4; border-left: 4px solid #4a5568; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.tpl-slate .bill-label          { color: #4a5568; }
.tpl-slate .invoice-table thead tr { border-bottom: none; }
.tpl-slate .invoice-table th    { background: #4a5568; color: #fff; padding: 10px 12px; }
.tpl-slate .invoice-table th:first-child { border-radius: 4px 0 0 4px; }
.tpl-slate .invoice-table th:last-child  { border-radius: 0 4px 4px 0; }
.tpl-slate .totals-grand        { color: #2d6a4f; border-top-color: #4a5568; }
.tpl-slate .invoice-biz-contact a:hover { color: #1a4731; }

/* Dark mode adjustments for bold/slate top bands */
[data-theme="dark"] .tpl-bold .invoice-top { background: #111113; }
[data-theme="dark"] .tpl-slate .invoice-top { background: #1e2a1e; border-bottom-color: #4a5568; }
[data-theme="dark"] .tpl-slate .invoice-biz-name    { color: #e2e8f0; }
[data-theme="dark"] .tpl-slate .invoice-biz-address { color: #a0aec0; }
[data-theme="dark"] .tpl-slate .invoice-biz-contact { color: #718096; }
[data-theme="dark"] .tpl-slate .invoice-biz-contact a { color: #4ade80; }
[data-theme="dark"] .tpl-slate .invoice-title-label { color: #718096; }
[data-theme="dark"] .tpl-slate .invoice-number,
[data-theme="dark"] .tpl-slate .invoice-number-input { color: #4ade80; border-bottom-color: #4ade80; }
[data-theme="dark"] .tpl-slate .date-row            { color: #a0aec0; }
[data-theme="dark"] .tpl-slate .bill-label          { color: #a0aec0; }
[data-theme="dark"] .tpl-slate .totals-grand        { color: #4ade80; border-top-color: #4a5568; }
[data-theme="dark"] .tpl-bold .invoice-bill-to   { background: rgba(234,88,12,0.1); }
[data-theme="dark"] .tpl-slate .invoice-bill-to  { background: rgba(45,106,79,0.1); }

/* ══════════════════════════════════════════════════
   PRINT — template overrides
   Append per-template print rules after base @media print
══════════════════════════════════════════════════ */

@media print {
  /* MINIMAL print */
  .tpl-minimal .invoice-document::before { display: none !important; }
  .tpl-minimal .invoice-number     { color: #0d1117 !important; }
  .tpl-minimal .invoice-number-input { color: #0d1117 !important; }
  .tpl-minimal .invoice-bill-to    { background: #f9fafb !important; border-left: 2px solid #9ca3af !important; }
  .tpl-minimal .invoice-table th   { background: transparent !important; color: #0d1117 !important; border-bottom: 1.5px solid #0d1117 !important; }
  .tpl-minimal .invoice-table thead tr { background: transparent !important; border-bottom: 1.5px solid #0d1117 !important; }
  .tpl-minimal .invoice-table tbody tr:nth-child(even) td { background: #fff !important; }
  .tpl-minimal .invoice-notes::after { display: none !important; }
  .tpl-minimal .totals-grand  { color: #0d1117 !important; border-top-color: #0d1117 !important; }

  /* BOLD print */
  .tpl-bold .invoice-top      { background: #1c1c1e !important; margin: 0 !important; padding: 20pt 36pt !important; border-radius: 0 !important; }
  .tpl-bold .invoice-document  { border-radius: 0 !important; border: none !important; box-shadow: none !important; }
  .tpl-bold .invoice-document::before { display: none !important; }
  .tpl-bold .invoice-biz-name    { color: #fff !important; }
  .tpl-bold .invoice-biz-address { color: rgba(255,255,255,0.82) !important; }
  .tpl-bold .invoice-biz-contact { color: rgba(255,255,255,0.72) !important; }
  .tpl-bold .invoice-title-label { color: rgba(255,255,255,0.65) !important; }
  .tpl-bold .invoice-number      { color: #fb923c !important; }
  .tpl-bold .invoice-number-input { color: #fb923c !important; }
  .tpl-bold .date-row            { color: rgba(255,255,255,0.88) !important; }
  .tpl-bold .date-input          { color: rgba(255,255,255,0.9) !important; }
  .tpl-bold .invoice-logo        { filter: none !important; }
  .tpl-bold .invoice-bill-to     { background: #fff7ed !important; border-left: 4px solid #ea580c !important; }
  .tpl-bold .bill-label          { color: #ea580c !important; }
  .tpl-bold .invoice-table th    { background: #ea580c !important; color: #fff !important; }
  .tpl-bold .invoice-table thead tr { background: #ea580c !important; border-bottom: none !important; }
  .tpl-bold .invoice-table tbody tr:nth-child(even) td { background: #fff7f0 !important; }
  .tpl-bold .totals-grand        { color: #ea580c !important; border-top-color: #ea580c !important; }
  .tpl-bold .invoice-notes::after { background: #ea580c !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }

  /* SLATE print */
  .tpl-slate .invoice-top         { background: #f1f5f0 !important; margin: 0 !important; padding: 20pt 36pt !important; border-bottom: 3px solid #4a5568 !important; }
  .tpl-slate .invoice-document::before { display: none !important; }
  .tpl-slate .invoice-biz-name    { color: #1a202c !important; }
  .tpl-slate .invoice-biz-address { color: #4a5568 !important; }
  .tpl-slate .invoice-number      { color: #2d6a4f !important; }
  .tpl-slate .invoice-number-input { color: #2d6a4f !important; }
  .tpl-slate .invoice-bill-to     { background: #f0fdf4 !important; border-left: 4px solid #4a5568 !important; }
  .tpl-slate .bill-label          { color: #4a5568 !important; }
  .tpl-slate .invoice-table th    { background: #4a5568 !important; color: #fff !important; }
  .tpl-slate .invoice-table thead tr { background: #4a5568 !important; border-bottom: none !important; }
  .tpl-slate .invoice-table tbody tr:nth-child(even) td { background: #f0fdf4 !important; }
  .tpl-slate .totals-grand        { color: #2d6a4f !important; border-top-color: #4a5568 !important; }
  .tpl-slate .invoice-notes::after { background: linear-gradient(90deg,#4a5568,#2d6a4f) !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }
}



/* ══════════════════════════════════════════════════
   NEW TEMPLATE PREVIEW PIECES
══════════════════════════════════════════════════ */
.tpl-prev-bar.ocean       { background: linear-gradient(90deg,#0891b2,#06b6d4,#67e8f9); }

/* Preview footer bars — mirror the invoice-notes::after accent */
.tpl-prev-footer-bar        { height: 3px; border-radius: 2px; margin: 5px -12px -10px; background: linear-gradient(90deg,#1a56db,#0ea5e9,#38bdf8); }
.tpl-prev-footer-bar.bold   { background: #ea580c; }
.tpl-prev-footer-bar.slate  { background: linear-gradient(90deg,#4a5568,#2d6a4f); }
.tpl-prev-footer-bar.ocean  { background: linear-gradient(90deg,#0891b2,#06b6d4,#67e8f9); }
.tpl-prev-footer-bar.rose   { background: linear-gradient(90deg,#9f1239,#e11d48,#fda4af); }
.tpl-prev-footer-bar.midnight { background: linear-gradient(90deg,#1e3a5f,#2d5a8e,#d4af37); }
.tpl-prev-footer-bar.forest { background: linear-gradient(90deg,#1a3a2a,#2d6a4f,#4ade80); }

.tpl-prev-logo.ocean      { background: #cffafe; }
.tpl-prev-bizname.ocean   { background: #0891b2; }
.tpl-prev-invnum.ocean    { background: #0891b2; }
.tpl-prev-billtobg.ocean  { background: #ecfeff; border-left: 3px solid #0891b2; padding: 5px 7px; border-radius: 0 3px 3px 0; }
.tpl-prev-tablehead.ocean { background: #0e7490; border-radius: 2px; }
.tpl-prev-total.ocean     { background: #a5f3fc; }

.tpl-prev-header-band.rose    { background: #9f1239; }
.tpl-prev-invnum-bold.rose    { color: #fda4af; font-size: 9px; font-weight: 800; letter-spacing: 0.1em; flex-shrink: 0; }
.tpl-prev-billtobg.rose       { background: #fff1f2; border-left: 3px solid #e11d48; padding: 5px 7px; border-radius: 0 3px 3px 0; }
.tpl-prev-tablehead.rose      { background: #e11d48; border-radius: 2px; }
.tpl-prev-total.rose          { background: #fecdd3; }

.tpl-prev-header-band.midnight { background: #1e3a5f; }
.tpl-prev-logo.midnight-logo   { background: rgba(212,175,55,0.4); }
.tpl-prev-invnum-bold.midnight { color: #d4af37; font-size: 9px; font-weight: 800; letter-spacing: 0.1em; flex-shrink: 0; }
.tpl-prev-billtobg.midnight    { background: #eff6ff; border-left: 3px solid #1e3a5f; padding: 5px 7px; border-radius: 0 3px 3px 0; }
.tpl-prev-tablehead.midnight   { background: #1e3a5f; border-radius: 2px; }
.tpl-prev-total.midnight       { background: #bfdbfe; }

.tpl-prev-forest-top  { background: #1a3a2a; border-radius: 3px 3px 0 0; padding: 6px 7px; margin: -10px -12px 7px; }
.tpl-prev-bizname.forest { background: rgba(255,255,255,0.8); }
.tpl-prev-line.forest    { background: rgba(255,255,255,0.4); }
.tpl-prev-invnum.forest  { background: #2d6a4f; }
.tpl-prev-billtobg.forest { background: #f0fdf4; border-left: 3px solid #1a3a2a; padding: 5px 7px; border-radius: 0 3px 3px 0; }
.tpl-prev-tablehead.forest { background: #1a3a2a; border-radius: 2px; }
.tpl-prev-total.forest    { background: #bbf7d0; }

[data-theme="dark"] .tpl-prev-billtobg.ocean   { background: rgba(8,145,178,0.12); }
[data-theme="dark"] .tpl-prev-billtobg.rose    { background: rgba(225,29,72,0.12); }
[data-theme="dark"] .tpl-prev-billtobg.midnight { background: rgba(30,58,95,0.2); }
[data-theme="dark"] .tpl-prev-billtobg.forest  { background: rgba(26,58,42,0.2); }
[data-theme="dark"] .tpl-prev-forest-top       { background: #0f2a1a; }

/* ══════════════════════════════════════════════════
   INVOICE TEMPLATE OVERRIDES — OCEAN
══════════════════════════════════════════════════ */
.tpl-ocean .invoice-document::before { background: linear-gradient(135deg,#0891b2 0%,#06b6d4 60%,#67e8f9 100%); }
.tpl-ocean .invoice-print-bar { display: none; } /* bar only shows in @media print via the rule below */
.tpl-ocean .invoice-biz-name    { color: #0e7490; }
.tpl-ocean .invoice-number, .tpl-ocean .invoice-number-input { color: #0891b2; border-bottom-color: #0891b2; }
.tpl-ocean .invoice-number-input:hover { background: rgba(8,145,178,0.06); }
.tpl-ocean .invoice-number-input:focus { background: rgba(8,145,178,0.1); }
.tpl-ocean .invoice-bill-to     { background: #ecfeff; border-left: 4px solid #0891b2; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.tpl-ocean .bill-label          { color: #0891b2; }
.tpl-ocean .invoice-table thead tr { border-bottom: none; }
.tpl-ocean .invoice-table th    { background: #0e7490; color: #fff; padding: 10px 12px; }
.tpl-ocean .invoice-table th:first-child { border-radius: 4px 0 0 4px; }
.tpl-ocean .invoice-table th:last-child  { border-radius: 0 4px 4px 0; }
.tpl-ocean .totals-grand        { color: #0891b2; border-top-color: #0891b2; }
.tpl-ocean .invoice-notes::after {
  content: ''; display: block;
  margin-top: 20px; height: 4px;
  background: linear-gradient(90deg,#0891b2 0%,#06b6d4 60%,#67e8f9 100%);
  border-radius: 2px;
}

/* ══════════════════════════════════════════════════
   INVOICE TEMPLATE OVERRIDES — ROSE
══════════════════════════════════════════════════ */
.tpl-rose .invoice-top {
  background: #9f1239;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin: -40px -44px 28px;
  padding: 28px 44px 24px;
}
.tpl-rose .invoice-biz-name    { color: #fff; }
.tpl-rose .invoice-biz-address { color: rgba(255,255,255,0.82); }
.tpl-rose .invoice-biz-contact { color: rgba(255,255,255,0.72); }
.tpl-rose .invoice-biz-contact a { color: #fecdd3; }
.tpl-rose .invoice-title-label { color: rgba(255,255,255,0.65); }
.tpl-rose .invoice-number, .tpl-rose .invoice-number-input { color: #fda4af; border-bottom-color: #fda4af; }
.tpl-rose .invoice-number-input:hover { background: rgba(253,164,175,0.1); }
.tpl-rose .invoice-number-input:focus { background: rgba(253,164,175,0.15); }
.tpl-rose .date-row            { color: rgba(255,255,255,0.88); }
.tpl-rose .date-input          { color: rgba(255,255,255,0.9); background: transparent; border-color: rgba(255,255,255,0.2); }
.tpl-rose .invoice-logo        { filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4)); }
.tpl-rose .invoice-bill-to     { background: #fff1f2; border-left: 4px solid #e11d48; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.tpl-rose .bill-label          { color: #e11d48; }
.tpl-rose .invoice-table thead tr { border-bottom: none; }
.tpl-rose .invoice-table th    { background: #e11d48; color: #fff; padding: 10px 12px; }
.tpl-rose .invoice-table th:first-child { border-radius: 4px 0 0 4px; }
.tpl-rose .invoice-table th:last-child  { border-radius: 0 4px 4px 0; }
.tpl-rose .totals-grand        { color: #9f1239; border-top-color: #e11d48; }
.tpl-rose .invoice-notes::after {
  content: ''; display: block;
  margin-top: 20px; height: 4px;
  background: linear-gradient(90deg,#9f1239 0%,#e11d48 60%,#fda4af 100%);
  border-radius: 2px;
}

/* ══════════════════════════════════════════════════
   INVOICE TEMPLATE OVERRIDES — MIDNIGHT
══════════════════════════════════════════════════ */
.tpl-midnight .invoice-top {
  background: #1e3a5f;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin: -40px -44px 28px;
  padding: 28px 44px 24px;
}
.tpl-midnight .invoice-biz-name    { color: #fff; }
.tpl-midnight .invoice-biz-address { color: rgba(255,255,255,0.82); }
.tpl-midnight .invoice-biz-contact { color: rgba(255,255,255,0.72); }
.tpl-midnight .invoice-biz-contact a { color: #bfdbfe; }
.tpl-midnight .invoice-title-label { color: rgba(255,255,255,0.65); }
.tpl-midnight .invoice-number, .tpl-midnight .invoice-number-input { color: #d4af37; border-bottom-color: #d4af37; }
.tpl-midnight .invoice-number-input:hover { background: rgba(212,175,55,0.1); }
.tpl-midnight .invoice-number-input:focus { background: rgba(212,175,55,0.15); }
.tpl-midnight .date-row            { color: rgba(255,255,255,0.88); }
.tpl-midnight .date-input          { color: rgba(255,255,255,0.9); background: transparent; border-color: rgba(255,255,255,0.2); }
.tpl-midnight .invoice-logo        { filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4)); }
.tpl-midnight .invoice-bill-to     { background: #eff6ff; border-left: 4px solid #1e3a5f; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.tpl-midnight .bill-label          { color: #1e3a5f; }
.tpl-midnight .invoice-table thead tr { border-bottom: none; }
.tpl-midnight .invoice-table th    { background: #1e3a5f; color: #fff; padding: 10px 12px; }
.tpl-midnight .invoice-table th:first-child { border-radius: 4px 0 0 4px; }
.tpl-midnight .invoice-table th:last-child  { border-radius: 0 4px 4px 0; }
.tpl-midnight .totals-grand        { color: #d4af37; border-top-color: #1e3a5f; }
.tpl-midnight .invoice-notes::after {
  content: ''; display: block;
  margin-top: 20px; height: 4px;
  background: linear-gradient(90deg,#1e3a5f 0%,#2d5a8e 60%,#d4af37 100%);
  border-radius: 2px;
}

/* ══════════════════════════════════════════════════
   INVOICE TEMPLATE OVERRIDES — FOREST
══════════════════════════════════════════════════ */
.tpl-forest .invoice-top {
  background: #1a3a2a;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin: -40px -44px 28px;
  padding: 28px 44px 24px;
  border-bottom: none;
}
.tpl-forest .invoice-biz-name    { color: #fff; }
.tpl-forest .invoice-biz-address { color: rgba(255,255,255,0.82); }
.tpl-forest .invoice-biz-contact { color: rgba(255,255,255,0.72); }
.tpl-forest .invoice-biz-contact a { color: #bbf7d0; }
.tpl-forest .invoice-title-label { color: rgba(255,255,255,0.65); }
.tpl-forest .invoice-number, .tpl-forest .invoice-number-input { color: #4ade80; border-bottom-color: #4ade80; }
.tpl-forest .invoice-number-input:hover { background: rgba(74,222,128,0.1); }
.tpl-forest .invoice-number-input:focus { background: rgba(74,222,128,0.15); }
.tpl-forest .date-row            { color: rgba(255,255,255,0.88); }
.tpl-forest .date-input          { color: rgba(255,255,255,0.9); background: transparent; border-color: rgba(255,255,255,0.2); }
.tpl-forest .invoice-logo        { filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4)); }
.tpl-forest .invoice-bill-to     { background: #f0fdf4; border-left: 4px solid #1a3a2a; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.tpl-forest .bill-label          { color: #1a3a2a; }
.tpl-forest .invoice-table thead tr { border-bottom: none; }
.tpl-forest .invoice-table th    { background: #1a3a2a; color: #fff; padding: 10px 12px; }
.tpl-forest .invoice-table th:first-child { border-radius: 4px 0 0 4px; }
.tpl-forest .invoice-table th:last-child  { border-radius: 0 4px 4px 0; }
.tpl-forest .totals-grand        { color: #2d6a4f; border-top-color: #1a3a2a; }
.tpl-forest .invoice-notes::after {
  content: ''; display: block;
  margin-top: 20px; height: 4px;
  background: linear-gradient(90deg,#1a3a2a 0%,#2d6a4f 60%,#4ade80 100%);
  border-radius: 2px;
}

/* Dark mode adjustments for new templates */
[data-theme="dark"] .tpl-rose .invoice-top     { background: #7f0e2e; }
[data-theme="dark"] .tpl-midnight .invoice-top { background: #0f2340; }
[data-theme="dark"] .tpl-forest .invoice-top   { background: #0f2a1a; }
[data-theme="dark"] .tpl-rose .invoice-bill-to     { background: rgba(225,29,72,0.1); }
[data-theme="dark"] .tpl-rose .bill-label           { color: #fb7185; }
[data-theme="dark"] .tpl-midnight .invoice-bill-to  { background: rgba(30,58,95,0.15); }
[data-theme="dark"] .tpl-midnight .bill-label       { color: #93c5fd; }
[data-theme="dark"] .tpl-forest .invoice-bill-to    { background: rgba(26,58,42,0.15); }
[data-theme="dark"] .tpl-forest .bill-label         { color: #4ade80; }
[data-theme="dark"] .tpl-ocean .invoice-bill-to    { background: rgba(8,145,178,0.1); }
[data-theme="dark"] .tpl-ocean .invoice-biz-name   { color: #22d3ee; }
[data-theme="dark"] .tpl-ocean .invoice-number,
[data-theme="dark"] .tpl-ocean .invoice-number-input { color: #22d3ee; border-bottom-color: #22d3ee; }
[data-theme="dark"] .tpl-ocean .bill-label          { color: #22d3ee; }
[data-theme="dark"] .tpl-ocean .totals-grand        { color: #22d3ee; border-top-color: #22d3ee; }

@media print {
  /* OCEAN print */
  .tpl-ocean .invoice-document::before { background: linear-gradient(135deg,#0891b2,#06b6d4,#67e8f9) !important; }
  .tpl-ocean .invoice-print-bar { display: block !important; background: linear-gradient(135deg,#0891b2 0%,#06b6d4 60%,#67e8f9 100%) !important; }
  .tpl-ocean .invoice-number      { color: #0891b2 !important; }
  .tpl-ocean .invoice-number-input { color: #0891b2 !important; }
  .tpl-ocean .invoice-bill-to     { background: #ecfeff !important; border-left: 4px solid #0891b2 !important; }
  .tpl-ocean .bill-label          { color: #0891b2 !important; }
  .tpl-ocean .invoice-table th    { background: #0e7490 !important; color: #fff !important; }
  .tpl-ocean .invoice-table thead tr { background: #0e7490 !important; border-bottom: none !important; }
  .tpl-ocean .invoice-table tbody tr:nth-child(even) td { background: #ecfeff !important; }
  .tpl-ocean .totals-grand        { color: #0891b2 !important; border-top-color: #0891b2 !important; }
  .tpl-ocean .invoice-notes::after { background: linear-gradient(90deg,#0891b2 0%,#06b6d4 60%,#67e8f9 100%) !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }

  /* ROSE print */
  .tpl-rose .invoice-top      { background: #9f1239 !important; margin: 0 !important; padding: 20pt 36pt !important; border-radius: 0 !important; }
  .tpl-rose .invoice-document  { border-radius: 0 !important; border: none !important; box-shadow: none !important; }
  .tpl-rose .invoice-document::before { display: none !important; }
  .tpl-rose .invoice-biz-name    { color: #fff !important; }
  .tpl-rose .invoice-biz-address { color: rgba(255,255,255,0.82) !important; }
  .tpl-rose .invoice-biz-contact { color: rgba(255,255,255,0.72) !important; }
  .tpl-rose .invoice-title-label { color: rgba(255,255,255,0.65) !important; }
  .tpl-rose .invoice-number      { color: #fda4af !important; }
  .tpl-rose .invoice-number-input { color: #fda4af !important; }
  .tpl-rose .date-row            { color: rgba(255,255,255,0.88) !important; }
  .tpl-rose .date-input          { color: rgba(255,255,255,0.9) !important; }
  .tpl-rose .invoice-bill-to     { background: #fff1f2 !important; border-left: 4px solid #e11d48 !important; }
  .tpl-rose .bill-label          { color: #e11d48 !important; }
  .tpl-rose .invoice-table th    { background: #e11d48 !important; color: #fff !important; }
  .tpl-rose .invoice-table thead tr { background: #e11d48 !important; border-bottom: none !important; }
  .tpl-rose .invoice-table tbody tr:nth-child(even) td { background: #fff1f2 !important; }
  .tpl-rose .totals-grand        { color: #9f1239 !important; border-top-color: #e11d48 !important; }
  .tpl-rose .invoice-notes::after { background: linear-gradient(90deg,#9f1239 0%,#e11d48 60%,#fda4af 100%) !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }

  /* MIDNIGHT print */
  .tpl-midnight .invoice-top      { background: #1e3a5f !important; margin: 0 !important; padding: 20pt 36pt !important; border-radius: 0 !important; }
  .tpl-midnight .invoice-document  { border-radius: 0 !important; border: none !important; box-shadow: none !important; }
  .tpl-midnight .invoice-document::before { display: none !important; }
  .tpl-midnight .invoice-biz-name    { color: #fff !important; }
  .tpl-midnight .invoice-biz-address { color: rgba(255,255,255,0.82) !important; }
  .tpl-midnight .invoice-biz-contact { color: rgba(255,255,255,0.72) !important; }
  .tpl-midnight .invoice-title-label { color: rgba(255,255,255,0.65) !important; }
  .tpl-midnight .invoice-number      { color: #d4af37 !important; }
  .tpl-midnight .invoice-number-input { color: #d4af37 !important; }
  .tpl-midnight .date-row            { color: rgba(255,255,255,0.88) !important; }
  .tpl-midnight .date-input          { color: rgba(255,255,255,0.9) !important; }
  .tpl-midnight .invoice-bill-to     { background: #eff6ff !important; border-left: 4px solid #1e3a5f !important; }
  .tpl-midnight .bill-label          { color: #1e3a5f !important; }
  .tpl-midnight .invoice-table th    { background: #1e3a5f !important; color: #fff !important; }
  .tpl-midnight .invoice-table thead tr { background: #1e3a5f !important; border-bottom: none !important; }
  .tpl-midnight .invoice-table tbody tr:nth-child(even) td { background: #eff6ff !important; }
  .tpl-midnight .totals-grand        { color: #d4af37 !important; border-top-color: #1e3a5f !important; }
  .tpl-midnight .invoice-notes::after { background: linear-gradient(90deg,#1e3a5f 0%,#2d5a8e 60%,#d4af37 100%) !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }

  /* FOREST print */
  .tpl-forest .invoice-top      { background: #1a3a2a !important; margin: 0 !important; padding: 20pt 36pt !important; border-radius: 0 !important; }
  .tpl-forest .invoice-document  { border-radius: 0 !important; border: none !important; box-shadow: none !important; }
  .tpl-forest .invoice-document::before { display: none !important; }
  .tpl-forest .invoice-biz-name    { color: #fff !important; }
  .tpl-forest .invoice-biz-address { color: rgba(255,255,255,0.82) !important; }
  .tpl-forest .invoice-biz-contact { color: rgba(255,255,255,0.72) !important; }
  .tpl-forest .invoice-title-label { color: rgba(255,255,255,0.65) !important; }
  .tpl-forest .invoice-number      { color: #4ade80 !important; }
  .tpl-forest .invoice-number-input { color: #4ade80 !important; }
  .tpl-forest .date-row            { color: rgba(255,255,255,0.88) !important; }
  .tpl-forest .date-input          { color: rgba(255,255,255,0.9) !important; }
  .tpl-forest .invoice-bill-to     { background: #f0fdf4 !important; border-left: 4px solid #1a3a2a !important; }
  .tpl-forest .bill-label          { color: #1a3a2a !important; }
  .tpl-forest .invoice-table th    { background: #1a3a2a !important; color: #fff !important; }
  .tpl-forest .invoice-table thead tr { background: #1a3a2a !important; border-bottom: none !important; }
  .tpl-forest .invoice-table tbody tr:nth-child(even) td { background: #f0fdf4 !important; }
  .tpl-forest .totals-grand        { color: #2d6a4f !important; border-top-color: #1a3a2a !important; }
  .tpl-forest .invoice-notes::after { background: linear-gradient(90deg,#1a3a2a 0%,#2d6a4f 60%,#4ade80 100%) !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }
}

/* Responsive: new templates top band margin fixes */
@media (min-width: 1280px) {
  .tpl-rose .invoice-top     { margin: -48px -56px 28px; padding: 28px 56px 24px; }
  .tpl-midnight .invoice-top { margin: -48px -56px 28px; padding: 28px 56px 24px; }
  .tpl-forest .invoice-top   { margin: -48px -56px 28px; padding: 28px 56px 24px; }
}
@media (max-width: 1023px) {
  .tpl-rose .invoice-top     { margin: -28px -30px 28px; padding: 20px 30px 18px; }
  .tpl-midnight .invoice-top { margin: -28px -30px 28px; padding: 20px 30px 18px; }
  .tpl-forest .invoice-top   { margin: -28px -30px 28px; padding: 20px 30px 18px; }
}


/* ══════════════════════════════════════════════════
   HISTORY — SEARCH & FILTER
══════════════════════════════════════════════════ */
.history-search-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; max-width: 760px; width: 100%;
  margin-bottom: 24px;
}
.history-search-input-wrap {
  flex: 1; min-width: 200px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.history-search-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.12);
}
.history-search-icon { color: var(--text-tertiary); flex-shrink: 0; }
.history-search-input {
  flex: 1; border: none; background: transparent;
  padding: 9px 0; font-size: 13.5px; color: var(--text-primary);
  font-family: var(--font); outline: none;
}
.history-search-input::placeholder { color: var(--text-tertiary); }
.history-search-clear {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%; border: none;
  background: var(--border); color: var(--text-secondary);
  cursor: pointer; flex-shrink: 0; padding: 0;
  transition: background 0.15s;
}
.history-search-clear:hover { background: var(--border-light); color: var(--text-primary); }

.history-filter-pills {
  display: flex; gap: 6px; flex-shrink: 0;
}
.history-pill {
  padding: 7px 14px; border-radius: 20px; font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); cursor: pointer; font-family: var(--font);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.history-pill:hover { border-color: var(--accent); color: var(--accent); }
.history-pill.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}

[data-theme="dark"] .history-search-input-wrap { background: #2c2c2e; border-color: #3a3a3c; }
[data-theme="dark"] .history-search-input      { color: #f5f5f7; }
[data-theme="dark"] .history-pill              { background: #2c2c2e; border-color: #3a3a3c; color: #a1a1a6; }
[data-theme="dark"] .history-pill:hover        { color: #4da3ff; border-color: #4da3ff; }
[data-theme="dark"] .history-pill.active       { background: #0a84ff; border-color: #0a84ff; color: #fff; }
[data-theme="dark"] .history-search-clear      { background: #3a3a3c; color: #a1a1a6; }

@media (max-width: 767px) {
  .history-search-bar { flex-direction: column; align-items: stretch; }
  .history-search-input-wrap { min-width: 0; }
  .history-filter-pills { justify-content: flex-start; }
}
/* ══════════════════════════════════════════════════
   RESPONSIVE — HAMBURGER
══════════════════════════════════════════════════ */
.mobile-top-blur {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  height: 88px; z-index: 110;
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  -webkit-mask-image: linear-gradient(to bottom, black 30%, rgba(0,0,0,0.6) 60%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 30%, rgba(0,0,0,0.6) 60%, transparent 100%);
  background: linear-gradient(to bottom, rgba(var(--bg-rgb), 0.85) 0%, rgba(var(--bg-rgb), 0.4) 60%, transparent 100%);
  pointer-events: none;
}
[data-theme="dark"] .mobile-top-blur {
  background: linear-gradient(to bottom, rgba(28,28,30,0.85) 0%, rgba(28,28,30,0.4) 60%, transparent 100%);
}

.mobile-brand-pill {
  display: none; position: fixed; top: 14px; right: 14px; z-index: 120;
  height: 40px; padding: 0 14px 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
  align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  font-family: var(--font); letter-spacing: -0.01em;
  pointer-events: none; user-select: none;
}
[data-theme="dark"] .mobile-brand-pill {
  background: rgba(30,30,32,0.92); border-color: #3a3a3c;
}
.mobile-brand-pill.sidebar-blurred {
  opacity: 0.18;
  filter: blur(2px);
  pointer-events: none;
  transition: opacity 0.28s, filter 0.28s;
}
.mobile-brand-pill {
  transition: opacity 0.28s, filter 0.28s;
}

.hamburger {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 200;
  width: 40px; height: 40px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  cursor: pointer; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; box-shadow: var(--shadow-sm); transition: background 0.15s;
}
.hamburger:hover { background: var(--bg); }
.hamburger span {
  display: block; width: 18px; height: 1.8px;
  background: var(--text-primary); border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
.hamburger.is-open span:nth-child(1) { transform: translateY(6.8px)  rotate(45deg); }
.hamburger.is-open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger.is-open span:nth-child(3) { transform: translateY(-6.8px) rotate(-45deg); }

.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.35); backdrop-filter: blur(2px);
  z-index: 99; opacity: 0; transition: opacity 0.25s;
}
.sidebar-overlay.visible { display: block; opacity: 1; }

/* ── ≥ 1280px ── */
@media (min-width: 1280px) {
  .main-content     { padding: 40px 56px 56px; }
  .invoice-document { padding: 48px 56px 64px; }
  .tpl-bold .invoice-top  { margin: -48px -56px 28px; padding: 28px 56px 24px; }
  .tpl-slate .invoice-top { margin: -48px -56px 28px; padding: 28px 56px 24px; border-radius: var(--radius-md) var(--radius-md) 0 0; }
  .app-footer       { padding: 18px 56px 18px calc(var(--sidebar-w) + 56px); }
}

/* ── ≤ 1023px ── */
@media (max-width: 1023px) {
  :root { --sidebar-w: 220px; }
  .main-content     { padding: 24px 28px 40px; }
  .invoice-document { padding: 28px 30px 40px; }
  .tpl-bold .invoice-top  { margin: -28px -30px 28px; padding: 20px 30px 18px; }
  .tpl-slate .invoice-top { margin: -28px -30px 28px; padding: 20px 30px 18px; }
  .view-header      { flex-direction: column; align-items: flex-start; gap: 14px; }
  .header-actions   { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .invoice-top      { flex-direction: column; gap: 18px; }
  .invoice-meta     { text-align: left; }
  .invoice-title-block     { justify-content: flex-start; }
  .invoice-dates .date-row { justify-content: flex-start; }
  .totals-block  { justify-content: flex-start; }
  .totals-table  { max-width: 100%; }
  .settings-card{max-width:100%}
  #view-invoice.active>*,#view-history.active>*,#view-settings.active>*,#view-templates.active>*,#view-help.active>*{max-width:100%}
  .app-footer    { padding: 16px 28px 16px calc(var(--sidebar-w) + 28px); }
  .revenue-dashboard { max-width: 100%; }
  .field-row-two { grid-template-columns: 1fr 1fr; }
}

/* ── ≤ 767px ── */
@media (max-width: 767px) {
  .sidebar { display: none; }

  .main-content { padding: 24px 16px 16px; }
  .invoice-document { padding: 20px 14px 32px; border-radius: var(--radius-md); width: 100%; max-width: 100%; }
  .tpl-bold .invoice-top    { margin: -20px -14px 20px; padding: 16px 14px 14px; border-radius: var(--radius-md) var(--radius-md) 0 0; }
  .tpl-slate .invoice-top   { margin: -20px -14px 20px; padding: 16px 14px 14px; border-radius: var(--radius-md) var(--radius-md) 0 0; }
  .tpl-rose .invoice-top    { margin: -20px -14px 20px; padding: 16px 14px 14px; border-radius: var(--radius-md) var(--radius-md) 0 0; }
  .tpl-midnight .invoice-top{ margin: -20px -14px 20px; padding: 16px 14px 14px; border-radius: var(--radius-md) var(--radius-md) 0 0; }
  .tpl-forest .invoice-top  { margin: -20px -14px 20px; padding: 16px 14px 14px; border-radius: var(--radius-md) var(--radius-md) 0 0; }

  .view-header    { flex-direction: column; align-items: flex-start; gap: 12px; }
  .view-header h1 { font-size: 22px; }
  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .header-actions select,
  .header-actions button { justify-content: center; min-width: 0; }
  /* Print button always full width */
  .header-actions button[onclick="window.print()"] { grid-column: 1 / -1; }

  .magic-card   { padding: 14px; }
  .magic-header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .magic-footer { flex-direction: column-reverse; align-items: stretch; gap: 8px; }
  .btn-ai       { width: 100%; justify-content: center; }
  #magicStatus  { text-align: center; }

  .invoice-top  { flex-direction: column; gap: 16px; }
  .invoice-meta { text-align: left; width: 100%; }
  .invoice-title-block     { justify-content: flex-start; }
  .invoice-dates .date-row { justify-content: flex-start; }
  .invoice-number          { font-size: 17px; }

  .bill-fields { flex-direction: column; gap: 8px; }
  .bill-input,
  .bill-input-wide { width: 100%; flex: none; min-width: 0; }

  .table-wrap    { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .invoice-table { width: 100%; }
  .invoice-table th,
  .invoice-table td { padding: 8px 6px; font-size: 12px; }
  .col-desc  { width: 40%; }
  .col-qty   { width: 12%; }
  .col-price { width: 20%; }
  .col-total { width: 20%; }
  .col-del   { width: 8%; }

  .totals-block { justify-content: flex-start; }
  .totals-table { max-width: 100%; width: 100%; }

  .settings-card { padding: 20px 14px; max-width: 100%; }
  .field-row-two { grid-template-columns: 1fr; }
  .base-ccy-row  { flex-direction: column; align-items: stretch; }
  .base-ccy-save-btn { width: 100%; text-align: center; }

  .history-list  { max-width: 100%; }

  /* ── Mobile card: structured 2-col grid layout ── */
  .history-card {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "info   amount"
      "badge  badge"
      "actions actions";
    gap: 0;
    padding: 14px 16px;
    align-items: start;
  }
  .history-card-info {
    grid-area: info;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-right: 12px;
  }
  .history-card-info .hc-number { font-size: 11px; font-weight: 600; }
  .history-card-info .hc-client { font-size: 14px; font-weight: 600; margin-top: 1px; }
  .history-card-info .hc-date   { font-size: 11px; margin-top: 2px; }

  .history-card-amount-group {
    grid-area: amount;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    padding-top: 2px;
  }
  .history-card-amount { font-size: 16px; }
  .hc-converted { font-size: 10.5px; }

  .hc-overdue-badge {
    grid-area: badge;
    display: inline-flex;
    width: fit-content;
    margin-top: 10px;
    margin-bottom: 10px;
  }

  .history-card-actions {
    grid-area: actions;
    display: flex;
    gap: 7px;
    border-top: 1px solid var(--border-light);
    padding-top: 10px;
    margin-top: 0;
  }
  .history-card-actions .btn-draft-email { flex: 1; justify-content: center; font-size: 12px; padding: 7px 10px; }
  .history-card-actions .btn-load        { flex: 1; text-align: center; font-size: 12px; padding: 7px 10px; }
  .history-card-actions .btn-del-invoice { flex: 1; text-align: center; font-size: 12px; padding: 7px 10px; }

  .btn-update      { flex: 1 1 auto; justify-content: center; }
  .btn-cancel-edit { flex: 1 1 auto; justify-content: center; grid-column: 1 / -1; }

  #currencySelect { flex: 1 1 auto; }
  .app-footer     { padding: 16px; }

  .revenue-dashboard        { max-width: 100%; }
  .revenue-dashboard-inner  { padding: 18px 16px 16px; }
  .revenue-amount           { font-size: 28px; }
  .revenue-stats-row        { gap: 8px; }
  .revenue-stat-pill        { padding: 8px 10px; }
  .revenue-stat-value       { font-size: 15px; }

  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal-card    { max-height: 92vh; border-radius: var(--radius-lg) var(--radius-lg) var(--radius-md) var(--radius-md); }
}

/* ── ≤ 479px ── */
@media (max-width: 479px) {
  .main-content     { padding: 16px 12px calc(80px + env(safe-area-inset-bottom)); }
  .invoice-document { padding: 16px 12px 28px; }
  .view-header h1   { font-size: 20px; }
  .sidebar-brand span { font-size: 14px; }
  .sidebar-tagline    { font-size: 7px; }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .header-actions select,
  .header-actions button { width: 100%; }
  /* Print button always full width */
  .header-actions button[onclick="window.print()"] { grid-column: 1 / -1; }

  .btn-update      { width: 100%; }
  .btn-cancel-edit { width: 100%; grid-column: 1 / -1; }

  .invoice-table th,
  .invoice-table td { padding: 7px 5px; font-size: 11.5px; }

  .totals-grand        { font-size: 15px; }
  .history-card-amount { font-size: 15px; }
  .app-footer          { padding: 14px 12px; font-size: 11.5px; }

  .revenue-amount    { font-size: 24px; }
  .revenue-stats-row { flex-direction: column; }
  .revenue-stat-pill {
    flex: none; width: 100%;
    flex-direction: row; justify-content: space-between; align-items: center;
  }

  .modal-header      { padding: 16px 16px 12px; }
  .modal-field-group { padding: 10px 16px 0; }
  .modal-actions     { padding: 14px 16px 0; }
  .modal-tone-badge  { margin: 14px 16px 4px; }
}
/* ══════════════════════════════════════════════════
   MOBILE BOTTOM TAB BAR (iOS 26 style)
══════════════════════════════════════════════════ */
.mobile-tab-bar {
  display: none; /* hidden on desktop */
}

@media (max-width: 767px) {
  /* Hide old mobile chrome */
  .hamburger         { display: none !important; }
  .mobile-brand-pill { display: none !important; }
  .mobile-top-blur   { display: none !important; }
  .sidebar-overlay   { display: none !important; }

  /* Tab bar */
  .mobile-tab-bar {
    display: flex;
    position: fixed;
    bottom: 10px; left: 44px; right: 44px;
    z-index: 200;
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(40px) saturate(200%) brightness(1.1);
    -webkit-backdrop-filter: blur(40px) saturate(200%) brightness(1.1);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-bottom-color: rgba(255, 255, 255, 0.3);
    border-radius: 28px;
    padding: 5px 6px 6px;
    justify-content: space-around;
    align-items: flex-end;
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.12),
      0 2px 8px rgba(0, 0, 0, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.8),
      inset 0 -1px 0 rgba(255, 255, 255, 0.2);
  }

  [data-theme="dark"] .mobile-tab-bar {
    background: rgba(30, 30, 32, 0.55);
    border-color: rgba(255, 255, 255, 0.1);
    border-bottom-color: rgba(255, 255, 255, 0.05);
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.4),
      0 2px 8px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      inset 0 -1px 0 rgba(0, 0, 0, 0.2);
  }

  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    flex: 1;
    padding: 3px 4px 3px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: var(--font);
    color: rgba(60, 60, 67, 0.6);
    transition: color 0.18s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }

  [data-theme="dark"] .tab-item {
    color: rgba(235, 235, 245, 0.55);
  }

  .tab-item:active { transform: scale(0.92); transition: transform 0.1s; }

  .tab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 25px;
    border-radius: 13px;
    transition: background 0.18s;
  }

  .tab-item svg {
    stroke-width: 1.6;
    transition: stroke-width 0.18s;
    width: 21px; height: 21px;
  }

  .tab-label {
    font-size: 9.5px;
    font-weight: 500;
    letter-spacing: 0.01em;
    line-height: 1;
  }

  /* Active state — pill highlight + bold icon + accent color */
  .tab-item.active { color: var(--accent); }
  .tab-item.active .tab-icon {
    background: rgba(0, 113, 227, 0.15);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 3px rgba(0,113,227,0.15);
  }
  .tab-item.active svg { stroke-width: 2.2; }
  .tab-item.active .tab-label { font-weight: 700; }

  [data-theme="dark"] .tab-item.active .tab-icon {
    background: rgba(0, 113, 227, 0.25);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), 0 1px 3px rgba(0,0,0,0.3);
  }
  [data-theme="dark"] .tab-item.active { color: #4da3ff; }

  /* Mobile brand pill — top left */
  /* Mobile top header row — flows with content */
  .mobile-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
  }

  .mobile-brand-pill-header {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 36px;
    padding: 0 12px 0 8px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text-primary);
    font-family: var(--font);
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(40px) saturate(200%) brightness(1.1);
    -webkit-backdrop-filter: blur(40px) saturate(200%) brightness(1.1);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-bottom-color: rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.12),
      0 2px 8px rgba(0, 0, 0, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.8),
      inset 0 -1px 0 rgba(255, 255, 255, 0.2);
  }
  [data-theme="dark"] .mobile-brand-pill-header {
    color: #f5f5f7;
    background: rgba(30, 30, 32, 0.55);
    border-color: rgba(255, 255, 255, 0.1);
    border-bottom-color: rgba(255, 255, 255, 0.05);
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.4),
      0 2px 8px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      inset 0 -1px 0 rgba(0, 0, 0, 0.2);
  }

  /* Theme toggle circle */
  .mobile-theme-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(40px) saturate(200%) brightness(1.1);
    -webkit-backdrop-filter: blur(40px) saturate(200%) brightness(1.1);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-bottom-color: rgba(255, 255, 255, 0.3);
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.12),
      0 2px 8px rgba(0, 0, 0, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.8),
      inset 0 -1px 0 rgba(255, 255, 255, 0.2);
    transition: transform 0.15s;
  }
  .mobile-theme-circle:active { transform: scale(0.92); }
  [data-theme="dark"] .mobile-theme-circle {
    color: #a1a1a6;
    background: rgba(30, 30, 32, 0.55);
    border-color: rgba(255, 255, 255, 0.1);
    border-bottom-color: rgba(255, 255, 255, 0.05);
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.4),
      0 2px 8px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      inset 0 -1px 0 rgba(0, 0, 0, 0.2);
  }

  /* Hide settings-view theme toggle — it's now in the header */
  #themeToggleBtn { display: none; }

  /* Push content down below the header */
  .main-content { padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); }

  /* Push content up above the tab bar */
  .page-wrapper { margin-left: 0; }
  .app-footer   { display: none; }

  /* Footer credit card inside Help view */
  .help-footer-credit {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    margin-top: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-size: 12.5px;
    color: var(--text-tertiary);
  }
  [data-theme="dark"] .help-footer-credit {
    background: #2c2c2e;
    border-color: #3a3a3c;
  }
}
.splash-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: #0a0a0f;
  opacity: 1;
  transition: opacity 0.5s cubic-bezier(0.4,0,0.2,1);
}
.splash-screen.splash-hiding {
  opacity: 0;
  pointer-events: none;
}

/* Animated background orbs */
.splash-bg {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
}
.splash-orb {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.35;
  animation: orbFloat 8s ease-in-out infinite;
}
.splash-orb-1 {
  width: 500px; height: 500px; background: #0071e3;
  top: -150px; left: -100px; animation-delay: 0s;
}
.splash-orb-2 {
  width: 400px; height: 400px; background: #7c3aed;
  bottom: -100px; right: -80px; animation-delay: -3s;
}
.splash-orb-3 {
  width: 300px; height: 300px; background: #0891b2;
  top: 50%; left: 55%; transform: translate(-50%,-50%);
  animation-delay: -5s;
}
@keyframes orbFloat {
  0%,100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-30px) scale(1.05); }
}
.splash-orb-3 {
  animation-name: orbFloat3;
}
@keyframes orbFloat3 {
  0%,100% { transform: translate(-50%,-50%) scale(1); }
  50%      { transform: translate(-50%,-54%) scale(1.08); }
}

/* Card */
.splash-card {
  position: relative; z-index: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(40px); -webkit-backdrop-filter: blur(40px);
  border-radius: 28px;
  padding: 44px 48px 40px;
  width: 100%; max-width: 480px;
  text-align: center;
  box-shadow: 0 32px 80px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05) inset;
  animation: splashCardIn 0.7s cubic-bezier(0.22,1,0.36,1) both;
}
@keyframes splashCardIn {
  from { opacity: 0; transform: translateY(32px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* Logo */
.splash-logo-wrap {
  display: inline-flex; align-items: center; justify-content: center;
  width: 72px; height: 72px; border-radius: 22px;
  background: rgba(0,113,227,0.18);
  border: 1px solid rgba(0,113,227,0.35);
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(0,113,227,0.25);
}
.splash-logo-wrap svg { filter: drop-shadow(0 2px 8px rgba(0,113,227,0.5)); }

/* Text */
.splash-title {
  font-size: 28px; font-weight: 700; color: #fff;
  letter-spacing: -0.5px; margin-bottom: 8px;
}
.splash-tagline {
  font-size: 15px; color: rgba(255,255,255,0.55);
  margin-bottom: 32px; line-height: 1.5;
}

/* Feature list */
.splash-features {
  display: flex; flex-direction: column; gap: 14px;
  margin-bottom: 32px; text-align: left;
}
.splash-feature {
  display: flex; align-items: center; gap: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 16px; padding: 12px 14px;
  transition: background 0.2s;
}
.splash-feature:hover { background: rgba(255,255,255,0.07); }
.splash-feature-icon {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  background: rgba(0,113,227,0.2); border: 1px solid rgba(0,113,227,0.3);
  display: flex; align-items: center; justify-content: center;
  color: #4da3ff;
}
.splash-feature-icon.ai       { background: rgba(124,58,237,0.2); border-color: rgba(124,58,237,0.3); color: #a78bfa; }
.splash-feature-icon.privacy  { background: rgba(52,199,89,0.15); border-color: rgba(52,199,89,0.3);  color: #4ade80; }
.splash-feature-icon.templates{ background: rgba(8,145,178,0.15); border-color: rgba(8,145,178,0.3);  color: #22d3ee; }
.splash-feature-title {
  font-size: 13.5px; font-weight: 600; color: #fff; margin-bottom: 2px;
}
.splash-feature-desc {
  font-size: 12px; color: rgba(255,255,255,0.45); line-height: 1.4;
}

/* CTA Button */
.splash-cta {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px 24px;
  background: #0071e3; color: #fff;
  font-size: 15px; font-weight: 600;
  border: none; border-radius: 16px; cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(0,113,227,0.45);
  margin-bottom: 14px;
}
.splash-cta:hover  { background: #0077ed; transform: translateY(-1px); box-shadow: 0 8px 28px rgba(0,113,227,0.55); }
.splash-cta:active { transform: translateY(0); }

.splash-note {
  font-size: 12px; color: rgba(255,255,255,0.3);
}


/* ── Splash: light mode ── */
@media (prefers-color-scheme: light) {
  .splash-screen        { background: #eef2ff; }
  .splash-orb           { opacity: 0.14; }
  .splash-card          { background: rgba(255,255,255,0.82); border-color: rgba(0,0,0,0.08); box-shadow: 0 32px 80px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.04) inset; }
  .splash-title         { color: #1d1d1f; }
  .splash-tagline       { color: rgba(0,0,0,0.48); }
  .splash-feature       { background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.08); }
  .splash-feature:hover { background: rgba(0,0,0,0.06); }
  .splash-feature-title { color: #1d1d1f; }
  .splash-feature-desc  { color: rgba(0,0,0,0.45); }
  .splash-note          { color: rgba(0,0,0,0.3); }
}
[data-theme="light"] .splash-screen        { background: #eef2ff; }
[data-theme="light"] .splash-orb           { opacity: 0.14; }
[data-theme="light"] .splash-card          { background: rgba(255,255,255,0.82); border-color: rgba(0,0,0,0.08); box-shadow: 0 32px 80px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.04) inset; }
[data-theme="light"] .splash-title         { color: #1d1d1f; }
[data-theme="light"] .splash-tagline       { color: rgba(0,0,0,0.48); }
[data-theme="light"] .splash-feature       { background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.08); }
[data-theme="light"] .splash-feature:hover { background: rgba(0,0,0,0.06); }
[data-theme="light"] .splash-feature-title { color: #1d1d1f; }
[data-theme="light"] .splash-feature-desc  { color: rgba(0,0,0,0.45); }
[data-theme="light"] .splash-note          { color: rgba(0,0,0,0.3); }
/* Mobile — fits tall content on short screens */
@media (max-width: 540px) {
  .splash-screen   { align-items: center; overflow-y: auto; padding: 16px 0; }
  .splash-card     { padding: 28px 20px 24px; border-radius: 28px; margin: 16px; }
  .splash-title    { font-size: 22px; margin-bottom: 6px; }
  .splash-tagline  { font-size: 14px; margin-bottom: 22px; }
  .splash-features { gap: 10px; margin-bottom: 22px; }
  .splash-feature  { padding: 10px 12px; gap: 10px; }
  .splash-feature-icon { width: 34px; height: 34px; border-radius: 10px; }
  .splash-feature-title { font-size: 13px; }
  .splash-feature-desc  { font-size: 11.5px; }
  .splash-logo-wrap { width: 60px; height: 60px; margin-bottom: 16px; }
  .splash-cta      { padding: 12px 20px; font-size: 14px; margin-bottom: 10px; }
  .splash-orb-1    { width: 260px; height: 260px; }
  .splash-orb-2    { width: 200px; height: 200px; }
  .splash-orb-3    { width: 160px; height: 160px; }
}

/* Extra-small phones (e.g. iPhone SE) */
@media (max-width: 380px) {
  .splash-card       { padding: 22px 16px 20px; }
  .splash-features   { gap: 8px; }
  .splash-feature    { padding: 8px 10px; }
  .splash-feature-icon { width: 30px; height: 30px; flex-shrink: 0; }
  .splash-logo-wrap  { width: 52px; height: 52px; }
  .splash-title      { font-size: 20px; }
}

/* ══════════════════════════════════════════════════
   TEMPLATE-AWARE SIDEBAR TINTING (desktop / tablet)
══════════════════════════════════════════════════ */
@media (min-width: 768px) {

  /* classic — blue */
  body[data-template="classic"] .nav-item.active,
  body:not([data-template]) .nav-item.active { background: rgba(0,113,227,0.12); color: #0071e3; }
  [data-theme="dark"] body[data-template="classic"] .nav-item.active,
  [data-theme="dark"] body:not([data-template]) .nav-item.active { background: rgba(0,113,227,0.18); color: #4da3ff; }

  /* minimal — charcoal */
  body[data-template="minimal"] .nav-item.active { background: rgba(29,29,31,0.08); color: #1d1d1f; }
  [data-theme="dark"] body[data-template="minimal"] .nav-item.active { background: rgba(245,245,247,0.12); color: #f5f5f7; }

  /* bold — orange */
  body[data-template="bold"] .nav-item.active { background: rgba(234,88,12,0.10); color: #ea580c; }
  [data-theme="dark"] body[data-template="bold"] .nav-item.active { background: rgba(251,146,60,0.18); color: #fb923c; }

  /* slate — forest green */
  body[data-template="slate"] .nav-item.active { background: rgba(45,106,79,0.10); color: #2d6a4f; }
  [data-theme="dark"] body[data-template="slate"] .nav-item.active { background: rgba(74,222,128,0.15); color: #4ade80; }

  /* ocean — cyan */
  body[data-template="ocean"] .nav-item.active { background: rgba(8,145,178,0.10); color: #0891b2; }
  [data-theme="dark"] body[data-template="ocean"] .nav-item.active { background: rgba(34,211,238,0.15); color: #22d3ee; }

  /* rose — rose red */
  body[data-template="rose"] .nav-item.active { background: rgba(225,29,72,0.10); color: #e11d48; }
  [data-theme="dark"] body[data-template="rose"] .nav-item.active { background: rgba(251,113,133,0.18); color: #fb7185; }

  /* midnight — navy / gold */
  body[data-template="midnight"] .nav-item.active { background: rgba(30,58,95,0.10); color: #1e3a5f; }
  [data-theme="dark"] body[data-template="midnight"] .nav-item.active { background: rgba(212,175,55,0.18); color: #d4af37; }

  /* forest — emerald */
  body[data-template="forest"] .nav-item.active { background: rgba(22,101,52,0.10); color: #166534; }
  [data-theme="dark"] body[data-template="forest"] .nav-item.active { background: rgba(74,222,128,0.15); color: #4ade80; }

}

/* ══════════════════════════════════════════════════
   TEMPLATE-AWARE TAB BAR TINTING (mobile only)
══════════════════════════════════════════════════ */
@media (max-width: 767px) {

  /* classic — blue */
  body[data-template="classic"] .tab-item.active,
  body:not([data-template]) .tab-item.active { color: #0071e3; }
  body[data-template="classic"] .tab-item.active .tab-icon,
  body:not([data-template]) .tab-item.active .tab-icon { background: rgba(0,113,227,0.15); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 3px rgba(0,113,227,0.15); }

  /* minimal — charcoal / light gray */
  body[data-template="minimal"] .tab-item.active { color: #1d1d1f; }
  body[data-template="minimal"] .tab-item.active .tab-icon { background: rgba(29,29,31,0.1); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5); }
  [data-theme="dark"] body[data-template="minimal"] .tab-item.active { color: #f5f5f7; }
  [data-theme="dark"] body[data-template="minimal"] .tab-item.active .tab-icon { background: rgba(245,245,247,0.15); }

  /* bold — orange */
  body[data-template="bold"] .tab-item.active { color: #ea580c; }
  body[data-template="bold"] .tab-item.active .tab-icon { background: rgba(234,88,12,0.12); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 3px rgba(234,88,12,0.15); }
  [data-theme="dark"] body[data-template="bold"] .tab-item.active { color: #fb923c; }
  [data-theme="dark"] body[data-template="bold"] .tab-item.active .tab-icon { background: rgba(251,146,60,0.2); }

  /* slate — forest green */
  body[data-template="slate"] .tab-item.active { color: #2d6a4f; }
  body[data-template="slate"] .tab-item.active .tab-icon { background: rgba(45,106,79,0.12); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 3px rgba(45,106,79,0.15); }
  [data-theme="dark"] body[data-template="slate"] .tab-item.active { color: #4ade80; }
  [data-theme="dark"] body[data-template="slate"] .tab-item.active .tab-icon { background: rgba(74,222,128,0.18); }

  /* ocean — cyan */
  body[data-template="ocean"] .tab-item.active { color: #0891b2; }
  body[data-template="ocean"] .tab-item.active .tab-icon { background: rgba(8,145,178,0.12); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 3px rgba(8,145,178,0.15); }
  [data-theme="dark"] body[data-template="ocean"] .tab-item.active { color: #22d3ee; }
  [data-theme="dark"] body[data-template="ocean"] .tab-item.active .tab-icon { background: rgba(34,211,238,0.18); }

  /* rose — rose red */
  body[data-template="rose"] .tab-item.active { color: #e11d48; }
  body[data-template="rose"] .tab-item.active .tab-icon { background: rgba(225,29,72,0.12); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 3px rgba(225,29,72,0.15); }
  [data-theme="dark"] body[data-template="rose"] .tab-item.active { color: #fb7185; }
  [data-theme="dark"] body[data-template="rose"] .tab-item.active .tab-icon { background: rgba(251,113,133,0.2); }

  /* midnight — navy / gold */
  body[data-template="midnight"] .tab-item.active { color: #1e3a5f; }
  body[data-template="midnight"] .tab-item.active .tab-icon { background: rgba(30,58,95,0.12); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 3px rgba(30,58,95,0.15); }
  [data-theme="dark"] body[data-template="midnight"] .tab-item.active { color: #d4af37; }
  [data-theme="dark"] body[data-template="midnight"] .tab-item.active .tab-icon { background: rgba(212,175,55,0.2); }

  /* forest — emerald */
  body[data-template="forest"] .tab-item.active { color: #166534; }
  body[data-template="forest"] .tab-item.active .tab-icon { background: rgba(22,101,52,0.12); box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 1px 3px rgba(22,101,52,0.15); }
  [data-theme="dark"] body[data-template="forest"] .tab-item.active { color: #4ade80; }
  [data-theme="dark"] body[data-template="forest"] .tab-item.active .tab-icon { background: rgba(74,222,128,0.18); }

}

/* ══════════════════════════════════════════════════
   PWA STANDALONE MODE
   Targets body[data-pwa="true"] (set by JS) AND
   the standard CSS media query as a fallback.
   Both are equivalent — JS attr allows more
   specificity in component-level overrides.
══════════════════════════════════════════════════ */
@media (display-mode: standalone) and (max-width: 767px) {
  .mobile-tab-bar {
    bottom: calc(env(safe-area-inset-bottom) + 24px);
    padding: 6px 6px 7px;
    border-radius: 28px;
  }
  .tab-item { padding: 4px 4px 3px; }
  .tab-icon  { width: 42px; height: 26px; border-radius: 13px; }
  .tab-item svg { width: 21px; height: 21px; }
  .tab-label { font-size: 9.5px; }
  .main-content {
    padding-bottom: calc(110px + env(safe-area-inset-bottom));
  }
  .pwa-hidden { display: none !important; }
}

@media (max-width: 767px) {
  body[data-pwa="true"] .mobile-tab-bar {
    bottom: calc(env(safe-area-inset-bottom) + 24px);
    padding: 6px 6px 7px;
    border-radius: 28px;
  }
  body[data-pwa="true"] .tab-item { padding: 4px 4px 3px; }
  body[data-pwa="true"] .tab-icon  { width: 42px; height: 26px; border-radius: 13px; }
  body[data-pwa="true"] .tab-item svg { width: 21px; height: 21px; }
  body[data-pwa="true"] .tab-label { font-size: 9.5px; }
  body[data-pwa="true"] .main-content {
    padding-bottom: calc(110px + env(safe-area-inset-bottom));
  }
}
body[data-pwa="true"] .pwa-hidden { display: none !important; }
body[data-pwa="true"] .pwa-only   { display: revert !important; }

/* ── Offline state — grey out network-dependent AI buttons ── */
body[data-offline="true"] #magicBtn,
body[data-offline="true"] .btn-draft-email {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
  animation: none;
  background: var(--border) !important;
  color: var(--text-secondary, #6e6e73) !important;
  box-shadow: none !important;
}

/* ── Mobile offline banner ── */
.mobile-offline-banner {
  display: none; /* hidden on desktop — status dot handles it */
}
@media (max-width: 767px) {
  .mobile-offline-banner {
    display: none; /* default hidden */
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 500;
    background: #cf222e;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    padding: 7px 16px;
    padding-top: max(7px, env(safe-area-inset-top));
    text-align: center;
    align-items: center;
    justify-content: center;
    gap: 6px;
    letter-spacing: 0.1px;
    animation: offlineBannerIn 0.3s cubic-bezier(0.22,1,0.36,1) both;
  }
  body[data-offline="true"] .mobile-offline-banner {
    display: flex;
  }
}
@keyframes offlineBannerIn {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
[data-theme="dark"] .mobile-offline-banner {
  background: #b91c1c;
}

/* ══════════════════════════════════════════════════
   PWA INSTALL NUDGE DIALOG
══════════════════════════════════════════════════ */
.pwa-nudge {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 16px 24px;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: nudgeBgIn 0.3s ease both;
}
@keyframes nudgeBgIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.pwa-nudge-card {
  position: relative;
  background: var(--surface);
  border-radius: 20px;
  padding: 20px 20px 18px;
  width: 100%;
  max-width: 400px;
  box-shadow:
    0 20px 60px rgba(0,0,0,0.18),
    0 4px 16px rgba(0,0,0,0.10),
    inset 0 1px 0 rgba(255,255,255,0.8);
  border: 1px solid var(--border);
  animation: nudgeCardIn 0.4s cubic-bezier(0.22,1,0.36,1) both;
}
@keyframes nudgeCardIn {
  from { opacity: 0; transform: translateY(32px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.pwa-nudge-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted, #6e6e73);
  transition: background 0.15s;
}
.pwa-nudge-close:hover { background: var(--border); }
.pwa-nudge-icon {
  margin-bottom: 12px;
}
.pwa-nudge-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  margin-bottom: 5px;
}
.pwa-nudge-text {
  font-size: 13px;
  color: var(--text-secondary, #6e6e73);
  line-height: 1.5;
  margin-bottom: 16px;
}
.pwa-nudge-instructions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 12.5px;
  color: var(--text-secondary, #6e6e73);
  line-height: 1.5;
}
.pwa-nudge-actions {
  display: flex;
  gap: 8px;
}
.pwa-nudge-btn-primary {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s, transform 0.12s;
}
.pwa-nudge-btn-primary:hover  { opacity: 0.88; }
.pwa-nudge-btn-primary:active { transform: scale(0.97); }
.pwa-nudge-btn-secondary {
  flex: 1;
  background: var(--bg);
  color: var(--text-secondary, #6e6e73);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, transform 0.12s;
}
.pwa-nudge-btn-secondary:hover  { background: var(--border); }
.pwa-nudge-btn-secondary:active { transform: scale(0.97); }

[data-theme="dark"] .pwa-nudge-card {
  box-shadow:
    0 20px 60px rgba(0,0,0,0.5),
    0 4px 16px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.06);
}

/* ══════════════════════════════════════════════════
   ANIMATIONS & MICRO-INTERACTIONS
══════════════════════════════════════════════════ */

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

/* ── View entrance ── */
@keyframes viewIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.view.active {
  animation: viewIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ── Cards stagger in ── */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.history-card {
  animation: cardIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.history-card:nth-child(1)  { animation-delay: 0.03s; }
.history-card:nth-child(2)  { animation-delay: 0.07s; }
.history-card:nth-child(3)  { animation-delay: 0.11s; }
.history-card:nth-child(4)  { animation-delay: 0.15s; }
.history-card:nth-child(5)  { animation-delay: 0.18s; }
.history-card:nth-child(n+6){ animation-delay: 0.21s; }

/* ── Template cards stagger ── */
.template-card {
  animation: cardIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.template-card:nth-child(1) { animation-delay: 0.04s; }
.template-card:nth-child(2) { animation-delay: 0.09s; }
.template-card:nth-child(3) { animation-delay: 0.13s; }
.template-card:nth-child(4) { animation-delay: 0.17s; }
.template-card:nth-child(5) { animation-delay: 0.20s; }
.template-card:nth-child(6) { animation-delay: 0.23s; }
.template-card:nth-child(7) { animation-delay: 0.26s; }
.template-card:nth-child(8) { animation-delay: 0.28s; }

/* ── Tab bar item press ── */
.tab-item {
  transition: color 0.18s, transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tab-item:active {
  transform: scale(0.88);
}
.tab-icon {
  transition: background 0.2s, box-shadow 0.2s, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tab-item.active .tab-icon {
  transform: scale(1.08);
}

/* ── Button ripple-press ── */
.btn-primary, .btn-secondary, .btn-ghost,
.btn-update, .btn-load, .btn-danger {
  transition: background 0.15s, opacity 0.15s,
              transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.15s;
}
/* AI buttons: don't transition background — it's handled by the keyframe animation */
.btn-ai, .btn-draft-email {
  transition: opacity 0.15s,
              transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s;
}
.btn-primary:active, .btn-secondary:active, .btn-ghost:active,
.btn-ai:active, .btn-update:active, .btn-load:active,
.btn-draft-email:active, .btn-danger:active {
  transform: scale(0.95);
}

/* ── Invoice document entrance ── */
@keyframes docIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.invoice-document {
  animation: docIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ── Revenue dashboard entrance ── */
@keyframes dashIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.revenue-dashboard {
  animation: dashIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) 0.1s both;
}

/* ── Settings card entrance ── */
.settings-card {
  animation: cardIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) 0.08s both;
}

/* ── Help cards stagger ── */
.help-quick-card {
  animation: cardIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.help-quick-card:nth-child(1) { animation-delay: 0.05s; }
.help-quick-card:nth-child(2) { animation-delay: 0.10s; }
.help-quick-card:nth-child(3) { animation-delay: 0.14s; }
.help-quick-card:nth-child(4) { animation-delay: 0.18s; }

/* ── Mobile brand pill bounce-in ── */
@keyframes pillIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0)     scale(1); }
}
@media (max-width: 767px) {
  .mobile-brand-pill-header {
    animation: pillIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s both;
  }
  .mobile-theme-circle {
    animation: pillIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) 0.18s both;
  }

  /* Tab bar slides up on load */
  /* Theme circle spin on press */
  .mobile-theme-circle {
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  .mobile-theme-circle:active {
    transform: scale(0.88) rotate(30deg);
  }
}

/* ── Table row entrance ── */
@keyframes rowIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}
.invoice-table tbody tr {
  animation: rowIn 0.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ── Focus ring pulse on inputs ── */
@keyframes focusPulse {
  0%   { box-shadow: 0 0 0 0 rgba(0, 113, 227, 0.3); }
  70%  { box-shadow: 0 0 0 5px rgba(0, 113, 227, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 113, 227, 0); }
}
.field-input:focus,
#magicInput:focus {
  animation: focusPulse 0.5s ease-out;
}

/* ── Sidebar nav item hover glide ── */
.nav-item {
  transition: background 0.18s ease, color 0.15s ease,
              transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nav-item:hover  { transform: translateX(2px); }
.nav-item.active { transform: translateX(0); }


/* ══════════════════════════════════════════════════
   CHANGELOG / VERSIONING
══════════════════════════════════════════════════ */
.version-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.02em;
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.version-badge.version-latest {
  background: rgba(0, 113, 227, 0.1);
  color: var(--accent);
  border-color: rgba(0, 113, 227, 0.25);
}
[data-theme="dark"] .version-badge { background: #3a3a3c; border-color: #48484a; }
[data-theme="dark"] .version-badge.version-latest { background: rgba(10,132,255,0.18); color: #4da3ff; border-color: rgba(10,132,255,0.3); }

.changelog-meta {
  font-size: 11.5px;
  color: var(--text-tertiary);
  padding: 10px 0 6px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.changelog-list {
  list-style: none;
  padding: 0;
  margin: 0 0 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.changelog-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.changelog-list li::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 1px;
  position: relative;
  top: 1px;
}
.cl-new::before    { background: #34c759; }
.cl-improved::before { background: #0071e3; }
.cl-fix::before    { background: #ff9f0a; }

/* ══════════════════════════════════════════════════
   HELP — ABOUT SECTION
══════════════════════════════════════════════════ */
.help-about {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.help-about-logo {
  flex-shrink: 0;
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: #e8f1fc;
}
.help-about-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}
.help-about-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 12px;
}
.help-about-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.help-about-tag {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
}
[data-theme="dark"] .help-about { border-color: #3a3a3c; }
[data-theme="dark"] .help-about-logo { background: rgba(0,113,227,0.15); }
[data-theme="dark"] .help-about-tag { background: #3a3a3c; border-color: #48484a; }

/* ══════════════════════════════════════════════════
   LIGHT / DARK MODE TRANSITION
══════════════════════════════════════════════════ */

/* Crossfade the whole page via View Transitions API */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.35s;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
::view-transition-old(root) { animation-name: theme-fade-out; }
::view-transition-new(root) { animation-name: theme-fade-in;  }

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

/* Suppress individual property transitions during the switch
   so they don't fight the view transition crossfade */
.theme-transitioning *,
.theme-transitioning *::before,
.theme-transitioning *::after {
  transition: none !important;
}

/* Fallback: smooth CSS transition for browsers without View Transitions */
@supports not (view-transition-name: none) {
  html {
    transition: background-color 0.3s ease, color 0.3s ease;
  }
  .page-wrapper, .sidebar, .main-content, .invoice-document {
    transition: background-color 0.3s ease, border-color 0.3s ease;
  }
}

/* ══════════════════════════════════════════════════
   SIDEBAR SHORTCUTS BUTTON
══════════════════════════════════════════════════ */
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.sidebar-shortcuts-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 3px 9px 3px 7px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar-shortcuts-btn:hover {
  background: var(--border-light);
  color: var(--text-secondary);
  border-color: var(--border);
}
[data-theme="dark"] .sidebar-shortcuts-btn { border-color: #3a3a3c; }
[data-theme="dark"] .sidebar-shortcuts-btn:hover { background: #3a3a3c; }

/* ══════════════════════════════════════════════════
   KEYBOARD SHORTCUTS DIALOG
══════════════════════════════════════════════════ */
.shortcuts-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  animation: modalIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.shortcuts-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.shortcuts-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.shortcuts-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}
.shortcuts-subtitle {
  font-size: 11.5px;
  color: var(--text-tertiary);
  margin-top: 1px;
}
.shortcuts-close {
  background: none; border: none;
  font-size: 20px; line-height: 1;
  color: var(--text-tertiary); cursor: pointer;
  padding: 4px 6px; border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  font-family: var(--font);
}
.shortcuts-close:hover { background: var(--border-light); color: var(--text-primary); }

.shortcuts-body { padding: 8px 0 16px; }

.shortcuts-group { padding: 10px 20px 4px; }
.shortcuts-group + .shortcuts-group { border-top: 1px solid var(--border-light); margin-top: 6px; }

.shortcuts-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}
.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
}
.shortcut-desc {
  font-size: 13px;
  color: var(--text-secondary);
}
.shortcut-keys {
  display: flex;
  align-items: center;
  gap: 3px;
}
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
  box-shadow: 0 1px 0 var(--border);
}
[data-theme="dark"] .shortcuts-header { border-bottom-color: #3a3a3c; }
[data-theme="dark"] .shortcuts-group + .shortcuts-group { border-top-color: #3a3a3c; }
[data-theme="dark"] kbd { background: #3a3a3c; border-color: #48484a; box-shadow: 0 1px 0 #48484a; }

/* ══════════════════════════════════════════════════
   HELP — KEYBOARD SHORTCUTS (mobile section)
══════════════════════════════════════════════════ */
.help-shortcuts-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.help-shortcuts-group {
  padding: 14px 16px 10px;
}
.help-shortcuts-group + .help-shortcuts-group {
  border-top: 1px solid var(--border-light);
}
.help-shortcuts-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}
.help-shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-secondary);
}
.help-shortcut-keys {
  display: flex;
  align-items: center;
  gap: 3px;
}
[data-theme="dark"] .help-shortcuts-grid { border-color: #3a3a3c; }
[data-theme="dark"] .help-shortcuts-group + .help-shortcuts-group { border-top-color: #3a3a3c; }

/* ══════════════════════════════════════════════════
   DISCOUNT ROW
══════════════════════════════════════════════════ */
.discount-row {
  /* hidden by default until a value is entered — the row still takes space
     so the layout doesn't jump; opacity fade looks intentional */
  opacity: 0.4;
  transition: opacity 0.2s;
}
.discount-row--active {
  opacity: 1;
}
.discount-label-group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.discount-controls {
  display: flex;
  align-items: center;
  gap: 3px;
}
.discount-amount-input {
  width: 64px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  text-align: right;
  -moz-appearance: textfield;
}
.discount-amount-input::-webkit-outer-spin-button,
.discount-amount-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.discount-amount-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.discount-type-btn {
  min-width: 28px;
  height: 22px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.discount-type-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
/* The print label sits next to "Discount" text on print, hidden on screen */
.discount-print-label {
  display: none;
  font-size: inherit;
  color: inherit;
}

/* ── Print overrides ── */
@media print {
  /* Hide the interactive controls, show the static label */
  .discount-controls { display: none !important; }
  .discount-print-label { display: inline !important; }

  /* Always show the row on print (active state irrelevant) */
  .discount-row { opacity: 1 !important; }

  /* Hide the row entirely if there's no discount */
  .discount-row:not(.discount-row--active) { display: none !important; }
}

[data-theme="dark"] .discount-amount-input {
  background: #1c1c1e;
  border-color: #3a3a3c;
  color: var(--text-primary);
}
[data-theme="dark"] .discount-type-btn {
  background: #1c1c1e;
  border-color: #3a3a3c;
  color: var(--text-secondary);
}
[data-theme="dark"] .discount-type-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ══════════════════════════════════════════════════
   AI GRADIENT SYSTEM — shared keyframe + all AI elements
══════════════════════════════════════════════════ */
@keyframes aiGradientShift {
  0%   { background-position: 0%   50%; }
  50%  { background-position: 80%  50%; }
  100% { background-position: 0%   50%; }
}

/* Splash screen AI feature icon */
.splash-feature-icon.ai {
  background: linear-gradient(110deg,
    rgba(94,92,230,0.3),
    rgba(168,85,247,0.3),
    rgba(6,182,212,0.25),
    rgba(94,92,230,0.3));
  background-size: 250% 250%;
  animation: aiGradientShift 18s ease-in-out infinite 2.5s;
  border-color: rgba(168,85,247,0.4);
  color: #c4b5fd;
}

/* Help "✦ AI-Powered" tag */
.help-about-tag.ai-tag {
  background: linear-gradient(110deg, #dbeafe, #ede9fe, #fce7f3, #dbeafe) !important;
  background-size: 250% 250% !important;
  animation: aiGradientShift 16s ease-in-out infinite 4s;
  border-color: transparent !important;
  color: #4f46e5 !important;
  font-weight: 600;
}
[data-theme="dark"] .help-about-tag.ai-tag {
  background: linear-gradient(110deg, #0d2a4a, #1a1040, #2d1050, #0d2a4a) !important;
  background-size: 250% 250% !important;
  color: #a78bfa !important;
  border-color: transparent !important;
}



/* Magic card dark mode ::before border */
[data-theme="dark"] .magic-card::before {
  opacity: 0.75;
}

/* Reduce motion — honour prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .btn-ai,
  .btn-draft-email,
  .magic-badge,
  .magic-card::before,
  .modal-ai-badge,
  .splash-feature-icon.ai,
  .help-about-tag.ai-tag {
    animation: none;
    background-size: 100% 100%;
  }
}
