/* =====================================================================
   QSPEED POS — Application styles
   One stone-tinted frame (sidebar + top bar) holds a white sheet where the
   work happens. Colour goes on data, status and the one primary action;
   QSPEED red marks the brand mark, the selected tab and today's takings.
   Bootstrap 5 stays underneath; this file restyles its components.
   ===================================================================== */

:root {
    /* frame and sheet */
    --frame: #f3f2ef;          /* stone, the workshop floor: sidebar + top bar */
    --sheet: #ffffff;          /* the page */
    --sheet-edge: #e6e4df;
    --raised: #f6f6f5;         /* a tone step inside the sheet */
    --active: #e6e4df;         /* the selected nav item */
    --border: #e8e6e1;         /* card edges */
    --rule: #f0eeea;           /* table rows */
    --control: #d3d1cb;        /* inputs and outlined buttons */

    /* ink */
    --text: #17171a;
    --muted: #5d5f64;          /* 6.2:1 on white, 5.6:1 on the frame */
    --faint: #66686c;

    /* colour */
    --brand: #c1121f;          /* QSPEED red */
    --primary: #1d1f20;        /* the one filled action: near-black */
    --positive: #247b50;  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
    --negative: #b4232a;  --pill-negative-bg: #ffedea; --pill-negative-ink: #831c1e;
    --pill-warning-bg: #fffbeb; --pill-warning-ink: #92400e; --notice-edge: #fde68a;
    --pill-neutral-bg: #efeeea; --pill-neutral-ink: #34353a;

    /* charts (assets/js/charts.js reads these) */
    --chart-1: #c1121f;  --chart-2: #a8a6a0;  --chart-muted: #a8a6a0;
    --grid: #ebe9e4;  --axis-ink: #5d5f64;  --ink: #17171a;  --surface: #ffffff;  --chart-span: .06;

    /* shape and size */
    --radius-sheet: 16px;  --radius-card: 8px;  --radius-control: 6px;  --radius-chip: 4px;
    --gap: 16px;  --card-pad: 20px;  --pad: 24px;
    --font: "Barlow", "Segoe UI", system-ui, sans-serif;               /* text, tables, controls */
    --font-display: "Barlow Semi Condensed", "Barlow", "Segoe UI", sans-serif;  /* titles and large figures */
    --mono: ui-monospace, Consolas, monospace;                         /* real code only */

    /* Bootstrap's own variables, pointed at ours */
    --bs-body-font-family: var(--font);
    --bs-body-font-size: 15px;
    --bs-body-line-height: 1.45;
    --bs-body-color: var(--text);
    --bs-body-bg: var(--sheet);
    --bs-secondary-color: var(--muted);
    --bs-border-color: var(--border);
    --bs-border-radius: var(--radius-control);
    --bs-border-radius-sm: var(--radius-chip);
    --bs-border-radius-lg: var(--radius-card);
    --bs-link-color: var(--text);
    --bs-link-color-rgb: 23, 23, 26;
    --bs-link-hover-color: var(--brand);
    --bs-link-hover-color-rgb: 193, 18, 31;
    --bs-emphasis-color: var(--text);
    --bs-secondary-bg: var(--raised);
    --bs-tertiary-bg: var(--raised);
    --bs-focus-ring-color: rgba(23, 23, 26, .18);
}

html { font-size: 15px; }
body {
    font-variant-numeric: tabular-nums;
    background: var(--frame);
    font-family: var(--font);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { font-family: var(--font-display); font-weight: 600; letter-spacing: 0; color: var(--text); }
.h4, h4 { font-size: 18px; } .h5, h5 { font-size: 16px; } .h6, h6 { font-size: 14px; }
.text-muted, .text-secondary { color: var(--muted) !important; }
.small, small { font-size: 13px; }
.fw-bold { font-weight: 600 !important; }
a { text-decoration: none; }
code, kbd, .font-monospace { font-family: var(--mono); font-size: .95em; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.num, table, .stat-value { font-variant-numeric: tabular-nums; }
/* The brand red is kept for the mark, the selected tab and today's data.
   Icons that used to carry it now sit quietly in the text's own grey. */
.text-qs { color: var(--muted) !important; }
::selection { background: rgba(193, 18, 31, .14); }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---- Shell: the frame and the sheet ------------------------------------
   Grid: sidebar 264px | sheet (fluid). The sheet is inset 8px from the
   window's right and bottom edges; inside it the content has 24px padding. */
.app-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    background: var(--frame);
    position: sticky; top: 0; height: 100vh;
    overflow-y: auto;
    padding: 0 10px 16px;
}
.sidebar .brand {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    height: 56px; padding: 0 8px;
}
.brand-mark { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand-mark svg { flex: none; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 17px; line-height: 1.1; }
.brand-scope { display: block; font-family: var(--font); font-weight: 400; font-size: 12px; color: var(--muted); }
.sidebar .nav-section {
    padding: 18px 10px 6px;
    font-size: 12px;
    color: var(--muted);
}
.sidebar a.nav-link {
    display: flex; align-items: center; gap: 10px;
    height: 34px; padding: 0 10px; margin: 1px 0;
    border-radius: var(--radius-control);
    color: #3b3c40;
    font-size: 14px;
    transition: background-color .12s;
}
.sidebar a.nav-link:hover { background: #ebe9e4; color: var(--text); }
.sidebar a.nav-link.active { background: var(--active); color: var(--text); font-weight: 500; }
.sidebar .nav-ico { width: 18px; text-align: center; color: var(--muted); font-size: 15px; }
.sidebar a.nav-link.active .nav-ico { color: var(--text); }
.sidebar a.nav-link .badge { margin-left: auto; }
.sidebar-toggle { display: none; }

.app-main { display: flex; flex-direction: column; min-width: 0; padding: 0 8px 8px 0; }
.topbar {
    position: sticky; top: 0; z-index: 1020;
    height: 56px; flex: none;
    background: var(--frame);
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 0 16px 0 8px;
}
.topbar-scope { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-scope strong { color: var(--text); font-weight: 500; }
.topbar .account { display: flex; align-items: center; gap: 8px; color: var(--text); height: 36px; padding: 0 10px; border-radius: var(--radius-control); }
.topbar .account:hover { background: #ebe9e4; }
.avatar {
    width: 28px; height: 28px; border-radius: 50%; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: #e6e4df; color: var(--text); font-size: 12px; font-weight: 600;
}
.account-role { color: var(--muted); font-size: 13px; }

.sheet {
    flex: 1;
    background: var(--sheet);
    border: 1px solid var(--sheet-edge);
    border-radius: var(--radius-sheet);
    display: flex; flex-direction: column;
    min-width: 0;
}
.content { padding: 28px var(--pad) 32px; flex: 1; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-title { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin: 0; line-height: 1.2; }
.page-sub { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-foot { padding: 14px var(--pad); color: var(--muted); font-size: 12px; border-top: 1px solid var(--rule); }

/* ---- Cards and surfaces ------------------------------------------------ */
.card {
    --bs-card-border-color: var(--border);
    --bs-card-border-radius: var(--radius-card);
    --bs-card-inner-border-radius: calc(var(--radius-card) - 1px);
    --bs-card-cap-bg: transparent;
    --bs-card-spacer-y: var(--card-pad);
    --bs-card-spacer-x: var(--card-pad);
    border: 1px solid var(--border);
    box-shadow: none;
}
.card-header { background: transparent; border-bottom: 0; padding: 16px var(--card-pad) 0; font-weight: 600; font-size: 15px; }
.card-footer { background: transparent; border-top: 1px solid var(--rule); }
.card-title { font-size: 15px; font-weight: 600; }
.bg-light { background: var(--raised) !important; }
.border, .border-top, .border-bottom, .border-start, .border-end { border-color: var(--border) !important; }
.shadow, .shadow-sm, .shadow-lg { box-shadow: none !important; }
hr { border-color: var(--border); opacity: 1; }

/* the old stat tiles, where a page still uses them: label over a plain figure */
.stat-card .stat-label { color: var(--muted); font-size: 13px; }
.stat-card .stat-value { font-size: 24px; font-weight: 400; }

/* ---- Tables: rules and alignment ----------------------------------------- */
.table {
    --bs-table-bg: transparent;
    --bs-table-striped-bg: transparent;
    --bs-table-hover-bg: var(--raised);
    --bs-table-border-color: var(--rule);
    --bs-table-color: var(--text);
    margin-bottom: 0;
    font-variant-numeric: tabular-nums;
}
.table > :not(caption) > * > * { padding: 11px 12px; vertical-align: middle; border-bottom-color: var(--rule); }
.table-sm > :not(caption) > * > * { padding: 8px 10px; }
.table > thead > tr > th, .table > thead > tr > td {
    background: transparent !important;
    color: var(--muted); font-weight: 400; font-size: 12px;
    text-transform: none; letter-spacing: 0;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table-light, .table-light > *, .table-dark, .table-dark > * { --bs-table-bg: transparent; --bs-table-color: var(--muted); }
.table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-bg-type: transparent; }
.table > tbody > tr:last-child > * { border-bottom: 0; }
.table td.num, .table th.num { text-align: right !important; }
.table-responsive { border-radius: inherit; }
.table-danger, .table-warning { --bs-table-bg: transparent !important; }
tr.table-danger > td:first-child, tr.table-warning > td:first-child { box-shadow: inset 3px 0 0 var(--negative); }

/* ---- Live search: the box, and the results while they refresh ---------- */
.live-search-box { width: 320px; max-width: 100%; }
[data-live].is-updating { opacity: .55; transition: opacity .12s; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
    --bs-btn-font-weight: 500;
    --bs-btn-font-size: 14px;
    --bs-btn-padding-y: 7px;
    --bs-btn-padding-x: 14px;
    --bs-btn-border-radius: var(--radius-control);
    --bs-btn-focus-box-shadow: 0 0 0 3px rgba(23, 23, 26, .16);
    transition: background-color .12s, border-color .12s, color .12s, transform .08s;
}
.btn:active { transform: translateY(1px); }
.btn-sm { --bs-btn-padding-y: 4px; --bs-btn-padding-x: 10px; --bs-btn-font-size: 13px; --bs-btn-border-radius: var(--radius-control); }
.btn-lg { --bs-btn-padding-y: 10px; --bs-btn-font-size: 15px; }
.btn-primary, .btn-success, .btn-dark {
    --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary); --bs-btn-color: #fff;
    --bs-btn-hover-bg: #000; --bs-btn-hover-border-color: #000; --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: #000; --bs-btn-active-border-color: #000;
    --bs-btn-disabled-bg: #e6e4df; --bs-btn-disabled-border-color: #e6e4df; --bs-btn-disabled-color: #55575c; --bs-btn-disabled-opacity: 1;
}
.btn-outline-primary, .btn-outline-secondary, .btn-secondary, .btn-light, .btn-outline-success, .btn-outline-dark,
.btn-outline-warning, .btn-warning, .btn-outline-info, .btn-info {
    --bs-btn-bg: #fff; --bs-btn-color: var(--text); --bs-btn-border-color: var(--control);
    --bs-btn-hover-bg: var(--raised); --bs-btn-hover-color: var(--text); --bs-btn-hover-border-color: #b9b7b1;
    --bs-btn-active-bg: var(--active); --bs-btn-active-color: var(--text); --bs-btn-active-border-color: #b9b7b1;
    --bs-btn-disabled-color: var(--muted); --bs-btn-disabled-bg: #fff; --bs-btn-disabled-border-color: var(--border);
}
.btn-outline-danger, .btn-danger {
    --bs-btn-bg: #fff; --bs-btn-color: var(--negative); --bs-btn-border-color: #e9c3c1;
    --bs-btn-hover-bg: var(--pill-negative-bg); --bs-btn-hover-color: var(--pill-negative-ink); --bs-btn-hover-border-color: #dca5a2;
    --bs-btn-active-bg: var(--pill-negative-bg); --bs-btn-active-color: var(--pill-negative-ink);
}
.btn-link { --bs-btn-color: var(--text); --bs-btn-hover-color: var(--brand); text-decoration: none; padding-left: 0; padding-right: 0; }
.btn-check:checked + .btn { background: var(--primary) !important; border-color: var(--primary) !important; color: #fff !important; }
.btn-group > .btn { --bs-btn-border-radius: var(--radius-control); }

/* ---- Pills and badges: pale tint, dark ink of the same hue ---------------- */
.badge {
    --bs-badge-font-weight: 500; --bs-badge-font-size: 12px; --bs-badge-padding-y: 3px; --bs-badge-padding-x: 7px;
    --bs-badge-border-radius: var(--radius-chip);
    flex: none; white-space: nowrap;
}
.badge.bg-success, .badge.text-bg-success { background: var(--pill-positive-bg) !important; color: var(--pill-positive-ink) !important; }
.badge.bg-danger, .badge.text-bg-danger, .badge-low { background: var(--pill-negative-bg) !important; color: var(--pill-negative-ink) !important; }
.badge.bg-warning, .badge.text-bg-warning { background: var(--pill-warning-bg) !important; color: var(--pill-warning-ink) !important; }
.badge.bg-secondary, .badge.bg-primary, .badge.bg-info, .badge.bg-light, .badge.bg-dark,
.badge.text-bg-secondary, .badge.text-bg-primary, .badge.text-bg-info, .badge.text-bg-light, .badge.text-bg-dark {
    background: var(--pill-neutral-bg) !important; color: var(--pill-neutral-ink) !important; border: 0;
}
/* Bootstrap's subtle colours and status text, mapped onto the same pairs */
.bg-success-subtle { background: var(--pill-positive-bg) !important; } .bg-danger-subtle { background: var(--pill-negative-bg) !important; }
.bg-warning-subtle { background: var(--pill-warning-bg) !important; }
.bg-secondary-subtle, .bg-primary-subtle, .bg-info-subtle, .bg-light-subtle { background: var(--pill-neutral-bg) !important; }
.text-success { color: var(--positive) !important; } .bg-success-subtle.text-success { color: var(--pill-positive-ink) !important; }
.text-danger { color: var(--negative) !important; } .bg-danger-subtle.text-danger { color: var(--pill-negative-ink) !important; }
.text-warning { color: var(--pill-warning-ink) !important; }
.text-primary, .text-info { color: var(--text) !important; }
/* a count on a queue that needs action (sidebar, tabs) */
.sidebar .badge, .count-badge { background: var(--brand) !important; color: #fff !important; border-radius: 999px; --bs-badge-padding-x: 7px; font-size: 11px; }

/* ---- Alerts: quiet notices, never a coloured ground --------------------- */
.alert {
    --bs-alert-border-radius: var(--radius-card);
    --bs-alert-padding-y: 10px; --bs-alert-padding-x: 14px;
    font-size: 14px;
}
.alert-success { --bs-alert-bg: var(--pill-positive-bg); --bs-alert-color: var(--pill-positive-ink); --bs-alert-border-color: #b7ecc8; }
.alert-danger { --bs-alert-bg: var(--pill-negative-bg); --bs-alert-color: var(--pill-negative-ink); --bs-alert-border-color: #f6cbc5; }
.alert-warning { --bs-alert-bg: var(--pill-warning-bg); --bs-alert-color: var(--pill-warning-ink); --bs-alert-border-color: var(--notice-edge); }
.alert-info, .alert-secondary, .alert-light, .alert-primary { --bs-alert-bg: var(--raised); --bs-alert-color: var(--text); --bs-alert-border-color: var(--border); }
.alert .alert-link { color: inherit; text-decoration: underline; }

/* ---- Forms ------------------------------------------------------------- */
.form-label { font-weight: 500; font-size: 13px; margin-bottom: 6px; color: var(--text); }
.form-text { color: var(--muted); font-size: 12px; }
.form-control, .form-select {
    border-color: var(--control); border-radius: var(--radius-control);
    min-height: 38px; font-size: 14px; color: var(--text); background-color: #fff;
}
.form-control-sm, .form-select-sm { min-height: 32px; font-size: 13px; }
.form-control::placeholder { color: var(--faint); }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: var(--text); box-shadow: 0 0 0 3px rgba(23, 23, 26, .12); }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.input-group-text { background: var(--raised); border-color: var(--control); color: var(--muted); }

/* ---- Navigation pieces: underline tabs, pagination, menus --------------- */
.nav-tabs { --bs-nav-tabs-border-color: var(--border); --bs-nav-tabs-border-width: 1px; border-bottom: 1px solid var(--border); gap: 18px; }
.nav-tabs .nav-link {
    border: 0; border-bottom: 2px solid transparent; border-radius: 0; margin-bottom: -1px;
    padding: 8px 2px; color: var(--muted); background: none; font-weight: 500;
}
.nav-tabs .nav-link:hover { color: var(--text); }
.nav-tabs .nav-link.active { color: var(--text); border-bottom-color: var(--brand); background: none; }
.nav-pills .nav-link { color: var(--muted); border-radius: var(--radius-control); }
.nav-pills .nav-link.active { background: var(--active); color: var(--text); }
.pagination { --bs-pagination-color: var(--text); --bs-pagination-border-color: var(--border); --bs-pagination-hover-bg: var(--raised);
    --bs-pagination-hover-color: var(--text); --bs-pagination-active-bg: var(--primary); --bs-pagination-active-border-color: var(--primary);
    --bs-pagination-focus-box-shadow: 0 0 0 3px rgba(23,23,26,.14); --bs-pagination-disabled-color: var(--muted); }
.dropdown-menu { --bs-dropdown-border-color: var(--border); --bs-dropdown-link-active-bg: var(--active); --bs-dropdown-link-active-color: var(--text);
    border-radius: var(--radius-card); box-shadow: 0 8px 24px rgba(0, 0, 0, .10); font-size: 14px; }
.list-group { --bs-list-group-border-color: var(--rule); --bs-list-group-action-hover-bg: var(--raised); --bs-list-group-active-bg: var(--active);
    --bs-list-group-active-color: var(--text); --bs-list-group-active-border-color: var(--rule); }
.modal-content { border: 0; border-radius: 12px; }
.modal-header, .modal-footer { border-color: var(--rule); }
.offcanvas { --bs-offcanvas-border-color: var(--border); }

/* ---- Dashboard ----------------------------------------------------------
   Grid: 12 columns at the sheet's inner width with one 16px gutter. The
   takings card spans 12; the work lists pair as 6 + 6 (6x + 5g = 6x + 5g). */
.dash-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); }
.span-12 { grid-column: span 12; } .span-6 { grid-column: span 6; } .span-4 { grid-column: span 4; } .span-8 { grid-column: span 8; }
.panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-card); padding: 18px var(--card-pad) 16px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 12px; }
.panel-title { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0; }
.panel-meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.panel-meta a, .view-all { color: var(--text); font-weight: 500; }
.panel-meta a:hover, .view-all:hover { color: var(--brand); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 18px; }
.kpis > div { padding: 2px 20px 0; border-left: 1px solid var(--border); }
.kpis > div:first-child { padding-left: 0; border-left: 0; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-family: var(--font-display); font-size: 26px; font-weight: 500; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi-value.lead { font-size: 34px; font-weight: 600; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.chart { width: 100%; min-height: 220px; }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--rule); }
.rows li:first-child { border-top: 0; }
.rows .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows .fig { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows .fig .unit { color: var(--muted); }
.empty-note { border: 1px dashed var(--control); border-radius: var(--radius-card); padding: 10px 12px; color: var(--muted); font-size: 13px; }
.stock-track { height: 4px; border-radius: 2px; background: var(--rule); margin-top: 5px; overflow: hidden; }
.stock-track > span { display: block; height: 100%; background: var(--negative); }

/* ---- Login: the frame and one sheet ------------------------------------- */
.login-page { min-height: 100vh; background: var(--frame); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.login-side { padding: 40px 48px; display: flex; flex-direction: column; justify-content: space-between; }
.login-side .brand-mark .brand-name { font-size: 17px; }
.login-pitch { max-width: 440px; }
.login-pitch h2 { font-size: 30px; font-weight: 600; line-height: 1.2; margin: 0 0 12px; }
.login-pitch p { color: var(--muted); font-size: 15px; margin: 0; }
.login-facts { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; font-size: 14px; }
.login-facts li { display: flex; gap: 10px; }
.login-facts i { color: var(--muted); }
.login-foot { color: var(--muted); font-size: 12px; }
.login-sheet { margin: 8px 8px 8px 0; background: #fff; border: 1px solid var(--sheet-edge); border-radius: var(--radius-sheet);
    display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-form { width: 100%; max-width: 360px; }
.login-form h1 { font-size: 26px; font-weight: 600; margin: 0 0 6px; }
.login-form .lede { color: var(--muted); margin: 0 0 24px; }
.login-form .btn { width: 100%; min-height: 40px; }
.login-help { color: var(--muted); font-size: 13px; margin-top: 16px; }

/* diagnostic tree option buttons */
.dx-option { text-align: left; padding: 12px 16px; }
.dx-crumb { font-size: 13px; }
.dx-tree-card { cursor: pointer; transition: border-color .12s, background-color .12s; border: 1px solid var(--border) !important; background: #fff; }
.dx-tree-card:hover, .dx-tree-card:focus-visible { border-color: var(--text) !important; background: var(--raised); }

/* ---- Knowledge Base ---------------------------------------------------
   Status colours: Active = green, Pending = amber, Archived = grey,
   Hidden (parent archived) = faded, Incomplete = red "!" marker.        */
:root {
    --kb-active: #2f8a4c;  --kb-active-bg: #ebf7ee;
    --kb-pending: #c77800; --kb-pending-bg: #fff6e6;
    --kb-archived: #8a8984; --kb-archived-bg: #f1f0ed;
    --kb-line: #cfccc5;
}
.kb-badge { display:inline-block; padding: 2px 7px; border-radius: var(--radius-chip); font-size: 12px; font-weight: 500; white-space: nowrap; }
.kb-badge-active   { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.kb-badge-pending  { background: var(--pill-warning-bg);  color: var(--pill-warning-ink); }
.kb-badge-archived { background: var(--kb-archived-bg); color: #3f403c; }
.kb-badge-hidden   { background: #fff; color: var(--muted); border: 1px dashed var(--control); }

.kb-tree-card { border-top: 3px solid var(--kb-active) !important; }
.kb-tree-card-pending  { border-top-color: var(--kb-pending) !important; background: #fffcf5; }
.kb-tree-card-archived { border-top-color: var(--kb-archived) !important; }
.kb-tree-card-archived .card-body { opacity: .8; }

.kb-tabcard { border-top-left-radius: 0; padding: 14px; }
.kb-toolbar { margin-bottom: 10px; }
.kb-legend span { margin-left: 10px; white-space: nowrap; color: var(--muted); }
.kb-dot { display:inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; border: 2px solid; }
.kb-dot-active   { border-color: var(--kb-active); background: #fff; }
.kb-dot-pending  { border-color: var(--kb-pending); background: var(--kb-pending-bg); border-style: dashed; }
.kb-dot-archived { border-color: var(--kb-archived); background: var(--kb-archived-bg); border-style: dashed; }
.kb-dot-hidden   { border-color: var(--control); background: #fff; opacity: .6; }
.kb-flag-mini { color: var(--kb-pending); margin-right: 3px; }
.kb-warn-mini { display:inline-block; background: var(--negative); color:#fff; border-radius:50%; width:14px; height:14px; line-height:14px;
                text-align:center; font-size: 11px; font-weight:700; margin-right:3px; }

/* Flowchart canvas (top-down tree drawn with nested lists + CSS connectors) */
.kb-canvas { overflow: auto; background: var(--raised); border: 1px solid var(--border); border-radius: var(--radius-card);
             min-height: 420px; max-height: 72vh; padding: 20px 10px; }
.kb-hide-archived .kb-li-archived { display: none; }
.kb-zoom { display: inline-block; min-width: 100%; }
.kb-tree, .kb-tree ul { display: flex; justify-content: center; margin: 0; padding: 0; position: relative; }
.kb-tree ul { padding-top: 20px; }
.kb-tree li { list-style: none; position: relative; padding: 20px 5px 0; display: flex; flex-direction: column; align-items: center; }
.kb-tree li::before, .kb-tree li::after { content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: 20px;
                                          border-top: 2px solid var(--kb-line); }
.kb-tree li::after { right: auto; left: 50%; border-left: 2px solid var(--kb-line); }
.kb-tree li:only-child::before, .kb-tree li:only-child::after { display: none; }
.kb-tree li:only-child { padding-top: 0; }
.kb-tree li:first-child::before, .kb-tree li:last-child::after { border: 0 none; }
.kb-tree li:last-child::before { border-right: 2px solid var(--kb-line); border-radius: 0 6px 0 0; }
.kb-tree li:first-child::after { border-radius: 6px 0 0 0; }
.kb-tree ul ul::before, .kb-tree > li > ul::before { content: ''; position: absolute; top: 0; left: 50%; width: 0; height: 20px;
                                                      border-left: 2px solid var(--kb-line); }
.kb-tree > li { padding-top: 0; }
.kb-tree > li::before, .kb-tree > li::after { display: none; }
.kb-li.kb-collapsed > ul { display: none; }

.kb-box { width: 178px; background: #fff; border: 1.5px solid var(--kb-active); border-radius: var(--radius-card); padding: 7px 9px 5px;
          font-size: 12px; line-height: 1.3; text-align: left; cursor: pointer; position: relative;
          transition: box-shadow .12s; }
.kb-box:hover, .kb-box:focus { box-shadow: 0 0 0 3px rgba(23, 23, 26, .12); outline: none; }
.kb-box.kb-selected { box-shadow: 0 0 0 3px rgba(193, 18, 31, .45); }
.kb-box.kb-hit { box-shadow: 0 0 0 3px #f2c94c; }
.kb-box.kb-leaf { background: #fff; }
.kb-box.kb-pending  { border: 1.5px dashed var(--kb-pending); background: var(--kb-pending-bg); }
.kb-box.kb-archived { border: 1.5px dashed var(--kb-archived); background: var(--kb-archived-bg); opacity: .8; }
.kb-box.kb-archived .kb-ans { text-decoration: line-through; text-decoration-color: rgba(0,0,0,.35); }
.kb-box.kb-hidden   { border-color: var(--control); opacity: .55; }
.kb-box.kb-root { width: 250px; background: var(--primary); color: #fff; border-color: var(--primary); text-align: center; padding: 10px; }
.kb-box.kb-root.kb-archived { background: #6f6e69; border-color: #6f6e69; }
.kb-box.kb-root.kb-pending  { background: #8a5200; border-color: var(--kb-pending); }
.kb-root-name { font-weight: 600; font-size: 13px; }
.kb-root-q { font-size: 12px; opacity: .85; margin-top: 3px; }
.kb-ans { font-weight: 600; color: var(--text); }
.kb-q   { color: var(--muted); font-style: italic; margin-top: 3px; }
.kb-dx  { color: var(--text); margin-top: 3px; }
.kb-cat { display: inline-block; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); border-radius: var(--radius-chip); padding: 0 5px; margin: 2px 2px 0 0; font-size: 11px; }
.kb-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 5px; font-size: 11px; color: var(--muted); }
.kb-toggle { border: 1px solid var(--control); background: #fff; border-radius: 10px; padding: 0 6px 0 3px; line-height: 1.35;
             font-size: 11px; color: var(--text); }
.kb-toggle:hover { background: var(--raised); }
.kb-flag { position: absolute; top: -10px; right: -8px; background: var(--kb-pending); color: #fff; border-radius: 10px;
           padding: 0 6px; font-size: 11px; font-weight: 600; z-index: 1; }
.kb-warn { position: absolute; top: -10px; left: -8px; background: var(--negative); color: #fff; border-radius: 50%; width: 19px; height: 19px;
           line-height: 19px; text-align: center; font-weight: 700; font-size: 12px; z-index: 1; }

/* Side panel, history and rules */
.kb-panel { width: 420px; }
.kb-dl { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; margin: 0; }
.kb-dl dt { color: var(--muted); font-weight: 400; }
.kb-dl dd { margin: 0; }
.kb-prop { border: 1px solid var(--notice-edge); background: var(--pill-warning-bg); border-radius: var(--radius-card); padding: 8px 10px; margin-bottom: 8px; }
.kb-catgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 10px; max-height: 190px; overflow: auto; }
.kb-act { display: inline-block; font-size: 12px; font-weight: 500; padding: 1px 7px; border-radius: var(--radius-chip); background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); white-space: nowrap; }
.kb-act-added, .kb-act-restored { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.kb-act-archived, .kb-act-deleted { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.kb-act-pending { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.kb-rules td { vertical-align: top; }

/* ---- Tablet and phone ---------------------------------------------------
   At 991px and below the frame folds away: the sidebar becomes a 56px bar
   with the mark and a Menu button, the sheet becomes the screen. */
@media (max-width: 991.98px) {
    .app-shell { display: block; }
    .sidebar { position: sticky; top: 0; z-index: 1030; height: auto; padding: 0 12px; overflow: visible; }
    .sidebar .brand { height: 52px; padding: 0 4px; }
    .sidebar-toggle { display: inline-flex; align-items: center; gap: 6px; }
    .sidebar-links { display: none; padding: 4px 0 16px; max-height: calc(100vh - 52px); overflow-y: auto; }
    .sidebar-links.open { display: block; }
    .app-main { padding: 0; }
    .topbar { position: static; height: 44px; padding: 0 16px; }
    .sheet { border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; }
    .content { padding: 20px 16px 24px; }
    .dash-grid > * { grid-column: span 12; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 14px; }
    .kpis > div:nth-child(odd) { padding-left: 0; border-left: 0; }
    .login-page { grid-template-columns: 1fr; }
    .login-side { padding: 24px 20px 8px; }
    .login-pitch, .login-foot { display: none; }
    .login-sheet { margin: 0 8px 8px; }
}
/* Touch screens (phones and tablets): fields at 16px, so a phone does not zoom
   the page in when one is tapped, and every control at least 44px tall for a
   thumb (40px for the small ones inside lists). */
@media (max-width: 991.98px) {
    .form-control, .form-select, .form-control-sm, .form-select-sm, textarea { font-size: 16px; }
    .form-control, .form-select { min-height: 44px; }
    .form-control-sm, .form-select-sm { min-height: 40px; }
    .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
    .btn-sm { min-height: 40px; min-width: 40px; }
    .nav-pills .nav-link, .nav-tabs .nav-link { min-height: 44px; display: flex; align-items: center; }
    .page-link { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
    .sidebar a.nav-link { height: 44px; }
    .form-check-input { width: 1.25em; height: 1.25em; }
    .dropdown-item { padding-top: 10px; padding-bottom: 10px; }
}

/* Phone tables: below 640px each row stacks into a block, its title on top
   and every other cell under it beside its column's name (labels set by
   app.js). Nothing is dropped and the order is kept; the page never scrolls
   sideways. Compact tables (the parts pickers and the cart) show two-line rows:
   the name and its button, then the other figures in one small line. */
@media (max-width: 640px) {
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tfoot { display: block; width: 100%; }
    .table-stack tr { display: flex; flex-direction: column; padding: 12px 0; border-bottom: 1px solid var(--rule); }
    .table-stack tbody tr:last-child { border-bottom: 0; }
    .table-stack > :not(caption) > tr > td {
        display: block; position: relative; width: auto !important; max-width: none;
        padding: 3px 0 3px calc(36% + 12px) !important; border: 0; text-align: left !important; white-space: normal;
    }
    .table-stack > :not(caption) > tr > td::before {
        content: attr(data-label); position: absolute; left: 0; top: 3px; width: 36%;
        color: var(--muted); font-size: 13px; line-height: 1.5;
    }
    .table-stack > :not(caption) > tr > td.num { text-align: left !important; }
    .table-stack > :not(caption) > tr > td.text-nowrap, .table-stack > :not(caption) > tr > td .text-nowrap { white-space: normal !important; }
    .table-stack > :not(caption) > tr > td .btn { margin: 2px 4px 2px 0; }
    .table-stack > :not(caption) > tr > td.stack-title { order: -1; padding-left: 0 !important; padding-bottom: 6px !important; font-weight: 500; font-size: 15px; }
    .table-stack > :not(caption) > tr > td.stack-title .small, .table-stack > :not(caption) > tr > td.stack-title .text-muted { font-weight: 400; }
    .table-stack > :not(caption) > tr > td[data-label=""] { padding-left: 0 !important; }
    .table-stack > :not(caption) > tr > td.stack-title::before, .table-stack > :not(caption) > tr > td[data-label=""]::before { content: none; }
    .table-stack > :not(caption) > tr > td.stack-empty { display: none; }
    .table-stack > :not(caption) > tr > td.stack-action { padding-top: 8px !important; }
    .table-stack > :not(caption) > tr > td[colspan] { text-align: center !important; }
    .table-stack .form-control, .table-stack .form-select { max-width: 100%; }
    /* A row that needs reordering keeps its red mark, on the whole block. */
    .table-stack tr.table-danger, .table-stack tr.table-warning { box-shadow: inset 3px 0 0 var(--negative); padding-left: 12px; }
    .table-stack tr.table-danger > td:first-child, .table-stack tr.table-warning > td:first-child { box-shadow: none; }
    /* Totals: one line, the words on the left and the figure on the right. */
    .table-stack tfoot tr { flex-direction: row; justify-content: space-between; align-items: baseline; gap: 12px; border-bottom: 0; border-top: 1px solid var(--border); }
    .table-stack > tfoot > tr > td { padding: 0 !important; }
    .table-stack > tfoot > tr > td::before { content: none; }
    .table-stack > tfoot > tr > td[colspan] { text-align: left !important; }

    /* Compact: line 1 the name and its button, line 2 the other figures. */
    .stack-compact tr { position: relative; flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 12px; row-gap: 2px; }
    .stack-compact > tbody > tr > td { padding: 0 !important; }
    .stack-compact > tbody > tr > td.stack-title { flex: 1 1 100%; min-width: 0; padding: 0 96px 0 0 !important; font-size: 14px; }
    .stack-compact > tbody > tr > td.stack-action { position: absolute; top: 12px; right: 0; padding: 0 !important; }
    .stack-compact > tbody > tr > td.stack-action .btn { margin: 0; }
    .stack-compact > tbody > tr > td:not(.stack-title):not(.stack-action) { order: 1; font-size: 13px; color: var(--muted); }
    .stack-compact > tbody > tr > td:not(.stack-title):not(.stack-action)::before { position: static; display: inline; width: auto; margin-right: 4px; color: var(--faint); }
    .stack-compact > tbody > tr > td[colspan] { flex: 1 1 100%; }
    .stack-compact .form-control-sm { display: inline-block; width: 72px; }
}

@media (max-width: 575.98px) {
    .topbar-scope span.date { display: none; }
    .account-role, .account-name { display: none; }
    .page-head { flex-direction: column; }
    .page-title { font-size: 20px; }
    .kpi-value { font-size: 20px; } .kpi-value.lead { font-size: 26px; }
    .rows .sub, .kpi-sub, .panel-meta, .legend, .kpi-label, .sheet-foot, .topbar-scope { font-size: 13px; }
    .rows .name { font-size: 15px; }
}

/* ---- Thermal receipt (58mm / 80mm) --------------------------------- */
.receipt {
    width: 80mm;
    max-width: 320px;
    margin: 0 auto;
    font-family: "Courier New", monospace;
    font-size: 12px;
    color: #000;
    background:#fff;
    padding: 8px 10px;
}
.receipt h2 { font-size: 15px; text-align:center; margin:0; }
.receipt .muted { text-align:center; font-size: 11px; }
.receipt hr { border: none; border-top: 1px dashed #000; margin: 6px 0; }
.receipt table { width:100%; border-collapse: collapse; }
.receipt td { font-size: 12px; padding: 1px 0; }
.receipt .r { text-align:right; }
@media print {
    .no-print { display:none !important; }
    /* A page (e.g. a report): just the sheet, without the menu, the top bar,
       the buttons or the page links; long tables run onto further pages. */
    .sidebar, .topbar, .pagination, .sheet .btn, .sheet .nav-pills { display: none !important; }
    body, .app-main { background: #fff !important; }
    .app-shell { display: block; }
    .app-main { padding: 0; }
    .sheet { border: 0; box-shadow: none; }
    .table-responsive { overflow: visible !important; }
    /* The receipt page: only the receipt itself. */
    body.receipt-page * { visibility: hidden; }
    body.receipt-page .receipt, body.receipt-page .receipt * { visibility: visible; }
    body.receipt-page .receipt { position: absolute; left:0; top:0; width: 80mm; }
}
