/* =====================================================================
   Site Expenses — styles
   Two layouts, chosen by <html data-layout="mobile|desktop">:
   - mobile:  top bar + bottom tab bar with a centre "Add" button
   - desktop: fixed left sidebar + wide, multi-column pages
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f3;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-soft: #fff1e8;
  --accent-text: #ffffff;
  --data: #2f6db5;
  --track: #e9ecf0;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fef5e1;
  --over: #b91c1c;
  --over-soft: #fde8e8;
  --material: #2f6db5;
  --labour: #0f8a7e;
  --contract: #8b5cf6;
  --other: #94a3b8;
  --side-bg: #14171c;
  --side-text: #aab2bf;
  --side-text-strong: #ffffff;
  --side-hover: rgba(255, 255, 255, .06);
  --side-active: rgba(255, 255, 255, .1);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --tabbar-h: 64px;
  --sidebar-w: 252px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1014; --surface: #161a20; --surface-2: #1b2027; --surface-3: #222830;
    --text: #eceef1; --text-2: #c9ced6; --muted: #949eab; --border: #262c34; --border-strong: #343b45;
    --accent: #f08a4b; --accent-hover: #f6a571; --accent-soft: #33221a; --accent-text: #1a1007;
    --data: #6ea2e0; --track: #252b33; --ok: #4ade80; --ok-soft: #15281c; --warn: #fbbf24; --warn-soft: #32290f;
    --over: #f87171; --over-soft: #351a1a; --material: #6ea2e0; --labour: #3cc4b4; --contract: #a78bfa; --other: #7b8592;
    --side-bg: #0a0c0f; --shadow-sm: none; --shadow: none; --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1014; --surface: #161a20; --surface-2: #1b2027; --surface-3: #222830;
  --text: #eceef1; --text-2: #c9ced6; --muted: #949eab; --border: #262c34; --border-strong: #343b45;
  --accent: #f08a4b; --accent-hover: #f6a571; --accent-soft: #33221a; --accent-text: #1a1007;
  --data: #6ea2e0; --track: #252b33; --ok: #4ade80; --ok-soft: #15281c; --warn: #fbbf24; --warn-soft: #32290f;
  --over: #f87171; --over-soft: #351a1a; --material: #6ea2e0; --labour: #3cc4b4; --contract: #a78bfa; --other: #7b8592;
  --side-bg: #0a0c0f; --shadow-sm: none; --shadow: none; --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  overflow-x: hidden;
}
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0; }
[hidden] { display: none !important; }
.num, .amount, td.r { font-variant-numeric: tabular-nums; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.strong { font-weight: 700; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid2-d { display: grid; gap: 16px; }
.grid3-d { display: grid; gap: 16px; }
html[data-layout="desktop"] .grid3-d { grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.page-head { flex-wrap: wrap; }
.page-head .actions { flex-wrap: wrap; }
html[data-layout="desktop"] .grid2-d { grid-template-columns: 1fr 1fr; gap: 12px; }
html[data-layout="desktop"] .layout-main-side > aside { margin-top: 0 !important; }
.only-desktop { display: none !important; }

/* ---------- Top bar (mobile) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.brand-mini { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mini img { width: 30px; height: 30px; border-radius: 8px; }
.brand-mini h1 { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-date { display: none; color: var(--muted); font-size: 14px; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; min-width: 38px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Page ---------- */
.view { max-width: 720px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex: none; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; font-size: 14px; background: none; border: 0; padding: 4px 0; cursor: pointer; margin-bottom: 6px; }
.back-link:hover { color: var(--text); }
.loading { display: flex; justify-content: center; padding: 60px 10px; }
.loading::after { content: ""; width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .ill { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; }
.empty .ill svg { width: 28px; height: 28px; }
.empty h3 { color: var(--text); font-size: 17px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
  min-width: 0;
}
.card h3 { font-size: 16px; font-weight: 700; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card.tap { cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .1s; }
.card.tap:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.card.tap:active { transform: scale(.995); }
.card.flush { padding: 0; overflow: hidden; }
.section-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 20px 2px 10px; }

/* ---------- Forms ---------- */
.field { display: block; }
.field > span, .label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field > span .opt { color: var(--muted); font-weight: 400; }
input, select, textarea {
  width: 100%;
  font: inherit; font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: 46px;
  appearance: none; -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
  padding-right: 34px; text-overflow: ellipsis;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; padding: 0; appearance: auto; -webkit-appearance: checkbox; accent-color: var(--accent); box-shadow: none; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: searchfield-cancel-button; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; pointer-events: none; }
.input-icon input { padding-left: 38px; }

.amount-field {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 10px 16px; transition: border-color .15s, box-shadow .15s;
}
.amount-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.amount-field span { font-size: 28px; font-weight: 600; color: var(--muted); }
.amount-field input { border: 0; padding: 2px 0; font-size: 34px; font-weight: 800; letter-spacing: -0.02em; min-height: 0; background: transparent; box-shadow: none !important; }
.amount-words { font-size: 12px; color: var(--muted); margin: 6px 4px 0; min-height: 18px; text-transform: capitalize; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  font-size: 14px; font-weight: 500; cursor: pointer; user-select: none; min-height: 38px;
  transition: background .15s, border-color .15s;
}
.chip input, .opt-card input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; pointer-events: none; }
.chip:has(input:checked), .chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.chip:has(input:focus-visible) { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.chip .x { border: 0; background: none; color: inherit; font-size: 14px; padding: 0 0 0 2px; cursor: pointer; opacity: .7; }

details.more { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 0 14px; }
details.more summary { padding: 12px 0; font-weight: 600; color: var(--text-2); cursor: pointer; list-style: none; font-size: 14px; display: flex; align-items: center; gap: 8px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: "+"; margin-left: auto; font-size: 18px; color: var(--muted); }
details.more[open] summary::after { content: "–"; }
details.more[open] { padding-bottom: 14px; border-style: solid; }
.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }

.form-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.form-section > h3 { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 10px 16px; min-height: 44px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); box-shadow: 0 1px 2px color-mix(in srgb, var(--accent) 40%, transparent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--over); border-color: color-mix(in srgb, var(--over) 35%, var(--border)); }
.btn.danger:hover { background: var(--over-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.icon { width: 46px; padding: 0; flex: none; }
.btn.lg { min-height: 52px; font-size: 16px; border-radius: 12px; }
.btn:disabled { opacity: .6; cursor: default; }
.form-actions { display: grid; gap: 10px; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; padding: 8px 0; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Attachments ---------- */
.attach-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.attach-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 84px; border-radius: var(--radius-sm); border: 1.5px dashed var(--border-strong);
  background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 14px; cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.attach-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.attach-btn svg { width: 24px; height: 24px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; margin-top: 12px; }
.thumbs:empty { display: none; }
.thumb {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 11px; color: var(--muted); padding: 6px; word-break: break-all;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .pdf { font-weight: 800; color: var(--over); font-size: 15px; display: block; }
.thumb button.rm {
  position: absolute; top: 5px; right: 5px; z-index: 2; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .65); color: #fff; font-size: 14px; line-height: 26px; cursor: pointer; padding: 0;
}
.thumb a { position: absolute; inset: 0; }

/* ---------- Budget check, bars, pills ---------- */
.budget-check { border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border); background: var(--surface); }
.budget-check.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.budget-check.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.budget-check.over { background: var(--over-soft); border-color: color-mix(in srgb, var(--over) 40%, transparent); }
.budget-check .title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.budget-check.ok .title { color: var(--ok); }
.budget-check.warn .title { color: var(--warn); }
.budget-check.over .title { color: var(--over); }
.budget-check .placeholder { color: var(--muted); font-size: 13px; }
.bc-line { font-size: 13px; margin-top: 10px; }
.bc-line .meta { display: flex; justify-content: space-between; gap: 8px; }

.bar { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; margin-top: 6px; position: relative; }
.bar > i { display: block; height: 100%; background: var(--data); border-radius: 99px; transition: width .4s ease; }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--over); }
.bar.thin { height: 6px; }
.split { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--track); margin-top: 10px; gap: 2px; }
.split > i { display: block; height: 100%; }
.split .material { background: var(--material); }
.split .labour { background: var(--labour); }
.split .contract { background: var(--contract); }
.split .other { background: var(--other); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

.pill { display: inline-flex; align-items: center; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--surface-3); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.over { background: var(--over-soft); color: var(--over); }
.pill.active { background: var(--accent-soft); color: var(--accent); }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.planned { background: var(--surface-3); color: var(--muted); }

.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { padding: 12px 0; border-top: 1px solid var(--border); }
.alert-list li:first-child { border-top: 0; padding-top: 0; }
.alert-list .meta { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; align-items: flex-end; }
.alert-list .lvl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; position: relative; }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi .k .ic { width: 26px; height: 26px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--text-2); flex: none; }
.kpi .k .ic svg { width: 15px; height: 15px; }
.kpi .k .ic.accent { background: var(--accent-soft); color: var(--accent); }
.kpi .v { font-size: 24px; font-weight: 800; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.02em; }
.kpi .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.wide { grid-column: 1 / -1; }
.kpi .v.over { color: var(--over); }
.kpi .v.warn { color: var(--warn); }
.kpi.hero { background: linear-gradient(135deg, var(--accent) 0%, #7c2d12 100%); border-color: transparent; color: #fff; }
.kpi.hero .k, .kpi.hero .d { color: rgba(255, 255, 255, .8); }
.kpi.hero .k .ic { background: rgba(255, 255, 255, .18); color: #fff; }
.kpi.hero .bar { background: rgba(255, 255, 255, .25); }
.kpi.hero .bar > i { background: #fff; }
.kpi.hero .bar.warn > i { background: #fde68a; }
.kpi.hero .bar.over > i { background: #fecaca; }

/* ---------- Lists ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 180px; }
.chips-line { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chips-line:empty { display: none; }
.chips-line .chip { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.summary { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 10px; font-size: 13px; color: var(--muted); margin: 2px 2px 12px; }
.summary b { color: var(--text); }
.day { margin-bottom: 14px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; color: var(--muted); padding: 6px 4px; position: sticky; top: 56px; background: var(--bg); z-index: 5; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.item { display: flex; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--border); cursor: pointer; align-items: center; transition: background .1s; }
.item:first-child { border-top: 0; }
.item:hover, .item:active { background: var(--surface-2); }
.item .av { width: 38px; height: 38px; border-radius: 11px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; }
.av.material { background: color-mix(in srgb, var(--material) 14%, transparent); color: var(--material); }
.av.labour { background: color-mix(in srgb, var(--labour) 14%, transparent); color: var(--labour); }
.av.contract { background: color-mix(in srgb, var(--contract) 14%, transparent); color: var(--contract); }
.av.other { background: var(--surface-3); color: var(--muted); }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { text-align: right; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item .amt small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 600; margin-top: 3px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.clip { display: inline-block; width: 13px; height: 13px; vertical-align: -2px; stroke: var(--muted); fill: none; stroke-width: 2; }

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 10px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl tr.grp td { background: var(--surface-2); font-weight: 700; font-size: 13px; color: var(--text-2); padding: 8px 8px; }
.tbl tr.tap { cursor: pointer; }
.tbl tr.tap:hover td { background: var(--surface-2); }
.tbl tr.subrow td:first-child { padding-left: 20px; color: var(--muted); }
.tbl .bar { margin-top: 6px; max-width: 220px; }
.data-table th { position: sticky; top: 0; background: var(--surface-2); padding: 12px 14px; text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }
.data-table td { padding: 12px 14px; vertical-align: middle; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table .cell-main { font-weight: 600; }
.data-table .cell-sub { color: var(--muted); font-size: 13px; max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.data-table .amt { font-weight: 700; font-size: 15px; }

/* ---------- Segmented ---------- */
.seg { display: flex; background: var(--surface-3); border-radius: 12px; padding: 4px; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap; min-height: 34px; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
/* Spend breakdown card */
#bd-dim { margin: 12px 0 4px; }
.bd-insight { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--text-2); margin: 10px 0 6px; }
.bd-insight:empty { display: none; }
.bd-tbl { margin-top: 12px; table-layout: fixed; }
.bd-tbl th:first-child { width: auto; }
.bd-tbl th:not(:first-child) { width: 76px; }
.bd-tbl td:first-child { overflow-wrap: anywhere; }
.bd-tbl tfoot td { border-top: 1px solid var(--border-strong); border-bottom: 0; font-weight: 600; color: var(--text-2); font-size: 13px; }
@media (max-width: 420px) { .bd-tbl th:not(:first-child) { width: 62px; } .bd-tbl { font-size: 13px; } }
.filters { margin-bottom: 16px; display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.filters .seg, .filters #custom { grid-column: 1 / -1; }
html[data-layout="desktop"] .filters .seg { grid-column: auto; }

/* Dashboard columns: one ordered column on phones, charts | alerts side by side on desktop */
.dash-cols { display: flex; flex-direction: column; }
.dash-cols .col { display: contents; }
.o1 { order: 1; } .o2 { order: 2; } .o3 { order: 3; } .o4 { order: 4; } .o5 { order: 5; }
html[data-layout="desktop"] .dash-cols { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 18px; align-items: start; }
html[data-layout="desktop"] .dash-cols .col { display: block; }

/* ---------- Charts ---------- */
.chart-box { position: relative; width: 100%; }
.chart-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---------- Mobile tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tabbar .side-brand, .tabbar .side-foot, .tabbar .l-long, .tabbar .side-label { display: none; }
.tabbar a {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabbar a svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }
.tabbar a[data-view="dashboard"] { order: 1; }
.tabbar a[data-view="expenses"] { order: 2; }
.tabbar a[data-view="add"] { order: 3; }
.tabbar a[data-view="projects"] { order: 4; }
.tabbar a[data-view="procurement"] { order: 5; }
.tabbar a[data-view="settings"] { order: 6; }
.tabbar a.nav-add .fab {
  width: 52px; height: 52px; border-radius: 18px; margin-top: -22px;
  background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 45%, transparent), 0 0 0 4px var(--bg);
}
.tabbar a.nav-add .fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
.tabbar a.nav-add { color: var(--text-2); }
.tabbar a.nav-add.active { color: var(--accent); }
.badge { position: absolute; top: 6px; left: calc(50% + 5px); min-width: 18px; height: 18px; border-radius: 9px; font-size: 11px; line-height: 18px; text-align: center; color: #fff; padding: 0 5px; font-weight: 700; }
.badge.warn { background: var(--warn); }
.badge.over { background: var(--over); }

/* ---------- Toast & sheet ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; max-width: 520px; width: 100%; background: #1f2937; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg); animation: up .2s ease-out; display: flex; gap: 10px; align-items: flex-start; }
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: #60a5fa; }
.toast.success::before { background: #22c55e; }
.toast.warn::before { background: #f59e0b; }
.toast.error::before { background: #ef4444; }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(15, 18, 22, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  animation: up .22s ease-out; box-shadow: var(--shadow-lg);
}
.sheet .grab { width: 40px; height: 4px; background: var(--border-strong); border-radius: 4px; margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.sheet-head h2 { font-size: 19px; font-weight: 800; }

.detail-amt { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; font-size: 14px; margin: 16px 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }

/* ---------- Login ---------- */
body.auth-mode { padding: 0; }
body.auth-mode .topbar, body.auth-mode .tabbar { display: none !important; }
body.auth-mode .view { max-width: none; padding: 0; margin: 0; }
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.auth-hero {
  position: relative; overflow: hidden;
  background: linear-gradient(150deg, #c2410c 0%, #9a3412 55%, #431407 100%);
  color: #fff; padding: calc(env(safe-area-inset-top) + 40px) 24px 72px;
}
.auth-hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .12;
  background-image: linear-gradient(rgba(255,255,255,.6) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.6) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, #000 0%, transparent 90%);
}
.auth-hero .logo { width: 56px; height: 56px; border-radius: 16px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); border: 2px solid rgba(255,255,255,.25); }
.auth-hero h1 { font-size: 28px; font-weight: 800; margin-top: 18px; letter-spacing: -0.02em; }
.auth-hero p { color: rgba(255, 255, 255, .85); margin-top: 6px; font-size: 15px; max-width: 420px; }
.auth-hero ul { display: none; list-style: none; padding: 0; margin: 36px 0 0; }
.auth-hero li { display: flex; gap: 12px; align-items: flex-start; margin-top: 18px; font-size: 15px; color: rgba(255, 255, 255, .92); }
.auth-hero li .ic { width: 36px; height: 36px; border-radius: 10px; background: rgba(255, 255, 255, .14); display: flex; align-items: center; justify-content: center; flex: none; }
.auth-hero li b { display: block; color: #fff; }
.auth-hero li span { color: rgba(255, 255, 255, .75); font-size: 14px; }
.auth-panel { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 0 16px 32px; }
.auth-card { width: 100%; max-width: 400px; margin-top: -44px; position: relative; z-index: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 24px 20px; }
.auth-card h2 { font-size: 22px; font-weight: 800; }
.auth-card .sub { color: var(--muted); margin: 4px 0 20px; font-size: 14px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 70px; }
.pw-wrap button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 8px 10px; cursor: pointer; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ---------- Settings ---------- */
.cat-row { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-top: 1px solid var(--border); cursor: pointer; border-radius: 8px; }
.cat-row:hover { background: var(--surface-2); }
.cat-row.sub { padding-left: 22px; font-size: 14px; }
.cat-row .grow { flex: 1; min-width: 0; }
.cat-row.off { opacity: .5; }
.cat-row .b { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; white-space: nowrap; }
.cat-row.add { color: var(--accent); font-weight: 600; }
.danger-zone { border-color: color-mix(in srgb, var(--over) 30%, var(--border)); }
.opt-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.opt-card { border: 1.5px solid var(--border-strong); border-radius: 12px; padding: 12px 8px; text-align: center; cursor: pointer; background: var(--surface); font-size: 13px; font-weight: 600; color: var(--text-2); position: relative; }
.opt-card input { position: absolute; opacity: 0; pointer-events: none; }
.opt-card svg { width: 26px; height: 26px; display: block; margin: 0 auto 6px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.opt-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------- Payment sources ---------- */
.src-ic { width: 34px; height: 34px; border-radius: 10px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--text-2); }
.src-ic svg { width: 18px; height: 18px; }
.src-ic.cash { background: var(--ok-soft); color: var(--ok); }
.src-ic.bank { background: color-mix(in srgb, var(--data) 14%, transparent); color: var(--data); }
.src-ic.upi { background: color-mix(in srgb, #7c3aed 14%, transparent); color: #8b5cf6; }
.src-ic.debit_card { background: color-mix(in srgb, var(--labour) 14%, transparent); color: var(--labour); }
.src-ic.credit_card { background: var(--warn-soft); color: var(--warn); }
.src-line { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.src-line:first-child { border-top: 0; }
.src-line .grow { flex: 1; min-width: 0; }
.src-line .t { font-weight: 600; font-size: 14px; }
.src-types { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.src-types .opt-card { padding: 10px 4px; font-size: 12px; }
.src-types .opt-card svg { width: 22px; height: 22px; }
@media (max-width: 420px) { .src-types { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.source-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.source-hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.o6 { order: 6; }

/* ---------- Procurement ---------- */
.po-line { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: var(--surface-2); }
.po-line-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.po-line-head .btn { margin-left: auto; min-height: 30px; }
.po-line-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.po-line-grid .desc { grid-column: 1 / -1; }
.po-line-grid .line-total { display: flex; flex-direction: column; justify-content: flex-end; }
.po-line-grid .line-total b { font-size: 17px; }
html[data-layout="desktop"] .po-line-grid { grid-template-columns: 2.2fr 1.3fr 1.3fr 1.3fr; }
html[data-layout="desktop"] .po-line-grid .desc { grid-column: span 1; }
.po-totals { margin-top: 14px; margin-left: auto; max-width: 320px; }
.po-totals > div { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.po-totals .grand { border-top: 1px solid var(--border-strong); margin-top: 4px; padding-top: 8px; font-size: 17px; }
.po-actions { grid-template-columns: 1fr 1fr; }
.grn-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.grn-row:first-of-type { border-top: 0; }
.grn-row .grow { flex: 1; min-width: 0; }
.doc { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; margin-right: 8px; text-decoration: none; }
.doc svg { width: 13px; height: 13px; }
.po-items td, .po-items th { white-space: nowrap; }
.po-items td:first-child { white-space: normal; min-width: 180px; }
.spend-switch { margin-bottom: 16px; }
.qty-table { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.qty-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 12px; border-top: 1px solid var(--border); }
.qty-row:first-child { border-top: 0; }
.qty-row .qty-in { display: flex; align-items: center; gap: 6px; }
.qty-row .qty-in input { width: 100px; text-align: right; font-weight: 700; }
.qty-row .qty-amt { grid-column: 1 / -1; text-align: right; font-size: 15px; }
html[data-layout="desktop"] .qty-row { grid-template-columns: 1fr auto 120px; }
html[data-layout="desktop"] .qty-row .qty-amt { grid-column: auto; }
input.invalid { border-color: var(--over) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--over) 18%, transparent) !important; }
.inv-lines { font-size: 12px; color: var(--muted); margin-top: 2px; }
html[data-layout="desktop"] .toolbar.po-toolbar { display: flex; }
.po-toolbar .search { flex: 1; }
.pill-wrap { display: flex !important; flex-wrap: wrap; gap: 4px; white-space: normal !important; }
.alloc { margin-top: 10px; }
.alloc .between { padding: 5px 0; border-top: 1px dashed var(--border); font-size: 13px; }
.alloc .between:first-child { border-top: 0; }
.po-mode .normal-only { display: none !important; }
.po-only { display: none !important; }
.po-mode .po-only { display: block !important; }
.target-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1.5px solid var(--border-strong); border-radius: 12px; cursor: pointer; background: var(--surface); }
.target-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.target-opt input { width: 18px; height: 18px; min-height: 0; margin-top: 2px; appearance: auto; -webkit-appearance: radio; accent-color: var(--accent); box-shadow: none; flex: none; }
.target-opt .grow { flex: 1; min-width: 0; }

/* ---------- Work cards ---------- */
.work-card .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.work-card h3 { font-size: 16px; }
.work-card .nums { display: flex; justify-content: space-between; align-items: baseline; margin-top: 14px; gap: 10px; }
.work-card .nums b { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }

/* ---------- Small phones ---------- */
@media (max-width: 360px) {
  .grid2 { grid-template-columns: 1fr; }
  .kpi .v { font-size: 20px; }
}

/* =====================================================================
   DESKTOP LAYOUT
   ===================================================================== */
html[data-layout="desktop"] body { padding: 0 0 0 var(--sidebar-w); }
html[data-layout="desktop"] body.auth-mode { padding: 0; }
html[data-layout="desktop"] .only-desktop { display: revert !important; }
html[data-layout="desktop"] .only-mobile { display: none !important; }

/* Sidebar */
html[data-layout="desktop"] .tabbar {
  top: 0; right: auto; bottom: 0; width: var(--sidebar-w); height: auto;
  flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 2px;
  background: var(--side-bg); border-top: 0; border-right: 1px solid rgba(255, 255, 255, .04);
  padding: 20px 14px; backdrop-filter: none;
}
html[data-layout="desktop"] .tabbar .side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; }
html[data-layout="desktop"] .side-brand img { width: 38px; height: 38px; border-radius: 11px; }
html[data-layout="desktop"] .side-brand b { display: block; color: #fff; font-size: 15px; line-height: 1.2; }
html[data-layout="desktop"] .side-brand span { color: var(--side-text); font-size: 12px; }
html[data-layout="desktop"] .tabbar .side-label { display: block; color: #6b7380; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 18px 12px 8px; order: 2; }
html[data-layout="desktop"] .tabbar a {
  flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
  padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--side-text);
}
html[data-layout="desktop"] .tabbar a:hover { background: var(--side-hover); color: var(--side-text-strong); }
html[data-layout="desktop"] .tabbar a.active { background: var(--side-active); color: var(--side-text-strong); font-weight: 600; }
html[data-layout="desktop"] .tabbar a.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
html[data-layout="desktop"] .tabbar a svg { width: 20px; height: 20px; }
html[data-layout="desktop"] .tabbar .l-long { display: inline; }
html[data-layout="desktop"] .tabbar .l-short { display: none; }
html[data-layout="desktop"] .tabbar a[data-view="add"] { order: 1; }
html[data-layout="desktop"] .tabbar a[data-view="dashboard"] { order: 3; }
html[data-layout="desktop"] .tabbar a[data-view="expenses"] { order: 4; }
html[data-layout="desktop"] .tabbar a[data-view="projects"] { order: 5; }
html[data-layout="desktop"] .tabbar a[data-view="procurement"] { order: 6; }
html[data-layout="desktop"] .tabbar a[data-view="settings"] { order: 7; }
html[data-layout="desktop"] .tabbar a.nav-add {
  background: var(--accent); color: #fff; font-weight: 700; justify-content: center; padding: 12px; margin-bottom: 4px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
html[data-layout="desktop"] .tabbar a.nav-add:hover { background: var(--accent-hover); color: #fff; }
html[data-layout="desktop"] .tabbar a.nav-add.active::before { display: none; }
html[data-layout="desktop"] .tabbar a.nav-add .fab { width: auto; height: auto; margin: 0; background: none; box-shadow: none; color: inherit; }
html[data-layout="desktop"] .tabbar a.nav-add .fab svg { width: 20px; height: 20px; }
html[data-layout="desktop"] .badge { position: static; margin-left: auto; }
html[data-layout="desktop"] .tabbar .side-foot { display: block; order: 10; margin-top: auto; padding: 14px 8px 0; border-top: 1px solid rgba(255, 255, 255, .06); color: #6b7380; font-size: 12px; }
html[data-layout="desktop"] .side-foot button { width: 100%; justify-content: flex-start; background: transparent; border-color: rgba(255, 255, 255, .1); color: var(--side-text); margin-bottom: 10px; }
html[data-layout="desktop"] .side-foot button:hover { background: var(--side-hover); color: #fff; }

/* Top bar */
html[data-layout="desktop"] .topbar { padding: 12px 36px; min-height: 60px; background: color-mix(in srgb, var(--bg) 85%, transparent); border-bottom: 1px solid var(--border); }
html[data-layout="desktop"] .brand-mini { display: none; }
html[data-layout="desktop"] .topbar-date { display: block; }
html[data-layout="desktop"] #layout-toggle { display: none; }

/* Page */
html[data-layout="desktop"] .view { max-width: 1280px; padding: 28px 36px 48px; margin: 0; }
html[data-layout="desktop"] .page-head { margin: 0 0 22px; }
html[data-layout="desktop"] .page-head h2 { font-size: 28px; }
html[data-layout="desktop"] .card { padding: 20px; margin-bottom: 18px; }
html[data-layout="desktop"] .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
html[data-layout="desktop"] .kpi { padding: 18px; }
html[data-layout="desktop"] .kpi .v { font-size: 28px; }
html[data-layout="desktop"] .kpi.wide { grid-column: span 2; }
html[data-layout="desktop"] .kpi.hero { grid-row: span 2; display: flex; flex-direction: column; justify-content: center; padding: 24px; }
html[data-layout="desktop"] .kpi.hero .v { font-size: 44px; }
html[data-layout="desktop"] .day-head { top: 60px; }
html[data-layout="desktop"] #toast-root { left: auto; right: 24px; bottom: 24px; align-items: flex-end; padding: 0; }
html[data-layout="desktop"] .toast { width: 380px; }
html[data-layout="desktop"] .sheet-backdrop { align-items: center; }
html[data-layout="desktop"] .sheet { border-radius: 20px; max-width: 560px; padding: 10px 24px 24px; }
html[data-layout="desktop"] .sheet.wide { max-width: 760px; }
html[data-layout="desktop"] .sheet .grab { visibility: hidden; height: 0; margin: 4px 0 6px; }

/* Grids */
html[data-layout="desktop"] .layout-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
html[data-layout="desktop"] .layout-2 > .card { margin-bottom: 0; }
html[data-layout="desktop"] .layout-main-side { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr); gap: 22px; align-items: start; }
html[data-layout="desktop"] .side-sticky { position: sticky; top: 84px; }
html[data-layout="desktop"] .dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
html[data-layout="desktop"] .dash-grid > .card { margin: 0; }
html[data-layout="desktop"] .dash-grid .span-2 { grid-column: 1 / -1; }
html[data-layout="desktop"] .cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
html[data-layout="desktop"] .cards-grid > .card { margin: 0; }
html[data-layout="desktop"] .filters { grid-template-columns: auto 1fr 1fr; align-items: center; }
html[data-layout="desktop"] .filters #custom { grid-column: 1 / -1; max-width: 420px; }
html[data-layout="desktop"] .settings-grid { columns: 2 380px; column-gap: 18px; }
html[data-layout="desktop"] .settings-grid > * { break-inside: avoid; }
html[data-layout="desktop"] .toolbar { display: grid; grid-template-columns: minmax(200px, 2fr) repeat(5, minmax(0, 1fr)); }
html[data-layout="desktop"] .toolbar .search { min-width: 0; }
@media (max-width: 1199px) {
  html[data-layout="desktop"] .toolbar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
html[data-layout="desktop"] .toolbar input[type="date"] { padding-right: 6px; }
html[data-layout="desktop"] .card.flush { overflow-x: auto; }
.data-table { table-layout: fixed; }
.data-table td > *, .data-table .cell-main, .data-table .cell-sub { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table .tag { max-width: 100%; }
.data-table col.c-date { width: 13%; } .data-table col.c-cat { width: 22%; } .data-table col.c-desc { width: 25%; }
.data-table col.c-work { width: 16%; } .data-table col.c-paid { width: 12%; } .data-table col.c-amt { width: 12%; }

/* Login on desktop: split screen */
html[data-layout="desktop"] .auth { flex-direction: row; }
html[data-layout="desktop"] .auth-hero { flex: 1.1; display: flex; flex-direction: column; justify-content: center; padding: 64px 72px; }
html[data-layout="desktop"] .auth-hero h1 { font-size: 40px; }
html[data-layout="desktop"] .auth-hero p { font-size: 17px; }
html[data-layout="desktop"] .auth-hero ul { display: block; }
html[data-layout="desktop"] .auth-panel { flex: 1; align-items: center; padding: 40px; }
html[data-layout="desktop"] .auth-card { margin-top: 0; padding: 36px 32px; box-shadow: var(--shadow); }

/* ================= Procurement flow ================= */
/* Flow strip on the Procurement tab: 7 steps, scrolls sideways on a phone. */
.pipe-wrap { margin: 0 -4px 14px; overflow-x: auto; scrollbar-width: none; }
.pipe-wrap::-webkit-scrollbar { display: none; }
.pipe { display: flex; list-style: none; gap: 0; padding: 2px 4px; min-width: min-content; }
.pipe li { display: flex; align-items: stretch; flex: 1 1 0; min-width: 118px; }
.pipe li + li::before { content: ""; width: 10px; flex: none; align-self: center; height: 2px; background: var(--border-strong); }
.pipe-step { flex: 1; display: grid; grid-template-columns: auto 1fr; grid-template-areas: "n l" "c c" "h h"; gap: 2px 6px; text-align: left;
  border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 11px; cursor: pointer; font: inherit; color: var(--text); }
.pipe-step:hover { border-color: var(--border-strong); }
.pipe-step .n { grid-area: n; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-3); color: var(--muted); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.pipe-step .l { grid-area: l; font-size: 12px; font-weight: 600; color: var(--text-2); align-self: center; white-space: nowrap; }
.pipe-step .c { grid-area: c; font-size: 22px; font-weight: 800; letter-spacing: -.02em; color: var(--muted); margin-top: 4px; }
.pipe-step .h { grid-area: h; font-size: 11px; color: var(--muted); line-height: 1.3; }
.pipe-step.busy .c { color: var(--text); }
.pipe-step.busy .n { background: var(--accent-soft); color: var(--accent); }
.pipe-step.here { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

/* Step tracker on a request / PO */
.flow { display: flex; list-style: none; margin: 0 0 14px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; scrollbar-width: none; gap: 0; }
.flow::-webkit-scrollbar { display: none; }
.flow-step { flex: 1 0 92px; display: flex; flex-direction: column; align-items: center; text-align: center; position: relative; gap: 3px; padding: 0 4px; }
.flow-step::before { content: ""; position: absolute; top: 13px; right: 50%; width: 100%; height: 2px; background: var(--border-strong); z-index: 0; }
.flow-step:first-child::before { display: none; }
.flow-step .dot { position: relative; z-index: 1; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--surface-3); color: var(--muted); border: 2px solid var(--surface); }
.flow-step .lbl { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.flow-step .note { font-size: 11px; color: var(--muted); line-height: 1.25; }
.flow-step.done .dot { background: var(--ok); color: #fff; }
.flow-step.done::before, .flow-step.now::before { background: var(--ok); }
.flow-step.done .lbl { color: var(--text-2); }
.flow-step.now .dot { background: var(--accent); color: var(--accent-text); box-shadow: 0 0 0 4px var(--accent-soft); }
.flow-step.now .lbl { color: var(--text); font-weight: 700; }
.flow-step.now .note { color: var(--accent); font-weight: 600; }
.flow-step.skip { opacity: .5; }
.flow-step.skip .dot { background: transparent; border: 2px dashed var(--border-strong); }
.flow-step.over .dot { background: var(--over); color: #fff; }

/* Link from a PO back to its request */
.src-note { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin: -4px 0 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); font-size: 13px; text-decoration: none; flex-wrap: wrap; }
.src-note svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.src-note span { flex: 1 1 auto; min-width: 0; }
.src-note .go { flex: none; color: var(--accent); font-weight: 600; }

/* Quote ranking */
.ranks { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.rank { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); flex-wrap: wrap; }
.rank .pos { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--muted); flex: none; }
.rank .t { font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rank .amt { text-align: right; flex: none; }
.rank .amt b { font-size: 16px; display: block; }
.rank .amt small { font-size: 11px; color: var(--muted); display: block; }
.rank .amt .btn { margin-top: 6px; }
.rank { flex-wrap: nowrap; align-items: flex-start; }
.rank.best { border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: var(--ok-soft); }
.rank.best .pos, .rank.chosen .pos { background: var(--ok); color: #fff; }
.rank.chosen { border-color: var(--ok); }
.rank.dim { opacity: .6; }

/* Item x vendor comparison */
.matrix-wrap { overflow-x: auto; margin: 8px -4px 0; }
.matrix { min-width: 100%; width: max-content; }
.matrix th, .matrix td { min-width: 112px; }
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 150px; max-width: 220px; white-space: normal; }
.matrix td .xs { display: block; }
.matrix tfoot td { border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.matrix tfoot tr.grand td { font-size: 15px; color: var(--text); border-top: 1px solid var(--border-strong); }
.matrix .cell-best { background: var(--ok-soft); }
.matrix .cell-best b { color: var(--ok); }

/* Quote sheet lines */
.q-line { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px 10px; align-items: end; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.q-line .t { grid-column: 1 / -1; display: flex; flex-direction: column; }
.q-line .tot { font-weight: 700; padding-bottom: 10px; min-width: 76px; text-align: right; }
html[data-layout="desktop"] .q-line { grid-template-columns: 2fr 1fr .8fr auto; }
html[data-layout="desktop"] .q-line .t { grid-column: auto; align-self: center; }

/* Select quote sheet */
.award-sum { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.award-sum .big { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.award-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 14px; }
.award-steps li::marker { font-weight: 700; color: var(--accent); }
/* ---------- Light / dark toggle ---------- */
#theme-toggle-side { margin-bottom: 8px !important; }
html[data-shown="dark"] .kpi.hero { background: linear-gradient(135deg, #b4521d 0%, #5c230e 100%); }
html[data-shown="dark"] .toast { background: #2a313b; }
html[data-shown="dark"] .auth-hero { background: linear-gradient(150deg, #9a3412 0%, #5c230e 55%, #1f0b04 100%); }
html[data-shown="dark"] input[type="date"], html[data-shown="dark"] input[type="datetime-local"], html[data-shown="dark"] select { color-scheme: dark; }
:root { color-scheme: light; }
html[data-shown="dark"] { color-scheme: dark; }

/* ---------- Procurement reports ---------- */
.rep-toolbar { justify-content: space-between; }
.rep-toolbar .seg { flex: 1 1 auto; max-width: 560px; overflow-x: auto; }
.rep-toolbar .seg button { white-space: nowrap; }
.rep-funnel { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.rep-funnel-row { display: grid; grid-template-columns: 76px 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.rep-funnel-row .l { color: var(--text-2); font-weight: 600; }
.rep-funnel-row .v { min-width: 96px; text-align: right; white-space: nowrap; }
.rep-mini { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.rep-mini > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rep-mini b { font-size: 16px; }
html[data-layout="desktop"] .layout-main-side > div:first-child .rep-mini { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tbl-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.rep-tbl { min-width: 560px; }
.rep-tbl td:first-child, .rep-tbl th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 150px; }
.rep-share .bar { max-width: 160px; height: 4px; margin-top: 6px; }
.kpi .v.ok { color: var(--ok); }
.age-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--track); margin: 6px 0 12px; }
.age-bar i { display: block; height: 100%; }
.age-not_due { background: var(--ok); }
.age-d1_30 { background: var(--warn); }
.age-d31_60 { background: color-mix(in srgb, var(--warn) 45%, var(--over)); }
.age-d61_90 { background: var(--over); }
.age-d90p { background: color-mix(in srgb, var(--over) 70%, #000); }
.age-legend { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.age-legend > div { display: flex; justify-content: space-between; gap: 10px; }
.age-legend > div.zero { color: var(--muted); }
.age-legend span { display: flex; align-items: center; gap: 8px; }
.age-legend span i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.age-legend .age-total { border-top: 1px solid var(--border); padding-top: 6px; font-weight: 700; }
.rep-cycle { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.rep-cycle-step { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--surface-2); }
.rep-cycle-step b { font-size: 22px; letter-spacing: -.02em; }
.rep-cycle-step > span { color: var(--muted); font-size: 13px; margin-left: 4px; }
.rep-cycle-step .l { font-weight: 600; font-size: 13px; margin-top: 2px; }

/* ---------- WhatsApp / share ---------- */
svg.i.wa { stroke-width: 1.6; }
.btn.wa { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.btn.wa:hover { background: #17824a; border-color: #17824a; }
.share-preview { white-space: pre-wrap; font: 13px/1.5 var(--font); background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; max-height: 260px; overflow: auto; margin: 0; }
.share-link { display: flex; gap: 8px; align-items: center; }
.share-link input { flex: 1; min-width: 0; font-size: 13px; }

@media print {
  .topbar, .tabbar, .pipe-wrap, #ptabs, .rep-toolbar, .page-head .actions, [data-csv], #toast-root, #sheet-root { display: none !important; }
  body, .view { background: #fff !important; color: #111 !important; padding: 0 !important; margin: 0 !important; }
  html[data-layout="desktop"] body { padding-left: 0 !important; }
  .card, .kpi { break-inside: avoid; box-shadow: none !important; border-color: #ccc !important; background: #fff !important; color: #111 !important; }
  .layout-main-side { display: block !important; }
  .tbl-scroll { overflow: visible !important; }
  .rep-tbl { min-width: 0 !important; }
}
.bar.paid > i { background: var(--ok); }
.bar.teal > i { background: var(--labour); }
.bar.muted > i { background: var(--muted); }
html[data-layout="mobile"] .page-head .actions { flex: 0 1 auto; max-width: 100%; flex-wrap: wrap; }

/* ---------- Contracts & "where does this go" ---------- */
.pill.contract { background: color-mix(in srgb, var(--contract) 14%, transparent); color: var(--contract); }
.where-tip { font-size: 13px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.where-tip summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.where-tip p { margin: 8px 0 4px; }
.where-tip ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.share-from { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.share-from .grow { min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
