:root {
  --navy: #0f172a;
  --navy-2: #1e293b;
  --amber: #f59e0b;
  --amber-d: #d97706;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
.muted { color: var(--muted); }
.error { color: var(--red); font-size: .9rem; }
.hidden, [hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1e293b, var(--navy));
  padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border-radius: 18px;
  padding: 2rem 1.5rem;
  box-shadow: 0 20px 40px rgba(0,0,0,.3);
}
.brand { text-align: center; margin-bottom: 1.25rem; }
.brand-mark {
  width: 56px; height: 56px; margin: 0 auto .5rem;
  display: grid; place-items: center;
  background: var(--amber); color: var(--navy);
  font-weight: 800; font-size: 1.4rem; border-radius: 14px;
}
.login-form { display: grid; gap: .9rem; }
label { display: grid; gap: .35rem; font-size: .85rem; font-weight: 600; color: var(--navy-2); }
input, select, textarea {
  font: inherit; padding: .7rem .75rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--amber); border-color: var(--amber); }
textarea { resize: vertical; min-height: 60px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border: 1px solid transparent; border-radius: 10px;
  padding: .7rem 1rem; background: #fff; color: var(--navy);
  border-color: var(--line);
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--amber); border-color: var(--amber-d); color: #1a1204; }
.btn-primary:hover { background: var(--amber-d); }
.btn-dark { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { color: var(--red); border-color: transparent; background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: .45rem .6rem; font-size: .85rem; }

/* ---------- App layout ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: #fff;
  padding: max(.75rem, env(safe-area-inset-top)) 1rem .75rem;
  display: flex; align-items: center; gap: .75rem;
}
.app-header .title { font-weight: 800; font-size: 1.05rem; flex: 1; }
.app-header .back { background: transparent; border: none; color: #fff; font-size: 1.4rem; cursor: pointer; padding: 0 .25rem; }
.chip-badge { font-size: .68rem; font-weight: 700; padding: .15rem .45rem; border-radius: 999px; background: var(--navy-2); color: #cbd5e1; }
.chip-badge.on { background: #064e3b; color: #6ee7b7; }

main { padding: 1rem; padding-bottom: 6rem; max-width: 760px; margin: 0 auto; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; margin-bottom: 1rem;
}
.card h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row { display: grid; gap: .75rem; }
.row.two { grid-template-columns: 1fr 1fr; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 460px) { .row.three { grid-template-columns: 1fr 1fr; } }

/* ---------- Estimate list ---------- */
.list-toolbar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.list-toolbar input { flex: 1; }
.est-item {
  display: flex; align-items: center; gap: .75rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: .6rem;
  cursor: pointer; box-shadow: var(--shadow);
}
.est-item:hover { border-color: var(--amber); }
.est-item .meta { flex: 1; min-width: 0; }
.est-item .name { font-weight: 700; }
.est-item .sub { font-size: .8rem; color: var(--muted); }
.est-item .amt { font-weight: 800; font-size: 1.05rem; }
.status { font-size: .68rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; }
.status.draft { background: #fef3c7; color: #92400e; }
.status.final { background: #dcfce7; color: #166534; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }

/* ---------- Line items ---------- */
.item-block {
  border: 1px solid var(--line); border-radius: 12px;
  padding: .85rem; margin-bottom: .75rem; background: #fbfcfe;
}
.item-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.item-head .grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.seg button { border: none; background: transparent; padding: .4rem .8rem; font-weight: 700; font-size: .8rem; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--navy); color: #fff; }
.line-total { text-align: right; font-weight: 800; }
.suggestions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.sugg-chip {
  font-size: .78rem; background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe;
  border-radius: 999px; padding: .25rem .6rem; cursor: pointer;
}
.sugg-chip b { font-weight: 800; }

/* Predictive dropdown */
.ac-wrap { position: relative; width: 100%; }
.ac-wrap input { width: 100%; }
.ac-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 40;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15,23,42,.16); max-height: 240px; overflow-y: auto;
}
.ac-item { padding: .6rem .75rem; font-size: .92rem; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item:active { background: #fff7ed; color: var(--amber-d); font-weight: 600; }

.thumb { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photo-row { display: flex; align-items: center; gap: .6rem; }

/* ---------- Totals ---------- */
.totals { display: grid; gap: .35rem; }
.totals .t { display: flex; justify-content: space-between; }
.totals .grand { font-size: 1.4rem; font-weight: 900; border-top: 2px solid var(--navy); padding-top: .5rem; margin-top: .25rem; }

/* ---------- Sticky action bar ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom));
  display: flex; gap: .6rem; max-width: 760px; margin: 0 auto;
}
.actionbar .btn { flex: 1; }

.fab {
  position: fixed; right: 1.1rem; bottom: calc(1.1rem + env(safe-area-inset-bottom));
  z-index: 25; width: 56px; height: 56px; border-radius: 50%;
  background: var(--amber); color: #1a1204; border: none; font-size: 1.8rem;
  box-shadow: 0 6px 16px rgba(0,0,0,.25); cursor: pointer;
}

.add-line { width: 100%; border: 1px dashed var(--line); background: #fff; color: var(--navy); padding: .7rem; border-radius: 10px; font-weight: 700; cursor: pointer; }
.add-line:hover { border-color: var(--amber); }

.toast {
  position: fixed; bottom: 5.5rem; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: .6rem 1rem; border-radius: 10px;
  z-index: 50; font-size: .9rem; box-shadow: 0 6px 16px rgba(0,0,0,.3); max-width: 90%;
}

/* ---------- Print / preview ---------- */
.preview { background: #fff; padding: 1.5rem; }
.preview table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.preview th, .preview td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.preview td.num, .preview th.num { text-align: right; }
@media print {
  .app-header, .actionbar, .fab, .no-print { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
}
