/* ===================================================================
   QuoteKit — app styles
   Screen chrome is dark; the document sheet is always paper-white so
   what you edit is exactly what prints.
   =================================================================== */

:root {
  --bg: #0d1219;
  --bg-2: #131b25;
  --bg-3: #1a232f;
  --line: #26313f;
  --ink: #e8edf4;
  --ink-2: #97a4b6;
  --ink-3: #64748b;
  --accent: #2f7d5d;
  --accent-ink: #fff;
  --danger: #e5484d;
  --radius: 12px;
  --paper: #fff;
  --paper-ink: #16202c;
  --paper-ink-2: #5b6a7d;
  --paper-line: #e2e8f0;
  --sheet-w: 820px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

svg { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

a { color: inherit; }

/* ---------------------------- top bar ---------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(13, 18, 25, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: -.01em;
  text-decoration: none;
}
.brand-mark { color: var(--accent); width: 20px; height: 20px; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: color-mix(in srgb, var(--accent) 55%, #fff);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

/* body[data-view] controls which parts of the chrome are relevant */
#btn-back { display: none; }
body[data-view="editor"] #btn-back,
body[data-view="settings"] #btn-back { display: inline-flex; }
body[data-view="docs"] #btn-print,
body[data-view="settings"] #btn-print { display: none; }
body[data-view="settings"] #btn-settings { display: none; }

/* ---------------------------- buttons ---------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  color: var(--ink);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: #212c3a; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #fff); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-3); }
.btn-danger { color: #ff8a8d; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  padding: 0;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-3); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ----------------------------- views ----------------------------- */

.view { display: none; }
body[data-view="docs"] #view-docs,
body[data-view="editor"] #view-editor,
body[data-view="settings"] #view-settings { display: block; }

.wrap { max-width: 980px; margin: 0 auto; padding: 28px 16px 80px; }
.wrap.narrow { max-width: 700px; }

h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0 0 4px; letter-spacing: -.01em; }
.muted { color: var(--ink-2); font-size: 14px; margin: 0; }
.hint { color: var(--ink-3); font-size: 13px; margin: 8px 0 0; }

/* -------------------------- document list ------------------------ */

.list-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.list-head-actions { display: flex; gap: 8px; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; }
.filters input, .filters select {
  font: inherit; font-size: 14px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.filters input { flex: 1; min-width: 0; }

.doc-list { display: flex; flex-direction: column; gap: 8px; }

.doc-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color .12s, background .12s;
}
.doc-card:hover { border-color: #35455a; background: var(--bg-3); }

.doc-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .07em;
  padding: 5px 8px; border-radius: 7px;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-2);
}
.doc-badge.invoice { background: color-mix(in srgb, #3b82f6 18%, transparent); border-color: color-mix(in srgb, #3b82f6 35%, transparent); color: #93c5fd; }
.doc-badge.quote { background: color-mix(in srgb, var(--accent) 20%, transparent); border-color: color-mix(in srgb, var(--accent) 38%, transparent); color: #7bd3a8; }

.doc-main { min-width: 0; }
.doc-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-sub { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-right { text-align: right; }
.doc-amount { font-weight: 650; font-variant-numeric: tabular-nums; }
.doc-status { font-size: 12px; color: var(--ink-3); text-transform: capitalize; }
.doc-status.paid, .doc-status.accepted { color: #6ee7a8; }
.doc-status.declined, .doc-status.overdue { color: #ff8a8d; }

.empty { text-align: center; padding: 70px 20px; color: var(--ink-2); }
.empty svg { width: 44px; height: 44px; color: var(--ink-3); margin-bottom: 12px; stroke-width: 1.4; }
.empty h2 { color: var(--ink); font-size: 19px; }
.empty p { max-width: 380px; margin: 6px auto 20px; font-size: 14px; }

/* --------------------------- editor bar -------------------------- */

.editor-bar {
  position: sticky;
  top: 57px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  /* Full-bleed so the sheet scrolls behind an opaque strip, but the controls
     still line up with the sheet's edges on wide screens. */
  padding: 12px max(16px, calc((100% - var(--sheet-w)) / 2));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.editor-bar-left, .editor-bar-right { display: flex; align-items: center; gap: 8px; }

#doc-status {
  font: inherit; font-size: 14px; font-weight: 550;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.saved-hint { font-size: 13px; color: var(--ink-3); opacity: 0; transition: opacity .25s; }
.saved-hint.show { opacity: 1; }

/* ============================ THE SHEET =========================== */

.sheet-scroll { padding: 16px 16px 90px; }

.sheet {
  position: relative;
  max-width: var(--sheet-w);
  margin: 0 auto;
  padding: 46px 52px 40px;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 40px rgba(0,0,0,.35);
  overflow: hidden;
}

.sheet-accent { position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--accent); }

/* Borderless inputs that read as plain document text. */
.ghost {
  font: inherit;
  color: inherit;
  width: 100%;
  padding: 3px 5px;
  margin: 0 -5px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  resize: none;
  /* Heights are driven by autogrow, so a scrollbar would only ever be a
     stray grey sliver next to the text. */
  overflow: hidden;
}
.ghost::placeholder { color: #b6c1cf; }
.ghost:hover { background: #f4f7fa; }
.ghost:focus { outline: none; background: #eef6f2; border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.ghost.right { text-align: right; }
.ghost.strong { font-weight: 650; }
.ghost.num { font-variant-numeric: tabular-nums; }

/* --- header --- */

.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 30px; }
.biz { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }

.logo-slot {
  flex: none;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, #fff);
  overflow: hidden;
}
.logo-slot img { width: 100%; height: 100%; object-fit: contain; }
.logo-fallback { font-weight: 700; font-size: 20px; color: var(--accent); letter-spacing: -.02em; }

.biz-name { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.biz-meta { font-size: 12.5px; color: var(--paper-ink-2); line-height: 1.6; }

.doc-meta { text-align: right; flex: none; }
.doc-type { font-size: 25px; font-weight: 750; letter-spacing: .04em; color: var(--accent); margin-bottom: 8px; }
.doc-meta dl { display: grid; grid-template-columns: auto 130px; gap: 2px 10px; align-items: center; margin: 0; font-size: 12.5px; }
.doc-meta dt { color: var(--paper-ink-2); text-align: right; }
.doc-meta dd { margin: 0; font-weight: 550; }

/* Native date inputs render as ISO on screen, which is fine while editing but
   wrong on a document going to a customer — swap in a formatted date to print. */
.print-date { display: none; }

/* --- parties --- */

.parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin: 32px 0 26px;
  padding: 20px 0 0;
  border-top: 1px solid var(--paper-line);
}
.party h3, .foot-notes h3 {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--paper-ink-2); margin: 0 0 7px;
}
.party .ghost { font-size: 13.5px; display: block; }
.party .ghost.strong { font-size: 15px; }

/* --- line items --- */

.items { margin-top: 6px; }

.items-head, .item-row {
  display: grid;
  grid-template-columns: 1fr 62px 70px 92px 100px 30px;
  gap: 10px;
  align-items: start;
}

.items-head {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--paper-ink-2);
  padding: 0 0 8px;
  border-bottom: 1.5px solid var(--paper-ink);
}
.items-head span:nth-child(n+2) { text-align: right; }
.items-head span:nth-child(3) { text-align: left; }

.item-row { padding: 9px 0; border-bottom: 1px solid var(--paper-line); font-size: 13.5px; }
.item-amount { text-align: right; font-variant-numeric: tabular-nums; padding-top: 3px; font-weight: 550; }

.row-del {
  width: 26px; height: 26px; padding: 0;
  display: grid; place-items: center;
  color: #b6c1cf; background: transparent; border: none; border-radius: 6px; cursor: pointer;
  opacity: 0; transition: opacity .12s, color .12s;
}
.item-row:hover .row-del, .row-del:focus-visible { opacity: 1; }
.row-del:hover { color: var(--danger); background: #fef2f2; }

.item-label { display: none; }

.add-row {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px; padding: 7px 12px 7px 8px;
  font: inherit; font-size: 13px; font-weight: 550;
  color: var(--accent); background: transparent;
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 8px; cursor: pointer;
}
.add-row:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.add-row svg { width: 15px; height: 15px; }

/* --- footer of sheet --- */

.foot { display: grid; grid-template-columns: 1fr 320px; gap: 40px; margin-top: 28px; }
.foot-notes { font-size: 13px; }
.foot-notes .terms-h { margin-top: 18px; }
.terms { font-size: 12px; color: var(--paper-ink-2); line-height: 1.65; white-space: pre-wrap; }

.totals { font-size: 13.5px; }
.t-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; }
/* A class selector beats the UA sheet's [hidden] rule at equal specificity,
   so hidden totals rows need to be excluded explicitly. */
.t-row[hidden] { display: none; }
.t-row > span:last-child { font-variant-numeric: tabular-nums; text-align: right; }
.t-row + .t-row { border-top: 1px solid var(--paper-line); }

.t-total {
  margin-top: 4px; padding: 12px 0;
  border-top: 1.5px solid var(--paper-ink) !important;
  border-bottom: 1.5px solid var(--paper-ink);
  font-size: 18px; font-weight: 700;
}
.t-due { font-weight: 650; color: var(--accent); }

.disc-wrap { display: inline-flex; align-items: center; gap: 4px; }
.disc-wrap .ghost.right { width: 74px; }
.ghost.tiny { width: 58px; font-size: 12px; padding: 3px 4px; }
.tiny-rate { width: 44px; text-align: right; display: inline-block; margin: 0 -2px; }

.sheet-foot {
  display: flex; justify-content: space-between; gap: 20px;
  margin-top: 36px; padding-top: 14px;
  border-top: 1px solid var(--paper-line);
  font-size: 11.5px; color: var(--paper-ink-2);
}

.watermark {
  margin-top: 20px;
  text-align: center;
  font-size: 10.5px;
  color: #9aa7b6;
  letter-spacing: .02em;
}

/* --------------------------- settings ---------------------------- */

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card > .muted { margin-bottom: 16px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 .span2 { grid-column: 1 / -1; }

.card label { display: block; font-size: 13px; font-weight: 550; color: var(--ink-2); }
.card label input, .card label select, .card label textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  font: inherit; font-size: 14.5px;
  color: var(--ink);
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.card label textarea { resize: vertical; line-height: 1.55; }
.card label input:focus, .card label select:focus, .card label textarea:focus { outline: none; border-color: var(--accent); }

.logo-row { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; flex-wrap: wrap; }
.logo-preview {
  width: 76px; height: 76px; flex: none;
  display: grid; place-items: center;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden;
  font-size: 26px; font-weight: 700; color: var(--ink-3);
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.logo-row .btn { margin-right: 8px; }

.swatches { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.swatch {
  width: 30px; height: 30px; padding: 0;
  border-radius: 8px; border: 2px solid transparent; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.14);
}
.swatch[aria-pressed="true"] { border-color: var(--ink); }

.perks { margin: 12px 0 16px; padding-left: 18px; color: var(--ink-2); font-size: 14px; }
.perks li { margin: 4px 0; }

.key-entry { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.key-entry label { margin-bottom: 10px; }
.key-entry input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px !important; }
.pro-line { font-size: 15px; margin: 0 0 14px; }
.pro-line strong { color: #6ee7a8; }

.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.version { text-align: center; margin-top: 24px; font-size: 13px; }

/* ----------------------------- toast ----------------------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  z-index: 100;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 18px;
  font-size: 14px;
  background: #eef2f7;
  color: #10161f;
  border-radius: 11px;
  box-shadow: 0 8px 30px rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: #fee2e2; color: #7f1d1d; }

/* ============================ RESPONSIVE ========================== */

@media (max-width: 760px) {
  .btn-label { display: none; }
  .wrap { padding-top: 20px; }
  h1 { font-size: 22px; }

  .list-head { flex-direction: column; align-items: stretch; }
  .list-head-actions .btn { flex: 1; }

  .sheet-scroll { padding: 12px 10px 90px; }
  .sheet { padding: 26px 20px 28px; border-radius: 12px; }

  .sheet-head { flex-direction: column; gap: 20px; }
  .doc-meta { text-align: left; width: 100%; }
  .doc-meta dl { grid-template-columns: 100px 1fr; }
  .doc-meta dt { text-align: left; }
  .ghost.right { text-align: left; }

  .parties { grid-template-columns: 1fr; gap: 22px; margin-top: 24px; }

  /* Line items become stacked cards — a table is unusable on a phone. */
  .items-head { display: none; }
  .item-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    padding: 14px 0;
  }
  .item-row .i-desc { grid-column: 1 / -1; }
  .item-label {
    display: block;
    font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    color: var(--paper-ink-2);
    margin-bottom: 2px;
  }
  .item-amount { text-align: right; align-self: end; }
  .row-del { opacity: 1; grid-column: 1 / -1; justify-self: end; margin-top: -4px; }

  .foot { grid-template-columns: 1fr; gap: 26px; }
  .totals { order: -1; }

  .grid2 { grid-template-columns: 1fr; }
  .editor-bar { top: 55px; }
  .editor-bar-right { width: 100%; }
  .editor-bar-right .btn { flex: 1; }
}

/* ============================== PRINT ============================= */

@media print {
  @page { size: A4; margin: 13mm; }

  html, body { background: #fff !important; color: #000; font-size: 11pt; }
  .topbar, .editor-bar, .no-print, #toast, .add-row, .row-del { display: none !important; }
  .view { display: none !important; }
  body[data-view="editor"] #view-editor { display: block !important; }

  .sheet-scroll { padding: 0; }
  .sheet {
    max-width: none;
    margin: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    color: #000;
  }
  .sheet-accent { position: static; height: 4px; margin-bottom: 22px; border-radius: 2px; }

  /* Inputs must print as flat text, not as form fields. */
  .ghost {
    background: none !important;
    border-color: transparent !important;
    padding: 0;
    margin: 0;
    color: #000;
    -webkit-appearance: none;
    appearance: none;
  }
  .ghost::placeholder { color: transparent; }
  select.ghost { text-align: right; }

  input[type="date"].ghost { display: none; }
  .print-date { display: inline; font-weight: 550; }

  /* Editing affordances and zero-value lines are noise on the customer's copy. */
  .print-hide { display: none !important; }
  select.ghost { display: none; }

  .item-row, .items-head { break-inside: avoid; }
  .foot, .totals, .sheet-foot { break-inside: avoid; }
  .items-head { display: grid !important; }
  .item-label { display: none !important; }

  /* Keep the accent colour and rules in the printed PDF. */
  .sheet-accent, .doc-type, .t-due, .logo-slot {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .watermark { margin-top: 26px; color: #8b98a8 !important; }
}
