/* ============================================================
   Free Invoice Generator — styles
   App UI: warm-dark teal + amber, Sora/Inter pairing.
   Printed invoice: classic, clean, black-on-white.
   ============================================================ */

:root {
  --teal-900: #0a2e2f;
  --teal-800: #0f3d3e;
  --teal-700: #155253;
  --teal-50:  #eef6f5;
  --amber:    #f4b942;
  --amber-dk: #d99a1f;
  --ink:      #14201f;
  --ink-soft: #41514f;
  --line:     #d9e3e1;
  --line-soft:#e8eeed;
  --paper:    #ffffff;
  --bg:       #f3f6f5;
  --danger:   #b3261e;
  --focus:    #1f7a7c;
  --radius:   14px;
  --radius-sm:10px;
  --shadow:   0 10px 30px -12px rgba(10, 46, 47, .28);
  --shadow-sm:0 2px 8px -4px rgba(10, 46, 47, .25);
  --font-ui:  'Inter', system-ui, sans-serif;
  --font-display: 'Sora', 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(1200px 480px at 80% -10%, rgba(244,185,66,.10), transparent 60%),
    var(--bg);
  line-height: 1.5;
}

.wrap { width: min(1180px, 100% - 2rem); margin-inline: auto; }

/* Accessibility */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--teal-800); color: #fff; padding: .6rem 1rem;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Header ---------- */
.site-header {
  background: var(--teal-800);
  color: #fff;
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow-sm);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: .85rem 0; }
.brand { display: flex; align-items: center; gap: .6rem; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--amber); color: var(--teal-900);
  font-family: var(--font-display); font-weight: 700; font-size: 1.25rem;
}
.brand-name { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
.ghost-link {
  color: #fff; text-decoration: none; font-weight: 500; font-size: .92rem;
  padding: .45rem .7rem; border: 1px solid rgba(255,255,255,.35); border-radius: 999px;
  transition: background .15s ease;
}
.ghost-link:hover { background: rgba(255,255,255,.12); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 2rem;
  padding: 2rem 0 3rem;
  align-items: start;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; gap: 1.5rem; }
  .preview-col { order: -1; } /* show preview first on mobile? No—keep editor first */
}
@media (max-width: 960px) {
  .preview-col { order: 2; }
  .editor { order: 1; }
}

/* ---------- Editor ---------- */
.editor-intro h1 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem);
  line-height: 1.15; letter-spacing: -.02em; margin: 0 0 .4rem;
  color: var(--teal-900);
}
.lede { color: var(--ink-soft); margin: 0 0 1.4rem; max-width: 44ch; }

.card {
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem 1.25rem;
  margin: 0 0 1.1rem;
  box-shadow: var(--shadow-sm);
}
.card legend {
  font-family: var(--font-display);
  font-weight: 600; font-size: 1rem; color: var(--teal-800);
  padding: 0 .4rem; margin-left: -.4rem;
}
.hint { font-weight: 400; color: var(--ink-soft); font-size: .82em; }

.field { margin-top: .85rem; }
.field:first-of-type { margin-top: .6rem; }
.field label { display: block; font-weight: 500; font-size: .86rem; margin-bottom: .3rem; color: var(--ink); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
@media (max-width: 460px) { .grid-2 { grid-template-columns: 1fr; } }

input, select, textarea {
  width: 100%;
  font: inherit; font-size: .95rem;
  color: var(--ink);
  background: #fcfdfd;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover, select:hover, textarea:hover { border-color: #b9c8c6; }
input:focus, select:focus, textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(31,122,124,.15);
  outline: none;
}
textarea { resize: vertical; min-height: 2.6rem; }
input[type="file"] { padding: .45rem; background: #fff; cursor: pointer; }
.micro { font-size: .76rem; color: var(--ink-soft); margin: .35rem 0 0; }

/* ---------- Line items ---------- */
.items-head {
  display: grid;
  grid-template-columns: 1fr 70px 110px 110px 34px;
  gap: .5rem;
  font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft);
  padding: 0 .15rem .5rem;
}
.ih-qty, .ih-price, .ih-total { text-align: right; }
.item-row {
  display: grid;
  grid-template-columns: 1fr 70px 110px 110px 34px;
  gap: .5rem;
  align-items: center;
  margin-bottom: .5rem;
}
.item-row .amt {
  text-align: right; font-variant-numeric: tabular-nums;
  font-weight: 600; color: var(--teal-800); padding-right: .15rem;
  font-size: .92rem;
}
.item-row input { padding: .5rem .55rem; }
.item-row .qty, .item-row .price { text-align: right; }
.rm-btn {
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--line); background: #fff; color: var(--danger);
  border-radius: 8px; cursor: pointer; font-size: 1.1rem; line-height: 1;
  display: grid; place-items: center;
  transition: background .15s ease, border-color .15s ease;
}
.rm-btn:hover { background: #fff0ef; border-color: #e3b6b3; }
@media (max-width: 560px) {
  .items-head { display: none; }
  .item-row {
    grid-template-columns: 1fr 34px;
    grid-template-areas: "desc desc" "qty rm" "price rm" "amt rm";
    gap: .4rem .5rem;
    padding: .6rem; border: 1px solid var(--line-soft); border-radius: 10px;
    background: #fafcfb;
  }
  .item-row .desc  { grid-area: desc; }
  .item-row .qty   { grid-area: qty; text-align: left; }
  .item-row .price { grid-area: price; text-align: left; }
  .item-row .amt   { grid-area: amt; text-align: left; }
  .item-row .rm-btn{ grid-area: rm; align-self: start; }
  .item-row .qty::before   { content: "Qty"; }
  .item-row .price::before { content: "Price"; }
  .item-row .mlabel { font-size: .72rem; color: var(--ink-soft); display: block; }
}

.add-btn {
  margin-top: .4rem;
  background: var(--teal-50); color: var(--teal-800);
  border: 1px dashed #9cc1bf; border-radius: var(--radius-sm);
  padding: .6rem .9rem; font: inherit; font-weight: 600; cursor: pointer;
  width: 100%;
  transition: background .15s ease;
}
.add-btn:hover { background: #e2efed; }

/* ---------- Actions ---------- */
.actions {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  margin-top: 1.2rem;
}
.primary-btn {
  background: var(--amber); color: var(--teal-900);
  border: none; border-radius: var(--radius-sm);
  padding: .8rem 1.2rem; font: inherit; font-weight: 700; font-size: 1rem;
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .12s ease, background .15s ease;
}
.primary-btn:hover { background: var(--amber-dk); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn.small { padding: .5rem .85rem; font-size: .88rem; }
.secondary-btn {
  background: #fff; color: var(--teal-800);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .8rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: .3rem;
  transition: border-color .15s ease, background .15s ease;
}
.secondary-btn:hover { border-color: var(--teal-700); background: var(--teal-50); }
.file-label { cursor: pointer; }
.link-btn {
  background: none; border: none; color: var(--ink-soft);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: underline;
  padding: .4rem;
}
.link-btn:hover { color: var(--ink); }
.link-btn.danger { color: var(--danger); }
.autosave { margin-top: .65rem; }

/* ---------- Cross-CTAs ---------- */
.cta-stack { display: grid; gap: .8rem; margin-top: 1.6rem; }
.cta {
  display: block; text-decoration: none;
  border-radius: var(--radius); padding: 1rem 1.15rem;
  border: 1px solid var(--line-soft);
  transition: transform .12s ease, box-shadow .15s ease;
}
.cta:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.cta strong { display: block; font-family: var(--font-display); font-size: 1rem; margin-bottom: .15rem; }
.cta span { font-size: .9rem; }
.cta.nudge { background: linear-gradient(135deg, #fff6e6, #fdeccf); color: #5b4413; border-color: #f0d9a8; }
.cta.pv { background: var(--teal-800); color: #fff; border-color: var(--teal-700); }
.cta.pv span { color: rgba(255,255,255,.85); }

/* ---------- Preview column ---------- */
.preview-col { position: sticky; top: 4.7rem; }
@media (max-width: 960px) { .preview-col { position: static; } }
.preview-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .7rem;
}
.preview-tag {
  font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-soft);
  background: #fff; border: 1px solid var(--line-soft);
  padding: .3rem .6rem; border-radius: 999px;
}

/* ============================================================
   THE INVOICE (also the print target) — classic & clean
   ============================================================ */
.invoice {
  background: #fff;
  color: #1b1b1b;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 2.4rem 2.4rem 2rem;
  font-family: var(--font-ui);
  font-size: .92rem;
  /* Aspect-ratio-ish: feels like paper */
  min-height: 60vh;
}
.inv-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1.5rem; padding-bottom: 1.4rem; border-bottom: 2px solid #1b1b1b;
}
.inv-brand { display: flex; gap: 1rem; align-items: flex-start; min-width: 0; }
.inv-logo { max-width: 120px; max-height: 70px; object-fit: contain; }
.inv-from { display: flex; flex-direction: column; min-width: 0; }
.inv-fromname { font-size: 1.1rem; font-weight: 700; color: #111; }
.inv-meta { color: #555; font-size: .85rem; white-space: pre-line; word-break: break-word; }
.inv-title { text-align: right; flex-shrink: 0; }
.inv-title h2 {
  font-family: var(--font-display);
  margin: 0; font-size: 1.9rem; letter-spacing: .12em; color: #111; font-weight: 700;
}
.inv-number { font-size: .9rem; color: #555; font-variant-numeric: tabular-nums; }

.inv-parties {
  display: flex; justify-content: space-between; gap: 1.5rem;
  padding: 1.3rem 0; border-bottom: 1px solid #e2e2e2;
}
.inv-billto { display: flex; flex-direction: column; min-width: 0; }
.inv-billto strong { font-size: 1rem; color: #111; margin-bottom: .1rem; }
.inv-dates { text-align: right; display: grid; gap: .55rem; flex-shrink: 0; }
.inv-dates > div { display: grid; }
.inv-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: #888; font-weight: 600; margin-bottom: .15rem;
}

.inv-table { width: 100%; border-collapse: collapse; margin-top: 1.2rem; }
.inv-table th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: #777; padding: 0 0 .6rem; border-bottom: 1.5px solid #1b1b1b; font-weight: 600;
}
.inv-table .c-qty, .inv-table .c-price, .inv-table .c-amt { text-align: right; }
.inv-table td {
  padding: .65rem 0; border-bottom: 1px solid #ededed;
  vertical-align: top; font-size: .9rem;
}
.inv-table td.c-desc { padding-right: 1rem; word-break: break-word; }
.inv-table .c-qty, .inv-table .c-price, .inv-table .c-amt {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.inv-table td.c-amt { font-weight: 600; }
.inv-empty td { color: #aaa; font-style: italic; text-align: center; padding: 1.2rem 0; }

.inv-summary { display: flex; justify-content: flex-end; margin-top: 1.1rem; }
.inv-totals { width: min(320px, 100%); }
.trow {
  display: flex; justify-content: space-between; gap: 1.5rem;
  padding: .4rem 0; font-size: .92rem;
}
.trow span:last-child { font-variant-numeric: tabular-nums; }
.trow.grand {
  margin-top: .35rem; padding-top: .7rem; border-top: 2px solid #1b1b1b;
  font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: #111;
}

.inv-foot {
  display: grid; gap: 1.1rem; margin-top: 1.8rem;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 520px) { .inv-foot { grid-template-columns: 1fr; } }
.inv-foot p { margin: .2rem 0 0; font-size: .85rem; color: #444; white-space: pre-line; word-break: break-word; }

@media (max-width: 480px) {
  .invoice { padding: 1.5rem 1.3rem; }
  .inv-title h2 { font-size: 1.4rem; }
  .inv-top { flex-direction: column; }
  .inv-title { text-align: left; }
}

/* ---------- Site footer ---------- */
.site-footer {
  border-top: 1px solid var(--line-soft);
  background: #fff;
  padding: 1.6rem 0;
}
.site-footer .wrap { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }
.site-footer p { margin: 0; font-size: .85rem; color: var(--ink-soft); }
.site-footer a { color: var(--teal-800); font-weight: 600; }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   PRINT — only the invoice prints, full clean page
   ============================================================ */
@media print {
  @page { margin: 14mm; }
  html, body {
    background: #fff !important;
    margin: 0; padding: 0;
  }
  .no-print { display: none !important; }
  .wrap, .layout {
    display: block !important;
    width: auto !important; margin: 0 !important; padding: 0 !important;
    gap: 0 !important;
  }
  .preview-col { position: static !important; }
  .editor { display: none !important; }

  .invoice {
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    min-height: auto !important;
    font-size: 11pt;
    color: #000 !important;
  }
  .inv-top, .trow.grand, .inv-table th { border-color: #000 !important; }
  .inv-table td { border-color: #ddd !important; }
  .invoice, .inv-table, .inv-foot, .trow { page-break-inside: avoid; }
  .inv-table tr { page-break-inside: avoid; }

  /* Crisp colors in print */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
