/* ============================================================
   mardis.studio — document generator
   Built to the Figma masters (612×792pt, US Letter).
   1pt in this stylesheet = 1px in the Figma frame.
   ============================================================ */

/* ---------- Fonts: A2 Regular XL Soft ---------- */
@font-face {
  font-family: "A2 Soft";
  src: url("/fonts/RegularXLSoft-MediumWEB.woff2") format("woff2"),
       url("/fonts/RegularXLSoft-MediumWEB.woff") format("woff");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "A2 Soft";
  src: url("/fonts/RegularXLSoft-BoldWEB.woff2") format("woff2"),
       url("/fonts/RegularXLSoft-BoldWEB.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   Brand tokens — exact values from the Figma masters
   ============================================================ */
:root {
  /* Page gradients (vertical, full bleed) */
  --grad-proposal: linear-gradient(180deg, #58B4D0 0%, #DFDACE 100%);
  --grad-invoice:  linear-gradient(180deg, #B0D169 0%, #58B4D0 100%);
  --grad-receipt:  linear-gradient(180deg, #58B4D0 0%, #B0D169 100%);

  /* Document colors */
  --card: #374D5E;        /* navy card */
  --cream: #E3E0D8;       /* primary text on navy */
  --sky: #63B3CA;
  --lime: #B0D16A;
  --muted: #8897A2;       /* overdue-fee gray */
  --ink: #22272A;         /* B&W ink + logo mark */

  /* Editor chrome */
  --app-bg: #14181b;
  --panel-bg: #1b2125;
  --panel-ink: #E3E0D8;
  --panel-ink-soft: rgba(227, 224, 216, 0.55);
  --panel-line: rgba(227, 224, 216, 0.14);
  --field-bg: rgba(227, 224, 216, 0.06);
  --radius: 10px;
}

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

html, body {
  font-family: "A2 Soft", "Helvetica Neue", Arial, sans-serif;
  font-weight: 500;
  background: var(--app-bg);
  color: var(--panel-ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ============================================================
   App shell: control panel (left) + live sheet preview (right)
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: 372px 1fr;
  min-height: 100vh;
}

/* ---------- Control panel ---------- */
.panel {
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-line);
  padding: 28px 26px 48px;
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
}
.brand { margin-bottom: 4px; }
.brand h1 { font-size: 17px; font-weight: 700; }
.brand h1 span { color: var(--panel-ink-soft); font-weight: 500; }
.tagline { font-size: 12.5px; color: var(--panel-ink-soft); margin-bottom: 22px; }

.panel-section { margin-bottom: 24px; }
.panel-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--panel-ink-soft);
  margin-bottom: 9px;
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  background: var(--field-bg);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 4px;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 8px 4px;
  font-size: 13px;
  color: var(--panel-ink-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--panel-ink); }
.seg button.on { background: var(--panel-ink); color: var(--panel-bg); font-weight: 700; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--panel-ink-soft); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%;
  background: var(--field-bg);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13.5px;
  transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus { outline: none; border-color: rgba(227,224,216,0.45); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.item-edit {
  display: grid;
  grid-template-columns: 1fr 96px 28px;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.item-edit input {
  background: var(--field-bg);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  width: 100%;
}
.item-edit input:focus { outline: none; border-color: rgba(227,224,216,0.45); }
.item-edit .num { text-align: right; font-variant-numeric: tabular-nums; }
.item-remove {
  appearance: none; border: 0; background: transparent;
  color: var(--panel-ink-soft); font-size: 16px; cursor: pointer;
  border-radius: 6px; height: 28px; line-height: 1;
}
.item-remove:hover { color: #ff8d7a; background: var(--field-bg); }

.btn {
  appearance: none; width: 100%;
  border: 1px solid var(--panel-line);
  background: var(--field-bg);
  color: var(--panel-ink);
  border-radius: var(--radius);
  padding: 10px; font-size: 13.5px; cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: rgba(227,224,216,0.12); }
.btn-primary {
  background: var(--panel-ink); color: var(--panel-bg);
  border-color: var(--panel-ink); font-weight: 700;
  padding: 13px; font-size: 14.5px;
}
.btn-primary:hover { background: #fff; }
.hint { font-size: 11.5px; color: var(--panel-ink-soft); margin-top: 8px; line-height: 1.5; }

.seg button:focus-visible, .btn:focus-visible, .item-remove:focus-visible {
  outline: 2px solid #fff; outline-offset: 2px;
}

/* ---------- Preview stage ---------- */
.stage {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 44px 36px 80px;
  overflow-y: auto;
  max-height: 100vh;
}

/* ============================================================
   THE SHEET — 8.5in × 11in, mapped 1:1 to the 612×792 Figma frame.
   Full-bleed gradient page, inset navy card (12pt margin, 12pt radius).
   ============================================================ */
.sheet {
  width: 8.5in;
  min-height: 11in;
  padding: 12pt;
  background: var(--grad-invoice);
  display: flex;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  flex-shrink: 0;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}
.sheet[data-look="proposal"] { background: var(--grad-proposal); --accent-logo: var(--sky);  --accent-date: var(--cream); }
.sheet[data-look="invoice"]  { background: var(--grad-invoice);  --accent-logo: var(--lime); --accent-date: var(--sky); }
.sheet[data-look="receipt"]  { background: var(--grad-receipt);  --accent-logo: var(--sky);  --accent-date: var(--lime); }
.sheet[data-look="bw"]       { background: #fff;                 --accent-logo: var(--ink);  --accent-date: var(--ink); }

.card {
  flex: 1;
  background: var(--card);
  border-radius: 12pt;
  color: var(--cream);
  display: flex;
  flex-direction: column;
  padding: 0 44pt 50pt;
  --line-color: var(--cream);
}
.sheet[data-look="bw"] .card {
  background: #fff;
  border: 1pt solid var(--ink);
  color: var(--ink);
  --line-color: var(--ink);
}

/* ---------- Outlined logotype, centered ---------- */
.logotype {
  margin-top: 61pt;
  text-align: center;
  font-size: 21pt;
  font-weight: 700;
  letter-spacing: 0.44em;
  text-indent: 0.44em; /* re-centers tracked-out text */
  text-transform: uppercase;
  color: var(--accent-logo);
}
@supports (-webkit-text-stroke: 1pt black) {
  .logotype {
    color: transparent;
    -webkit-text-stroke: 1.1pt var(--accent-logo);
  }
}

/* ---------- Title + meta ---------- */
.doc-head {
  margin-top: 64pt;
  display: grid;
  grid-template-columns: 295pt 1fr;
  align-items: start;
}
.doc-title {
  font-size: 35pt;
  font-weight: 700;
  letter-spacing: 0.18em;
  line-height: 1.43;
  text-transform: uppercase;
}
.doc-meta { padding-top: 6pt; }
.doc-meta .meta-block + .meta-block { margin-top: 17pt; }
.doc-meta .lbl {
  display: block;
  font-size: 11pt;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.doc-meta .val { display: block; font-size: 12.5pt; margin-top: 3pt; }

/* ---------- Line items: right-aligned text over chaos→order rules ---------- */
.items { margin-top: 62pt; }
.item-row { padding-top: 7pt; }
.item-row .item-text {
  text-align: right;
  font-size: 12.5pt;
  line-height: 1;
  padding-bottom: 5pt;
}
.item-row .item-amount { margin-left: 14pt; font-variant-numeric: tabular-nums; }
.item-line {
  display: block;
  width: 100%;
  height: 16pt;
  margin-top: -8pt; /* squiggle baseline sits at the row rule */
  color: var(--line-color);
  overflow: visible;
}

/* ---------- Total ---------- */
.total-row {
  margin-top: 27pt;
  text-align: right;
  font-size: 12.5pt;
  font-variant-numeric: tabular-nums;
}
.total-row .eq { padding: 0 4pt; }

/* ---------- Footer: date columns + logo mark ---------- */
.doc-foot {
  margin-top: auto;
  padding-top: 40pt;
  display: flex;
  align-items: flex-end;
  gap: 45pt;
}
.foot-col .lbl {
  display: block;
  font-size: 11pt;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.foot-col .val { display: block; font-size: 12pt; margin-top: 4pt; }
.foot-col.is-accent .lbl, .foot-col.is-accent .val { color: var(--accent-date); }
.foot-col.is-muted .lbl, .foot-col.is-muted .val { color: var(--muted); }
.sheet[data-look="bw"] .foot-col.is-muted .lbl,
.sheet[data-look="bw"] .foot-col.is-muted .val { color: var(--ink); opacity: 0.55; }

.logo-mark {
  margin-left: auto;
  width: 52pt;
  height: 50pt;
  color: var(--ink);
  flex-shrink: 0;
}
.sheet[data-look="bw"] .logo-mark { color: var(--ink); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .panel { max-height: none; position: static; border-right: 0; border-bottom: 1px solid var(--panel-line); }
  .stage { max-height: none; padding: 28px 12px 60px; }
  .sheet { transform-origin: top center; transform: scale(0.62); margin-bottom: calc(-11in * 0.38); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ============================================================
   PRINT = the PDF. @page is exact US Letter, zero margins.
   ============================================================ */
@page { size: letter; margin: 0; }
@media print {
  html, body { background: #fff; }
  .panel { display: none !important; }
  .app { display: block; }
  .stage { padding: 0; max-height: none; overflow: visible; display: block; }
  .sheet {
    box-shadow: none;
    margin: 0 !important;
    width: 8.5in;
    height: 11in;
    min-height: 0;
    transform: none !important; /* cancel the responsive preview scale */
  }
}
