/* ==========================================================================
   Invoice Generator — styles
   Screen UI is theme-aware; the invoice document itself stays paper-white in
   both themes, because it is a document, not chrome.
   ========================================================================== */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --text: #16202e;
  --text-muted: #66748a;
  --border: #dfe4ec;
  --border-strong: #c6cedb;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgba(16, 26, 42, .06), 0 8px 24px rgba(16, 26, 42, .06);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --surface: #171e29;
    --surface-2: #1c2431;
    --text: #e8edf5;
    --text-muted: #97a3b6;
    --border: #2a3444;
    --border-strong: #3a4658;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is display:none at the lowest precedence, so any
   author `display` declaration silently defeats it. Several elements here are
   toggled via the hidden property AND carry a display rule (.inv-total-row,
   .inv-logo), so restate it as a winning rule. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }

/* ---------------------------------------------------------------- header */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; height: 60px;
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 650; font-size: 16px; color: var(--text); text-decoration: none;
}
.brand-mark { font-size: 20px; }
.header-actions { display: flex; gap: 8px; }

/* --------------------------------------------------------------- buttons */
.btn {
  font: inherit; font-weight: 550;
  padding: 8px 15px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 11px; font-size: 13.5px; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-ghost {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ----------------------------------------------------------- page intro */
.page-intro { padding-top: 26px; max-width: 780px; margin-left: 0; }
.page-intro h1 {
  margin: 0 0 8px;
  font-size: 27px; line-height: 1.2; letter-spacing: -.02em;
}
.page-intro p { margin: 0; color: var(--text-muted); max-width: 68ch; }
.page-intro .tool-crosslink { margin-top: 10px; font-size: 13.5px; }
.page-intro .tool-crosslink a { color: var(--accent); font-weight: 550; }
@media (max-width: 560px) {
  .page-intro h1 { font-size: 23px; }
}

/* Confirms a silent cross-tool data hand-off (quote -> invoice) actually
   happened, since the alternative is fields simply changing with no
   explanation. */
.import-toast {
  /* 60px header height (.header-inner) + 14px gap, so it never overlaps the nav. */
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%);
  z-index: 50; max-width: min(92vw, 480px);
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); border-radius: 10px;
  padding: 11px 12px 11px 16px;
  font-size: 13.5px;
}
.import-toast button {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 4px;
}
.import-toast button:hover { color: var(--text); }

/* Tool cards on the hub page. */
.tool-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px;
  margin: 22px 0 30px;
}
@media (max-width: 640px) {
  .tool-grid { grid-template-columns: 1fr; }
}
.tool-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; text-decoration: none; color: var(--text);
  transition: border-color .15s, transform .1s;
}
.tool-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.tool-card__icon { font-size: 28px; line-height: 1; }
/* Explicit color, not inherited: `.prose a:not(.btn-cta)` (0-2-1) otherwise
   beats `.tool-card`'s own color (0-1-0) and paints this accent blue. */
.tool-card__name { font-size: 17px; font-weight: 650; margin-top: 2px; color: var(--text); }
.tool-card__desc { font-size: 13.5px; color: var(--text-muted); line-height: 1.5; }
.tool-card__cta { font-size: 13.5px; font-weight: 600; color: var(--accent); margin-top: 6px; }

/* Cross-links to the profession guides — internal linking consolidates
   authority across the cluster rather than stranding each page. */
.prof-links { list-style: none; padding: 0; margin: 14px 0 0; }
.prof-links li {
  padding: 11px 0; border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 2px 12px; align-items: baseline;
}
.prof-links li:first-child { border-top: 1px solid var(--border); }
.prof-links a { font-weight: 550; text-decoration: none; }
.prof-links a:hover { text-decoration: underline; }
.prof-links span { color: var(--text-muted); font-size: 13.5px; }

/* --------------------------------------------------------------- layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 24px;
  /* Columns must stretch to the full row height, otherwise the preview column
     ends where its own content ends and the sticky preview un-pins partway
     down the (much taller) editor column. */
  align-items: stretch;
  padding-top: 22px; padding-bottom: 40px;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.editor { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-title { margin: 0 0 14px; font-size: 13px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.card-head { display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; }
.card-head .card-title { margin: 0; }

/* ---------------------------------------------------------------- fields */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > span { font-size: 12.5px; font-weight: 550; color: var(--text-muted); }

input, textarea, select {
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--text-muted) 70%, transparent); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
@media (max-width: 560px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.hint { margin: 6px 0 0; font-size: 12px; color: var(--text-muted); }

/* ------------------------------------------------------------------ logo */
.logo-row { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.logo-preview {
  width: 88px; height: 88px; flex: none;
  border: 1px dashed var(--border-strong); border-radius: 8px;
  display: grid; place-items: center; overflow: hidden;
  background: var(--surface-2);
  font-size: 11.5px; color: var(--text-muted);
}
.logo-preview[data-empty="false"] { border-style: solid; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.logo-controls .hint { width: 100%; margin: 0; }

/* ------------------------------------------------------------ line items */
.items { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px 100px 34px;
  gap: 8px; align-items: center;
}
.item-row .amount-cell {
  font-variant-numeric: tabular-nums; font-size: 13.5px;
  color: var(--text-muted); text-align: right; padding-right: 2px;
}
.item-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px 100px 34px;
  gap: 8px;
  font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.item-head span:not(:first-child) { text-align: right; }
.btn-remove {
  background: none; border: 1px solid var(--border); border-radius: 7px;
  color: var(--text-muted); cursor: pointer;
  width: 34px; height: 34px; font-size: 16px; line-height: 1;
}
.btn-remove:hover { border-color: #e0564f; color: #e0564f; }
@media (max-width: 560px) {
  .item-row, .item-head { grid-template-columns: minmax(0, 1fr) 64px 84px 32px; }
}

.privacy-note {
  margin: 0; padding: 12px 14px;
  font-size: 13px; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* --------------------------------------------------------------- preview */
.preview-pane { min-width: 0; }
.preview-sticky { position: sticky; top: 82px; }
@media (max-width: 960px) { .preview-sticky { position: static; } }

.preview-bar {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 8px;
}
.saved-flag { text-transform: none; letter-spacing: 0; font-weight: 500; }

/* The invoice document — deliberately fixed to a light palette. */
.invoice {
  background: #ffffff;
  color: #1a2230;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 32px;
  font-size: 13.5px;
}

.inv-top { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.inv-logo { max-height: 56px; max-width: 190px; object-fit: contain; margin-bottom: 10px; display: block; }
.inv-biz { font-size: 16px; font-weight: 650; }
.inv-muted { color: #67748a; white-space: pre-line; font-size: 12.5px; line-height: 1.5; }
.inv-title-block { text-align: right; flex: none; }
.inv-title { margin: 0; font-size: 26px; letter-spacing: .1em; font-weight: 650; color: #1a2230; }

.inv-meta {
  display: flex; justify-content: space-between; gap: 24px;
  margin: 26px 0 20px; padding-top: 18px; border-top: 1px solid #e6eaf1;
}
.inv-label {
  font-size: 10.5px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .07em; color: #8a94a6;
}
.inv-strong { font-weight: 600; margin-top: 2px; }
.inv-dates { text-align: right; display: flex; flex-direction: column; gap: 4px; }
.inv-dates .inv-label { display: inline; margin-right: 6px; }

.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.inv-table th {
  font-size: 10.5px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .07em; color: #8a94a6; text-align: left;
  padding: 0 0 8px; border-bottom: 1px solid #e6eaf1;
}
.inv-table th.c-num, .inv-table td.c-num { text-align: right; }
.inv-table td {
  padding: 9px 0; border-bottom: 1px solid #f0f2f7;
  vertical-align: top; font-variant-numeric: tabular-nums;
}
.inv-table td.c-desc { white-space: pre-line; padding-right: 14px; }
.inv-empty { color: #99a2b2; font-style: italic; }

.inv-totals { margin-left: auto; width: min(300px, 100%); }
.inv-total-row {
  display: flex; justify-content: space-between; gap: 20px;
  padding: 6px 0; font-variant-numeric: tabular-nums;
}
.inv-total-row span:first-child { color: #67748a; }
.inv-grand {
  border-top: 1.5px solid #1a2230; margin-top: 6px; padding-top: 10px;
  font-size: 16px; font-weight: 650;
}
.inv-grand span:first-child { color: #1a2230; }

.inv-foot {
  margin-top: 26px; padding-top: 16px; border-top: 1px solid #e6eaf1;
  display: flex; flex-direction: column; gap: 12px;
}
.inv-foot p { margin: 3px 0 0; color: #67748a; white-space: pre-line; font-size: 12.5px; }
.inv-foot:not(:has(> div:not([hidden]))) { display: none; }

/* Quote/estimate-specific: a screen-only warning when today is past the
   "valid until" date. Deliberately excluded from the printed PDF via
   .no-print below — a client shouldn't receive a quote pre-flagged as
   expired; the warning is there to prompt the sender to reissue it instead. */
.doc-expiry-note {
  margin-top: 8px; font-size: 12px; font-weight: 600;
  color: #9a5a12; background: #fdf1de; border: 1px solid #f0d8ae;
  border-radius: 6px; padding: 6px 10px; display: inline-block;
}
.estimate-disclaimer {
  font-size: 11.5px; color: #8a94a6; margin-top: 6px; text-align: right;
}

/* A screen-only CTA offered after a quote's preview — hidden from the PDF
   automatically since print only reveals .print-doc, but marked explicitly
   in case it is ever moved inside the document article. */
.convert-cta {
  margin-top: 16px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.convert-cta p { margin: 0 0 10px; font-size: 13.5px; color: var(--text-muted); }
.convert-cta p strong { color: var(--text); }

/* -------------------------------------------------------------- ad slots */
.ad-slot {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  margin: 18px auto;
}
.ad-slot__label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); opacity: .7;
}
/* Fixed dimensions reserve space so a later ad insert shifts nothing. */
.ad-slot__inner {
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}
.ad-slot--leaderboard .ad-slot__inner { width: 728px; height: 90px; max-width: 100%; }
.ad-slot--rect .ad-slot__inner { width: 300px; height: 250px; }
@media (max-width: 780px) {
  .ad-slot--leaderboard .ad-slot__inner { width: 320px; height: 100px; }
}

/* ------------------------------------------------------------------- nav */
.site-nav { display: flex; gap: 18px; align-items: center; }
.site-nav a {
  color: var(--text-muted); text-decoration: none;
  font-size: 14px; font-weight: 500;
}
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
@media (max-width: 720px) {
  .site-nav { display: none; }
}

/* ----------------------------------------------------------------- prose */
.prose { padding: 10px 20px 48px; max-width: 760px; }
.prose h2 { font-size: 21px; margin: 32px 0 10px; letter-spacing: -.01em; }
.prose h2:first-child { margin-top: 12px; }
.prose h3 { font-size: 16px; margin: 26px 0 6px; }
.prose p { color: var(--text-muted); margin: 0 0 12px; }
.prose ul, .prose ol { color: var(--text-muted); margin: 0 0 12px; padding-left: 22px; }
.prose li { margin-bottom: 7px; }
.prose li > strong { color: var(--text); }
/* Excludes button-styled links: a bare `.prose a` rule outranks `.btn-cta`
   (0-1-1 vs 0-1-0) and would paint the label the same blue as its background. */
.prose a:not(.btn-cta) { color: var(--accent); }
.prose .lede { font-size: 16.5px; color: var(--text); }

/* Numbered how-to steps — visually distinct from a plain list. */
.steps { list-style: none; padding: 0; margin: 0 0 12px; counter-reset: step; }
.steps > li {
  position: relative; padding-left: 42px; margin-bottom: 18px;
  counter-increment: step;
}
.steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: -1px;
  width: 27px; height: 27px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text);
  font-size: 13px; font-weight: 650;
}
.steps strong { display: block; color: var(--text); margin-bottom: 2px; }

/* FAQ — native disclosure widgets, no JS required. */
.faq { border-top: 1px solid var(--border); margin-top: 8px; }
.faq details {
  border-bottom: 1px solid var(--border);
}
.faq summary {
  cursor: pointer; padding: 14px 0; font-weight: 550;
  list-style: none; display: flex; justify-content: space-between; gap: 16px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: '+'; color: var(--text-muted); font-size: 18px; line-height: 1;
  flex: none; transition: transform .18s;
}
.faq details[open] summary::after { content: '−'; }
.faq details > p { margin: 0 0 14px; color: var(--text-muted); }

.callout {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 0 0 14px;
}
.callout p { margin: 0; }
.callout p + p { margin-top: 8px; }

.meta-line { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }

/* Primary call-to-action on the profession guides. */
.cta-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin: 22px 0 30px;
}
.cta-box p { margin: 0 0 14px; }
.btn-cta {
  display: inline-block;
  background: var(--accent); color: var(--accent-text);
  text-decoration: none; font-weight: 600;
  padding: 11px 20px; border-radius: 9px;
}
.btn-cta:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.cta-note { font-size: 13px; color: var(--text-muted); margin: 12px 0 0 !important; }

/* ---------------------------------------------------------------- footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 26px 0 34px;
  color: var(--text-muted); font-size: 13px;
}
.site-footer p { margin: 0; }
.footer-links {
  display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 10px;
}
.footer-links a { color: var(--text-muted); text-decoration: none; }
.footer-links a:hover { color: var(--text); text-decoration: underline; }

/* ==========================================================================
   PRINT — only the element carrying .print-doc reaches paper.
   Every tool's preview document (invoice, quote, and future ones) shares this
   class rather than the print rule targeting a tool-specific ID, so one rule
   serves the whole cluster.

   The visibility technique keeps the document's internal layout intact while
   collapsing everything else, which display:none on ancestors would break.
   ========================================================================== */
@media print {
  @page { size: A4; margin: 14mm; }

  body { background: #fff; }
  body * { visibility: hidden; }
  .print-doc, .print-doc * { visibility: visible; }

  .print-doc {
    position: absolute; inset: 0 auto auto 0;
    width: 100%;
    margin: 0; padding: 0;
    border: none; border-radius: 0; box-shadow: none;
    font-size: 11pt;
  }

  .preview-sticky { position: static; }
  .no-print { display: none !important; }

  /* Keep rows and the totals block from splitting across pages. */
  .inv-table tr, .inv-totals, .inv-foot { break-inside: avoid; }
  .inv-table thead { display: table-header-group; }
}
