/* ═══════════════ LIVORA Quote Studio ═══════════════ */
:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #241d16;
  --ink-soft: #4c4238;
  --muted: #8a7d6f;
  --faint: #b3a89c;
  --line: #e9e2d8;
  --line-strong: #d9cfc1;
  --accent: #a05a2c;
  --accent-dark: #82461f;
  --accent-soft: #f3e7db;
  --danger: #c0392b;
  --green: #1e7d4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(36,29,22,.05), 0 8px 28px rgba(36,29,22,.07);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 760px; margin: 0 auto; padding: 0 14px 130px; }
.hidden { display: none !important; }

/* ─── Top bar ─── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 2px 10px;
  background: linear-gradient(var(--bg) 82%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-dark));
  color: #fff; font-family: 'Fraunces', serif; font-size: 22px; font-weight: 600;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(160,90,44,.35);
}
.brand-name { font-family: 'Fraunces', serif; font-size: 19px; font-weight: 700; letter-spacing: .2px; line-height: 1.1; }
.brand-name span { color: var(--accent); font-weight: 500; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: .6px; text-transform: uppercase; font-weight: 600; }
.top-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink-soft); font-size: 15px; cursor: pointer;
  display: grid; place-items: center; transition: all .15s;
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--accent); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

/* ─── Cards & fields ─── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.card-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--muted); margin-bottom: 10px;
}
.field {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fbfaf8;
  padding: 10px 12px; font-size: 14.5px; font-family: inherit; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }
.field::placeholder { color: var(--faint); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.cust-card .field { margin-bottom: 10px; }

/* ─── Sections ─── */
.section-card { margin-bottom: 12px; }
.sec-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; cursor: pointer; user-select: none;
}
.sec-head .chev { color: var(--faint); font-size: 12px; transition: transform .2s; }
.sec-card.collapsed .chev { transform: rotate(-90deg); }
.sec-title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sec-name {
  font-weight: 600; font-size: 15px; border: none; background: transparent; color: var(--ink);
  font-family: inherit; width: auto; min-width: 120px; padding: 2px 4px; border-radius: 6px;
}
.sec-name:focus { outline: none; background: var(--accent-soft); }
.sec-count { font-size: 11px; color: var(--muted); background: var(--bg); padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.sec-sub { font-size: 12px; color: var(--muted); margin-top: 2px; font-weight: 500; }
.sec-body { padding: 0 16px 14px; border-top: 1px dashed var(--line); }

/* item rows */
.item-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.item-row:last-child { border-bottom: none; }
.item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 7px; }
.item-desc {
  flex: 1; font-size: 13.5px; font-weight: 600; border: none; background: transparent;
  font-family: inherit; color: var(--ink); padding: 3px 4px; border-radius: 6px;
}
.item-desc:focus { outline: none; background: var(--accent-soft); }
.item-dims { display: grid; grid-template-columns: 1fr 1fr 1fr 1.15fr; gap: 6px; }
.item-row.lump .item-dims { grid-template-columns: 1fr 1.15fr; }
.dim-field { position: relative; }
.dim-field label {
  position: absolute; top: -6px; left: 8px; font-size: 9px; font-weight: 700; letter-spacing: .6px;
  color: var(--faint); background: var(--card); padding: 0 4px; text-transform: uppercase; z-index: 1;
}
.dim-field input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fbfaf8;
  padding: 9px 6px 7px; font-size: 13px; text-align: center; font-family: inherit; color: var(--ink);
}
.dim-field input:focus { outline: none; border-color: var(--accent); background: #fff; }
.item-amount {
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
  font-variant-numeric: tabular-nums; color: var(--accent-dark);
}
.amount-box { background: var(--accent-soft); border-radius: 8px; padding: 9px 8px 7px; width: 100%; text-align: center; }
.item-del {
  border: none; background: none; color: var(--faint); font-size: 16px; cursor: pointer; padding: 4px;
}
.item-del:hover { color: var(--danger); }
.sec-subtotal { display: flex; justify-content: space-between; padding-top: 10px; font-size: 13px; color: var(--muted); font-weight: 600; }
.sec-subtotal b { color: var(--ink); font-variant-numeric: tabular-nums; }

.add-item-btn {
  width: 100%; margin-top: 10px; padding: 9px; border: 1.5px dashed var(--line-strong);
  background: transparent; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 13px;
  cursor: pointer; transition: all .15s; font-family: inherit;
}
.add-item-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.add-section {
  width: 100%; padding: 13px; border: 1.5px dashed var(--line-strong); background: transparent;
  border-radius: var(--radius); color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer;
  font-family: inherit; transition: all .15s;
}
.add-section:hover { border-color: var(--accent); color: var(--accent); background: #fff; }

/* quiet danger button — clear quote lives at the bottom, out of the way */
.clear-quote {
  width: 100%; margin-top: 10px; padding: 13px;
  background: transparent;
  border: 1.5px dashed rgba(192, 57, 43, .4);
  border-radius: var(--radius);
  color: var(--danger); font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.clear-quote:hover { background: rgba(192, 57, 43, .05); border-color: var(--danger); }

/* ─── Sticky summary bar ─── */
.sum-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: rgba(255,255,255,.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
}
.sum-count { font-size: 12px; color: var(--muted); font-weight: 600; }
.sum-total { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.sum-total small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.sum-adj { display: flex; gap: 8px; align-items: flex-end; }
.adj-field { position: relative; }
.adj-field label {
  position: absolute; top: -7px; left: 8px; font-size: 9px; font-weight: 700; letter-spacing: .6px;
  color: var(--faint); background: #fff; padding: 0 4px; text-transform: uppercase; z-index: 1;
}
.adj-field input {
  width: 92px; border: 1px solid var(--line); border-radius: 9px; background: #fbfaf8;
  padding: 9px 8px 7px; font-size: 13px; text-align: center; font-family: inherit; color: var(--ink);
}
.adj-field input:focus { outline: none; border-color: var(--accent); background: #fff; }
.sum-btns { display: flex; gap: 8px; }
.bar-spacer { height: 24px; }

/* ─── Buttons ─── */
.btn {
  border: none; border-radius: 12px; padding: 12px 18px; font-size: 14.5px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all .15s; white-space: nowrap;
}
.btn.primary { background: linear-gradient(145deg, var(--accent), var(--accent-dark)); color: #fff; box-shadow: 0 4px 14px rgba(160,90,44,.35); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: var(--card); border: 1px solid var(--line); color: var(--ink-soft); }
.btn.ghost:hover { border-color: var(--line-strong); }
.btn.full { width: 100%; margin-top: 12px; }

/* ─── Modal ─── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(36,29,22,.45); }
.modal-sheet {
  position: relative; width: 100%; max-width: 560px; margin: 0 auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 82vh; overflow-y: auto; animation: sheetUp .22s ease;
  box-shadow: 0 -8px 40px rgba(36,29,22,.18);
}
.modal-sheet.small { max-width: 480px; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.modal-sheet .field { margin-bottom: 10px; }
.modal-foot { margin-top: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); margin-top: 2px; cursor: pointer; }

/* library grid */
.lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lib-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
  cursor: pointer; transition: all .12s; text-align: left; font-family: inherit;
}
.lib-item:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(160,90,44,.12); }
.lib-name { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.3; }
.lib-cat { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 3px; font-weight: 600; }
.lib-rate { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-top: 5px; font-variant-numeric: tabular-nums; }
.lib-rate small { font-weight: 500; color: var(--faint); }

/* ═══════════════ QUOTE VIEW (final template) ═══════════════ */
.quote-view { background: var(--bg); min-height: 100vh; padding: 70px 12px 120px; }
.quote-close {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 14px; z-index: 60;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255,255,255,.95);
  font-size: 15px; color: var(--ink-soft); cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 4px 16px rgba(36,29,22,.12);
  transition: all .15s;
}
.quote-close:hover { color: var(--danger); border-color: var(--danger); }
.quote-actions {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; max-width: 760px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.92); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
.quote-total { flex: 1; min-width: 0; }
.qt-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.qt-amount { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.3px; line-height: 1.15; }
.qt-breakdown { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote-actions .btn { flex: 0 0 auto; }
.quote-sheet {
  max-width: 760px; margin: 0 auto; background: #fff; border-radius: 12px;
  box-shadow: var(--shadow); padding: 28px 24px; overflow-x: auto;
}

/* quote sheet internals */
.qs-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; border-bottom: 3px double #241d16; padding-bottom: 12px; }
.qs-brand { font-family: 'Fraunces', serif; font-size: 26px; font-weight: 700; letter-spacing: .3px; }
.qs-brand span { color: var(--accent); }
.qs-company { font-size: 12px; color: var(--ink-soft); margin-top: 4px; line-height: 1.5; }
.qs-title {
  text-align: center; font-family: 'Fraunces', serif; font-size: 21px; font-weight: 700;
  letter-spacing: 6px; margin: 14px 0 4px; color: var(--ink);
}
.qs-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; margin: 10px 0 4px; }
.qs-meta b { font-weight: 700; }
.qs-cust { border: 1.5px solid #241d16; padding: 8px 12px; font-size: 12.5px; margin: 8px 0 14px; min-height: 34px; }
.qs-cust .lbl { font-weight: 700; }

.qs-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.qs-table th {
  background: #241d16; color: #fff; font-weight: 600; text-align: left;
  padding: 6px 8px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px;
}
.qs-table td { border: 1px solid #c9bfb2; padding: 5px 8px; vertical-align: top; }
.qs-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.qs-table .room-row td { background: var(--accent-soft); font-weight: 700; font-size: 11px; color: #241d16; }
.qs-table .subtotal-row td { font-weight: 600; background: #fbf8f4; border-top: 1px solid var(--line-strong); font-size: 10.5px; color: var(--ink-soft); }
.qs-table .lump-row td.desc { font-style: italic; }
.qs-words { margin-top: 12px; font-size: 12px; font-weight: 500; border: 1px solid #241d16; padding: 8px 12px; color: var(--ink); }
.qs-words .lbl { font-weight: 700; }
.qs-total-row td { border-top: 2px solid #241d16; font-weight: 700; }
.qs-grand td { background: #241d16; color: #fff; font-weight: 700; border: 1px solid #241d16; }

.qs-note { margin-top: 16px; font-size: 11.5px; }
.qs-note h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #241d16; padding-bottom: 3px; margin-bottom: 6px; }
.qs-terms { list-style: none; }
.qs-terms li { display: flex; gap: 8px; margin-top: 3px; }
.qs-terms .n { font-weight: 700; min-width: 16px; }
.qs-spec { margin-top: 14px; font-size: 11.5px; }
.qs-spec h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #241d16; padding-bottom: 3px; margin-bottom: 6px; }
.qs-spec-table { width: 100%; border-collapse: collapse; font-size: 10.5px; }
.qs-spec-table td { border: 1px solid #c9bfb2; padding: 4px 8px; vertical-align: top; line-height: 1.4; }
.qs-spec-table .spec-c { font-weight: 600; background: #fbf8f4; width: 32%; font-size: 10px; text-transform: uppercase; letter-spacing: .3px; }
.qs-sigs { display: flex; justify-content: space-between; gap: 20px; margin-top: 44px; }
.qs-sig { flex: 1; text-align: center; font-size: 12px; font-weight: 600; border-top: 1px solid #241d16; padding-top: 8px; }
.qs-sig small { display: block; font-weight: 400; color: var(--muted); font-size: 10.5px; margin-top: 2px; }
.qs-foot { margin-top: 16px; text-align: center; font-size: 10.5px; color: var(--muted); }

/* desktop niceties */
@media (min-width: 640px) {
  .modal { align-items: center; padding: 20px; }
  .modal-sheet { border-radius: 20px; max-height: 80vh; }
  .lib-grid { grid-template-columns: repeat(3, 1fr); }
  .quote-sheet { padding: 40px 44px; }
}

/* ─── Print (A4) — natural flow, clean breaks, readable sizes ─── */
@media print {
  @page { size: A4; margin: 12mm 10mm; }
  body { background: #fff; font-size: 11px; }
  #builder, .sum-bar, .quote-actions, .quote-close, .modal { display: none !important; }
  .quote-view { padding: 0; background: #fff; min-height: auto; }
  .quote-sheet { box-shadow: none; border-radius: 0; padding: 0; max-width: none; }
  /* table header repeats; rows & section titles never split across pages */
  .qs-table { font-size: 10.5px; }
  .qs-table th { padding: 4px 6px; font-size: 10px; }
  .qs-table td { padding: 4px 6px; }
  .qs-table tr { break-inside: avoid; }
  .qs-table .room-row { break-after: avoid; }
  .qs-words { margin-top: 10px; padding: 6px 10px; font-size: 11px; }
  .qs-note { margin-top: 12px; font-size: 10.5px; }
  .qs-note h4, .qs-spec h4 { break-after: avoid; }
  .qs-spec { margin-top: 12px; font-size: 10.5px; }
  .qs-spec-table { font-size: 9.5px; }
  .qs-spec-table td { padding: 3px 6px; line-height: 1.4; }
  .qs-spec-table tr { break-inside: avoid; }
  .qs-sigs { margin-top: 30px; break-inside: avoid; }
  .qs-foot { margin-top: 12px; }
  .qs-brand { font-size: 24px; }
  .qs-cust { padding: 6px 10px; margin: 6px 0 10px; }
}

