:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-2);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;          /* no horizontal scrolling, ever */
  overscroll-behavior-x: none; /* kill the horizontal rubber-band bounce */
}

h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); font-weight: 400; font-size: .85rem; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  padding-top: max(.75rem, env(safe-area-inset-top));
  background: var(--bg);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; appearance: none; border: 0; background: transparent; color: #fff; cursor: pointer; padding: 0; }
.brand-mark { color: #38bdf8; font-size: 1.3rem; }
.brand-name { font-size: 1.05rem; }
.nav-btn { appearance: none; border: 1px solid transparent; background: rgba(255,255,255,.1); color: #e2e8f0; font-size: .9rem; font-weight: 600; padding: .5rem .9rem; border-radius: 9px; cursor: pointer; }
.nav-btn:active { background: rgba(255,255,255,.18); }
.nav-btn.active { background: #fff; color: var(--bg); }
.nav-btn.ghost { background: transparent; border-color: rgba(255,255,255,.22); color: #cbd5e1; }

main { padding: 1rem; max-width: 1200px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .95rem;
  margin-bottom: .85rem;
}

/* Quote layout */
.quote-layout { display: grid; grid-template-columns: 1fr 340px; gap: 1rem; align-items: start; }
.quote-summary { position: sticky; top: 122px; }
@media (max-width: 860px) {
  .quote-layout { grid-template-columns: 1fr; }
  .quote-summary { position: static; }
}

/* Fields */
.field { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; font-weight: 600; color: var(--muted); flex: 1; }
.field-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.field select, .field input, input.inp, select.inp {
  font-size: 1rem;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-weight: 500;
  width: 100%;
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2364748b' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem; }

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 600;
  padding: .6rem 1rem;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:active { background: var(--surface-2); }
.btn-sm { padding: .4rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; margin-top: .75rem; }
.btn-danger { background: #fff; border-color: var(--border); color: var(--red); }
.icon-btn {
  appearance: none; border: 1px solid var(--border); background: #fff; color: var(--muted);
  width: 38px; height: 38px; border-radius: 9px; font-size: 1.1rem; cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn.danger { color: var(--red); }
.icon { display: inline-flex; align-items: center; justify-content: center; }
.icon svg { display: block; }

/* Sections */
.section-list-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.section-list-header h2 { margin: 0; }
.section-card .section-top { display: flex; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.section-card .section-name { flex: 1; font-size: 1.05rem; font-weight: 700; }
.subhead { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: .8rem 0 .35rem; }

.measure-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.measure-row .inp { max-width: 140px; }
.waste-row .suffix-input { max-width: 120px; }
.waste-row .suffix-input .inp { max-width: 120px; }
.measure-row .unit { color: var(--muted); font-size: .85rem; }
.measure-row .spacer { flex: 1; }
.section-area { font-weight: 700; }

.modifier-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid var(--border); background: #fff; border-radius: 999px;
  padding: .45rem .8rem; font-size: .9rem; font-weight: 600; cursor: pointer; user-select: none;
}
.chip.on { background: #eff6ff; border-color: var(--primary); color: var(--primary-dark); }
.chip .chip-meta { font-weight: 500; color: var(--muted); font-size: .8rem; }
.chip.on .chip-meta { color: var(--primary); }

.section-subtotal { display: flex; justify-content: space-between; align-items: baseline; margin-top: .8rem; padding-top: .7rem; border-top: 1px dashed var(--border); }
.section-subtotal .amt { font-size: 1.15rem; font-weight: 800; }

/* Extras */
.extras-list { display: flex; flex-direction: column; gap: .6rem; }
.extra-row { display: flex; align-items: center; gap: .75rem; }
.extra-row .extra-name { flex: 1; font-weight: 600; }
.extra-row .extra-price { color: var(--muted); font-size: .85rem; }
.stepper { display: flex; align-items: center; gap: .5rem; }
.stepper .qty { min-width: 2ch; text-align: center; font-weight: 800; font-size: 1.1rem; }
.step-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border); background: #fff;
  font-size: 1.4rem; font-weight: 700; color: var(--text); cursor: pointer; line-height: 1;
}
.step-btn:active { background: var(--surface-2); }

/* Promotions */
.promo-list { display: flex; flex-direction: column; gap: .5rem; }
.promo-item { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem; border: 1px solid var(--border); border-radius: 10px; }
.promo-item.on { border-color: var(--green); background: #f0fdf4; }
.promo-item input { margin-top: .2rem; width: 20px; height: 20px; flex: none; }
.promo-item .promo-name { font-weight: 700; }
.promo-item .promo-desc { font-size: .85rem; color: var(--muted); }
.promo-item .promo-amt { margin-left: auto; font-weight: 700; color: var(--green); white-space: nowrap; }

/* Summary */
.summary-card h2 { margin-bottom: 1rem; }
.sum-row { display: flex; justify-content: space-between; padding: .35rem 0; font-size: .95rem; }
.sum-row.sub { color: var(--muted); font-size: .85rem; padding-left: .6rem; }
.sum-row.discount { color: var(--green); }
.sum-divider { border-top: 1px solid var(--border); margin: .5rem 0; }
.sum-total { display: flex; justify-content: space-between; align-items: baseline; margin-top: .5rem; padding-top: .6rem; border-top: 2px solid var(--text); }
.sum-total .label { font-weight: 700; }
.sum-total .amt { font-size: 1.6rem; font-weight: 900; }
.sum-empty { color: var(--muted); font-size: .9rem; }
.sum-row.strong { font-weight: 700; }
.profit-box { margin-top: .75rem; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 12px; padding: .7rem .85rem; }
.profit-row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; color: #166534; }
.profit-row .profit-amt { font-size: 1.25rem; font-weight: 900; }
.profit-sub { font-size: .8rem; color: #16a34a; margin-top: .15rem; }

/* Settings */
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; flex-wrap: wrap; gap: .5rem; }
.settings-actions { display: flex; gap: .5rem; }
.settings-status { min-height: 1.2rem; color: var(--green); font-weight: 600; font-size: .9rem; margin: 0 0 .5rem; }
.editor-row {
  display: grid; gap: .5rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border);
}
.editor-row:last-of-type { border-bottom: 0; }
.editor-row.product, .editor-row.sub { grid-template-columns: 1fr 130px 38px; }
.editor-row.modifier { grid-template-columns: 1fr 140px 130px 110px 38px; }
.editor-row.promotion { grid-template-columns: 1fr 1.4fr 120px 38px; }
.editor-row.extra { grid-template-columns: 1fr 120px 38px; }
.editor-row .col-label { display: none; }
@media (max-width: 720px) {
  .editor-row { grid-template-columns: 1fr !important; gap: .35rem; padding: .8rem 0; }
  .editor-row .col-label { display: block; font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
  .editor-row .icon-btn { justify-self: end; }
}
/* Hide the app shell until the auth check resolves (prevents a flash before redirect) */
body.booting .app-header,
body.booting main { visibility: hidden; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin: .25rem 0 1rem; font-size: 1.4rem; }
.login-card .field { margin-bottom: .9rem; }
.login-brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--bg); }
.login-brand .brand-mark { color: #38bdf8; font-size: 1.3rem; }
.login-error { color: var(--red); font-size: .9rem; font-weight: 600; min-height: 1.1rem; margin: 0 0 .5rem; }

/* Header logout */
.header-right { display: flex; align-items: center; gap: .75rem; }
.logout-btn { appearance: none; border: 1px solid rgba(255,255,255,.25); background: transparent; color: #cbd5e1; font-size: .85rem; font-weight: 600; padding: .45rem .8rem; border-radius: 8px; cursor: pointer; }
.logout-btn:active { background: rgba(255,255,255,.1); }

/* Section header totals (top-right) */
.section-head-totals { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; white-space: nowrap; }
.section-head-totals .head-area { font-size: .8rem; color: var(--muted); font-weight: 600; }
.section-head-totals .amt { font-size: 1.15rem; font-weight: 800; }

/* Inline mini add buttons (+) */
.add-inline { margin: .25rem 0 .25rem; }
.add-mini {
  width: 40px; height: 40px; border-radius: 10px; border: 1px dashed var(--border);
  background: #fff; color: var(--primary); font-size: 1.5rem; font-weight: 700; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.add-mini:active { background: var(--surface-2); }

/* Centered add-section button below sections */
.add-section-wrap { display: flex; justify-content: center; margin: 0 0 1.25rem; }
.add-fab {
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--primary); color: #fff;
  font-size: 2rem; font-weight: 400; line-height: 1; cursor: pointer; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
}
.add-fab:active { background: var(--primary-dark); }

/* Modifier chip remove (×) */
.chip-x {
  appearance: none; border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 1.1rem; line-height: 1; padding: 0 0 0 .15rem; font-weight: 700; opacity: .7;
}
.chip-x:hover { opacity: 1; }

/* Dashboard */
.dashboard { max-width: 760px; margin: 0 auto; }
.new-quote-cta {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: .6rem;
  background: var(--primary); color: #fff; border: 0; border-radius: var(--radius);
  font-size: 1.15rem; font-weight: 700; padding: 1.25rem; cursor: pointer; box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.new-quote-cta:active { background: var(--primary-dark); }
.new-quote-cta .cta-plus { font-size: 1.5rem; font-weight: 400; line-height: 1; }
.dash-head { margin-bottom: .6rem; }
.dash-head h2 { margin: 0; font-size: 1rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.dash-quotes { display: flex; flex-direction: column; gap: .6rem; }
.dash-empty { color: var(--muted); text-align: center; padding: 1.5rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.dash-quote-card { display: flex; align-items: center; gap: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: .3rem .6rem .3rem .3rem; }
.dash-quote-main { flex: 1; min-width: 0; text-align: left; appearance: none; border: 0; background: transparent; cursor: pointer; padding: .7rem; border-radius: 10px; }
.dash-quote-main:active { background: var(--surface-2); }
.dash-quote-name { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-quote-meta { font-size: .82rem; color: var(--muted); margin-top: .15rem; }
.dash-quote-total { font-weight: 800; font-size: 1.05rem; white-space: nowrap; }

/* Quote workspace top bar */
.quote-bar {
  position: sticky; top: 58px; z-index: 15;
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface-2); padding: .6rem 0 .8rem; margin-bottom: .25rem;
}
.back-btn { appearance: none; width: 42px; height: 42px; flex: none; border: 1px solid var(--border); background: #fff; border-radius: 10px; font-size: 1.3rem; cursor: pointer; color: var(--text); line-height: 1; }
.back-btn:active { background: var(--surface-2); }
.quote-title-input { flex: 1; min-width: 0; font-size: 1.05rem; font-weight: 700; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.quote-bar .btn { flex: none; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal {
  background: #fff; border-radius: var(--radius); width: 100%; max-width: 460px;
  max-height: 85vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 1rem; overflow-y: auto; }
.modal-actions { padding: 1rem; border-top: 1px solid var(--border); }

/* Pickers + saved list */
.picker-list { display: flex; flex-direction: column; gap: .5rem; }
.picker-item {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .75rem .85rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
.picker-item.on { border-color: var(--primary); background: #eff6ff; }
.picker-name { font-weight: 700; }
.picker-meta { font-size: .82rem; color: var(--muted); }
.picker-check { color: var(--primary); font-weight: 800; font-size: 1.2rem; width: 1.2rem; text-align: center; flex: none; }
.saved-item { display: flex; align-items: center; gap: .6rem; padding: .6rem; border: 1px solid var(--border); border-radius: 10px; }
.saved-info { flex: 1; cursor: pointer; min-width: 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem;
  transform: translateX(-50%) translateY(2rem);
  background: var(--bg); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); opacity: 0; pointer-events: none; z-index: 60; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }

.prefix-input { position: relative; display: flex; align-items: center; }
.prefix-input .prefix { position: absolute; left: .7rem; color: var(--muted); font-weight: 600; pointer-events: none; }
.prefix-input input { padding-left: 1.4rem; }
.suffix-input { position: relative; display: flex; align-items: center; }
.suffix-input .suffix { position: absolute; right: .7rem; color: var(--muted); font-weight: 600; pointer-events: none; }
.suffix-input input { padding-right: 1.8rem; }
