/* ============ Plumbing Bros AI — design system ============ */
:root {
  --navy: #0B2A5B;
  --blue: #1761C4;
  --blue-600: #1257ad;
  --gold: #F5B301;
  --accent: #1761C4;            /* overridden per business unit */
  --ok: #1e9e5a;
  --warn: #e0a106;
  --danger: #d93a3a;

  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #e2e8f1;
  --text: #16263f;
  --muted: #6b7a90;
  --shadow: 0 1px 2px rgba(16,38,63,.06), 0 8px 28px rgba(16,38,63,.08);
  --shadow-lg: 0 20px 60px rgba(11,42,91,.18);
  --radius: 16px;
  --radius-sm: 10px;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}
[data-theme="dark"] {
  --bg: #0a1322;
  --surface: #111d31;
  --surface-2: #16263f;
  --border: #22344f;
  --text: #e8eef7;
  --muted: #92a3bc;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.35);
  --shadow-lg: 0 24px 70px rgba(0,0,0,.55);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 2rem;
  background: radial-gradient(1200px 600px at 20% -10%, #1761C4 0%, transparent 50%),
              radial-gradient(900px 500px at 110% 110%, #F5B301 0%, transparent 45%),
              var(--navy);
}
.login-card {
  width: 100%; max-width: 410px; background: var(--surface); border-radius: 22px;
  padding: 2.6rem 2.4rem; box-shadow: var(--shadow-lg);
}
.login-card .brand-lockup { margin-bottom: 1.6rem; }
.login-card h1 { font-size: 1.35rem; margin-bottom: .2rem; }
.login-card p.sub { color: var(--muted); font-size: .9rem; margin-bottom: 1.6rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .35rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: .7rem .85rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: .95rem; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.demo-creds { margin-top: 1.2rem; font-size: .78rem; color: var(--muted); background: var(--surface-2);
  border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: .7rem .85rem; }
.demo-creds b { color: var(--text); }
.login-err { color: var(--danger); font-size: .85rem; margin-top: .8rem; min-height: 1rem; }

/* ---------- Brand lockup ---------- */
.brand-lockup { display: flex; align-items: center; gap: .65rem; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--blue), var(--navy)); color: #fff; flex: none;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.12);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-mark.logo { background: #fff; box-shadow: inset 0 0 0 1px var(--border); padding: 0; overflow: hidden; }
.brand-mark.logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-mark.lg { width: 52px; height: 52px; border-radius: 14px; }
.brand-text { line-height: 1.05; }
.brand-text .b1 { font-weight: 800; letter-spacing: -.3px; }
.brand-text .b2 { font-size: .68rem; color: var(--gold); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy); color: #cdd9ec; padding: 1.1rem .8rem; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: .3rem; overflow-y: auto;
}
[data-theme="dark"] .sidebar { background: #07101d; }
.sidebar .brand-lockup { padding: .4rem .6rem 1rem; }
.sidebar .brand-text .b1 { color: #fff; font-size: 1rem; }
.nav-item {
  display: flex; align-items: center; gap: .7rem; padding: .68rem .75rem; border-radius: 11px;
  color: #b8c6dd; font-weight: 600; font-size: .9rem; transition: background .15s, color .15s; cursor: pointer;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #000)); color: #fff; box-shadow: var(--shadow); }
.nav-sep { font-size: .68rem; text-transform: uppercase; letter-spacing: .6px; color: #62789b; padding: 1rem .8rem .3rem; }
.sidebar-foot { margin-top: auto; padding: .6rem; font-size: .72rem; color: #62789b; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 1rem;
  padding: .85rem 1.6rem; background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.topbar h2 { font-size: 1.15rem; font-weight: 800; letter-spacing: -.3px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); display: grid; place-items: center; transition: background .15s, transform .15s;
}
.icon-btn:hover { background: var(--surface-2); transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; }
.biz-select { padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-weight: 600; font-size: .85rem; }
.user-chip { display: flex; align-items: center; gap: .55rem; padding: .35rem .35rem .35rem .7rem; border: 1px solid var(--border); border-radius: 100px; background: var(--surface); }
.user-chip .who { line-height: 1.1; }
.user-chip .who .n { font-weight: 700; font-size: .82rem; }
.user-chip .who .r { font-size: .68rem; color: var(--muted); text-transform: capitalize; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--gold)); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .8rem; }

.content { padding: 1.6rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; flex-wrap: wrap; }
.page-head .ph-title h1 { font-size: 1.5rem; letter-spacing: -.5px; }
.page-head .ph-title p { color: var(--muted); font-size: .9rem; margin-top: .15rem; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; padding: .7rem 1.25rem;
  border-radius: 11px; font-weight: 700; font-size: .88rem; border: 1px solid transparent; transition: all .18s; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-gold { background: var(--gold); color: #3a2c00; }
.btn-gold:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; filter: none; }
.btn-sm { padding: .45rem .8rem; font-size: .8rem; border-radius: 9px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 1.25rem 1.35rem; }
.card h3 { font-size: 1rem; margin-bottom: .15rem; }
.card .card-sub { color: var(--muted); font-size: .82rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1.1rem; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.auto-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* ---------- KPI ---------- */
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.3rem; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; right: -20px; top: -20px; width: 90px; height: 90px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.kpi .k-label { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .k-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.5px; margin-top: .35rem; }
.kpi .k-foot { font-size: .78rem; color: var(--muted); margin-top: .3rem; }
.kpi .k-foot .up { color: var(--ok); font-weight: 700; }
.kpi-ico { position: absolute; right: 1rem; top: 1rem; width: 30px; height: 30px; color: var(--accent); opacity: .9; z-index: 1; }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .22rem .6rem; border-radius: 100px; font-size: .72rem; font-weight: 700; }
.badge-blue { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.badge-gold { background: color-mix(in srgb, var(--gold) 22%, transparent); color: #8a6500; }
.badge-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: #97700a; }
.badge-danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--muted); }
.status-draft { background: var(--surface-2); color: var(--muted); }
.status-sent { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.status-approved { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.status-declined { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.demo-badge { background: color-mix(in srgb, var(--gold) 25%, transparent); color: #8a6500; }

/* ---------- Tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: .73rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: .65rem .8rem; border-bottom: 1px solid var(--border); }
table.tbl td { padding: .75rem .8rem; border-bottom: 1px solid var(--border); font-size: .88rem; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: background .12s; cursor: pointer; }
table.tbl tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Wizard / stepper ---------- */
.stepper { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.step { display: flex; align-items: center; gap: .5rem; padding: .5rem .8rem; border-radius: 100px; background: var(--surface); border: 1px solid var(--border); font-size: .8rem; font-weight: 600; color: var(--muted); }
.step .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-size: .72rem; font-weight: 800; border: 1px solid var(--border); }
.step.active { border-color: var(--accent); color: var(--text); box-shadow: var(--shadow); }
.step.active .dot { background: var(--accent); color: #fff; border-color: var(--accent); }
.step.done .dot { background: var(--ok); color: #fff; border-color: var(--ok); }

/* ---------- Agent card ---------- */
.agent-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.agent-head { display: flex; align-items: center; gap: .8rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.agent-ico { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, var(--accent), var(--navy)); color: #fff; display: grid; place-items: center; flex: none; }
.agent-ico svg { width: 20px; height: 20px; }
.agent-head .a-meta { flex: 1; min-width: 0; }
.agent-head .a-meta .a-name { font-weight: 800; font-size: .95rem; }
.agent-head .a-meta .a-role { font-size: .76rem; color: var(--muted); }
.agent-body { padding: 1.1rem 1.2rem; }
.reasoning { font-size: .82rem; color: var(--muted); font-style: italic; border-left: 3px solid var(--accent); padding: .35rem .75rem; margin-top: .9rem; background: var(--surface-2); border-radius: 0 8px 8px 0; }
.reasoning svg { width: 14px; height: 14px; vertical-align: -2px; margin-right: 2px; flex: none; }

/* confidence ring */
.conf { display: flex; align-items: center; gap: .5rem; }
.ring { --p: 0; width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p)*1%), var(--surface-2) 0);
  display: grid; place-items: center; }
.ring::before { content: ""; position: absolute; }
.ring span { width: 32px; height: 32px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: .68rem; font-weight: 800; }

/* lists */
.li-check, .li-x, .li-dot { display: flex; gap: .55rem; align-items: flex-start; padding: .4rem 0; font-size: .88rem; }
.li-check svg, .li-x svg, .li-dot svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.li-check svg { color: var(--ok); }
.li-x svg { color: var(--danger); }
.li-dot svg { color: var(--accent); }

/* pricing editor */
.price-row { display: grid; grid-template-columns: 1fr 70px 70px 100px 100px 32px; gap: .5rem; align-items: center; padding: .4rem 0; }
.price-row input { padding: .45rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: .85rem; width: 100%; }
.price-row .num input { text-align: right; }
.totbox { background: var(--surface-2); border-radius: var(--radius-sm); padding: 1rem 1.1rem; margin-top: 1rem; }
.totline { display: flex; justify-content: space-between; padding: .28rem 0; font-size: .9rem; }
.totline.grand { font-size: 1.25rem; font-weight: 800; border-top: 2px solid var(--border); margin-top: .5rem; padding-top: .7rem; }

/* quote document */
.quote-doc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.2rem; box-shadow: var(--shadow); }
.quote-doc h1 { font-size: 1.5rem; }
.quote-doc h4 { margin: 1.4rem 0 .4rem; color: var(--accent); font-size: .8rem; text-transform: uppercase; letter-spacing: .6px; }
.quote-doc .qd-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--accent); padding-bottom: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; gap: 1rem; }
.quote-doc p { margin: .4rem 0; }

.spinner { width: 18px; height: 18px; border: 2.5px solid color-mix(in srgb, var(--accent) 30%, transparent); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: flex; flex-direction: column; align-items: center; gap: .8rem; padding: 2.5rem; color: var(--muted); }

.toast-wrap { position: fixed; bottom: 1.4rem; right: 1.4rem; z-index: 200; display: flex; flex-direction: column; gap: .6rem; }
.toast { background: var(--navy); color: #fff; padding: .8rem 1.1rem; border-radius: 11px; box-shadow: var(--shadow-lg); font-size: .88rem; font-weight: 600; animation: slideup .3s; max-width: 340px; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); }
@keyframes slideup { from { transform: translateY(20px); opacity: 0; } }

.reveal { opacity: 0; transform: translateY(14px); transition: opacity .5s, transform .5s; }
.reveal.visible { opacity: 1; transform: none; }

.banner { display: flex; align-items: center; gap: .7rem; padding: .8rem 1.1rem; border-radius: var(--radius-sm); font-size: .85rem; font-weight: 600; margin-bottom: 1.2rem; }
.banner-warn { background: color-mix(in srgb, var(--gold) 18%, transparent); color: #8a6500; border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); }

.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.chart-box { position: relative; height: 260px; }

.markdown h1 { font-size: 1.4rem; margin: 1rem 0 .6rem; }
.markdown h2 { font-size: 1.15rem; margin: 1.1rem 0 .5rem; }
.markdown h3 { font-size: 1rem; margin: .9rem 0 .4rem; }
.markdown ul, .markdown ol { margin: .5rem 0 .5rem 1.3rem; }
.markdown li { margin: .25rem 0; }
.markdown p { margin: .6rem 0; }
.markdown blockquote { border-left: 3px solid var(--gold); padding: .4rem .9rem; color: var(--muted); background: var(--surface-2); border-radius: 0 8px 8px 0; margin: .6rem 0; }
.markdown code { background: var(--surface-2); padding: .1rem .35rem; border-radius: 5px; font-size: .85em; }

/* ---------- responsive ---------- */
@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 120; width: 256px; transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: grid !important; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 110; }
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .cols-3, .cols-2 { grid-template-columns: 1fr; }
}
.menu-toggle { display: none; }
@media (max-width: 560px) {
  .content { padding: 1rem; }
  .cols-4 { grid-template-columns: 1fr; }
  .user-chip .who { display: none; }
  .price-row { grid-template-columns: 1fr 50px 80px 30px; }
  .price-row .pr-unit, .price-row .pr-line { display: none; }
}

/* print / PDF */
@media print {
  .sidebar, .topbar, .no-print, .stepper { display: none !important; }
  .app { display: block; }
  .content { max-width: none; padding: 0; }
  body { background: #fff; }
  .quote-doc { border: none; box-shadow: none; padding: 0; }
}
