/* ============================================================
   INVOICE GENERATOR — styles.css
   Clean, professional, monochromatic — dark mode via .dark on <body>.
============================================================ */

/* ── Design Tokens ────────────────────────────────────── */
:root {
  --clr-bg:           #f5f5f7;
  --clr-surface:      #ffffff;
  --clr-border:       #e4e4e7;
  --clr-border-focus: #71717a;
  --clr-text:         #18181b;
  --clr-text-muted:   #52525b;
  --clr-text-subtle:  #a1a1aa;

  /* Single accent colour — used on icons, active states, primary CTA */
  --clr-accent:       #2563eb;
  --clr-accent-bg:    rgba(37,99,235,.08);
  --clr-accent-border:rgba(37,99,235,.2);

  /* Shadows — very subtle */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 24px rgba(0,0,0,.08), 0 4px 8px rgba(0,0,0,.04);

  --radius:    10px;
  --radius-sm: 6px;
  --header-h:  62px;
}

/* Dark mode */
body.dark {
  --clr-bg:          #0f0f11;
  --clr-surface:     #1a1a1e;
  --clr-border:      #27272a;
  --clr-border-focus:#71717a;
  --clr-text:        #fafafa;
  --clr-text-muted:  #a1a1aa;
  --clr-text-subtle: #52525b;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 24px rgba(0,0,0,.5);
}

/* ── Reset ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  background-color: var(--clr-bg);
  color: var(--clr-text);
  line-height: 1.6;
  transition: background-color .3s, color .3s;
}

img { max-width: 100%; display: block; }
.hidden { display: none !important; }
.req { color: #ef4444; }

/* ── Site Navigation Bar ─────────────────────────────── */
.site-nav {
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  padding: 0 1.5rem;
}

.site-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.site-nav-inner::-webkit-scrollbar { display: none; }

.site-nav-inner a {
  display: inline-flex;
  align-items: center;
  padding: .55rem 1rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}

.site-nav-inner a:hover {
  color: var(--clr-accent);
  border-bottom-color: var(--clr-accent);
}

/* ── App Header ───────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: #0f172a;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 2rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: .85rem;
}

.brand-logo-wrap {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.14);
}

.brand-logo-wrap svg { width: 18px; height: 18px; color: rgba(255,255,255,.85); }

.brand-name {
  display: block;
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
  letter-spacing: -.01em;
  line-height: 1.2;
  margin: 0;
  padding: 0;
}

.brand-tagline {
  display: block;
  font-size: .67rem;
  color: rgba(255,255,255,.38);
  font-weight: 400;
  letter-spacing: .01em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── Currency Picker ──────────────────────────────────── */
.currency-picker { position: relative; }

.currency-picker-btn {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 6px;
  color: rgba(255,255,255,.75);
  font-family: inherit;
  font-size: .8rem;
  font-weight: 500;
  padding: .38rem .7rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.currency-picker-btn:hover { background: rgba(255,255,255,.14); color: #fff; }
.currency-picker-btn:focus-visible { outline: 2px solid rgba(255,255,255,.35); outline-offset: 2px; }

/* Dropdown panel */
.currency-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 290px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,.14);
  z-index: 500;
  overflow: hidden;
  animation: dropIn .15s ease;
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Search bar inside dropdown */
.currency-search-wrap {
  padding: .6rem .6rem .4rem;
  border-bottom: 1px solid var(--clr-border);
}

.currency-search {
  width: 100%;
  background: var(--clr-bg);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: .45rem .65rem;
  font-size: .83rem;
  font-family: inherit;
  color: var(--clr-text);
  outline: none;
  transition: border-color .2s, box-shadow .15s;
}

.currency-search:focus {
  border-color: var(--clr-border-focus);
  box-shadow: 0 0 0 3px rgba(113,113,122,.12);
}

/* Scrollable list */
.currency-list {
  list-style: none;
  max-height: 250px;
  overflow-y: auto;
  padding: .3rem 0;
  scrollbar-width: thin;
  scrollbar-color: #d4d4d8 transparent;
}

.currency-list::-webkit-scrollbar { width: 4px; }
.currency-list::-webkit-scrollbar-thumb { background: #d4d4d8; border-radius: 99px; }

.currency-list li {
  display: grid;
  grid-template-columns: 28px 44px 1fr;
  align-items: center;
  gap: .5rem;
  padding: .45rem .75rem;
  cursor: pointer;
  font-size: .83rem;
  transition: background .1s;
}

.currency-list li:hover  { background: var(--clr-bg); }

.currency-list li.selected {
  background: var(--clr-bg);
  color: var(--clr-text);
}

body.dark .currency-list li.selected { background: rgba(255,255,255,.05); }

.curr-symbol {
  font-weight: 600;
  color: var(--clr-text-muted);
  font-size: .84rem;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.curr-code {
  font-weight: 600;
  font-size: .78rem;
  color: var(--clr-text);
  letter-spacing: .02em;
}

.curr-name {
  font-size: .76rem;
  color: var(--clr-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.currency-list li.selected .curr-symbol { color: var(--clr-text); }
.currency-list li.selected .curr-code   { color: var(--clr-text); }
.currency-list li.selected .curr-name   { color: var(--clr-text-muted); }

/* Empty state */
.currency-empty {
  padding: 1rem;
  text-align: center;
  font-size: .83rem;
  color: var(--clr-text-subtle);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}

.icon-btn:hover { background: rgba(255,255,255,.16); }
.theme-icon { width: 17px; height: 17px; color: rgba(255,255,255,.7); }

/* ── Layout ───────────────────────────────────────────── */
.app-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.75rem 2rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.75rem;
  height: calc(100vh - var(--header-h) - var(--ad-top-h));
  overflow: hidden;
}

/* Left panel scrolls */
.form-panel {
  overflow-y: auto;
  height: 100%;
  padding-right: .3rem;
  scrollbar-width: thin;
  scrollbar-color: #d4d4d8 transparent;
}

.form-panel::-webkit-scrollbar { width: 4px; }
.form-panel::-webkit-scrollbar-thumb { background: #d4d4d8; border-radius: 99px; }
body.dark .form-panel::-webkit-scrollbar-thumb { background: #3f3f46; }

/* ── Cards ────────────────────────────────────────────── */
.card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  transition: background .3s, border-color .3s;
  position: relative;
  overflow: hidden;
}

/* Thin accent strip — consistent on all cards */
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--clr-accent);
  opacity: .18;
  border-radius: var(--radius) var(--radius) 0 0;
}
.card:hover::before { opacity: .35; }

.card-title {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--clr-text-subtle);
  margin-bottom: 1.25rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--clr-border);
}

/* Accent icon boxes — consistent colour across all cards */
.card-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--clr-accent-bg);
  border: 1px solid var(--clr-accent-border);
}

.card-icon svg { width: 15px; height: 15px; color: var(--clr-accent); }

/* All variants share the accent style */
.ci-indigo,
.ci-violet,
.ci-sky,
.ci-amber,
.ci-rose,
.ci-emerald {
  background: var(--clr-accent-bg);
  border: 1px solid var(--clr-accent-border);
}

.ci-indigo svg,
.ci-violet svg,
.ci-sky svg,
.ci-amber svg,
.ci-rose svg,
.ci-emerald svg { color: var(--clr-accent); }

/* ── Form Elements ────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: .72rem;
  font-weight: 500;
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .4rem;
}

.form-input,
.form-textarea {
  width: 100%;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  font-size: .88rem;
  color: var(--clr-text);
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .3s;
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--clr-text-subtle); }

.form-input:focus,
.form-textarea:focus {
  border-color: var(--clr-accent);
  box-shadow: 0 0 0 3px var(--clr-accent-bg);
}

.form-input.error,
.form-textarea.error {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}

.form-textarea { resize: vertical; min-height: 68px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-row.three-col { grid-template-columns: 1fr 1fr 1fr; }

/* ── Logo Upload ──────────────────────────────────────── */
.logo-upload-area {
  position: relative;
  border: 1.5px dashed var(--clr-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--clr-bg);
}

.logo-upload-area:hover {
  border-color: var(--clr-border-focus);
  background: var(--clr-surface);
}

.logo-file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

#logoPlaceholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  color: var(--clr-text-muted);
  font-size: .84rem;
  pointer-events: none;
}

.upload-svg {
  width: 28px;
  height: 28px;
  color: var(--clr-text-subtle);
  margin-bottom: .1rem;
}

#logoPlaceholder small { color: var(--clr-text-subtle); font-size: .73rem; }

.logo-preview-wrap { position: relative; display: inline-block; }
.logo-preview-wrap img { max-height: 80px; max-width: 200px; margin: 0 auto; border-radius: var(--radius-sm); }

.remove-logo-btn {
  position: absolute;
  top: -8px; right: -8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-logo-btn svg { width: 10px; height: 10px; }

/* ── Items Table ──────────────────────────────────────── */
.items-header {
  display: grid;
  grid-template-columns: 3fr 1fr 1.4fr 1.2fr 36px;
  gap: .5rem;
  padding: .5rem .75rem;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--clr-accent);
  background: var(--clr-accent-bg);
  border-radius: var(--radius-sm);
  margin-bottom: .6rem;
  border: 1px solid var(--clr-accent-border);
}

.item-row {
  display: grid;
  grid-template-columns: 3fr 1fr 1.4fr 1.2fr 36px;
  gap: .5rem;
  align-items: center;
  padding: .4rem 0;
  border-bottom: 1px solid var(--clr-border);
  transition: background .15s;
}

.item-row:last-child { border-bottom: none; }
.item-row:hover { background: var(--clr-bg); border-radius: var(--radius-sm); }

.item-total-cell {
  font-size: .88rem;
  font-weight: 600;
  color: var(--clr-accent);
  text-align: right;
  padding-right: .25rem;
}

.btn-remove-item {
  width: 28px; height: 28px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--clr-text-subtle);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
}

.btn-remove-item svg { width: 12px; height: 12px; }
.btn-remove-item:hover { background: #fef2f2; border-color: #fca5a5; color: #ef4444; }
body.dark .btn-remove-item:hover { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.3); color: #f87171; }

/* ── Calc Grid ────────────────────────────────────────── */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem;
  align-items: center;
}

.calc-grid .form-label { margin-bottom: 0; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .65rem 1.3rem;
  border-radius: var(--radius-sm);
  font-size: .86rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit;
  white-space: nowrap;
  transition: all .15s;
  letter-spacing: .01em;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: #1e3a5f;
  color: #fff;
  border-color: #1e3a5f;
  box-shadow: 0 1px 4px rgba(30,58,95,.25);
}

.btn-primary:hover {
  background: #163050;
  border-color: #163050;
  box-shadow: 0 4px 14px rgba(30,58,95,.3);
}

body.dark .btn-primary {
  background: #2d5986;
  border-color: #2d5986;
  color: #fff;
}
body.dark .btn-primary:hover { background: #255079; border-color: #255079; }

.btn-outline {
  background: transparent;
  color: var(--clr-text-muted);
  border-color: var(--clr-border);
}

.btn-outline:hover {
  background: var(--clr-bg);
  border-color: var(--clr-border-focus);
  color: var(--clr-text);
}

.btn-ghost {
  background: transparent;
  color: var(--clr-accent);
  border: 1px dashed var(--clr-accent-border);
  width: 100%;
  margin-top: .75rem;
  padding: .6rem;
  border-radius: var(--radius-sm);
  font-size: .84rem;
  font-weight: 500;
  transition: background .15s, border-color .15s;
}

.btn-ghost:hover {
  background: var(--clr-accent-bg);
  border-color: rgba(37,99,235,.4);
}

/* ── Actions Bar ──────────────────────────────────────── */
.actions-bar {
  display: flex;
  justify-content: flex-end;
  padding: .25rem 0 1.75rem;
}

.actions-bar .btn-primary {
  padding: .7rem 1.8rem;
  font-size: .9rem;
}

/* ── Preview Panel ────────────────────────────────────── */
.preview-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-sticky {
  display: flex;
  flex-direction: column;
  height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--clr-border);
}

/* Preview top bar */
.preview-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1rem;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  flex-shrink: 0;
}

.preview-topbar-left {
  display: flex;
  align-items: center;
  gap: .45rem;
}

.preview-topbar-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* Subtle decorative dots */
.preview-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--clr-border);
}

.preview-label {
  font-size: .68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--clr-text-subtle);
  margin-left: .3rem;
}

/* Clear button in topbar — subtle destructive ghost */
.btn-topbar-clear {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .32rem .7rem;
  border-radius: 5px;
  font-size: .75rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--clr-border);
  color: var(--clr-text-subtle);
  font-family: inherit;
  transition: background .15s, border-color .15s, color .15s;
}

.btn-topbar-clear:hover {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #dc2626;
}

body.dark .btn-topbar-clear:hover {
  background: rgba(220,38,38,.1);
  border-color: rgba(220,38,38,.3);
  color: #f87171;
}

/* Print button — same filled style as Download PDF */
.btn-print {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .34rem .85rem;
  border-radius: 5px;
  font-size: .76rem;
  font-weight: 500;
  cursor: pointer;
  background: #1e3a5f;
  border: 1px solid #1e3a5f;
  color: #fff;
  font-family: inherit;
  transition: background .15s, box-shadow .15s;
  box-shadow: 0 1px 3px rgba(30,58,95,.2);
}

.btn-print:hover { background: #163050; box-shadow: 0 3px 10px rgba(30,58,95,.3); }

.preview-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: #eceef1;
  scrollbar-width: thin;
  scrollbar-color: #d4d4d8 transparent;
}

body.dark .preview-scroll { background: #0a0a0c; }

.preview-scroll::-webkit-scrollbar { width: 4px; }
.preview-scroll::-webkit-scrollbar-thumb { background: #d4d4d8; border-radius: 99px; }

/* ── Invoice Document ─────────────────────────────────── */
.invoice-doc {
  background: #fff;
  color: #1c1c1e;
  margin: 1.25rem;
  border-radius: 8px;
  padding: 0;
  min-height: 500px;
  font-size: .88rem;
  line-height: 1.65;
  box-shadow: 0 2px 16px rgba(0,0,0,.08);
  border-top: 4px solid #1e3a5f;
  overflow: hidden;
}

.invoice-doc > *:not(.inv-header-band) {
  padding-left: 2.5rem;
  padding-right: 2.5rem;
}

.inv-header-band {
  background: linear-gradient(135deg, #f8fafc 0%, #eef2f7 100%);
  padding: 2rem 2.5rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

/* Invoice header band */
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.inv-brand { flex: 1; }

.inv-logo {
  max-height: 56px;
  max-width: 150px;
  margin-bottom: .75rem;
  object-fit: contain;
}

.inv-biz-name {
  font-size: 1rem;
  font-weight: 700;
  color: #1a2535;
  margin-bottom: .2rem;
  letter-spacing: -.01em;
}

.inv-biz-detail {
  font-size: .77rem;
  color: #6b6b6b;
  white-space: pre-line;
  line-height: 1.5;
}

.inv-meta { text-align: right; min-width: 185px; }

.inv-title {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: .2em;
  color: #fff;
  line-height: 1;
  margin-bottom: .85rem;
  background: #1e3a5f;
  display: inline-block;
  padding: .45rem .9rem .4rem;
  border-radius: 4px;
}

.inv-meta-table { margin-left: auto; }

.inv-meta-table td {
  padding: .2rem .4rem;
  font-size: .79rem;
}

.inv-meta-table td:first-child { color: #888; font-weight: 500; text-align: left; padding-right: 1rem; }
.inv-meta-table td:last-child  { color: #1a2535; font-weight: 600; text-align: right; }

.inv-divider {
  border: none;
  height: 1px;
  background: #e8e8e8;
  margin: 1.5rem 0;
}

/* Header band resets — header lives inside the band now */
.inv-header-band .inv-header {
  margin-bottom: 0;
}

/* Bill To section */
.inv-bill-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
  padding-top: 1.5rem;
}

.inv-bill-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #a0a0a0;
  margin-bottom: .4rem;
}

.inv-bill-name {
  font-size: .93rem;
  font-weight: 700;
  color: #1a2535;
  margin-bottom: .2rem;
}

.inv-bill-detail {
  font-size: .77rem;
  color: #6b6b6b;
  white-space: pre-line;
}

/* Items table */
.inv-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: .84rem;
}

.inv-items-table thead tr {
  background: #1e3a5f;
}

.inv-items-table thead th {
  padding: .65rem .85rem;
  text-align: left;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.8);
}

.inv-items-table thead th:first-child  { border-radius: 5px 0 0 0; }
.inv-items-table thead th:last-child   { border-radius: 0 5px 0 0; text-align: right; }
.inv-items-table thead th:nth-child(3),
.inv-items-table thead th:nth-child(4) { text-align: center; }

.inv-items-table tbody tr {
  border-bottom: 1px solid #f0f0f0;
  transition: background .1s;
}

.inv-items-table tbody tr:nth-child(even) { background: #fafafa; }
.inv-items-table tbody tr:hover { background: #f5f5f7; }

.inv-items-table tbody td {
  padding: .65rem .85rem;
  color: #333;
  vertical-align: top;
}

.inv-items-table tbody td:last-child   { text-align: right; font-weight: 600; color: #1a2535; }
.inv-items-table tbody td:nth-child(3),
.inv-items-table tbody td:nth-child(4) { text-align: center; }

/* Totals footer */
.inv-items-table tfoot td {
  padding: .4rem .85rem;
  font-size: .84rem;
  color: #555;
}

.inv-items-table tfoot td:last-child { text-align: right; }

.inv-items-table tfoot tr.subtotal-row td { padding-top: .75rem; }

.inv-items-table tfoot tr.total-row {
  border-top: 1.5px solid #1e3a5f;
}

.inv-items-table tfoot tr.total-row td {
  font-size: 1rem;
  font-weight: 700;
  color: #1e3a5f;
  padding: .7rem .85rem;
}

.inv-items-table tfoot tr.total-row td:last-child {
  font-size: 1.05rem;
  font-weight: 800;
}

.text-muted-inv { color: #ccc; font-style: italic; }

/* Bottom padding for invoice content */
.invoice-doc > *:last-child { padding-bottom: 2rem; }

/* Notes / Terms */
.inv-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid #ebebeb;
}

.inv-footer-section h4 {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #a0a0a0;
  margin-bottom: .4rem;
}

.inv-footer-section p {
  font-size: .8rem;
  color: #6b6b6b;
  white-space: pre-line;
  line-height: 1.55;
}

/* Empty state */
.inv-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 340px;
  gap: .75rem;
}

.inv-empty-state svg {
  width: 44px;
  height: 44px;
  opacity: .15;
  color: #18181b;
}

.inv-empty-state p {
  font-size: .88rem;
  color: #a1a1aa;
  text-align: center;
  max-width: 220px;
  line-height: 1.5;
}

/* ── Tax Rows ─────────────────────────────────────────── */
.tax-section { margin-bottom: .5rem; }

.tax-section-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .6rem;
}

.btn-add-tax {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .74rem;
  font-weight: 500;
  color: var(--clr-accent);
  background: var(--clr-accent-bg);
  border: 1px solid var(--clr-accent-border);
  border-radius: 5px;
  padding: .28rem .6rem;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .01em;
  transition: background .15s, border-color .15s;
}

.btn-add-tax:hover {
  background: rgba(37,99,235,.14);
  border-color: rgba(37,99,235,.35);
}

.tax-rows-head {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1.3fr 30px;
  gap: .4rem;
  padding: .35rem .5rem;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--clr-accent);
  background: var(--clr-accent-bg);
  border-radius: 5px;
  margin-bottom: .4rem;
  border: 1px solid var(--clr-accent-border);
}

.tax-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1.3fr 30px;
  gap: .4rem;
  align-items: center;
  padding: .3rem 0;
  border-bottom: 1px solid var(--clr-border);
}

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

.tax-amount-cell {
  font-size: .88rem;
  font-weight: 600;
  color: var(--clr-accent);
  text-align: right;
  padding-right: .2rem;
}

.calc-divider {
  border: none;
  border-top: 1px dashed var(--clr-border);
  margin: 1rem 0;
}

/* ── Toast ────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.75rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1e3a5f;
  color: #fff;
  padding: .65rem 1.4rem;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  z-index: 999;
  white-space: nowrap;
  pointer-events: none;
}

.toast.show   { transform: translateX(-50%) translateY(0); }
.toast.success { background: #166534; }
.toast.error   { background: #991b1b; }

/* ── Responsive (tablet / mobile) ────────────────────── */
@media (max-width: 1024px) {
  .app-main {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
    padding: 1.25rem;
  }

  .form-panel { overflow-y: visible; height: auto; }
  .preview-panel { height: auto; overflow: visible; }
  .preview-sticky { height: auto; }
  .preview-scroll { max-height: 680px; }
}

@media (max-width: 640px) {
  .app-main { padding: 1rem; gap: 1.25rem; }
  .header-inner { padding: 0 1rem; }
  .brand-tagline { display: none; }

  .form-row,
  .form-row.three-col { grid-template-columns: 1fr; }

  .items-header { display: none; }

  .item-row {
    grid-template-columns: 1fr 1fr;
    padding: .75rem .5rem;
    border-bottom: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    margin-bottom: .5rem;
  }

  .item-row .form-input:first-child { grid-column: 1 / -1; }

  .calc-grid { grid-template-columns: 1fr 1fr; }
  .invoice-doc { padding: 1.5rem; margin: .75rem; }
  .inv-header { flex-direction: column; gap: .75rem; }
  .inv-meta { text-align: left; }
  .inv-bill-section,
  .inv-footer { grid-template-columns: 1fr; }
}

/* ============================================================
   ADS — All ad-related styles isolated here.
   Ad logic lives in js/ads.js (separate from invoice logic).
============================================================ */

/* ── Ad Toggle Button (in header) ────────────────────── */
.ad-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 6px;
  color: rgba(255,255,255,.55);
  font-family: inherit;
  font-size: .74rem;
  font-weight: 500;
  padding: .35rem .65rem;
  cursor: pointer;
  letter-spacing: .01em;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.ad-toggle-btn:hover { background: rgba(255,255,255,.14); color: rgba(255,255,255,.85); }

/* When ads are hidden, dim the toggle label */
body.ads-hidden .ad-toggle-btn { opacity: .5; }

/* ── Ad Slot — Base ───────────────────────────────────── */
/* Slots are invisible containers until AdSense fills them */
.ad-slot {
  position: relative;
  text-align: center;
  transition: opacity .25s;
  /* No border, no background, no min-height — invisible when empty */
}

/* "Advertisement" label shown only once AdSense fills the slot */
.ad-label {
  display: none; /* Hidden until AdSense activates */
  font-size: .62rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--clr-text-subtle);
  margin-bottom: .3rem;
  user-select: none;
}

/* Show label when the adjacent ins tag has a filled ad */
.adsbygoogle[data-ad-status="filled"] ~ .ad-label,
.ad-slot:has(.adsbygoogle[data-ad-status="filled"]) .ad-label {
  display: block;
}

/* The ins tag (real AdSense) */
.ad-ins { width: 100%; }

/* Post-download "Sponsored" label — always visible when panel is open */
.pd-ad-label {
  display: block;
  font-size: .62rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--clr-text-subtle);
  margin: 0;
  position: static;
  user-select: none;
}

/* ── Slot-specific sizing & spacing ───────────────────── */

/* A — Top Banner — only shows visible chrome when ad is filled */
.ad-slot-top {
  padding: 0;
  background: transparent;
}
.ad-slot-top:has(.adsbygoogle[data-ad-status="filled"]) {
  padding: .5rem 2rem .4rem;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
}

/* B — In-Form (between cards in the left panel) */
.ad-slot-in-form {
  margin-bottom: 0;
  padding: 0;
  overflow: hidden;
  max-height: 0;
  transition: max-height .3s, margin .3s, padding .3s;
}

/* Only show when ad is filled */
.ad-slot-in-form:has(.adsbygoogle[data-ad-status="filled"]) {
  max-height: 400px;
  margin-bottom: 1rem;
  padding: .5rem 0;
}

/* C — Below Preview (inside right panel, below invoice window) */
.ad-slot-below-preview {
  padding: .5rem .5rem .4rem;
  border-top: 1px solid var(--clr-border);
  background: var(--clr-surface);
  flex-shrink: 0;
}

/* no placeholder to style */

/* D — Footer */
.ad-slot-footer {
  padding: .75rem 2rem .5rem;
}

/* ── Trust Strip ──────────────────────────────────────── */
.trust-strip {
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  border-bottom: 1px solid var(--clr-border);
  padding: .65rem 1.5rem;
}

.trust-strip-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .4rem 1.5rem;
}

.trust-badge {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  white-space: nowrap;
}

.trust-badge svg { color: var(--clr-accent); flex-shrink: 0; }

/* ── SEO Content Section ──────────────────────────────── */
.seo-section {
  background: var(--clr-bg);
  padding: 3.5rem 1.5rem 3rem;
}

.seo-inner {
  max-width: 940px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 3rem;
}

/* Each top-level content block */
.seo-block {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.seo-block > h2 {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--clr-text);
  border-bottom: 2px solid var(--clr-accent-bg);
  padding-bottom: .5rem;
  margin: 0;
}

.seo-block > p {
  font-size: .9rem;
  color: var(--clr-text-muted);
  line-height: 1.75;
  margin: 0;
}

.seo-block a { color: var(--clr-accent); }
.seo-block a:hover { text-decoration: underline; }

/* ── Why grid ── */
.why-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.why-item {
  display: flex;
  gap: .85rem;
  align-items: flex-start;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.why-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: var(--clr-accent-bg);
  border: 1px solid var(--clr-accent-border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--clr-accent);
}

.why-item strong {
  display: block;
  font-size: .875rem;
  font-weight: 700;
  color: var(--clr-text);
  margin-bottom: .25rem;
}

.why-item p {
  font-size: .8rem;
  color: var(--clr-text-muted);
  line-height: 1.55;
  margin: 0;
}

/* ── Steps list ── */
.steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.steps-list li {
  display: flex;
  align-items: flex-start;
  gap: .9rem;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: .9rem 1.1rem;
  font-size: .875rem;
  color: var(--clr-text-muted);
  line-height: 1.55;
}

.steps-list .step-num {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: var(--clr-accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  font-weight: 800;
}

.steps-list li strong { color: var(--clr-text); }

/* ── Invoice Format grid ── */
.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.format-item {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-left: 3px solid var(--clr-accent);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.format-item h3 {
  font-size: .82rem;
  font-weight: 700;
  color: var(--clr-accent);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 0 0 .4rem;
}

.format-item p {
  font-size: .82rem;
  color: var(--clr-text-muted);
  line-height: 1.6;
  margin: 0;
}

/* ── Who Uses It grid ── */
.who-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.who-item {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}

.who-item h3 {
  font-size: .875rem;
  font-weight: 700;
  color: var(--clr-text);
  margin: 0 0 .4rem;
}

.who-item p {
  font-size: .82rem;
  color: var(--clr-text-muted);
  line-height: 1.6;
  margin: 0;
}

/* ── About block ── */
.seo-about {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
}

.seo-about h2 {
  border-bottom-color: var(--clr-accent-bg);
}

/* ── FAQ block ── */
.seo-faq { gap: 1rem; }

.faq-item {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
}

.faq-q {
  font-size: .9rem;
  font-weight: 700;
  color: var(--clr-text);
  margin: 0 0 .4rem;
}

.faq-a {
  font-size: .85rem;
  color: var(--clr-text-muted);
  line-height: 1.7;
  margin: 0;
}

/* ── Resources/Blog grid ── */
.seo-blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.seo-blog-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 1.2rem;
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s;
  display: block;
}

.seo-blog-card:hover {
  border-color: var(--clr-accent-border);
  box-shadow: var(--shadow-md);
}

.seo-blog-card h3 {
  font-size: .875rem;
  font-weight: 700;
  color: var(--clr-accent);
  margin: 0 0 .4rem;
}

.seo-blog-card p {
  font-size: .82rem;
  color: var(--clr-text-muted);
  line-height: 1.55;
  margin: 0;
}

/* ── App Footer ───────────────────────────────────────── */
.app-footer {
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  padding-bottom: .75rem;
}

.footer-nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: .25rem 1.25rem;
  padding: .5rem 1rem .25rem;
}

.footer-nav a {
  font-size: .75rem;
  color: var(--clr-text-subtle);
  text-decoration: none;
  transition: color .15s;
}

.footer-nav a:hover { color: var(--clr-accent); }

.footer-copy {
  font-size: .7rem;
  color: var(--clr-text-subtle);
  text-align: center;
  padding: .35rem 0 .25rem;
  user-select: none;
}

/* ── Sticky Bottom Bar (Variant B / C) ───────────────── */
.ad-sticky-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 400;
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  box-shadow: 0 -4px 20px rgba(0,0,0,.08);
  padding: .5rem 1rem .5rem 2.5rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  transition: transform .3s ease, opacity .3s ease;
}

.sticky-close-btn {
  position: absolute;
  top: 50%;
  left: .55rem;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: var(--clr-border);
  color: var(--clr-text-subtle);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.sticky-close-btn:hover { background: var(--clr-bg); color: var(--clr-text); }

.ad-label-sticky {
  position: static;
  font-size: .6rem;
  letter-spacing: .06em;
  color: var(--clr-text-subtle);
  opacity: .75;
  white-space: nowrap;
}

.ad-sticky-bottom .ad-content { flex: 1; min-width: 0; }

.ad-placeholder-sticky {
  min-height: 50px;
}

/* ── Post-Download Panel ──────────────────────────────── */
.ad-post-download {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: min(340px, calc(100vw - 2rem));
  z-index: 450;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .25s ease;
}

.ad-post-download.pd-visible {
  transform: translateY(0);
  opacity: 1;
}

.ad-post-download.hidden { display: none !important; }

.pd-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .75rem .5rem;
  border-bottom: 1px solid var(--clr-border);
  background: var(--clr-bg);
}

.pd-title {
  flex: 1;
  font-size: .77rem;
  font-weight: 500;
  color: var(--clr-text);
}

.pd-close-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--clr-border);
  color: var(--clr-text-subtle);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.pd-close-btn:hover { background: var(--clr-bg); color: var(--clr-text); }

.pd-progress-track {
  height: 2px;
  background: var(--clr-border);
}
.pd-progress-bar {
  height: 100%;
  width: 100%;
  background: #1e3a5f;
}
body.dark .pd-progress-bar { background: #2d5986; }

.pd-ad-content {
  padding: .5rem;
}

/* ── Hide all ads when toggled off ───────────────────── */
body.ads-hidden .ad-slot {
  display: none;
}

/* ── Compensate main height for top banner ────────────
   ads.js sets --ad-top-h dynamically via JS measurement.
   Default 0 = no top banner (first load / ads hidden).
──────────────────────────────────────────────────────── */
:root { --ad-top-h: 0px; }

/* ── Responsive ───────────────────────────────────────── */

@media (max-width: 1024px) {
  .ad-slot-top  { padding: .4rem 1rem .3rem; }
  .ad-slot-footer { padding: .5rem 1rem .4rem; }

  .ad-slot-below-preview {
    border-top: none;
    padding: .5rem 0;
  }
}

@media (max-width: 640px) {
  .ad-slot-top   { padding: .35rem .75rem .3rem; }
  .ad-label      { font-size: .6rem; }
}

/* ── Print: hide all ads ──────────────────────────────── */
@media print {
  .app-header,
  .site-nav,
  .form-panel,
  .preview-topbar,
  .ad-slot,
  .ad-sticky-bottom,
  .ad-post-download,
  .trust-strip,
  .seo-section,
  .app-footer,
  .toast { display: none !important; }

  body {
    background: #fff !important;
    background-image: none !important;
  }

  .app-main { display: block; padding: 0; margin: 0; max-width: none; height: auto; overflow: visible; }
  .preview-panel { display: block; width: 100%; height: auto; overflow: visible; }
  .preview-sticky { border: none; box-shadow: none; border-radius: 0; overflow: visible; height: auto; }
  .preview-scroll { background: #fff; overflow: visible; max-height: none; }
  .invoice-doc { margin: 0; border-radius: 0; box-shadow: none; padding: 0; border-top: none; }
  .invoice-doc > *:not(.inv-header-band) { padding-left: 1.5rem; padding-right: 1.5rem; }
  .inv-header-band { background: #fff; border-bottom: 1px solid #e8e8e8; padding: 1.5rem 1.5rem 1rem; }
  .inv-title { background: #1e3a5f; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv-items-table thead tr { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
