/* ============================================================
   Quote Generator — styles.css
   Vanilla CSS. No webfonts, no CDNs — system font stack only.
   ============================================================ */

:root {
  --bg: #f5f3ef;
  --panel: #ffffff;
  --ink: #212a33;
  --muted: #66707b;
  --line: #e4e0d8;
  --line-doc: #e7e2d8;
  --accent: #0f766e;
  --accent-ink: #0b5c55;
  --accent-soft: #e7f1ef;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #15803d;
  --ok-soft: #e9f7ee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 28, .05), 0 8px 24px rgba(20, 24, 28, .07);
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", Georgia, "Palatino Linotype", "Book Antiqua", "Times New Roman", serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

[hidden] { display: none !important; }

::selection { background: var(--accent-soft); }

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

.input:focus-visible { outline: none; }

/* ---------------- accessibility helpers ---------------- */

.vh {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------- header ---------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.app-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 11px; }

.logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif);
  font-size: 19px; font-weight: 700;
}

.brand h1 { font-size: 15.5px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.brand p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

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

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border: 1px solid #d8d3c8;
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s, transform .05s;
}
.btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }

.btn-accent { background: var(--accent-soft); border-color: #cfe2df; color: var(--accent-ink); }
.btn-accent:hover { background: #dbebe8; }

.btn-small { padding: 6px 11px; font-size: 12.5px; }
.btn svg { flex: 0 0 auto; }

/* ---------------- hint line + footer ---------------- */

.save-hint {
  max-width: 1280px;
  margin: 10px auto 0;
  padding: 0 20px;
  font-size: 12px;
  color: var(--muted);
}

.app-foot {
  max-width: 1280px;
  margin: 0 auto;
  padding: 26px 20px 42px;
  font-size: 12.5px;
  color: var(--muted);
}
.app-foot a { color: var(--accent-ink); font-weight: 600; }

/* ---------------- layout ---------------- */

.layout {
  max-width: 1280px;
  margin: 14px auto 0;
  padding: 0 20px;
  display: grid;
  grid-template-columns: minmax(0, 11fr) minmax(0, 9fr);
  gap: 26px;
  align-items: start;
}

.editor-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.preview-col { min-width: 0; scrollbar-width: thin; scrollbar-color: #cfc9bd transparent; }
.preview-col::-webkit-scrollbar { width: 8px; }
.preview-col::-webkit-scrollbar-thumb { background: #cfc9bd; border-radius: 4px; }

@media (min-width: 1081px) {
  .preview-col {
    position: sticky;
    top: 66px;
    max-height: calc(100vh - 84px);
    overflow: auto;
    padding-right: 2px;
  }
}

body.mode-ro .layout { grid-template-columns: 1fr; max-width: 940px; }
body.mode-ro .editor-col { display: none; }
body.mode-ro .edit-only { display: none; }
body.mode-ro .save-hint { display: none; }
body.mode-ro .preview-bar { display: none; }

body.mode-error .layout { display: none; }
body.mode-error .save-hint { display: none; }

/* ---------------- cards ---------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  box-shadow: 0 1px 2px rgba(25, 28, 34, .04);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 2.5px;
  background: var(--accent);
  flex: 0 0 auto;
}

.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -2px 0 12px;
}
.card-head-row h2 { margin: 0; }

/* ---------------- fields ---------------- */

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

.field { min-width: 0; }
.card > .field + .field { margin-top: 12px; }

.field > label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #4c5560;
  margin-bottom: 5px;
}

.input {
  width: 100%;
  min-width: 0;
  padding: 8px 11px;
  border: 1px solid #d8d3c8;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.35;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: #9aa2ab; }

select.input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2366707b' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.join { display: flex; align-items: stretch; }
.join .input { border-radius: 0; }
.join-left { flex: 0 0 auto; width: auto; min-width: 78px; border-radius: 9px 0 0 9px !important; }
.join-mid { flex: 1 1 auto; border-left: none; border-right: none; }
.join-mid:focus { border-left: 1px solid var(--accent); border-right: 1px solid var(--accent); margin-left: -1px; margin-right: -1px; }
.join-right {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  padding: 0 11px;
  border: 1px solid #d8d3c8;
  border-left: none;
  border-radius: 0 9px 9px 0;
  background: #f7f5f1;
  color: #4c5560;
  font-size: 13.5px;
  font-weight: 600;
}

/* ---------------- totals strip ---------------- */

.totals-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.ts-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 13px;
  min-width: 0;
}
.ts-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.ts-val {
  display: block;
  margin-top: 2px;
  font-size: 16.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ts-total { background: var(--accent); border-color: var(--accent); }
.ts-total .ts-label { color: #c9e5e1; }
.ts-total .ts-val { color: #fff; }

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

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 104px 96px auto;
  grid-template-rows: auto;
  gap: 8px 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fcfbf8;
  margin-bottom: 10px;
}
.item-row:last-child { margin-bottom: 0; }

.ir-desc { grid-column: 1; grid-row: 1; min-width: 0; }
.ir-qty { grid-column: 2; grid-row: 1; min-width: 0; }
.ir-price { grid-column: 3; grid-row: 1; min-width: 0; }
.ir-total {
  grid-column: 4;
  grid-row: 1;
  align-self: center;
  text-align: right;
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  padding-bottom: 9px;
  white-space: nowrap;
}
.ir-actions { grid-column: 5; grid-row: 1; display: flex; gap: 6px; padding-bottom: 3px; }

.iconbtn {
  width: 30px; height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.iconbtn:hover { color: var(--accent-ink); border-color: var(--accent); }
.iconbtn-danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.iconbtn:disabled { opacity: .35; cursor: default; pointer-events: none; }
.iconbtn svg { pointer-events: none; }

/* ---------------- quick date buttons + hints + badges ---------------- */

.quick { display: flex; gap: 6px; margin-top: 7px; }
.quick .btn { padding: 4px 9px; font-size: 11.5px; border-radius: 7px; }

.hint { margin: 6px 2px 0; font-size: 12px; color: var(--muted); }
.hint-danger { color: var(--danger); font-weight: 600; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .02em;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------------- preview column ---------------- */

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  min-height: 26px;
}
.preview-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.print-hint { margin: 10px 2px 0; font-size: 12px; color: var(--muted); }

/* ---------------- the document ---------------- */

.doc {
  background: #fff;
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: var(--shadow);
  color: #26221b;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  padding: 38px 42px 30px;
  max-width: 800px;
  margin: 0 auto;
  overflow-wrap: break-word;
}

.doc-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.doc-biz { min-width: 0; }
.doc-bizname { font-size: 21px; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
.doc-bizmeta { font-size: 12.5px; color: #6d675c; margin-top: 3px; }

.doc-titlebox { text-align: right; flex: 0 0 auto; }
.doc-word {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: .28em;
  margin-right: -.28em;
  text-transform: uppercase;
  color: var(--accent-ink);
}
.doc-num { margin-top: 4px; font-size: 13px; color: #6d675c; font-variant-numeric: tabular-nums; }

.doc-parties {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px 40px;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line-doc);
}

.doc-label {
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #8a8375;
  margin-bottom: 6px;
}

.doc-forname { font-size: 16.5px; font-weight: 700; }
.doc-sub { font-size: 13px; color: #5d574b; margin-top: 2px; }

.doc-info { min-width: 220px; }
.doc-inforow {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 5px 0;
  border-bottom: 1px dotted var(--line-doc);
  font-size: 13px;
}
.doc-inforow span { color: #8a8375; }
.doc-inforow b { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.doc-validchip {
  display: inline-block;
  margin-top: 18px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 700;
}

.doc-expired {
  margin-top: 18px;
  padding: 11px 14px;
  border-radius: 9px;
  background: var(--danger-soft);
  border-left: 4px solid var(--danger);
  color: #7f1d1d;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
}
.doc-expired strong { font-weight: 700; }

.doc-items { width: 100%; border-collapse: collapse; margin-top: 22px; font-size: 13.5px; }
.doc-items th {
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #8a8375;
  text-align: left;
  padding: 0 8px 8px 2px;
  border-bottom: 2px solid #3a352c;
}
.doc-items td { padding: 9px 8px 9px 2px; border-bottom: 1px solid var(--line-doc); vertical-align: top; }
.doc-items .col-i { width: 22px; color: #8a8375; }
.doc-items .col-n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-amount { font-weight: 600; }
.doc-empty { color: #a49c8d; font-style: italic; }
.doc-emptyrow { text-align: center; color: #a49c8d; font-style: italic; padding: 22px 0 !important; }

.doc-totwrap { display: flex; justify-content: flex-end; margin-top: 16px; }
.doc-totals { width: 270px; font-size: 13.5px; }
.doc-totrow { display: flex; justify-content: space-between; gap: 14px; padding: 5px 0; }
.doc-totrow .lab { color: #5d574b; }
.doc-totrow .val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.doc-tot-muted .lab, .doc-tot-muted .val { color: #8a8375; }

.doc-tot-grand {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 2px solid #3a352c;
  font-size: 16px;
}
.doc-tot-grand span { font-weight: 700; }
.doc-tot-grand b { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.doc-tot-dep, .doc-tot-dep2 {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 5px 0;
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--accent-ink);
  font-weight: 600;
}
.doc-tot-dep b, .doc-tot-dep2 b { font-variant-numeric: tabular-nums; white-space: nowrap; }

.doc-notes { margin-top: 24px; }
.doc-notes p { margin: 0; font-size: 13px; color: #45403a; }

.doc-accept {
  margin-top: 18px;
  padding: 13px 16px;
  border-radius: 9px;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  font-family: var(--sans);
  font-size: 13px;
  color: #14453f;
}
.doc-accept .doc-label { color: var(--accent-ink); }
.doc-accept p { margin: 0; }

.doc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 26px 44px; margin-top: 34px; }
.sig-role {
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #8a8375;
  margin-bottom: 8px;
}
.sig-line { border-bottom: 1.5px solid #3a352c; height: 34px; }
.sig-name { margin-top: 6px; font-size: 13.5px; font-weight: 700; }
.sig-cap { font-size: 11.5px; color: #8a8375; font-family: var(--sans); }

.doc-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 34px;
  padding-top: 12px;
  border-top: 1px solid var(--line-doc);
  font-family: var(--sans);
  font-size: 11.5px;
  color: #8a8375;
}

/* ---------------- read-only bar ---------------- */

.ro-bar { background: #fff; border-bottom: 1px solid var(--line); }
.ro-inner {
  max-width: 940px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.ro-text { font-size: 13.5px; color: var(--ink); max-width: 560px; margin: 0; }
.ro-text strong { font-weight: 700; }
.ro-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- error card ---------------- */

.error-wrap { max-width: 520px; margin: 60px auto; padding: 0 20px; }
.error-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 34px 30px;
  text-align: center;
  box-shadow: var(--shadow);
}
.error-mark {
  width: 44px; height: 44px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 22px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.error-card h2 { margin: 0 0 8px; font-size: 19px; }
.error-card p { margin: 0 0 10px; color: #4c5560; font-size: 14px; }
.error-card .muted { color: var(--muted); font-size: 13px; }
.error-card .btn { margin-top: 12px; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 8px);
  background: #232a31;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  max-width: min(560px, calc(100vw - 32px));
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-warn { background: #7a2e1d; }

/* ---------------- modal ---------------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(24, 28, 32, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 70;
}
.modal-card {
  background: #fff;
  border-radius: 14px;
  padding: 22px 22px 20px;
  max-width: 430px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-card h3 { margin: 0 0 8px; font-size: 16.5px; }
.modal-card p { margin: 0 0 16px; color: #4c5560; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
body.modal-open { overflow: hidden; }

/* ---------------- responsive ---------------- */

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .doc { max-width: 760px; }
}

@media (max-width: 820px) {
  .grid2 { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr; }
  .totals-strip { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .item-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "desc desc"
      "qty price"
      "total actions";
    align-items: center;
    row-gap: 10px;
  }
  .ir-desc { grid-area: desc; }
  .ir-qty { grid-area: qty; }
  .ir-price { grid-area: price; }
  .ir-total { grid-area: total; text-align: left; padding-bottom: 0; }
  .ir-actions { grid-area: actions; justify-self: end; padding-bottom: 0; }
}

@media (max-width: 640px) {
  .brand p { display: none; }
  .app-header-inner { padding: 10px 14px; }
  .layout { padding: 0 14px; margin-top: 12px; }
  .save-hint { padding: 0 14px; }
  .app-foot { padding: 20px 14px 34px; }
  .doc-parties { grid-template-columns: 1fr; }
  .doc-info { min-width: 0; }
}

@media (max-width: 560px) {
  .btn { padding: 7px 11px; font-size: 12.5px; }
  .doc { padding: 24px 18px 22px; font-size: 14px; }
  .doc-word { font-size: 22px; letter-spacing: .2em; margin-right: -.2em; }
  .doc-bizname { font-size: 18px; }
  .doc-items { font-size: 12.5px; }
  .doc-items td, .doc-items th { padding-left: 4px; padding-right: 4px; }
  .doc-totals { width: 100%; max-width: 300px; }
  .doc-sign { grid-template-columns: 1fr; gap: 20px; }
}

/* ---------------- print: only the quote document prints ---------------- */

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

  html, body { background: #fff !important; }

  .no-print,
  .app-header,
  .save-hint,
  .preview-bar,
  .print-hint,
  .ro-bar,
  .toast,
  .modal,
  .totals-strip,
  .editor-col,
  .app-foot {
    display: none !important;
  }

  .layout { display: block; max-width: none; margin: 0; padding: 0; }
  .preview-col { position: static; max-height: none; overflow: visible; }

  .doc {
    border: none;
    border-top: 3px solid var(--accent);
    box-shadow: none;
    border-radius: 0;
    max-width: none;
    padding: 0;
    margin: 0;
    font-size: 12pt;
  }

  .doc-items, .doc-sign, .doc-accept, .doc-expired, .doc-totwrap, .sig, .doc-tot-grand {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  thead { display: table-header-group; }

  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ---------------- reduced motion ---------------- */

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