:root {
  --navy: #1E293E;
  --gold: #CBA54D;
  --light-gold: #E0C585;
  --bg: #F9FAFB;
  --white: #FFFFFF;
  --border: #DCE0E5;
  --muted: #676F7E;
  --danger: #B42318;
  --ok: #1B7A4E;
  --header-h: 72px;
  --radius: 8px;
  --max: 1120px;
  --font-heading: "Playfair Display", Georgia, serif;
  --font-body: "Source Sans 3", "Source Sans Pro", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; scroll-padding-top: var(--header-h); }

body {
  font-family: var(--font-body);
  color: var(--navy);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 3.25rem;
}

img { display: block; max-width: 100%; height: auto; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }

.container { width: min(100% - 48px, var(--max)); margin-inline: auto; }

.site-header {
  position: fixed; inset: 0 0 auto; z-index: 1000;
  height: var(--header-h);
  background: rgba(30, 41, 62, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(203, 165, 77, 0.15);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: var(--header-h); gap: 24px; }
.brand { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.brand-logo { height: 44px; width: 44px; object-fit: cover; object-position: center 18%; border-radius: 4px; background: var(--white); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--font-heading); font-weight: 700; color: var(--white); font-size: 1.05rem; letter-spacing: 0.04em; }
.brand-sub { font-size: 0.7rem; color: var(--gold); letter-spacing: 0.08em; text-transform: uppercase; }
.nav { display: flex; align-items: center; gap: 20px; }
.nav-links { display: flex; gap: 18px; align-items: center; }
.nav-links a { color: rgba(249,250,251,0.88); font-weight: 600; font-size: 0.95rem; }
.nav-links a:hover, .nav-links a:focus-visible { color: var(--gold); }
.nav-toggle { display: none; flex-direction: column; gap: 5px; background: none; border: 0; cursor: pointer; padding: 8px; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: var(--white); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 6px; font-weight: 700; font-size: 0.95rem;
  border: 1px solid transparent; cursor: pointer; font-family: inherit; line-height: 1.2;
}
.btn-sm { padding: 7px 12px; font-size: 0.85rem; }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover, .btn-gold:focus-visible { background: var(--light-gold); }
.btn-navy { background: var(--navy); color: #F9FAFB; }
.btn-navy:hover, .btn-navy:focus-visible { background: #2a3a55; }
.btn-nav { padding: 8px 14px; font-size: 0.85rem; }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--border); }
.btn-ghost:hover { background: #EEF1F5; }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: #F3D1CD; }
.btn-danger-ghost:hover { background: #FDF2F0; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.tool-page { padding: calc(var(--header-h) + 32px) 0 64px; }
.tool-intro { margin-bottom: 24px; max-width: 720px; }
.tool-intro h1 { font-family: var(--font-heading); font-size: clamp(1.8rem, 3vw, 2.4rem); margin: 8px 0 12px; }
.tool-intro p { color: var(--muted); }
.privacy-note { margin-top: 10px; font-size: 0.95rem; color: var(--navy); background: #EEF2F7; border-left: 3px solid var(--gold); padding: 10px 14px; border-radius: 0 6px 6px 0; }
.back-to-tools { margin-bottom: 4px; font-size: 0.9rem; font-weight: 600; }
.back-to-tools a { color: var(--navy); }
.back-to-tools a:hover { color: var(--gold); }

.tool-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.tab-button {
  appearance: none; border: 1px solid var(--border); background: var(--white); color: var(--navy);
  padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 0.9rem; cursor: pointer; font-family: inherit;
}
.tab-button.active, .tab-button[aria-current="page"] { background: var(--navy); color: #F9FAFB; border-color: var(--navy); }

.view[hidden] { display: none !important; }
.view-title { font-family: var(--font-heading); font-size: 1.5rem; margin-bottom: 6px; }
.view-intro { color: var(--muted); margin-bottom: 16px; }
.view-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 8px; }
.view-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.subhead { font-family: var(--font-heading); font-size: 1.15rem; margin: 28px 0 12px; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 16px 0 8px; }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: 0 8px 24px rgba(30,41,62,0.04); }
.stat-label { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-family: var(--font-heading); font-size: 1.55rem; margin-top: 6px; }

.setup-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  background: #F7F1E3; border: 1px solid #E8D7A8; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
}
.setup-banner[hidden] { display: none !important; }
.setup-banner p { margin: 0; color: var(--navy); max-width: 640px; }

.card, .form-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 20px; margin-bottom: 20px; box-shadow: 0 8px 24px rgba(30,41,62,0.04);
}
.form-card h3 { font-family: var(--font-heading); font-size: 1.15rem; margin: 18px 0 12px; }
.form-card h3:first-child { margin-top: 0; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.form-control {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
  font: inherit; color: var(--navy); background: var(--white);
}
textarea.form-control { min-height: 88px; resize: vertical; }
.form-control:focus { outline: 2px solid rgba(203,165,77,0.45); border-color: var(--gold); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.form-error { color: var(--danger); margin-top: 10px; font-size: 0.9rem; }
.form-ok { color: var(--ok); margin-top: 10px; font-size: 0.9rem; font-weight: 600; }
.hint { font-size: 0.85rem; color: var(--muted); margin-top: 8px; }

.logo-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.logo-preview {
  width: 80px; height: 80px; border: 1px solid var(--border); border-radius: 14px; background: #F3F5F8;
  display: grid; place-items: center; overflow: hidden; font-size: 0.7rem; color: var(--muted); text-align: center;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }

.doc-list { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--white); }
.doc-list:empty::after,
.empty-state {
  display: block; text-align: center; padding: 48px 24px; color: var(--muted); border: 1px dashed #C5CBD4;
  border-radius: var(--radius); background: #F3F5F8;
}
.doc-row {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; background: var(--white); width: 100%; text-align: left; font: inherit; color: inherit;
}
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: #F7F8FA; }
.doc-row .meta { flex: 1; min-width: 0; }
.doc-row .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-row .sub { font-size: 0.85rem; color: var(--muted); }
.doc-row .amount { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 6.5rem; text-align: right; }
.status-pill {
  display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; text-transform: capitalize; background: #EEF1F5; color: var(--navy);
}
.status-pill.paid, .status-pill.accepted { background: #E5F4EC; color: var(--ok); }
.status-pill.sent, .status-pill.invoiced { background: #EEF2F7; color: var(--navy); }
.status-pill.overdue, .status-pill.declined, .status-pill.void { background: #FDF2F0; color: var(--danger); }
.status-pill.draft { background: #EEF1F5; color: var(--muted); }

.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 20px; align-items: start; }
.lines-head, .line-row {
  display: grid; grid-template-columns: minmax(0, 2.2fr) 70px 110px 100px 36px; gap: 8px; align-items: center;
}
.lines-head { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.line-row { margin-bottom: 8px; }
.line-row .form-control { min-height: 40px; padding: 8px 10px; }
.line-remove { appearance: none; border: 0; background: transparent; color: var(--danger); font-size: 1.25rem; cursor: pointer; line-height: 1; }

.print-sheet {
  background: var(--white); border: 1px solid var(--border); border-radius: 12px; padding: 28px;
  box-shadow: 0 18px 40px -28px rgba(26,23,20,0.45); font-size: 0.95rem;
}
.ps-header { display: flex; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); padding-bottom: 18px; margin-bottom: 18px; flex-wrap: wrap; }
.ps-brand { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.ps-logo { width: 72px; height: 72px; border-radius: 10px; object-fit: contain; background: #F3F5F8; }
.ps-logo-fallback { width: 72px; height: 72px; border-radius: 10px; background: var(--navy); color: var(--gold); display: grid; place-items: center; font-family: var(--font-heading); font-size: 1.8rem; }
.ps-company { font-family: var(--font-heading); font-size: 1.35rem; }
.ps-muted { color: var(--muted); font-size: 0.85rem; white-space: pre-line; }
.ps-doc-type { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.ps-number { font-family: var(--font-heading); font-size: 1.6rem; }
.ps-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 22px; }
.ps-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.ps-table { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
.ps-table th, .ps-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.ps-table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ps-table td.num, .ps-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ps-totals { margin-left: auto; width: min(280px, 100%); }
.ps-totals div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; }
.ps-totals .grand { border-top: 2px solid var(--navy); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 1.05rem; }
.ps-footer { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; white-space: pre-line; }

.site-footer {
  background: var(--navy); color: rgba(249,250,251,0.85); text-align: center; padding: 40px 0 28px; margin-top: 24px;
}
.footer-brand-name { font-family: var(--font-heading); font-size: 1.2rem; color: #fff; letter-spacing: 0.08em; }
.footer-brand-sub { display: block; color: var(--gold); font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 4px; }
.footer-tagline { margin-top: 10px; font-style: italic; }
.footer-rule { border: 0; border-top: 1px solid rgba(203,165,77,0.25); margin: 18px auto; width: min(280px, 60%); }
.footer-copy { font-size: 0.85rem; }
.footer-links { margin-top: 8px; font-size: 0.85rem; }
.footer-links a:hover { color: var(--gold); }
.footer-sep { margin: 0 8px; opacity: 0.5; }

.bridgeroy-soft-cta {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; gap: 0.75rem; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 0.65rem 1rem; background: #1E293E; color: #F9FAFB;
  font: 500 13px/1.4 var(--font-body); box-shadow: 0 -4px 20px rgba(30,41,62,.25);
}
.bridgeroy-soft-cta a { color: #CBA54D; font-weight: 600; text-decoration: underline; }
.bridgeroy-soft-cta-close { appearance: none; border: 0; background: transparent; color: rgba(249,250,251,.7); cursor: pointer; font-size: 18px; line-height: 1; padding: 0.25rem; }

@media (max-width: 900px) {
  .stats-grid, .form-grid-2, .editor-layout, .ps-grid { grid-template-columns: 1fr; }
  .lines-head { display: none; }
  .line-row { grid-template-columns: 1fr 1fr; }
  .line-row .desc { grid-column: 1 / -1; }
  .nav-toggle { display: flex; }
  .nav { display: none; position: absolute; top: var(--header-h); left: 0; right: 0; background: var(--navy); padding: 16px 24px 24px; flex-direction: column; align-items: stretch; }
  .nav.open { display: flex; }
  .nav-links { flex-direction: column; align-items: flex-start; gap: 12px; }
  .doc-row .amount { display: none; }
}

@media print {
  body { background: #fff; padding: 0; color: #000; }
  .no-print, .site-header, .site-footer, .bridgeroy-soft-cta, .tool-tabs, .tool-intro, .editor-controls, .view-head { display: none !important; }
  .tool-page { padding: 0; }
  .container { width: 100%; max-width: none; }
  #editor-view { display: block !important; }
  .print-sheet { border: 0; box-shadow: none; border-radius: 0; padding: 0; max-width: none; }
  .editor-layout { display: block; }
}
