/* ============================================================
   VRXHA Quotation Generator
   ============================================================ */
:root {
  --green-900: #0a3324;
  --green-800: #0e3d2b;
  --green-700: #135238;
  --gold: #c79a3b;
  --gold-light: #e7c977;
  --gold-grad: linear-gradient(135deg, #b8860b 0%, #f6e7a6 35%, #c9a13b 60%, #f3e3a0 80%, #a9771c 100%);
  --ink: #1f2421;
  --muted: #5d675f;
  --line: #e3e0d6;
  --paper: #ffffff;
  --bg: #11160f;
  --panel: #1a201a;
  --panel-2: #222a22;
  --field: #11160f;
  --radius: 12px;
  --shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
}

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

html, body { height: 100%; }

body {
  font-family: "Manrope", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1d2a1d 0%, var(--bg) 55%);
  color: #e9ede7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100%;
}

/* ---------------- Top bar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(12, 18, 11, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(199, 154, 59, 0.25);
}
.topbar-brand { display: flex; align-items: center; gap: 14px; }
.topbar-logo { width: 42px; height: 42px; object-fit: contain; }
.topbar-brand h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: .2px; }
.topbar-brand span { font-size: .72rem; color: var(--gold-light); letter-spacing: 1.5px; text-transform: uppercase; }
.topbar-actions { display: flex; gap: 10px; }

.btn {
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease;
}
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: #d7ddd3; border: 1px solid rgba(255,255,255,.18); }
.btn-ghost:hover { background: rgba(255,255,255,.06); }
.btn-gold { background: var(--gold-grad); color: #3a2c05; box-shadow: 0 6px 18px rgba(199,154,59,.35); }
.btn-gold:hover { filter: brightness(1.05); }
.btn-gold.busy { opacity: .7; pointer-events: none; }
.btn-green { background: var(--green-700); color: #eaf3ec; border: 1px solid rgba(199,154,59,.35); }
.btn-green:hover { background: #16623f; }
.btn-green.busy { opacity: .7; pointer-events: none; }
.btn-mini { background: rgba(199,154,59,.16); color: var(--gold-light); border: 1px solid rgba(199,154,59,.4); padding: 6px 12px; font-size: .78rem; border-radius: 7px; }
.btn-mini:hover { background: rgba(199,154,59,.28); }

/* ---------------- Layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0;
  height: calc(100vh - 71px);
}

/* ---------------- Editor ---------------- */
.editor {
  overflow-y: auto;
  padding: 20px;
  background: var(--bg);
  border-right: 1px solid rgba(255,255,255,.06);
}
.editor::-webkit-scrollbar { width: 9px; }
.editor::-webkit-scrollbar-thumb { background: #2c352c; border-radius: 10px; }

.card {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card-title { font-size: .8rem; text-transform: uppercase; letter-spacing: 1.4px; color: var(--gold-light); font-weight: 700; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-head .card-title { margin-bottom: 0; }
.card-hint { font-size: .72rem; color: var(--muted); margin: -4px 0 12px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field span { font-size: .72rem; color: #9aa89a; font-weight: 600; letter-spacing: .3px; }
.field-grid { display: grid; grid-template-columns: 1fr 110px; gap: 12px; }
.field.grow { flex: 1; margin-bottom: 0; }

input[type="text"], input[type="number"], input[type="date"], textarea, select {
  font-family: inherit;
  font-size: .85rem;
  color: #eef2ec;
  background: var(--field);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  transition: border .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(199,154,59,.15);
}
textarea { resize: vertical; line-height: 1.5; }
input[type="date"] { color-scheme: dark; }

/* toggle rows */
.toggle-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.toggle-row.inline { gap: 12px; align-items: flex-end; }
.toggle-row:last-child { margin-bottom: 0; }
.toggle-input { flex: 1; }
.toggle-label { font-size: .8rem; color: #c3ccc1; }

/* switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch.sm { width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #3a423a; border-radius: 22px; transition: .2s;
}
.slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: #cfd6cd; border-radius: 50%; transition: .2s;
}
.switch.sm .slider::before { height: 14px; width: 14px; }
.switch input:checked + .slider { background: var(--gold); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #1a1206; }
.switch.sm input:checked + .slider::before { transform: translateX(16px); }

/* items */
.items-list { display: flex; flex-direction: column; gap: 12px; }
.item-card {
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-2);
  position: relative;
}
.item-card .item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.item-card .item-no { font-size: .72rem; font-weight: 700; color: var(--gold-light); letter-spacing: 1px; }
.item-remove {
  background: rgba(220,80,60,.12); color: #ff9a86; border: 1px solid rgba(220,80,60,.4);
  border-radius: 6px; width: 24px; height: 24px; cursor: pointer; font-size: 1rem; line-height: 1;
}
.item-remove:hover { background: rgba(220,80,60,.25); }
.item-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-grid .full { grid-column: 1 / -1; }
.item-card .field { margin-bottom: 0; }
.item-amount { font-size: .75rem; color: var(--gold-light); text-align: right; margin-top: 8px; font-weight: 600; }

/* ---------------- Preview ---------------- */
.preview-wrap {
  overflow: auto;
  padding: 32px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.012) 0 2px, transparent 2px 22px),
    #0b0f0a;
}
.preview-scale { transform-origin: top left; }

/* A4 page : 794 x 1123 px @96dpi */
.page {
  width: 794px;
  min-height: 1123px;
  background: var(--paper);
  color: var(--ink);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
  padding: 46px 52px 0;
  display: flex;
  flex-direction: column;
}

.leaf-corner { position: absolute; width: 230px; height: 230px; opacity: .5; pointer-events: none; }
.leaf-corner.top-right { top: -30px; right: -30px; }
.leaf-corner.bottom-left { bottom: 150px; left: -40px; transform: rotate(180deg); }

/* header */
.q-header { display: flex; justify-content: space-between; align-items: flex-start; position: relative; z-index: 2; }
.q-brand { display: flex; flex-direction: column; align-items: flex-start; }
.q-logo { width: 118px; height: 96px; object-fit: contain; }
.q-wordmark { display: flex; flex-direction: column; margin-top: 2px; }
.q-name {
  font-family: "Cormorant Garamond", serif;
  font-size: 2.7rem; font-weight: 700; letter-spacing: .55rem;
  color: #b08423;
  line-height: 1;
}
.q-tagline { font-size: .62rem; letter-spacing: .33rem; color: #7c5e1f; font-weight: 600; margin-top: 3px; }

.q-contacts { display: flex; flex-direction: column; gap: 11px; padding-left: 26px; border-left: 2px solid var(--gold); margin-top: 6px; }
.q-contact { display: flex; align-items: center; gap: 11px; font-size: .82rem; color: #2b332c; }
.q-contact.hide { display: none; }
.q-ic {
  width: 24px; height: 24px; flex: none; border-radius: 50%;
  background: var(--green-800); color: var(--gold-light);
  display: flex; align-items: center; justify-content: center; font-size: .72rem;
}

/* title */
.q-title-wrap { text-align: center; margin-top: 26px; position: relative; z-index: 2; }
.q-title {
  font-family: "Cormorant Garamond", serif;
  font-size: 3.5rem; font-weight: 700; letter-spacing: .35rem; color: var(--green-800);
  line-height: 1;
}
.q-title-flourish { width: 12px; height: 12px; margin: 10px auto 0; background: var(--gold); transform: rotate(45deg); opacity: .85; }
.q-meta { font-size: .74rem; color: var(--muted); margin-top: 6px; letter-spacing: .5px; }
.q-meta.hide { display: none; }

/* client */
.q-client { margin-top: 16px; font-size: .98rem; position: relative; z-index: 2; }
.q-client-label { color: #2b332c; font-weight: 600; }
.q-client-name { color: var(--gold); font-weight: 700; margin-left: 6px; }
.q-intro { text-align: center; font-size: .85rem; color: #4a544c; max-width: 560px; margin: 8px auto 0; line-height: 1.5; position: relative; z-index: 2; }

/* table */
.q-table { width: 100%; border-collapse: collapse; margin-top: 22px; font-size: .82rem; position: relative; z-index: 2; }
.q-table thead th {
  background: var(--green-800); color: #f3ead0; font-weight: 600;
  padding: 11px 10px; text-align: left; font-size: .8rem;
  border-right: 1px solid rgba(255,255,255,.08);
}
.q-table thead th:last-child { border-right: none; }
.c-sn { width: 8%; text-align: center !important; }
.c-qty { width: 12%; }
.c-rate, .c-amt { width: 15%; text-align: right !important; }
.q-table tbody td {
  padding: 12px 10px; vertical-align: top; border-bottom: 1px solid var(--line);
  color: #333b34;
}
.q-table tbody tr:nth-child(even) td { background: #faf8f2; }
.td-sn { text-align: center; font-weight: 600; }
.td-desc { font-weight: 600; color: #2b332c; }
.td-spec { color: #5a635b; font-size: .78rem; }
.td-rate, .td-amt { text-align: right; white-space: nowrap; }
.td-amt { font-weight: 600; }

/* total */
.q-total-wrap { margin-top: 0; display: flex; flex-direction: column; align-items: flex-end; position: relative; z-index: 2; }
.q-total-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 40px;
  width: 46%; background: var(--gold-grad); color: #3a2c05;
  padding: 11px 16px; font-weight: 700;
}
.q-total-label { font-size: .9rem; letter-spacing: .5px; }
.q-total-val { font-size: 1.05rem; }
.q-total-words { width: 46%; text-align: center; font-size: .76rem; font-style: italic; color: #4a544c; padding: 6px 8px; border: 1px solid var(--line); border-top: none; }

/* notes + terms */
.q-blocks { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 30px; padding: 0 6px; position: relative; z-index: 2; }
.q-block-title { font-size: .82rem; font-weight: 700; letter-spacing: .5px; color: var(--green-800); margin-bottom: 10px; }
.q-block ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.q-block li { position: relative; padding-left: 16px; font-size: .78rem; color: #4a544c; line-height: 1.45; }
.q-block li::before { content: ""; position: absolute; left: 0; top: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); }
.q-block.hide { display: none; }

.q-sign { margin-top: 22px; }
.q-sign-for { font-size: .8rem; font-weight: 700; color: var(--green-800); display: block; margin-bottom: 34px; }
.q-sign-line { width: 190px; border-top: 1px solid #8a9489; }
.q-sign-cap { font-size: .72rem; color: var(--muted); margin-top: 4px; display: block; }

/* footer band */
.q-footer {
  margin: auto -52px 0; margin-top: 36px; padding: 26px 52px 24px;
  background:
    radial-gradient(120% 140% at 0% 0%, #11543a 0%, var(--green-900) 60%);
  color: #e8e2cf; display: flex; align-items: center; justify-content: space-between; gap: 24px;
  position: relative; z-index: 2;
  border-top: 4px solid var(--gold);
}
.q-footer.hide { display: none; }
.q-footer-tag { display: flex; align-items: center; gap: 14px; }
.leaf-mini { font-size: 1.8rem; color: var(--gold-light); }
.q-footer-tag em { display: block; font-size: .8rem; color: #cdd6c6; font-style: italic; }
.q-footer-tag strong { display: block; font-family: "Cormorant Garamond", serif; font-size: 1.5rem; color: var(--gold-light); line-height: 1.1; }
.q-footer-tag small { display: block; font-size: .68rem; color: #aab8a4; margin-top: 2px; }
.q-footer-cats { display: flex; gap: 18px; }
.q-cat { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: .6rem; text-align: center; color: #cdd6c6; max-width: 74px; }
.q-cat span { font-size: 1.4rem; color: var(--gold-light); }

/* ---------------- Email modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(6, 10, 6, 0.72);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%; max-width: 460px;
  background: var(--panel);
  border: 1px solid rgba(199,154,59,.3);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  overflow: hidden;
  animation: modalIn .18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.modal-head h2 { font-size: 1rem; font-weight: 700; color: var(--gold-light); }
.modal-close {
  background: none; border: none; color: #cfd6cd; font-size: 1.5rem; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: #fff; }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-note { font-size: .74rem; color: var(--muted); margin-top: 4px; }
.modal-status {
  margin-top: 14px; padding: 10px 12px; border-radius: 8px; font-size: .82rem;
}
.modal-status.info { background: rgba(199,154,59,.14); color: var(--gold-light); border: 1px solid rgba(199,154,59,.35); }
.modal-status.success { background: rgba(40,160,90,.16); color: #8de0ad; border: 1px solid rgba(40,160,90,.4); }
.modal-status.error { background: rgba(220,80,60,.14); color: #ff9a86; border: 1px solid rgba(220,80,60,.4); }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08);
}

/* print */
@media print {
  html, body { margin: 0 !important; padding: 0 !important; height: auto; background: #fff; }
  .topbar, .editor { display: none !important; }
  main, .layout { display: block; height: auto; margin: 0 !important; padding: 0 !important; }
  .preview-wrap { padding: 0 !important; margin: 0 !important; overflow: visible; background: #fff; display: block; }
  .preview-scale { transform: none !important; height: auto !important; margin: 0 !important; padding: 0 !important; }
  .page {
    box-shadow: none;
    width: 210mm;
    height: 293mm;          /* under A4 (297mm) so nothing spills onto a 2nd page */
    min-height: 0;
    margin: 0 !important;
    overflow: hidden;
    page-break-after: avoid;
    break-inside: avoid;
  }
  .q-footer { margin-top: auto; break-inside: avoid; page-break-inside: avoid; }
  @page { size: A4; margin: 0; }
}

/* responsive editor collapse */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .editor { border-right: none; border-bottom: 1px solid rgba(255,255,255,.08); max-height: none; }
  .preview-wrap { padding: 16px; justify-content: flex-start; }
  .topbar { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .topbar-actions .btn { flex: 1 1 auto; min-width: 0; text-align: center; }
}

/* phones */
@media (max-width: 560px) {
  .topbar { padding: 10px 12px; gap: 10px; }
  .topbar-brand { gap: 10px; }
  .topbar-logo { width: 34px; height: 34px; }
  .topbar-brand h1 { font-size: .95rem; }
  .topbar-brand span { display: none; }
  .topbar-actions { gap: 8px; }
  .topbar-actions .btn { padding: 9px 10px; font-size: .78rem; }
  .editor { padding: 14px; }
  .preview-wrap { padding: 10px; }
  .field-grid { grid-template-columns: 1fr; }
  .item-grid { grid-template-columns: 1fr; }
  /* prevent iOS zoom-on-focus */
  input[type="text"], input[type="number"], input[type="date"], input[type="email"], textarea, select { font-size: 16px; }
  .modal { max-width: 100%; }
  .modal-body { max-height: 64vh; }
}
