/* Appearance (#97): dark mode, text size and density for the staff app and platform admin.
 *
 * <html> gets classes from app.services.appearance: "mcl", "dark" (Dark chosen, or System + the device is dark),
 * "size-large", "density-compact". Backgrounds, text, lines and the accent come from the small <style id="mcl-theme">
 * block that service writes into the head (per theme, contrast-checked). This file holds the dark values of the fixed
 * status colors, and dark fixes for page styles that still use fixed light colors. Customer pages don't load it.
 */
html { color-scheme: light; }
html.dark { color-scheme: dark;
  --red: #ff8b7e; --red-bg: #3d1e1b; --on-red: #2a0905; --blue: #93b6ff; --blue-bg: #1c2948;
  --warn: #f1c453; --warn-bg: #382c0f; --warn-line: #6b5414; --ai: #c9b1ff; --ai-bg: #2b2245; --ai-line: #4b3b7a;
  --human-line: #2f5b49; --green: #86e9a8; --green-bg: #173a26; --dept: #bcc0ff; --dept-bg: #262b52;
  --hover: rgba(255, 255, 255, .06); --shadow: rgba(0, 0, 0, .55);
  /* page-specific palettes (today.css, checklist.css, job_forms.css, field_invoice.css) */
  --bad: #ff8b7e; --bad-bg: #3d1e1b; --ok-bg: #173a2b;
  --supply: #93b6ff; --supply-bg: #1c2948; --bypass: #f5b46a; --bypass-bg: #3a2a12; --return: #c9b1ff; --return-bg: #2b2245;
}
/* The phone pages' own accent variables follow the theme accent everywhere (light and dark). */
html.mcl { --td: var(--accent); --td-ink: var(--accent-ink); --ck: var(--accent); --ck-ink: var(--accent-ink);
  --jf: var(--accent); --jf-ink: var(--accent-ink); --fi: var(--accent); --fi-ink: var(--accent-ink); }
html.dark body { background: var(--bg); color: var(--ink); }

/* ---------------------------------------------------------------- staff app pieces (app.css) */
html.dark pre.code, html.dark .sim-log { background: #0b0e0c; border: 1px solid var(--line); }
html.dark:not(.brand-bar) .admin-topbar { --bar: #0b0f14; --bar-line: var(--line); }
html.dark .viz, html.dark .dash, html.dark .reports {
  --viz-surface: var(--panel); --viz-grid: #343b38; --viz-axis: #4c5551; --viz-muted: #a1aaa5; --viz-ink2: #c9d0cc;
  --s1: #5c9df0; --s2: #f08c5f; --s3: #3cca94; --good-ink: #74e08d; --bad-ink: #ff8b7e; }
html.dark .project-days .pd-today td { background: rgba(147, 182, 255, .1); }
html.dark .note-item.note-conflict { background: rgba(241, 196, 83, .1); }
html.dark .softphone .dot { background: #59605c; }
html.dark .btn.confirm { color: var(--warn); }
html.dark img.brand-logo { background: #fff; border-radius: 4px; padding: 1px 3px; }
/* Logos, QR codes, plans and signatures keep a white card in dark mode so they stay readable. */
html.dark .logo-box, html.dark .qr-box, html.dark .plan-diagram, html.dark .ps-viewport { color: #1d2421; }

/* Inline colors in a few templates (kept as-is there so other work merges cleanly). */
html.dark [style*="background:#f7f7f5"], html.dark [style*="background:#f4f5f2"] { background: var(--panel-2) !important; color: var(--ink); }
html.dark [style*="background:#fffbea"] { background: var(--warn-bg) !important; }
html.dark [style*="background:#eef6ff"] { background: var(--blue-bg) !important; }
html.dark [style*="background:#f0faf3"] { background: var(--green-bg) !important; }
html.dark [style*="color:#555"] { color: var(--muted) !important; }
html.dark [style*="color:#a33"] { color: var(--red) !important; }
html.dark [style*="color:#2f6b4f"] { color: var(--green) !important; }

/* Native sheets (native.js) and the field voice button (field_voice.js) use the variables / html.dark themselves. */

/* ---------------------------------------------------------------- chat assistant in the app (sales-chat.css) */
html.dark .vsc-root[data-mode="app"] { --vsc-ink: var(--ink); --vsc-muted: var(--muted); --vsc-line: var(--line); color: var(--ink); }
html.dark .vsc-root[data-mode="app"] .vsc-panel, html.dark .vsc-root[data-mode="app"] .vsc-teaser,
html.dark .vsc-root[data-mode="app"] .vsc-bot .vsc-bubble, html.dark .vsc-root[data-mode="app"] .vsc-chip,
html.dark .vsc-root[data-mode="app"] .vsc-mic { background: var(--panel); color: var(--ink); }
html.dark .vsc-root[data-mode="app"] .vsc-log, html.dark .vsc-root[data-mode="app"] .vsc-extras { background: var(--bg); }
html.dark .vsc-root[data-mode="app"] input, html.dark .vsc-root[data-mode="app"] textarea {
  background: var(--input-bg); color: var(--ink); border-color: var(--line); }
html.dark .vsc-root[data-mode="app"] .vsc-x:hover, html.dark .vsc-root[data-mode="app"] .vsc-chip:hover { background: var(--panel-2); }
html.dark .vsc-root[data-mode="app"] .vsc-voice-status { background: var(--warn-bg); color: var(--ink); border-color: var(--warn-line); }

/* ---------------------------------------------------------------- photo picker, photos, maps */
html.dark :where(.pp) :where(.pp-btn) { background: var(--panel); border-color: var(--line); }
html.dark .media-chip { background: var(--panel); border-color: var(--line); }
html.dark .media-thumb, html.dark .media-cell .media-thumb { background-color: var(--panel-2); border-color: var(--line); }
html.dark #dmap-map { background: #1d2320; }
html.dark .leaflet-popup-content-wrapper, html.dark .leaflet-popup-tip { background: var(--panel); color: var(--ink); }
html.dark .leaflet-bar a, html.dark .leaflet-control-attribution { background: var(--panel); color: var(--ink); border-color: var(--line); }
html.dark .leaflet-control-attribution a { color: var(--accent); }
html.dark .pin.sel { outline-color: #fff; }

/* ---------------------------------------------------------------- leads, equipment (crm.css), vault, porting */
html.dark .lead-col { background: var(--panel-2); }
html.dark .lead-card, html.dark .equip-item { background: var(--panel); border-color: var(--line); }
html.dark .stage-won { background: var(--green-bg); } html.dark .stage-lost { background: var(--red-bg); }
html.dark .lead-fu, html.dark .lead-due, html.dark .badge-warn { color: var(--warn); }
html.dark .badge-alert { color: var(--red); } html.dark .badge-ok { color: var(--green); } html.dark .badge-muted { color: var(--muted); }
html.dark .vault-entries li a:hover, html.dark .vault-notes, html.dark .gen-out { background: var(--panel-2); }
html.dark .vault-toast { color: var(--bg); }
html.dark .port-steps li.done { background: var(--green-bg); color: var(--green); border-color: var(--human-line); }
html.dark .port-ok { color: var(--green); }
html.dark .port-explain { background: var(--panel-2); }

/* ---------------------------------------------------------------- phone pages (today, checklist, job forms, field invoice) */
html.dark .td-banner { color: var(--ink); }
html.dark .td-tag { background: var(--panel-2); }
html.dark .td-tag.status-in_progress, html.dark .td-tag.status-en_route, html.dark .td-btn-on { color: var(--green); }
html.dark .td-tag.status-completed { background: var(--panel-2); }
html.dark .ck-meter { background: var(--panel-2); }
html.dark .ck-box { background: var(--input-bg); border-color: #59625d; }
html.dark .ck-na { color: var(--muted); } html.dark .ck-na:active { background: var(--panel-2); }
html.dark .ck-row.is-done { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
html.dark .ck-row.is-na { background: var(--panel-2); }
html.dark .ck-row.is-na .ck-box { background: #3a423e; border-color: #3a423e; }
html.dark .ck-row.is-na .ck-title, html.dark .ck-row.is-na .ck-hint { color: var(--muted); }
html.dark .ck-row.is-fail { background: var(--red-bg); }
html.dark .ck-row.is-pending .ck-meta::after, html.dark .ck-req-note b { color: var(--bypass); }
html.dark .ck-req { color: var(--bypass); background: var(--bypass-bg); }
html.dark .ck-tag-photo { color: #9fd8ff; background: #10324a; }
html.dark .ck-sync.is-offline { color: var(--warn); } html.dark .ck-sync.is-error { color: var(--red); }
html.dark .jf-input, html.dark .jf-choice, html.dark .jf-btn { background: var(--input-bg); color: var(--ink); border-color: #4a534e; }
html.dark .jf-input:disabled { background: var(--panel-2); }
html.dark .jf-tag { background: var(--panel-2); } html.dark .jf-tag-warn { background: var(--warn-bg); color: var(--warn); }
html.dark .jf-banner { background: var(--human-bg); border-color: var(--human-line); }
html.dark .jf-field.is-missing { box-shadow: 0 0 0 2px var(--red-bg); border-color: var(--red); }
html.dark .jf-req, html.dark .jf-error, html.dark .jf-sync.is-error { color: var(--red); }
html.dark .jf-sync.is-busy, html.dark .jf-sync.is-offline { color: var(--warn); }
html.dark .fi-status { background: var(--panel-2); }
html.dark .fi-st-approved, html.dark .fi-banner-ok { background: var(--human-bg); }

/* ---------------------------------------------------------------- text size and density (any theme) */
html.size-large body { font-size: 16px; }
html.size-large .small, html.size-large .kv, html.size-large .audit, html.size-large .msg-meta { font-size: 14px; }
html.size-large .tag, html.size-large .count, html.size-large .hour, html.size-large .nav-group-title { font-size: 12.5px; }
html.size-large .job, html.size-large .week-job, html.size-large .tabs a { font-size: 14px; }
html.size-large .tabbar .tab { font-size: 12.5px; }
html.density-compact .page { padding: 10px; }
html.density-compact .card { padding: 10px 12px; }
html.density-compact .table th, html.density-compact .table td { padding: 4px 8px; }
html.density-compact .btn { padding: 4px 10px; }
html.density-compact input, html.density-compact select, html.density-compact textarea { padding: 4px 6px; }
html.density-compact .settings-form { gap: 10px; }
html.density-compact .conv-list li a { padding: 6px 10px; }
html.density-compact .messages { gap: 6px; padding: 10px; }
html.density-compact .topbar { height: 46px; }

/* ---------------------------------------------------------------- Account > Appearance page */
.ap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ap-choice { position: relative; display: grid; gap: 6px; padding: 10px; border: 2px solid var(--line); border-radius: 10px;
  background: var(--panel); cursor: pointer; }
.ap-choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--human-bg); }
.ap-choice:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.ap-choice input { position: absolute; opacity: 0; pointer-events: none; }
.ap-choice strong { font-size: 14px; }
.ap-swatch { display: flex; height: 44px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.ap-swatch span { flex: 1; }
.ap-swatch .ap-acc { flex: 0 0 30%; }
.ap-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.ap-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ap-seg label { padding: 8px 14px; cursor: pointer; border-right: 1px solid var(--line); background: var(--panel); }
.ap-seg label:last-child { border-right: 0; }
.ap-seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ap-seg label:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
.ap-seg input { position: absolute; opacity: 0; pointer-events: none; }
.ap-custom[hidden] { display: none; }
.ap-preview { display: grid; gap: 8px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
#ap-form .card > h3:first-child { margin-top: 0; }
