/*
 * RevMap Dealer — theme.
 *
 * The token names and values are the map editor's, so both apps stay in step:
 * change a value here and there, and they keep matching. Everything below is
 * written against tokens only, which is what makes the light theme work
 * without a second set of rules.
 */

/* Light is the default. Dark is opt-in via data-theme="dark", and the
   editor's data-theme="light" is honoured too so either convention works.
   Putting light in :root means it is also what you get with no JavaScript. */
/* Dark is the default. Light is opt-in via data-theme="light"; the explicit
   data-theme="dark" is honoured too, so either convention works and the
   default also holds with no JavaScript. */
:root,
[data-theme="dark"] {
    --bg: #0f0f10;
    --panel: #171718;
    --panel2: #1f1f21;
    --line: #323236;
    --text: #d7d7db;
    --muted: #9a9aa2;
    --accent: #42bd2e;
    --danger: #ff5a5f;
    --pro: #ffb000;

    --bg2: #0b0b0c;
    --surface: #141416;
    --surface2: #121214;
    --cell: #101012;
    --cell-alt: #0e0e10;
    --grid-line: #2f2f35;
    --strong: #ffffff;
    --overlay: 255, 255, 255;
    --shadow: 0, 0, 0;
    --accent-ink: #08210a;
    --danger-soft: #ff9a9d;
    --panel-rgb: 23, 23, 24;
    --surface-rgb: 20, 20, 22;
    --scrim: 0, 0, 0;
    --text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    --topbar-bg: #1a1a1c;
    --window-shadow: 0 14px 40px rgba(0, 0, 0, .45);

    /* Tints for status colours, per theme so both stay legible. */
    --accent-soft: rgba(66, 189, 46, .12);
    --accent-line: rgba(66, 189, 46, .55);
    --pro-soft: rgba(255, 176, 0, .12);
    --pro-line: rgba(255, 176, 0, .40);
    --danger-fill: rgba(255, 90, 95, .12);
    --danger-line: rgba(255, 90, 95, .40);
    --accent-text: var(--accent);
    --pro-text: var(--pro);
    --danger-text: var(--danger);
    --info: #4aa3ff;
    --info-soft: rgba(74, 163, 255, .12);
    --info-line: rgba(74, 163, 255, .40);
    --placeholder: #83838c;

}

[data-theme="light"] {
    --bg: #f4f4f6;
    --panel: #ffffff;
    --panel2: #ececed;
    --line: #d5d5da;
    --text: #26262b;
    --muted: #6b6b73;
    --accent: #2f9e22;
    --danger: #d63b40;
    --pro: #b57e00;

    --bg2: #e7e7ea;
    --surface: #f0f0f2;
    --surface2: #e9e9ec;
    --cell: #ffffff;
    --cell-alt: #f2f2f4;
    --grid-line: #d5d5da;
    --strong: #111114;
    --overlay: 0, 0, 0;
    --shadow: 0, 0, 0;
    --accent-ink: #ffffff;
    --danger-soft: #c0353a;
    --panel-rgb: 255, 255, 255;
    --surface-rgb: 240, 240, 242;
    --scrim: 20, 20, 25;
    --text-shadow: none;
    --topbar-bg: #f0f1f3;
    --window-shadow: 0 6px 18px rgba(30, 30, 40, .16);

    --accent-soft: rgba(47, 158, 34, .12);
    --accent-line: rgba(47, 158, 34, .50);
    --pro-soft: rgba(181, 126, 0, .12);
    --pro-line: rgba(181, 126, 0, .40);
    --danger-fill: rgba(214, 59, 64, .10);
    --danger-line: rgba(214, 59, 64, .40);
    /* Darker variants for small text on light; the fills above stay the
       editor's colours so the two apps still look the same. */
    --accent-text: #237d1a;
    --pro-text: #8a6000;
    --danger-text: #c0353a;
    --info: #1f6feb;
    --info-soft: rgba(31, 111, 235, .10);
    --info-line: rgba(31, 111, 235, .35);
    --placeholder: #6b6b73;
}

/* Not part of either palette — these apply whatever the theme is. Keeping them
   out of the theme blocks stops them being lost when a palette is edited. */
:root {
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

/* ---- Bootstrap bindings -------------------------------------------------- */
:root {
    --bs-body-font-family: var(--sans);
    --bs-body-font-size: .9rem;
    --bs-body-color: var(--text);
    --bs-body-bg: var(--bg);
    --bs-emphasis-color: var(--strong);
    --bs-border-color: var(--line);
    --bs-secondary-color: var(--muted);
    --bs-link-color: var(--accent-text);
    --bs-link-hover-color: var(--accent-text);
    --bs-border-radius: 10px;
    --bs-border-radius-sm: 8px;
    --bs-border-radius-lg: 12px;
    --bs-focus-ring-color: var(--accent-soft);
}

html, body { min-height: 100vh; background: var(--bg); }
body { color: var(--text); }
.text-muted, .form-text { color: var(--muted) !important; }
a { color: var(--accent-text); text-underline-offset: 2px; }
a:hover { color: var(--accent-text); }
.skip { position: absolute; left: 1rem; top: .5rem; z-index: 2000; background: var(--panel); padding: .5rem 1rem; border-radius: 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ---- Buttons (the editor's .topBtn look: tinted, not solid) -------------- */
.btn { font-weight: 500; border-radius: 10px; }
/* Dark keeps the editor's tinted button; light gets a solid fill, because a
   tint on a white surface reads as disabled. */
.btn-primary {
    --bs-btn-color: var(--text); --bs-btn-bg: var(--accent-soft); --bs-btn-border-color: var(--accent-line);
    --bs-btn-hover-color: var(--text); --bs-btn-hover-bg: rgba(66, 189, 46, .22); --bs-btn-hover-border-color: var(--accent-line);
    --bs-btn-active-color: var(--text); --bs-btn-active-bg: rgba(66, 189, 46, .28); --bs-btn-active-border-color: var(--accent);
    --bs-btn-disabled-color: var(--muted); --bs-btn-disabled-bg: var(--accent-soft); --bs-btn-disabled-border-color: var(--accent-line);
    font-weight: 600;
}
[data-theme="light"] .btn-primary {
    --bs-btn-color: #fff; --bs-btn-bg: #27851c; --bs-btn-border-color: #27851c;
    --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #237d1a; --bs-btn-hover-border-color: #237d1a;
    --bs-btn-active-color: #fff; --bs-btn-active-bg: #1f7016; --bs-btn-active-border-color: #1f7016;
    --bs-btn-disabled-color: #fff; --bs-btn-disabled-bg: #27851c; --bs-btn-disabled-border-color: #27851c;
}
.btn-outline-primary {
    --bs-btn-color: var(--accent-text); --bs-btn-bg: transparent; --bs-btn-border-color: var(--accent-line);
    --bs-btn-hover-color: var(--text); --bs-btn-hover-bg: var(--accent-soft); --bs-btn-hover-border-color: var(--accent);
    --bs-btn-active-color: var(--text); --bs-btn-active-bg: var(--accent-soft); --bs-btn-active-border-color: var(--accent);
    font-weight: 600;
}
.btn-outline-secondary {
    --bs-btn-color: var(--text); --bs-btn-bg: var(--cell); --bs-btn-border-color: var(--grid-line);
    --bs-btn-hover-color: var(--strong); --bs-btn-hover-bg: var(--surface); --bs-btn-hover-border-color: var(--grid-line);
    --bs-btn-active-color: var(--strong); --bs-btn-active-bg: var(--surface2); --bs-btn-active-border-color: var(--grid-line);
}
.btn-outline-danger {
    --bs-btn-color: var(--danger-text); --bs-btn-bg: transparent; --bs-btn-border-color: var(--danger-line);
    --bs-btn-hover-color: var(--strong); --bs-btn-hover-bg: var(--danger-fill); --bs-btn-hover-border-color: var(--danger);
    --bs-btn-active-color: var(--strong); --bs-btn-active-bg: var(--danger-fill); --bs-btn-active-border-color: var(--danger);
}
.btn-link { --bs-btn-color: var(--accent-text); --bs-btn-hover-color: var(--accent-text); }
.btn-icon {
    border: 0; background: transparent; font-size: 1.25rem; line-height: 1;
    padding: .3rem .5rem; color: var(--text); border-radius: 10px;
}
.btn-icon:hover { background: rgba(var(--overlay), .08); color: var(--strong); }

/* ---- Forms --------------------------------------------------------------- */
.form-control, .form-select {
    background: var(--cell-alt); border: 1px solid var(--grid-line); color: var(--text); border-radius: 10px;
}
.form-control:focus, .form-select:focus {
    background: var(--cell-alt); color: var(--text);
    border-color: var(--accent-line); box-shadow: 0 0 0 .2rem var(--accent-soft);
}
.form-control::placeholder { color: var(--placeholder); }
.form-control:disabled, .form-select:disabled { background: var(--surface2); color: var(--muted); }
.form-select option { background: var(--panel); color: var(--text); }
.form-check-input { background-color: var(--cell-alt); border-color: var(--grid-line); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { border-color: var(--accent-line); box-shadow: 0 0 0 .2rem var(--accent-soft); }
.form-label { font-weight: 600; font-size: .85rem; margin-bottom: .3rem; color: var(--text); }
legend.form-label { float: none; }
.input-group-text { background: var(--surface2); border-color: var(--grid-line); color: var(--muted); }
kbd { background: var(--cell-alt); border: 1px solid var(--grid-line); color: var(--muted); border-radius: 5px; }

/* ---- Top bar ------------------------------------------------------------- */
.topbar {
    position: sticky; top: 0; z-index: 1020;
    height: 60px; display: flex; align-items: center; gap: .85rem; padding: 0 1rem;
    border-bottom: 1px solid var(--line);
    background: var(--topbar-bg);
    backdrop-filter: blur(20px);
}
.omni { position: relative; flex: 1; max-width: 620px; }
.omni > .bi-search { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.omni input {
    width: 100%; height: 38px; padding: 0 2.4rem;
    border: 1px solid var(--grid-line); border-radius: 10px; background: var(--cell-alt);
    font-size: .95rem; color: var(--text);
}
.omni input::placeholder { color: var(--placeholder); }
.omni input:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 .2rem var(--accent-soft); }
.omni kbd { position: absolute; right: .6rem; top: 50%; transform: translateY(-50%); font-family: var(--mono); font-size: .72rem; padding: .1rem .35rem; }
.tokens { margin-left: auto; display: flex; align-items: baseline; gap: .35rem; white-space: nowrap; }
.tokens-num { font-family: var(--mono); font-weight: 700; font-size: 1.1rem; line-height: 1; color: var(--accent-text); }
.tokens-of { font-size: .78rem; color: var(--muted); }
.tokens.is-empty .tokens-num { color: var(--danger-text); }
@media (max-width: 575.98px) { .tokens-of { display: none; } .topbar { padding: 0 .6rem; gap: .5rem; } }

/* ---- Rail (sidebar) ------------------------------------------------------ */
.rail {
    background: linear-gradient(180deg, var(--surface), var(--cell));
    color: var(--text); display: flex; flex-direction: column; border-right: 1px solid var(--line);
    --bs-offcanvas-width: 250px; --bs-offcanvas-bg: var(--surface); --bs-offcanvas-color: var(--text);
    --bs-offcanvas-border-color: var(--line);
}
@media (min-width: 992px) {
    .rail { position: fixed; inset: 0 auto 0 0; width: 236px; z-index: 1030; }
    .shell { margin-left: 236px; }
}
.rail-head {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    height: 60px; padding: 0 1rem; border-bottom: 1px solid var(--line); background: var(--topbar-bg);
}
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; min-width: 0; }
.brand img { height: 22px; width: auto; display: block; flex: none; }
.brand .logoLight { display: none; }
[data-theme="light"] .brand .logoDark { display: none; }
[data-theme="light"] .brand .logoLight { display: block; }
.brandName {
    font-weight: 600; letter-spacing: .06em; font-size: 11px; color: var(--muted);
    text-transform: uppercase; padding-left: .55rem; border-left: 1px solid var(--line);
    align-self: stretch; display: flex; align-items: center;
}
.brand:hover .brandName { color: var(--text); }
.rail-nav { flex: 1; overflow-y: auto; padding: .5rem 0 1rem; }
.rail-group {
    font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); padding: 1rem 1.1rem .35rem;
}
.rail-link {
    display: flex; align-items: center; gap: .65rem; padding: .45rem 1.1rem;
    color: var(--muted); text-decoration: none; border-left: 2px solid transparent; font-size: 13px;
}
.rail-link .bi { font-size: 1rem; width: 1.1rem; text-align: center; }
.rail-link:hover { color: var(--text); background: rgba(var(--overlay), .06); }
.rail-link.active {
    color: var(--text); border-left-color: var(--accent);
    background: var(--accent-soft); font-weight: 600;
}
.rail-link:focus-visible { outline-offset: -2px; }
.rail-badge {
    margin-left: auto; background: var(--pro-soft); border: 1px solid var(--pro-line); color: var(--pro-text);
    font-weight: 700; font-size: 11px; border-radius: 999px; padding: 0 .45rem; min-width: 1.5rem; text-align: center;
}
.rail-ext { margin-left: auto; font-size: .68rem !important; opacity: .45; }
.rail-badge + .rail-ext { margin-left: .35rem; }
.rail-foot { font-size: 11px; padding: .85rem 1.1rem; border-top: 1px solid var(--line); color: var(--muted); }
.rail-foot strong { color: var(--text); font-weight: 600; }

/* ---- Page ---------------------------------------------------------------- */
.page { max-width: 1480px; padding: 2rem 1.5rem 4rem; }
@media (max-width: 575.98px) { .page { padding: 1.25rem .75rem 3rem; } }
.foot { padding: 0 1.5rem 2rem; font-size: 11px; color: var(--muted); }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem 1.5rem; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0 0 .3rem; font-size: 21px; font-weight: 700; letter-spacing: .01em; color: var(--strong); }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.crumbs { font-size: 12px; margin-bottom: .3rem; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent-text); }

.section-title, h2.section {
    margin: 0 0 .7rem; font-size: 15px; font-weight: 650; color: var(--strong);
    display: flex; align-items: baseline; gap: .6rem;
}
.section-title .count { font-size: 12px; font-weight: 400; color: var(--muted); }
.block { margin-bottom: 1.75rem; }

.panel {
    background: rgba(var(--panel-rgb), .98); border: 1px solid var(--grid-line);
    border-radius: 12px; box-shadow: var(--window-shadow);
}
.panel-body { padding: 1.1rem 1.35rem; }
.panel-body.border-top { border-top: 1px solid var(--grid-line) !important; }
.panel + .panel { margin-top: 1rem; }

/* ---- Tables -------------------------------------------------------------- */
.table { --bs-table-bg: transparent; --bs-table-color: var(--text); --bs-table-border-color: var(--grid-line); margin-bottom: 0; }
.table-wrap {
    background: rgba(var(--panel-rgb), .98); border: 1px solid var(--grid-line);
    border-radius: 12px; box-shadow: var(--window-shadow);
    /* Last resort only: the rules below shrink the table enough that this
       almost never engages, but it stops a table ever spilling past the panel. */
    overflow-x: auto;
}
/* Long values wrap and make the row taller rather than pushing the table into
   a horizontal scrollbar, which hides columns off the right edge. */
.table-wrap .table { table-layout: auto; width: 100%; }
/* Ordinary prose uses break-word, which keeps natural column sizing and only
   breaks a word when it truly does not fit. */
.table-wrap .table td, .table-wrap .table th { overflow-wrap: break-word; word-break: normal; }
.table-wrap .table td .rawid { white-space: normal; overflow-wrap: break-word; }
/* VINs, part numbers, file names and email addresses are single unbreakable
   tokens. Left alone they set a minimum width the column cannot go under, and
   a narrow column then pushes the whole table past its panel. "anywhere" is
   the one value that also lowers min-content, so these may break and the row
   grows taller instead. */
.table-wrap .table td .code,
.table-wrap .table td a {
    white-space: normal;          /* .code is nowrap by default, which blocks the break */
    overflow-wrap: anywhere;
}
.table-wrap .table td .code { display: inline-block; max-width: 100%; }
.table .num, .table th.num, .table td[data-nowrap] { white-space: nowrap; overflow-wrap: normal; }
.table-wrap .table > :not(caption) > * > * { padding: .6rem .9rem; border-bottom-color: var(--grid-line); background: transparent; }
.table-wrap .table thead th {
    font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); background: var(--surface); border-bottom: 1px solid var(--grid-line); white-space: nowrap;
}
.table-wrap .table tbody tr:last-child > * { border-bottom: 0; }
.table-wrap .table tbody tr:hover > * { background: rgba(var(--overlay), .04); }
.table td { vertical-align: top; }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); font-size: 13px; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: "↕"; opacity: .35; margin-left: .3rem; font-size: .75em; }
th[data-sort].asc::after { content: "↑"; opacity: .9; color: var(--accent-text); }
th[data-sort].desc::after { content: "↓"; opacity: .9; color: var(--accent-text); }
.table-filter { max-width: 300px; }
tr.is-muted > * { color: var(--muted); }

/* ---- Codes --------------------------------------------------------------- */
.code {
    font-family: var(--mono); font-size: 12px; white-space: nowrap;
    background: var(--cell-alt); border: 1px solid var(--grid-line); padding: 1px 5px; border-radius: 5px;
}
.code.pn { color: var(--strong); }
/* Part numbers link to the matching calibrations but must not read as links:
   same colour, no underline — the pointer and a faint tint are the only cue. */
a.pn-link, a.pn-link:hover, a.pn-link:focus { color: var(--strong); text-decoration: none; }
a.pn-link:hover { border-color: var(--accent-line); background: var(--accent-soft); }
a.pn-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
td .code, dd .code { display: inline-block; }
.rawid { font-family: var(--mono); font-size: 11.5px; color: var(--muted); word-break: break-all; white-space: pre-wrap; }
mark.hit { background: var(--accent-soft); color: var(--accent-text); padding: 0 .15em; border-radius: 3px; }
.token-big {
    font-family: var(--mono); font-size: 1.8rem; font-weight: 700; letter-spacing: .14em; color: var(--accent-text);
    background: var(--cell-alt); border: 1px dashed var(--accent-line); border-radius: 12px;
    padding: .7rem 1rem; text-align: center; user-select: all;
}
code {
    font-family: var(--mono); background: var(--cell-alt); border: 1px solid var(--grid-line);
    padding: 1px 5px; border-radius: 5px; font-size: 12px; color: var(--text);
}

/* ---- Pills --------------------------------------------------------------- */
.pill {
    display: inline-block; font-size: 11.5px; font-weight: 600;
    padding: 2px 8px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.pill-status { text-transform: uppercase; letter-spacing: .04em; font-size: 10.5px; }
.pill-ok { color: var(--accent-text); background: var(--accent-soft); border-color: var(--accent-line); }
.pill-warn { color: var(--pro-text); background: var(--pro-soft); border-color: var(--pro-line); }
.pill-bad { color: var(--danger-text); background: var(--danger-fill); border-color: var(--danger-line); }
.pill-info { color: var(--info); background: var(--info-soft); border-color: var(--info-line); }
.pill-muted { color: var(--muted); background: rgba(var(--overlay), .05); border-color: var(--grid-line); }

/* ---- Alerts -------------------------------------------------------------- */
.alert { border-radius: 12px; border-width: 1px; font-size: 13px; }
.alert-success { color: var(--accent-text); background: var(--accent-soft); border-color: var(--accent-line); }
.alert-danger { color: var(--danger-text); background: var(--danger-fill); border-color: var(--danger-line); }
.alert-warning { color: var(--pro-text); background: var(--pro-soft); border-color: var(--pro-line); }
.alert-info { color: var(--info); background: var(--info-soft); border-color: var(--info-line); }
.alert .btn-close { filter: none; }

/* ---- Stats strip --------------------------------------------------------- */
.strip {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    border: 1px solid var(--grid-line); border-radius: 12px; background: rgba(var(--panel-rgb), .98);
    box-shadow: var(--window-shadow); margin-bottom: 1.75rem; overflow: hidden;
}
.strip > a, .strip > div { padding: 1rem 1.15rem; text-decoration: none; color: inherit; border-right: 1px solid var(--grid-line); }
.strip > :last-child { border-right: 0; }
.strip > a:hover { background: rgba(var(--overlay), .05); }
.strip .v { font-size: 25px; font-weight: 700; line-height: 1; color: var(--strong); }
.strip .l { font-size: 12px; color: var(--muted); margin-top: .35rem; }
.strip .attention .v { color: var(--pro-text); }

/* ---- Identification inbox ------------------------------------------------ */
.ident {
    background: rgba(var(--panel-rgb), .98); border: 1px solid var(--grid-line);
    border-radius: 12px; box-shadow: var(--window-shadow); margin-bottom: .75rem;
}
.ident-main { display: grid; grid-template-columns: 1.5rem minmax(0, 1.2fr) minmax(0, 1.5fr) minmax(0, 1.6fr); gap: .5rem 1.25rem; padding: 1rem 1.25rem; }
@media (max-width: 1199.98px) { .ident-main { grid-template-columns: 1.5rem minmax(0, 1fr) minmax(0, 1fr); } .ident-act { grid-column: 2 / -1; } }
@media (max-width: 767.98px) { .ident-main { grid-template-columns: 1.5rem minmax(0, 1fr); } .ident-main > * { grid-column: 2; } .ident-main > .ident-check { grid-column: 1; grid-row: 1; } }
.ident-label { font-size: 10.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .25rem; }
.ident-owned { margin-top: .5rem; font-size: 12.5px; }
.suggest { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }
.suggest .btn { font-size: 12px; padding: .2rem .6rem; }
.ident.is-dup { border-left: 2px solid var(--pro); }

/* An identification still waiting to be dealt with, shown on the customer page */
.panel.is-pending {
    border-color: var(--pro-line);
    box-shadow: var(--window-shadow), inset 3px 0 0 var(--pro);
    background: linear-gradient(90deg, var(--pro-soft), rgba(var(--panel-rgb), .98) 60%);
}

/* ---- Key/value ----------------------------------------------------------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.kv dt { font-weight: 500; color: var(--muted); font-size: 12.5px; }
.kv { min-width: 0; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
/* SA2 and block lists are long single tokens: let them wrap inside the panel
   instead of running past its edge. */
.kv dd .code { white-space: normal; display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
.chart-box { position: relative; height: 240px; }

/* ---- Modal / dropdown ---------------------------------------------------- */
.modal-content {
    background: var(--surface); border: 1px solid rgba(var(--overlay), .08);
    border-radius: 14px; box-shadow: var(--window-shadow); color: var(--text);
}
.modal-header, .modal-footer { border-color: rgba(var(--overlay), .06); }
.modal-backdrop { --bs-backdrop-bg: rgb(var(--scrim)); }
.dropdown-menu {
    --bs-dropdown-bg: var(--panel); --bs-dropdown-border-color: var(--line); --bs-dropdown-color: var(--text);
    --bs-dropdown-link-color: var(--text); --bs-dropdown-link-hover-bg: rgba(var(--overlay), .06);
    --bs-dropdown-link-hover-color: var(--strong); --bs-dropdown-header-color: var(--muted);
    --bs-dropdown-divider-bg: rgba(var(--overlay), .08);
    border-radius: 12px; box-shadow: var(--window-shadow); padding: 8px;
}
.dropdown-item { border-radius: 8px; }
.btn-close { filter: invert(1) grayscale(1) brightness(2); }
[data-theme="light"] .btn-close { filter: none; }

/* Theme picker inside the account menu */
.theme-row { display: flex; align-items: center; gap: .5rem; padding: .25rem .5rem .35rem; }
.theme-row .form-select { padding: .25rem 1.75rem .25rem .5rem; font-size: 12.5px; }

/* ---- Live search dropdown ------------------------------------------------ */
.omni-drop {
    position: absolute; top: calc(100% + .4rem); left: 0; right: 0; z-index: 1040;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    box-shadow: var(--window-shadow); max-height: min(70vh, 30rem); overflow-y: auto; padding: 6px;
}
.omni-group {
    font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
    padding: .5rem .6rem .25rem; display: flex; align-items: center; gap: .45rem;
}
.omni-group:not(:first-child) { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .6rem; }
.omni-item {
    display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap;
    padding: .4rem .6rem; text-decoration: none; color: var(--text); font-size: 13px; border-radius: 7px;
}
.omni-item:hover, .omni-item.is-active { background: rgba(var(--overlay), .06); color: var(--strong); }
.omni-item.is-active { box-shadow: inset 2px 0 0 var(--accent); }
.omni-label { font-weight: 500; }
.omni-meta { font-size: 11.5px; color: var(--muted); }
.omni-all { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .5rem; color: var(--accent-text); font-weight: 600; }
.omni-empty { padding: .9rem; color: var(--muted); font-size: 13px; }

/* ---- Searchable picker --------------------------------------------------- */
.picker { position: relative; display: block; }
.picker-btn {
    display: flex; align-items: center; gap: .5rem; width: 100%; min-height: 38px;
    padding: .35rem .75rem; text-align: left;
    background: var(--cell-alt); border: 1px solid var(--grid-line); border-radius: 10px;
    color: var(--text); font-size: .9rem;
}
.picker-btn:hover { border-color: var(--accent-line); }
.picker-btn[aria-expanded="true"] { border-color: var(--accent-line); box-shadow: 0 0 0 .2rem var(--accent-soft); }
.picker-btn .picker-value { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-btn.is-empty .picker-value { color: var(--placeholder); }
.picker-btn .bi { color: var(--muted); font-size: .8rem; flex: none; }
.picker-pop {
    position: absolute; z-index: 1050; top: calc(100% + .35rem); left: 0; min-width: 100%; width: max-content;
    max-width: min(28rem, 92vw);
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--window-shadow);
    display: flex; flex-direction: column; overflow: hidden;
}
.picker-pop.drop-up { top: auto; bottom: calc(100% + .35rem); }
.picker-search { padding: 6px; border-bottom: 1px solid var(--line); }
.picker-search input {
    width: 100%; height: 34px; padding: 0 .65rem; font-size: .9rem;
    background: var(--cell-alt); border: 1px solid var(--grid-line); border-radius: 8px; color: var(--text);
}
.picker-search input:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 .2rem var(--accent-soft); }
.picker-list { overflow-y: auto; max-height: 17rem; padding: 6px; }
.picker-opt {
    display: flex; align-items: baseline; gap: .5rem; width: 100%;
    padding: 7px 10px; background: none; border: 0; border-radius: 7px; color: var(--text);
    text-align: left; font-size: 12.5px; cursor: pointer;
}
.picker-opt:hover, .picker-opt.is-active { background: rgba(var(--overlay), .06); color: var(--strong); }
.picker-opt.is-active { box-shadow: inset 2px 0 0 var(--accent); }
.picker-opt.is-selected { background: rgba(var(--overlay), .10); }
.picker-opt.is-selected::after { content: " ✓"; color: var(--accent-text); font-size: 11px; margin-left: auto; }
.picker-opt[disabled] { color: var(--muted); opacity: .6; cursor: not-allowed; }
.picker-opt[disabled]:hover { background: none; }
.picker-opt .picker-id { font-family: var(--mono); font-size: 10.5px; color: var(--muted); flex: none; }
.picker-opt .picker-tail { margin-left: auto; font-size: 10.5px; color: var(--muted); flex: none; }
.picker-none { padding: .9rem; color: var(--muted); font-size: 12.5px; text-align: center; }

/* ---- Login --------------------------------------------------------------- */
.login-page {
    min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem;
    background: linear-gradient(rgba(var(--scrim), .82), rgba(var(--scrim), .92)), var(--bg) url(img/login-bg.jpg) center / cover no-repeat;
}
[data-theme="light"] .login-page {
    background: linear-gradient(rgba(244, 244, 246, .45), rgba(244, 244, 246, .72)), var(--bg) url(img/login-bg.jpg) center / cover no-repeat;
}
.login-card {
    width: 100%; max-width: 390px; background: var(--panel); border: 1px solid var(--line);
    border-radius: 14px; padding: 1.75rem; box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
[data-theme="light"] .login-card { box-shadow: 0 24px 60px rgba(20, 20, 25, .28); }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-bottom: 1.75rem; text-align: center; }
.login-brand img { height: 42px; width: auto; display: block; }
.login-brand .logoLight { display: none; }
[data-theme="light"] .login-brand .logoDark { display: none; }
[data-theme="light"] .login-brand .logoLight { display: block; }
.login-card h1 { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }

/* ---- AJAX loading state -------------------------------------------------- */
.page.is-busy #page-content { opacity: .5; transition: opacity .12s ease-out; pointer-events: none; }
.page.is-busy::after {
    content: ""; position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 2000;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    background-size: 50% 100%; animation: rm-load .9s linear infinite;
}
@keyframes rm-load { from { background-position: -50% 0; } to { background-position: 150% 0; } }

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

/* ---- Immobilizer --------------------------------------------------------- */
.immo-panel { position: relative; overflow: hidden; }
/* The drifting prism field from the standalone tool, re-tinted to the theme
   accent and drawn behind the content. */
.immo-prisms { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: .55; }
[data-theme="dark"] .immo-prisms { opacity: .75; }
.immo-panel > .panel-body { position: relative; z-index: 1; }

.immo-dropzone {
    display: flex; align-items: center; gap: 1.1rem; width: 100%;
    padding: 1.5rem; margin: 0; cursor: pointer;
    border: 2px dashed var(--grid-line); border-radius: 14px;
    background: rgba(var(--overlay), .03);
    transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.immo-dropzone:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.immo-dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.immo-dropzone.is-dragover {
    border-color: var(--accent); background: var(--accent-soft); transform: scale(1.01);
}
.immo-dropzone.is-busy { pointer-events: none; opacity: .75; }
.immo-dz-icon {
    flex: none; width: 56px; height: 56px; border-radius: 14px;
    display: grid; place-items: center; color: var(--accent-text);
    background: var(--accent-soft); border: 1px solid var(--accent-line);
}
.immo-dz-body { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.immo-dz-title { font-weight: 600; color: var(--strong); }
.immo-dz-hint { font-size: 12.5px; color: var(--muted); }
.immo-controls { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }

.immo-status { margin-top: 1rem; padding: .9rem 1rem; border: 1px solid var(--grid-line); border-radius: 12px; background: rgba(var(--overlay), .03); }
.immo-status-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.immo-progress { margin-top: .7rem; height: 6px; border-radius: 999px; background: rgba(var(--overlay), .10); overflow: hidden; }
.immo-progress > span {
    display: block; height: 100%; width: 0; border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), var(--info));
    transition: width .15s ease;
}
.immo-working { margin-top: .7rem; display: flex; align-items: center; gap: .5rem; }
.immo-spinner {
    width: 15px; height: 15px; border-radius: 50%; display: inline-block;
    border: 2px solid rgba(var(--overlay), .18); border-top-color: var(--accent);
    animation: immo-spin .8s linear infinite;
}
@keyframes immo-spin { to { transform: rotate(360deg); } }

.immo-result { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--grid-line); }
.immo-result.is-success { animation: immo-rise .35s ease-out; }
@keyframes immo-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.immo-bad { color: var(--danger-text); }
.immo-warn { color: var(--pro-text); }

@media (prefers-reduced-motion: reduce) {
    .immo-prisms { display: none; }
    .immo-result.is-success { animation: none; }
}
@media (max-width: 575.98px) {
    .immo-dropzone { flex-direction: column; align-items: flex-start; }
}

/* A calibration carrying a comment: the row shows it on hover, and this marks
   which rows have one so you are not hunting for them. */
.note-flag { color: var(--muted); font-size: .8rem; margin-left: .25rem; vertical-align: baseline; }
tr.has-note:hover .note-flag { color: var(--accent-text); }

/* ---- Credit movements ------------------------------------------------------ */
.amt-up { color: var(--accent-text); }
.amt-down { color: var(--danger-text); }

/* ---- Bar chart (credit sales): one series, server-rendered, no JS ----------- */
.bars {
    display: flex; align-items: stretch; gap: 2px; height: 170px;
    border-bottom: 1px solid var(--grid-line); padding-top: 1.6rem;
}
.bars .bar { position: relative; flex: 1 1 0; min-width: 0; display: flex; align-items: flex-end; cursor: default; outline: none; }
/* The hit target is the whole column, not just the coloured part. */
.bars .bar > span {
    display: block; width: 100%; max-width: 22px; margin: 0 auto;
    background: var(--accent); border-radius: 4px 4px 0 0; opacity: .85;
}
.bars .bar:hover > span, .bars .bar:focus-visible > span { opacity: 1; }
.bars .bar:hover, .bars .bar:focus-visible { background: rgba(var(--overlay), .04); }
.bars .bar.is-now::before {
    content: ""; position: absolute; left: 50%; bottom: -7px; width: 4px; height: 4px;
    margin-left: -2px; border-radius: 50%; background: var(--muted);
}
.bars .bar::after {
    content: attr(data-tip); position: absolute; bottom: calc(100% - 1.4rem); left: 50%;
    transform: translateX(-50%); white-space: nowrap; pointer-events: none;
    background: var(--surface); color: var(--strong); border: 1px solid var(--grid-line);
    border-radius: 8px; padding: .3rem .55rem; font-size: 12px; opacity: 0; transition: opacity .12s; z-index: 2;
}
.bars .bar:nth-child(-n+4)::after { left: 0; transform: none; }
.bars .bar:nth-last-child(-n+4)::after { left: auto; right: 0; transform: none; }
.bars .bar:hover::after, .bars .bar:focus-visible::after { opacity: 1; }
.bars-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: .6rem; }
@media (prefers-reduced-motion: reduce) { .bars .bar::after { transition: none; } }

/* File pickers: the browser's own button ignores the theme otherwise. */
.form-control::file-selector-button {
    background: var(--surface2); color: var(--text); border-color: var(--grid-line);
}
.form-control:hover:not(:disabled):not([readonly])::file-selector-button { background: var(--surface); color: var(--strong); }
.btn-quiet { --bs-btn-color: var(--muted); --bs-btn-hover-color: var(--danger-text); text-decoration: none; }
