/* ==========================================================================
   Southern Star CRM — design system
   Palette and type inherited from the brand package so an estimate opened on a
   homeowner's phone reads as the same company as the website.
   ========================================================================== */

:root {
  /* Brand, sampled from the logo */
  --gold:            #BF964E;
  --gold-hover:      #D8AE66;
  --gold-soft:       rgba(191, 150, 78, .13);
  --gold-line:       rgba(191, 150, 78, .34);
  --lamp:            #FFD9A3;

  /* Day surfaces — the working UI */
  --canvas:          #F4F1E8;
  --surface:         #FFFDF8;
  --surface-2:       #EFEADC;
  --surface-sunk:    #E9E3D3;
  --line:            #DED5C1;
  --line-strong:     #C9BE A6;
  --line-strong:     #C9BEA6;

  --ink:             #14120F;
  --ink-2:           #4A4439;
  --ink-3:           #7A7264;

  /* Status */
  --good:            #2F6B4F;
  --good-soft:       rgba(47, 107, 79, .12);
  --warn:            #9A6B18;
  --warn-soft:       rgba(154, 107, 24, .14);
  --bad:             #A8412F;
  --bad-soft:        rgba(168, 65, 47, .12);
  --info:            #2B5673;
  --info-soft:       rgba(43, 86, 115, .12);

  /* Type */
  --display: 'Archivo', system-ui, -apple-system, sans-serif;
  --body:    'Jost', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --wordmark:'Bodoni Moda', Georgia, 'Times New Roman', serif;
  --mono:    'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Scale */
  --r-sm: 6px;  --r: 10px;  --r-lg: 14px;  --r-xl: 20px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
  --shadow-sm: 0 1px 2px rgba(20, 18, 15, .06), 0 1px 3px rgba(20, 18, 15, .04);
  --shadow:    0 2px 4px rgba(20, 18, 15, .06), 0 6px 16px rgba(20, 18, 15, .07);
  --shadow-lg: 0 8px 24px rgba(20, 18, 15, .12), 0 24px 56px rgba(20, 18, 15, .14);

  --nav-w: 232px;
  --header-h: 60px;
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas:       #0B111A;
    --surface:      #141C28;
    --surface-2:    #1B2431;
    --surface-sunk: #0F1620;
    --line:         #2A3542;
    --line-strong:  #3B4857;
    --ink:          #F3F0E9;
    --ink-2:        #B6BFCB;
    --ink-3:        #8B95A3;
    --gold:         #D8AE66;
    --gold-hover:   #E9C68A;
    --gold-soft:    rgba(216, 174, 102, .14);
    --gold-line:    rgba(216, 174, 102, .32);
    --good:         #6FBF92;  --good-soft: rgba(111, 191, 146, .14);
    --warn:         #E0B055;  --warn-soft: rgba(224, 176, 85, .14);
    --bad:          #E58A74;  --bad-soft:  rgba(229, 138, 116, .14);
    --info:         #7FB2D4;  --info-soft: rgba(127, 178, 212, .14);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow:    0 2px 6px rgba(0, 0, 0, .35), 0 8px 20px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5), 0 32px 64px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --canvas: #0B111A; --surface: #141C28; --surface-2: #1B2431; --surface-sunk: #0F1620;
  --line: #2A3542; --line-strong: #3B4857;
  --ink: #F3F0E9; --ink-2: #B6BFCB; --ink-3: #8B95A3;
  --gold: #D8AE66; --gold-hover: #E9C68A; --gold-soft: rgba(216,174,102,.14); --gold-line: rgba(216,174,102,.32);
  --good: #6FBF92; --good-soft: rgba(111,191,146,.14);
  --warn: #E0B055; --warn-soft: rgba(224,176,85,.14);
  --bad: #E58A74; --bad-soft: rgba(229,138,116,.14);
  --info: #7FB2D4; --info-soft: rgba(127,178,212,.14);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 400 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
h1, h2, h3, h4, h5 { font-family: var(--display); font-weight: 600; margin: 0; line-height: 1.22; letter-spacing: -.005em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 var(--sp-3); }
a { color: var(--ink); text-decoration-color: var(--gold-line); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--gold); }
img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--sp-5) 0; }

::selection { background: var(--gold-soft); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 3px; }

/* ---------- Utility ---------- */
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.strong { font-weight: 500; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caps {
  font-size: 11px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 500;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.row { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.row-tight { display: flex; gap: var(--sp-1); align-items: center; }
.between { display: flex; gap: var(--sp-3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.hide-mobile { display: initial; }
.hide-desktop { display: none; }
.mt-0 { margin-top: 0 } .mt-2 { margin-top: var(--sp-2) } .mt-3 { margin-top: var(--sp-3) }
.mt-4 { margin-top: var(--sp-4) } .mt-5 { margin-top: var(--sp-5) }
.mb-0 { margin-bottom: 0 } .mb-2 { margin-bottom: var(--sp-2) } .mb-3 { margin-bottom: var(--sp-3) }
.mb-4 { margin-bottom: var(--sp-4) } .mb-5 { margin-bottom: var(--sp-5) }

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--nav-w); z-index: 40;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.brand {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--line);
}
.brand .star { color: var(--gold); font-size: 15px; line-height: 1; }
.brand .name {
  font-family: var(--wordmark); font-weight: 500; font-size: 15px;
  letter-spacing: .1em; text-transform: uppercase; line-height: 1.1;
}
.brand .role { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }

.nav { padding: var(--sp-3) var(--sp-2); display: flex; flex-direction: column; gap: 1px; }
.nav-group { margin-top: var(--sp-3); padding: 0 var(--sp-2) var(--sp-1); }
.nav-group:first-child { margin-top: 0; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); text-decoration: none; font-size: 14.5px; line-height: 1.2;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--gold-soft); color: var(--ink); font-weight: 500; box-shadow: inset 2px 0 0 var(--gold); }
.nav a svg { width: 17px; height: 17px; flex: 0 0 17px; stroke-width: 1.7; }
.nav .count {
  margin-left: auto; font-family: var(--mono); font-size: 11px;
  background: var(--surface-sunk); color: var(--ink-3); padding: 1px 6px; border-radius: 99px;
}
.nav a.on .count { background: var(--gold); color: var(--canvas); }

.sidebar-foot { margin-top: auto; padding: var(--sp-3); border-top: 1px solid var(--line); }

.main { flex: 1 1 auto; min-width: 0; margin-left: var(--nav-w); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--header-h); padding: var(--sp-2) var(--sp-5);
  background: color-mix(in srgb, var(--canvas) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; }
.content { padding: var(--sp-5); flex: 1 1 auto; }
.content.narrow { max-width: 760px; }
.content.wide { max-width: 1500px; }

/* ---------- Mobile shell ---------- */
.tabbar { display: none; }
.drawer-scrim { display: none; }

@media (max-width: 900px) {
  .hide-mobile { display: none !important; }
  .hide-desktop { display: initial; }
  .sidebar {
    transform: translateX(-100%); transition: transform .18s ease;
    width: min(290px, 86vw); box-shadow: var(--shadow-lg);
  }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .drawer-scrim {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgba(11, 17, 26, .5);
  }
  .main { margin-left: 0; }
  .topbar { padding: var(--sp-2) var(--sp-3); }
  .content { padding: var(--sp-4) var(--sp-3); padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0) + var(--sp-5)); }
  .tabbar {
    display: flex; position: fixed; inset: auto 0 0 0; z-index: 38;
    background: color-mix(in srgb, var(--surface) 95%, transparent);
    backdrop-filter: blur(12px); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .tabbar a {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; height: var(--tabbar-h); text-decoration: none;
    color: var(--ink-3); font-size: 10.5px; letter-spacing: .02em;
  }
  .tabbar a svg { width: 21px; height: 21px; stroke-width: 1.7; }
  .tabbar a.on { color: var(--gold); }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: 500 14.5px/1 var(--body); padding: 10px 15px; min-height: 40px;
  border-radius: var(--r-sm); border: 1px solid transparent; cursor: pointer;
  background: var(--gold); color: #1A1407; text-decoration: none;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--gold-hover); }
.btn:active { transform: translateY(.5px); }
.btn svg { width: 16px; height: 16px; stroke-width: 1.9; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--gold-line); }
.btn.quiet { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn.quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { min-height: 32px; padding: 6px 11px; font-size: 13.5px; }
.btn.sm svg { width: 14px; height: 14px; }
.btn.lg { min-height: 48px; padding: 13px 22px; font-size: 16px; }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }

/* ---------- Forms ---------- */
label, .label { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink-2); margin-bottom: 5px; }
.label .opt { color: var(--ink-3); font-weight: 400; }
input, select, textarea {
  width: 100%; font: 400 15.5px/1.4 var(--body); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); padding: 10px 11px; min-height: 42px;
  transition: border-color .12s ease, box-shadow .12s ease;
  -webkit-appearance: none; appearance: none;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%237A7264' stroke-width='1.6'%3E%3Cpath d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 11px;
  padding-right: 32px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft);
}
input[type="checkbox"], input[type="radio"] {
  width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--gold);
  -webkit-appearance: auto; appearance: auto;
}
input[type="date"], input[type="datetime-local"], input[type="time"] { min-width: 0; }
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: .75; }
input[readonly], input[disabled], select[disabled], textarea[disabled] {
  background: var(--surface-sunk); color: var(--ink-3); cursor: not-allowed;
}
.field { margin-bottom: var(--sp-4); }
.field.inline-check { display: flex; align-items: flex-start; gap: 9px; }
.field.inline-check label { margin: 0; font-size: 14.5px; color: var(--ink); font-weight: 400; }
.help { font-size: 12.5px; color: var(--ink-3); margin-top: 5px; line-height: 1.45; }
.err { font-size: 12.5px; color: var(--bad); margin-top: 5px; font-weight: 500; }
.field.bad input, .field.bad select, .field.bad textarea { border-color: var(--bad); }
.field.bad input:focus { box-shadow: 0 0 0 3px var(--bad-soft); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 var(--sp-4); }
.grid .full, .grid-3 .full { grid-column: 1 / -1; }
@media (max-width: 680px) { .grid, .grid-3 { grid-template-columns: 1fr; } }

.money-input { position: relative; }
.money-input::before {
  content: "$"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); font-family: var(--mono); font-size: 14px; pointer-events: none;
}
.money-input input { padding-left: 26px; font-family: var(--mono); }
.suffix-input { position: relative; }
.suffix-input .suffix {
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); font-size: 13px; pointer-events: none;
}
.suffix-input input { padding-right: 46px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--sp-4); }
.card-head {
  display: flex; align-items: center; gap: var(--sp-3); justify-content: space-between;
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.card-head h2, .card-head h3 { font-size: 15.5px; }
.card-body { padding: var(--sp-4); }
.card-body.flush { padding: 0; }
.card-foot {
  padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--line);
  background: var(--surface-2); border-radius: 0 0 var(--r) var(--r);
}

/* ---------- Stat tiles ---------- */
.stats {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  margin-bottom: var(--sp-5);
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: var(--sp-4); text-decoration: none; display: block; box-shadow: var(--shadow-sm);
}
a.stat:hover { border-color: var(--gold-line); }
.stat .k { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); font-weight: 500; }
.stat .v {
  font-family: var(--display); font-weight: 600; font-size: 27px;
  line-height: 1.1; margin-top: 7px; letter-spacing: -.015em;
}
.stat .sub { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.stat .sub.up { color: var(--good); }
.stat .sub.down { color: var(--bad); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th {
  text-align: left; font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 500; padding: 10px var(--sp-3);
  border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2);
}
table.data th a { color: inherit; text-decoration: none; }
table.data th a:hover { color: var(--ink); }
table.data th.sorted { color: var(--gold); }
table.data td { padding: 11px var(--sp-3); border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--gold-soft); }
table.data tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-family: var(--mono); font-size: 13.5px; white-space: nowrap; }
table.data td .t1 { font-weight: 500; }
table.data td .t2 { font-size: 12.5px; color: var(--ink-3); }
table.data td.tight { width: 1%; white-space: nowrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 11.5px; font-weight: 500; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 99px;
  background: var(--surface-sunk); color: var(--ink-2);
  border: 1px solid transparent;
}
.badge.gold  { background: var(--gold-soft); color: color-mix(in srgb, var(--gold) 76%, var(--ink)); border-color: var(--gold-line); }
.badge.good  { background: var(--good-soft); color: var(--good); }
.badge.warn  { background: var(--warn-soft); color: var(--warn); }
.badge.bad   { background: var(--bad-soft);  color: var(--bad); }
.badge.info  { background: var(--info-soft); color: var(--info); }
.badge.plain { background: transparent; border-color: var(--line-strong); color: var(--ink-3); }
.badge .dot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; }
.tier-pill {
  font-family: var(--display); font-size: 10.5px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  padding: 2px 8px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); color: var(--ink-2);
}
.tier-pill.best { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }

/* ---------- Flash ---------- */
.flashes { position: sticky; top: var(--header-h); z-index: 29; padding: 0 var(--sp-5); }
@media (max-width: 900px) { .flashes { padding: 0 var(--sp-3); } }
.flash {
  display: flex; align-items: flex-start; gap: 10px; margin-top: var(--sp-3);
  padding: 11px var(--sp-4); border-radius: var(--r); font-size: 14.5px;
  border: 1px solid; box-shadow: var(--shadow-sm);
}
.flash svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; stroke-width: 1.9; }
.flash.success { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 40%, transparent); color: var(--good); }
.flash.error   { background: var(--bad-soft);  border-color: color-mix(in srgb, var(--bad) 40%, transparent);  color: var(--bad); }
.flash.info    { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 40%, transparent); color: var(--info); }
.flash .x { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; opacity: .6; padding: 0 2px; }
.flash .x:hover { opacity: 1; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--ink-3); }
.empty .star { color: var(--gold); font-size: 22px; opacity: .6; }
.empty h3 { margin: var(--sp-3) 0 var(--sp-2); color: var(--ink); font-size: 17px; }
.empty p { max-width: 42ch; margin: 0 auto var(--sp-4); font-size: 14.5px; line-height: 1.55; }

/* ---------- Kanban ---------- */
.board {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  overflow-x: auto; padding-bottom: var(--sp-4); -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
.board .col {
  flex: 0 0 272px; scroll-snap-align: start;
  background: var(--surface-sunk); border: 1px solid var(--line);
  border-radius: var(--r); padding: var(--sp-2); max-height: calc(100vh - 230px);
  display: flex; flex-direction: column;
}
.board .col.drop { border-color: var(--gold); background: var(--gold-soft); }
.board .col > h2 {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2);
  font-size: 11px; letter-spacing: .11em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 500; padding: var(--sp-2) var(--sp-2) var(--sp-3);
  font-family: var(--body);
}
.board .col > h2 .n { font-family: var(--mono); font-size: 11px; }
.board .col > h2 .sum { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.board .list { overflow-y: auto; display: flex; flex-direction: column; gap: var(--sp-2); padding: 0 1px 1px; }
.board .card-lead {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 11px; text-decoration: none; display: block; box-shadow: var(--shadow-sm);
  cursor: grab; touch-action: pan-y;
}
.board .card-lead:hover { border-color: var(--gold-line); }
.board .card-lead.dragging { opacity: .4; }
.board .card-lead .nm { font-weight: 500; font-size: 14.5px; line-height: 1.3; }
.board .card-lead .meta { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.board .card-lead .val { font-family: var(--mono); font-size: 13px; margin-top: 6px; }
.board .card-lead .tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
.board .col-empty { font-size: 12.5px; color: var(--ink-3); text-align: center; padding: var(--sp-4) var(--sp-2); }

/* ---------- Modal / sheet ---------- */
dialog.sheet {
  border: 0; padding: 0; background: transparent; max-width: none; max-height: none;
  width: 100%; height: 100%; margin: 0;
}
dialog.sheet::backdrop { background: rgba(11, 17, 26, .58); backdrop-filter: blur(2px); }
dialog.sheet .panel {
  background: var(--canvas); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 48px); margin: 24px auto; overflow: auto;
  padding: var(--sp-5);
}
dialog.sheet .panel.wide { width: min(1080px, calc(100vw - 24px)); }
@media (max-width: 700px) {
  dialog.sheet .panel {
    width: 100vw; max-height: 100vh; margin: 0; border-radius: 0; border: 0;
    min-height: 100vh; padding: var(--sp-4) var(--sp-3) calc(var(--sp-7) + env(safe-area-inset-bottom, 0));
  }
}
.sheet-head { display: flex; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.sheet-head h2 { flex: 1 1 auto; }
.sheet-foot {
  display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap;
  margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--line);
}

/* ---------- Detail layout ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--sp-4); align-items: start; }
@media (max-width: 1080px) { .detail { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px var(--sp-4); font-size: 14.5px; }
.kv dt { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; padding-top: 2px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative; padding: 0 0 var(--sp-4) var(--sp-5); border-left: 1px solid var(--line);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -4.5px; top: 5px;
  width: 8px; height: 8px; border-radius: 99px; background: var(--gold-line);
  border: 2px solid var(--surface);
}
.timeline li.accent::before { background: var(--gold); }
.timeline .when { font-size: 12px; color: var(--ink-3); font-family: var(--mono); }
.timeline .what { font-size: 14.5px; margin-top: 2px; }
.timeline .who { font-size: 12.5px; color: var(--ink-3); }

/* ---------- Tabs & filters ---------- */
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: var(--sp-4); }
.tabs a {
  padding: 9px var(--sp-3); font-size: 14.5px; color: var(--ink-3); text-decoration: none;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--gold); font-weight: 500; }

.filters { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: flex-end; margin-bottom: var(--sp-4); }
.filters .f { flex: 0 1 auto; min-width: 140px; }
.filters .f label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.filters .f input, .filters .f select { min-height: 38px; font-size: 14.5px; }
.filters .f.search { flex: 1 1 240px; }

.search-box { position: relative; }
.search-box svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--ink-3); pointer-events: none;
}
.search-box input { padding-left: 34px; }

/* ---------- Progress & meters ---------- */
.meter { height: 6px; background: var(--surface-sunk); border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--gold); border-radius: 99px; }
.meter.good > span { background: var(--good); }
.meter.warn > span { background: var(--warn); }
.meter.bad > span  { background: var(--bad); }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bars .b { display: grid; grid-template-columns: 1fr auto; gap: 3px var(--sp-3); align-items: baseline; }
.bars .b .n { font-size: 14px; }
.bars .b .v { font-family: var(--mono); font-size: 13px; }
.bars .b .track { grid-column: 1 / -1; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; gap: var(--sp-2); justify-content: center; margin-top: var(--sp-4); }
.pager .n { font-size: 13.5px; color: var(--ink-3); font-family: var(--mono); }

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .tabbar, .flashes, .no-print { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Estimate builder ---------- */
.builder { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-4); }
@media (max-width: 1080px) { .builder { grid-template-columns: 1fr; } }

.builder .opt {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: var(--sp-4); display: flex; flex-direction: column;
}
.builder .opt.pick { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold-soft); }
.builder .opt .tier-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2); margin-bottom: var(--sp-3);
}
.builder .opt .tier-name {
  font-family: var(--display); font-size: 12px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--gold);
}
.builder .opt .pkg { font-size: 12.5px; color: var(--ink-3); margin-bottom: var(--sp-3); }
.builder .money-input input { font-size: 19px; font-weight: 500; min-height: 48px; }
.builder .money-input::before { font-size: 17px; }
.builder textarea { font-size: 14px; }
.builder .cost-note {
  display: flex; justify-content: space-between; gap: var(--sp-2);
  font-size: 12px; margin-top: 6px;
}

/* The three totals, pinned where the owner can see them while scrolling. */
.builder-bar {
  position: sticky; bottom: 0; z-index: 25; margin: var(--sp-4) calc(var(--sp-5) * -1) 0;
  padding: var(--sp-3) var(--sp-5) calc(var(--sp-3) + env(safe-area-inset-bottom, 0));
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap;
}
@media (max-width: 900px) {
  .builder-bar {
    margin: var(--sp-4) calc(var(--sp-3) * -1) 0;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0));
    padding: var(--sp-3);
  }
}

/* ---------- Presentation / proposal controls ---------- */
.present-bar {
  position: sticky; top: 0; z-index: 20; display: flex; gap: var(--sp-2);
  align-items: center; padding: var(--sp-3) var(--sp-4);
  background: color-mix(in srgb, var(--canvas) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}

/* ---------- Calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line);
       border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.cal .d { background: var(--surface); min-height: 128px; padding: var(--sp-2); display: flex; flex-direction: column; gap: 5px; }
.cal .d.today { background: var(--gold-soft); }
.cal .d .dn { font-size: 11px; color: var(--ink-3); font-family: var(--mono); display: flex; justify-content: space-between; }
.cal .d.today .dn { color: var(--gold); font-weight: 500; }
.cal .ev {
  display: block; text-decoration: none; font-size: 12px; line-height: 1.35;
  padding: 5px 7px; border-radius: var(--r-sm); border-left: 2px solid var(--gold);
  background: var(--surface-2); color: var(--ink);
}
.cal .ev:hover { border-color: var(--gold-hover); background: var(--gold-soft); }
.cal .ev.install { border-left-color: var(--good); }
.cal .ev.service { border-left-color: var(--bad); }
.cal .ev.followup { border-left-color: var(--info); }
.cal .ev.done { opacity: .5; }
.cal .ev .t { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.cal-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; margin-bottom: 4px; }
.cal-head div { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
                text-align: center; font-weight: 500; }
@media (max-width: 860px) {
  .cal, .cal-head { grid-template-columns: 1fr; }
  .cal .d { min-height: auto; }
  .cal .d:empty { display: none; }
  .cal-head { display: none; }
  .cal .d .dn { font-size: 12.5px; font-weight: 500; color: var(--ink); }
}

/* ---------- Upgrades ---------- */
.upgrades { display: flex; flex-direction: column; gap: 7px; }
.upg {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); cursor: pointer;
}
.upg:hover { border-color: var(--gold-line); }
.upg.on { border-color: var(--gold); background: var(--gold-soft); }
.upg.blocked { opacity: .42; pointer-events: none; }
.upg input[type="checkbox"] { margin-top: 2px; flex: 0 0 auto; }
.upg .body { flex: 1 1 auto; min-width: 0; }
.upg .nm { font-size: 14px; font-weight: 500; line-height: 1.3; }
.upg .ds { font-size: 12.5px; color: var(--ink-3); line-height: 1.45; margin-top: 2px; }
.upg .pr { font-family: var(--mono); font-size: 13px; white-space: nowrap; margin-left: auto; }
.upg .qty { width: 62px; min-height: 32px; padding: 4px 6px; font-size: 13px; margin-top: 5px; }
.upg .why { font-size: 11.5px; color: var(--bad); margin-top: 3px; }

/* Running total on the builder and the proposal */
.running {
  display: flex; flex-direction: column; gap: 4px; margin-top: var(--sp-3);
  padding-top: var(--sp-3); border-top: 1px dashed var(--line); font-size: 13.5px;
}
.running .r { display: flex; justify-content: space-between; gap: var(--sp-3); }
.running .r span:last-child { font-family: var(--mono); }
.running .r.tot { font-weight: 500; font-size: 15.5px; padding-top: 5px;
                  border-top: 1px solid var(--line); margin-top: 3px; }
.running .r.disc span:last-child { color: var(--good); }

.demo-flag {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500;
  letter-spacing: .08em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px;
  background: var(--warn-soft); color: var(--warn); border: 1px solid currentColor;
}

/* ---------- Running from the home screen ----------
   With no browser chrome the app owns the whole screen, including the strip
   behind the status bar and the bar at the bottom of the phone. */
html.standalone body { overscroll-behavior-y: none; }
html.standalone .topbar { padding-top: calc(var(--sp-2) + env(safe-area-inset-top, 0)); }
html.standalone .sidebar { padding-top: env(safe-area-inset-top, 0); }
@media (max-width: 900px) {
  html.standalone .tabbar { padding-bottom: calc(env(safe-area-inset-bottom, 0) + 4px); }
  html.standalone .content {
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0) + var(--sp-5));
  }
}
