/* =====================================================================
 * À La Cart Builder — styles (mobile-first, scales up to desktop)
 * ===================================================================== */

:root {
  --navy:      #0f2036;
  --navy-2:    #17304f;
  --orange:    #e8571f;
  --orange-d:  #c8460f;
  --paper:     #f3f2ef;
  --card:      #ffffff;
  --ink:       #14202e;
  --muted:     #6b7785;
  --line:      #d8dbe0;
  --line-dark: #1d2b3c;
  --ok:        #1c7a43;
  --danger:    #c0392b;
  --radius:    12px;
  --shadow:    0 2px 0 var(--line-dark);
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  font: inherit;
  font-weight: 700;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: .7em 1.1em;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
  transition: filter .12s ease, background .12s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-dark { background: var(--navy); color: #fff; }
.btn-dark:hover { background: var(--navy-2); }
.btn-outline { background: #fff; color: var(--ink); border-color: var(--line-dark); }
.btn-outline:hover { background: #f6f6f4; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-block { width: 100%; }
.btn-sm { padding: .5em .8em; font-size: .85rem; border-radius: 8px; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #fdecea; }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- Brand ---------- */
.brand, .topbar-brand { display: flex; align-items: center; gap: .6rem; }
.brand-badge {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 9px;
  background: var(--orange); color: #fff; font-size: 1.2rem;
  flex: 0 0 auto;
}
.brand-kicker { font-size: .62rem; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.brand-name { font-size: 1.1rem; font-weight: 800; line-height: 1.05; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 2px solid var(--line-dark);
  border-radius: var(--radius);
  box-shadow: 6px 6px 0 rgba(15,32,54,.12);
  padding: 1.6rem;
}
.login-card .brand { margin-bottom: 1.2rem; }
.login-title { font-size: 1.5rem; font-weight: 800; }
.login-sub { color: var(--muted); margin: .25rem 0 1.2rem; font-size: .92rem; }

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field-label { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.input {
  font: inherit;
  padding: .75rem .85rem;
  border: 2px solid var(--line-dark);
  border-radius: 9px;
  background: #fff;
  width: 100%;
}
.input:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(232,87,31,.15); }
.form-error { color: var(--danger); font-size: .9rem; margin: 0; }
.input-money { display: flex; align-items: center; gap: .3rem; }
.input-money > span { font-weight: 800; font-size: 1.2rem; color: var(--muted); }
.total-field .input { font-size: 1.3rem; font-weight: 700; }
.row { display: flex; gap: .5rem; align-items: center; }
.row .input { flex: 1; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem;
  padding: .7rem 1rem;
  background: #fff;
  border-bottom: 2px solid var(--line-dark);
}
.topbar .brand-name { color: var(--ink); }
.topbar-actions { display: flex; gap: .4rem; }
.topbar-actions .btn-ghost { color: var(--ink); border-color: var(--line-dark); }
.topbar-actions .btn-ghost:hover { background: #f2f2f0; }

/* ---------- Page & cards ---------- */
.page { max-width: 820px; margin: 0 auto; padding: 1rem 1rem 6rem; display: flex; flex-direction: column; gap: 1rem; }
.card {
  background: var(--card);
  border: 2px solid var(--line-dark);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  background: var(--navy);
  color: #fff;
  padding: .85rem 1rem;
  display: flex; align-items: baseline; gap: .7rem;
}
.card-head h2 { font-size: 1.15rem; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.step { font-size: .62rem; letter-spacing: .18em; text-transform: uppercase; color: var(--orange); font-weight: 800; }
.card-body { padding: 1rem; }
.hint { color: var(--muted); font-size: .9rem; margin: .2rem 0 .8rem; }
.empty-hint { color: var(--muted); text-align: center; padding: 1.4rem 1rem; }
.muted { color: var(--muted); font-weight: 500; }

/* ---------- Projects bar ---------- */
.projects-bar { display: flex; gap: .5rem; align-items: stretch; margin-bottom: 1rem; flex-wrap: wrap; }
.project-tabs { display: flex; gap: .4rem; overflow-x: auto; flex: 1; padding-bottom: 2px; }
.project-tab {
  flex: 0 0 auto;
  text-align: left;
  border: 2px solid var(--line-dark);
  background: #fff;
  border-radius: 9px;
  padding: .5rem .7rem;
  cursor: pointer;
  min-width: 120px;
}
.project-tab .pt-opt { display: block; font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.project-tab .pt-room { display: block; font-weight: 800; font-size: .95rem; }
.project-tab .pt-count { display: block; font-size: .7rem; color: var(--muted); }
.project-tab.active { background: var(--orange); border-color: var(--orange); color: #fff; }
.project-tab.active .pt-opt, .project-tab.active .pt-count { color: rgba(255,255,255,.85); }

/* ---------- Build grid ---------- */
.panel-tools { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.build-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.col-title { font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: .5rem; }

.options-list, .scope-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.option {
  display: flex; align-items: center; gap: .7rem;
  border: 2px solid var(--line-dark);
  border-radius: 9px;
  padding: .7rem .8rem;
  cursor: pointer;
  background: #fff;
  user-select: none;
}
.option:hover { background: #f7f7f5; }
.opt-box {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 2px solid var(--line-dark);
  border-radius: 6px;
  font-weight: 800;
  color: var(--muted);
}
.option.selected { background: #fde9df; border-color: var(--orange); }
.option.selected .opt-box { background: var(--orange); border-color: var(--orange); color: #fff; }
.opt-label { font-weight: 600; }

.scope-list { counter-reset: none; }
.scope-empty { color: var(--muted); border: 2px dashed var(--line); border-radius: 9px; padding: 1rem; text-align: center; list-style: none; }
.scope-item {
  display: flex; align-items: center; gap: .6rem;
  border: 2px solid var(--line-dark);
  border-radius: 9px;
  padding: .6rem .7rem;
  background: #fff;
}
.scope-num { font-weight: 800; color: var(--orange); min-width: 1.6em; }
.scope-text { flex: 1; font-weight: 600; }
.scope-ctrls { display: flex; gap: .15rem; }
.scope-ctrls button {
  border: none; background: #eef0f2; color: var(--ink);
  width: 30px; height: 30px; border-radius: 7px; cursor: pointer; font-size: .9rem; font-weight: 700;
}
.scope-ctrls button:hover { background: #e0e3e7; }

/* ---------- Action bar ---------- */
.action-bar {
  position: sticky; bottom: 0;
  display: flex; gap: .6rem;
  padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom));
  background: rgba(243,242,239,.96);
  backdrop-filter: blur(6px);
  border-top: 2px solid var(--line-dark);
  margin: 0 -1rem;
}
.action-bar .btn { flex: 1; }
.status-msg { display: none; } /* replaced by the centered toast below */

/* ---------- Toast (centered confirmation) ---------- */
.toast {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.94);
  display: flex; align-items: center; gap: .7rem;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line-dark);
  border-radius: 16px;
  padding: 1.05rem 1.5rem;
  font-weight: 700; font-size: 1.05rem;
  box-shadow: 0 14px 44px rgba(15,32,54,.28);
  z-index: 60;
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  max-width: min(90vw, 380px);
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast-icon {
  flex: 0 0 auto;
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--ok); color: #fff;
  font-weight: 800; font-size: 1.1rem;
}
.toast.err .toast-icon { background: var(--danger); }
.toast-msg { line-height: 1.3; }

/* ---------- Estimates list ---------- */
.est-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.est-row:last-child { border-bottom: none; }
.est-name { font-weight: 800; font-size: 1.05rem; }
.est-meta { color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: .2rem; }
.est-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.badge { font-size: .65rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: .18em .5em; border-radius: 20px; }
.badge-draft { background: #eef0f2; color: var(--muted); }
.badge-final { background: #dff3e6; color: var(--ok); }

/* ---------- Modals ---------- */
body.modal-open { overflow: hidden; }
.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(15,32,54,.5);
  display: grid; place-items: center;
  padding: 1rem;
}
/* Keep modals closed until opened (the [hidden] attribute must win over display:grid). */
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 460px;
  background: #fff; border: 2px solid var(--line-dark); border-radius: var(--radius);
  padding: 1.2rem; max-height: 85vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: .8rem;
}
.modal-card h3 { font-size: 1.2rem; font-weight: 800; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .3rem; }
.new-room summary { cursor: pointer; color: var(--orange); font-weight: 700; font-size: .9rem; }
.new-room .row { margin-top: .5rem; }

.edit-items-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.edit-item { display: flex; gap: .35rem; align-items: center; }
.edit-item .edit-item-input { flex: 1; }
.mini { border: 2px solid var(--line-dark); background: #fff; border-radius: 7px; padding: .5em .6em; font-weight: 700; cursor: pointer; font-size: .8rem; }
.mini.save { background: var(--navy); color: #fff; border-color: var(--navy); }
.mini.del { color: var(--danger); border-color: var(--danger); }
.add-row { margin-top: .3rem; }

/* =====================================================================
 * Estimate document (estimate.php)
 * ===================================================================== */
.doc-body { background: #e9e9e6; }
.doc-toolbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem; background: var(--navy);
}
.doc-toolbar-right { display: flex; gap: .5rem; }
.doc {
  max-width: 760px;
  margin: 1.2rem auto;
  background: #fff;
  border: 1px solid #ccc;
  padding: 2rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
}
.doc-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 3px solid var(--navy); padding-bottom: 1rem; flex-wrap: wrap; }
.doc-brand { display: flex; gap: .9rem; align-items: center; }
.doc-logo { width: 72px; height: 72px; object-fit: contain; }
.doc-logo-placeholder {
  width: 72px; height: 72px; border: 2px solid var(--line-dark);
  display: grid; place-items: center; font-size: .7rem; font-weight: 800; color: var(--muted); letter-spacing: .1em;
}
.doc-company { font-size: 1.5rem; font-weight: 800; }
.doc-company-meta { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.doc-title-block { text-align: right; }
.doc-kicker { font-size: .7rem; letter-spacing: .16em; text-transform: uppercase; color: var(--orange); font-weight: 800; }
.doc-title { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
.doc-date { font-size: .82rem; color: var(--muted); }
.doc-customer { display: flex; gap: 2rem; margin: 1.2rem 0; flex-wrap: wrap; }
.doc-customer .lbl { display: block; font-size: .62rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.doc-customer .val { font-weight: 700; font-size: 1.05rem; }
.doc-project { margin: 1.2rem 0; }
.doc-project-title { font-size: 1.05rem; font-weight: 800; background: var(--navy); color: #fff; padding: .5rem .8rem; border-radius: 6px; }
.doc-scope { margin: .7rem 0 0; padding-left: 1.6rem; }
.doc-scope li { padding: .28rem 0; border-bottom: 1px dotted var(--line); }
.doc-empty { color: var(--muted); font-style: italic; }
.doc-total {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 1.6rem; padding: 1rem 1.2rem;
  background: var(--navy); color: #fff; border-radius: 8px;
}
.doc-total-label { font-size: .8rem; letter-spacing: .16em; text-transform: uppercase; font-weight: 800; }
.doc-total-value { font-size: 1.8rem; font-weight: 800; }
.doc-footer { margin-top: 1.6rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .78rem; text-align: center; }
.doc-footer p { margin: .2rem 0; }

/* ---------- Print ---------- */
@media print {
  .no-print, .doc-toolbar { display: none !important; }
  .doc-body { background: #fff; }
  .doc { margin: 0; border: none; box-shadow: none; max-width: none; padding: 0; }
  @page { margin: 16mm; }
}

/* =====================================================================
 * Desktop (mobile-first: everything above is the phone layout)
 * ===================================================================== */
@media (min-width: 720px) {
  .build-grid { grid-template-columns: 1fr 1fr; }
  .card-body { padding: 1.4rem; }
}
