:root {
  --navy: #0f2a4a; --navy-2: #173a63; --sun: #f2a516; --sun-soft: #fdf3dc; --ink: #1d2433; --muted: #657088;
  --line: #dfe4ec; --bg: #f3f5f9; --card: #fff; --ok: #1d8a4c; --bad: #c0392b; --radius: 10px;
  --shadow: 0 1px 2px rgba(15,42,74,.06), 0 4px 16px rgba(15,42,74,.06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--navy-2); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #cfd8e6; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { font-weight: 800; font-size: 22px; color: #fff; padding: 4px 10px 18px; letter-spacing: -.3px; display: flex; align-items: center; gap: 8px; }
.logo .dot { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffd36b, var(--sun)); box-shadow: 0 0 0 4px rgba(242,165,22,.18); }
.logo small { display: block; font-size: 11px; font-weight: 500; color: #8fa1bb; letter-spacing: .3px; }
.nav-h { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #7d90ab; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #d6deea; text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.on { background: rgba(242,165,22,.16); color: #fff; }
.nav a.on svg { color: var(--sun); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .me { margin-top: 18px; padding: 10px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.side .me a { color: #9fb2cc; }
.main { min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top h1 { font-size: 20px; margin: 0; color: var(--navy); }
.top .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.page { padding: 22px 28px 90px; max-width: 1180px; }
.bnav { display: none; }

/* ---------- Building blocks ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card > h3 { margin: 0 0 12px; font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--navy); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(12, 1fr); }
.c12 { grid-column: span 12; } .c8 { grid-column: span 8; } .c6 { grid-column: span 6; } .c4 { grid-column: span 4; } .c3 { grid-column: span 3; }
.fld label { display: block; font-size: 12.5px; font-weight: 600; color: #3b4559; margin-bottom: 4px; }
.fld label .req { color: var(--bad); }
.fld .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #cbd2de; border-radius: 8px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(23,58,99,.12); }
textarea { min-height: 84px; resize: vertical; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; padding-top: 22px; }
.chk input { width: 18px; height: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; border-radius: 8px; border: 1px solid transparent; background: var(--navy); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; font-size: 14px; }
.btn:hover { background: var(--navy-2); }
.btn.sun { background: var(--sun); color: #231700; }
.btn.sun:hover { background: #e39a0d; }
.btn.ghost { background: #fff; color: var(--navy); border-color: #cbd2de; }
.btn.ghost:hover { background: #f4f6fa; }
.btn.danger { background: #fff; color: var(--bad); border-color: #f0c6c0; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.icon { padding: 7px; }
.btn svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; min-width: 160px; }

table.list { width: 100%; border-collapse: collapse; background: var(--card); }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfd; position: sticky; top: 0; }
table.list td { padding: 11px 12px; border-bottom: 1px solid #edf0f5; vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f8fafd; }
.tbl-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); background: #fff; }
.r { text-align: right; } .nowrap { white-space: nowrap; }
.sub { color: var(--muted); font-size: 13px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f6; color: #4a5468; text-transform: capitalize; }
.pill.draft { background: #eef1f6; } .pill.sent { background: #e2eefc; color: #1b5aa6; } .pill.accepted { background: #def5e6; color: #17703e; }
.pill.declined { background: #fde4e1; color: #a12a1b; } .pill.expired { background: #fbf0d6; color: #8a5a00; }
.empty { text-align: center; padding: 42px 16px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.stat .v { font-size: 26px; font-weight: 800; color: var(--navy); }
.stat .l { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.step { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px dashed #cbd2de; border-radius: 10px; text-decoration: none; color: inherit; background: #fff; }
.step .n { width: 26px; height: 26px; border-radius: 50%; background: var(--sun-soft); color: #8a5a00; display: grid; place-items: center; font-weight: 800; flex: none; }
.step.done .n { background: #def5e6; color: var(--ok); }

/* ---------- Drawer & modal ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15,25,40,.42); z-index: 50; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100%); background: var(--bg); z-index: 51; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.15); animation: slide .2s ease-out; }
.drawer header, .modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: #fff; border-bottom: 1px solid var(--line); }
.drawer header h2, .modal header h2 { margin: 0; font-size: 17px; color: var(--navy); }
.drawer .body { padding: 18px; overflow-y: auto; flex: 1; }
.drawer footer, .modal footer { display: flex; gap: 8px; justify-content: space-between; padding: 12px 18px; background: #fff; border-top: 1px solid var(--line); }
.drawer footer .r-acts { display: flex; gap: 8px; margin-left: auto; }
.section-t { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; color: var(--navy); margin: 18px 0 8px; grid-column: span 12; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.section-t:first-child { margin-top: 0; }
.modal { position: fixed; z-index: 52; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(720px, calc(100% - 24px)); max-height: calc(100% - 40px); background: #fff; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: pop .15s; }
.modal .body { padding: 14px 18px; overflow-y: auto; }
@keyframes fade { from { opacity: 0; } } @keyframes slide { from { transform: translateX(30px); opacity: .4; } } @keyframes pop { from { transform: translate(-50%, -48%); opacity: 0; } }

.pick-list { display: flex; flex-direction: column; gap: 4px; }
.pick-grp { font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px; color: #8a5a00; background: var(--sun-soft); padding: 5px 10px; border-radius: 6px; margin-top: 8px; font-weight: 700; }
.pick { display: flex; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; }
.pick:hover { background: #f4f6fa; border-color: var(--line); }
.pick .p { font-weight: 700; white-space: nowrap; }

.img-up { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.img-up .prev { width: 120px; height: 80px; border: 1px dashed #cbd2de; border-radius: 8px; display: grid; place-items: center; background: #fff center/contain no-repeat; color: var(--muted); font-size: 12px; }
.img-up .prev.sig { width: 200px; }

/* ---------- Proposal editor ---------- */
.ed { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.ed .sum { position: sticky; top: 84px; }
.items-t { width: 100%; border-collapse: collapse; table-layout: fixed; }
.items-t th:nth-child(6), .items-t td.del { width: 44px; }
.items-t th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); text-align: left; padding: 6px; border-bottom: 1px solid var(--line); }
.items-t td { padding: 6px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.items-t input, .items-t textarea { padding: 6px 8px; font-size: 14px; }
.items-t textarea { min-height: 34px; height: 50px; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.items-t th:nth-child(2) { width: 82px; } .items-t th:nth-child(3) { width: 72px; } .items-t th:nth-child(4) { width: 120px; } .items-t th:nth-child(5) { width: 118px; }
.items-t .amt { text-align: right; font-weight: 600; padding-top: 12px; white-space: nowrap; }
.items-t .grp-r td { background: var(--sun-soft); font-weight: 700; color: #6b4a00; font-size: 12.5px; padding: 6px 8px; }
.items-t .type { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; color: var(--muted); }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.tot-t { width: 100%; border-collapse: collapse; }
.tot-t td { padding: 6px 0; }
.tot-t .gt td { border-top: 2px solid var(--navy); font-size: 19px; font-weight: 800; color: var(--navy); padding-top: 10px; }
.margin { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: #f4f6fa; font-size: 13px; color: var(--muted); }
.dirty { font-size: 12.5px; color: #8a5a00; }
.saved { font-size: 12.5px; color: var(--ok); }
.calc-out { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 12px; }
.calc-out div { background: #f4f6fa; border-radius: 8px; padding: 8px 10px; }
.calc-out b { display: block; font-size: 18px; color: var(--navy); }
.calc-out span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; position: relative; }
.photo img { width: 100%; height: 110px; object-fit: cover; display: block; }
.photo input { border: 0; border-top: 1px solid var(--line); border-radius: 0; font-size: 13px; padding: 7px 8px; }
.photo .x { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; }
details.calc summary { cursor: pointer; font-weight: 700; color: var(--navy); font-size: 14px; text-transform: uppercase; letter-spacing: .6px; list-style: none; display: flex; justify-content: space-between; }
details.calc summary::-webkit-details-marker { display: none; }
details.calc summary::after { content: "Show ▾"; font-size: 12px; text-transform: none; color: var(--muted); letter-spacing: 0; font-weight: 500; }
details.calc[open] summary::after { content: "Hide ▴"; }
details.calc[open] summary { margin-bottom: 12px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 80% 10%, rgba(242,165,22,.25), transparent 40%), var(--navy); }
.login .box { background: #fff; width: min(380px, 100%); border-radius: 14px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login .logo { color: var(--navy); padding: 0 0 16px; }
.login .logo small { color: var(--muted); }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 14px; animation: fade .2s; max-width: 90vw; }
.toast.err { background: var(--bad); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Mobile ---------- */
@media (max-width: 960px) {
  .ed { grid-template-columns: 1fr; }
  .ed .sum { position: static; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .top { padding: 12px 14px; }
  .top h1 { font-size: 17px; }
  .page { padding: 14px 12px 96px; }
  .top .acts { flex-wrap: nowrap; }
  .hide-sm { display: none !important; }
  .items-t { table-layout: auto; }
  .grid { grid-template-columns: 1fr; }
  .grid > * { grid-column: span 1 !important; }
  .bnav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
  .bnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: 11px; color: var(--muted); text-decoration: none; font-weight: 600; }
  .bnav a.on { color: var(--navy); }
  .bnav a.on svg { color: var(--sun); }
  .bnav svg { width: 22px; height: 22px; }
  table.list .hide-m { display: none; }
  .items-t thead { display: none; }
  .items-t tr.it { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .items-t tr.it td { border: 0; padding: 0; }
  .items-t tr.it td.d { grid-column: 1 / -1; }
  .items-t tr.it td.amt { grid-column: span 2; text-align: left; padding-top: 6px; }
  .items-t tr.it td.del { text-align: right; }
  .items-t .q, .items-t .u, .items-t .pr { width: 100%; }
  .items-t tr.it td::before { content: attr(data-l); display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; }
  .items-t tr.grp-r { display: block; }
  .items-t tr.grp-r td { display: block; }
  .modal { top: auto; bottom: 0; transform: translateX(-50%); width: 100%; border-radius: 14px 14px 0 0; max-height: 88vh; animation: none; }
}
