:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --ink: #1b2333;
    --muted: #6b7690;
    --line: #e3e8f2;
    --brand: #2f5bea;
    --brand-dark: #1f43bb;
    --good: #12a05c;
    --warn: #d98600;
    --bad: #d8353a;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 8px 24px rgba(20, 30, 60, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* Icon-only rail: 72px wide, labels are read by screen readers and
   revealed as hover/focus tooltips built from the data-label attribute. */
.sidebar {
    width: 72px;
    flex: 0 0 72px;
    background: #10182b;
    color: #cfd7ea;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 8px;
    gap: 16px;
}

.brand {
    display: flex; align-items: center; justify-content: center;
    width: 100%; padding: 2px 0 14px; border-bottom: 1px solid #1f2942;
}
.brand-mark {
    background: var(--brand); color: #fff; font-weight: 700; letter-spacing: .5px;
    padding: 8px 7px; border-radius: 9px; font-size: 12px;
}
.brand-logo {
    width: 40px; height: 40px; flex: 0 0 40px;
    object-fit: contain; background: #fff; border-radius: 9px; padding: 3px;
}

.sidebar nav { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; }
.nav-link {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    width: 48px; height: 44px; border-radius: 11px;
    color: #cfd7ea; font-size: 14.5px;
}
.nav-link:hover { background: #1a2440; text-decoration: none; color: #fff; }
.nav-link:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.nav-link.is-active { background: var(--brand); color: #fff; }
.nav-icon { font-size: 19px; line-height: 1; opacity: .95; }
.nav-link.is-active .nav-icon { opacity: 1; }
.nav-link .badge.nav-count {
    position: absolute; top: 3px; right: 1px;
    min-width: 18px; padding: 1px 4px; font-size: 11px; line-height: 1.4;
    border: 1px solid #10182b;
}

/* Hover / focus label bubble so the rail stays discoverable. */
.nav-link[data-label]::after,
.nav-signout[data-label]::after {
    content: attr(data-label);
    position: absolute; left: calc(100% + 10px); top: 50%;
    transform: translateY(-50%);
    background: #1f2942; color: #fff; font-size: 12.5px; font-weight: 500;
    white-space: nowrap; padding: 5px 9px; border-radius: 7px;
    box-shadow: 0 6px 18px rgba(8, 12, 24, .35);
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity .12s ease-in-out;
    z-index: 30;
}
.nav-link:hover::after, .nav-link:focus-visible::after,
.nav-signout:hover::after, .nav-signout:focus-visible::after {
    opacity: 1; visibility: visible;
}

.sidebar-foot {
    margin-top: auto; width: 100%;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    border-top: 1px solid #1f2942; padding-top: 14px;
}
.who { display: flex; justify-content: center; }
.who-mark {
    display: grid; place-items: center;
    width: 34px; height: 34px; border-radius: 50%;
    background: #1f2942; color: #fff; font-size: 14px; font-weight: 600;
}
.nav-signout {
    position: relative;
    display: grid; place-items: center;
    width: 38px; height: 34px; padding: 0; font-size: 16px;
}
/* Light / dark toggle, same shape as the sign-out button above it. */
.theme-switcher { display: flex; justify-content: center; width: 100%; margin: 0; }
.nav-theme {
    position: relative;
    display: grid; place-items: center;
    width: 38px; height: 34px; padding: 0; font-size: 16px;
}
.nav-theme[data-label]::after {
    content: attr(data-label);
    position: absolute; left: calc(100% + 10px); top: 50%;
    transform: translateY(-50%);
    background: #1f2942; color: #fff; font-size: 12.5px; font-weight: 500;
    white-space: nowrap; padding: 5px 9px; border-radius: 7px;
    box-shadow: 0 6px 18px rgba(8, 12, 24, .35);
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity .12s ease-in-out;
    z-index: 30;
}
.nav-theme:hover::after, .nav-theme:focus-visible::after { opacity: 1; visibility: visible; }

/* Rail shape toggle, matching the two buttons above it. */
.nav-switcher { display: flex; justify-content: center; width: 100%; margin: 0; }
.nav-shape {
    position: relative;
    display: grid; place-items: center;
    width: 38px; height: 34px; padding: 0; font-size: 16px;
}
.nav-shape[data-label]::after {
    content: attr(data-label);
    position: absolute; left: calc(100% + 10px); top: 50%;
    transform: translateY(-50%);
    background: #1f2942; color: #fff; font-size: 12.5px; font-weight: 500;
    white-space: nowrap; padding: 5px 9px; border-radius: 7px;
    box-shadow: 0 6px 18px rgba(8, 12, 24, .35);
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity .12s ease-in-out;
    z-index: 30;
}
.nav-shape:hover::after, .nav-shape:focus-visible::after { opacity: 1; visibility: visible; }

/* ------------------------------------------------- rail with visible names
   The same rail, widened so every icon is followed by its menu name. Set by
   the « / » button in the sidebar foot, remembered for the current session. */
.sidebar.is-text { width: 208px; flex: 0 0 208px; align-items: stretch; padding: 16px 12px; }
.sidebar.is-text .brand { justify-content: flex-start; padding-left: 4px; }
.sidebar.is-text nav { align-items: stretch; }
.sidebar.is-text .nav-link {
    width: auto; height: 40px; gap: 11px;
    justify-content: flex-start; padding: 0 10px;
}
.sidebar.is-text .nav-icon { flex: 0 0 20px; text-align: center; }
.nav-text { font-size: 14px; font-weight: 500; line-height: 1.2; }
/* Long names shorten instead of wrapping, so rows keep one height. */
.sidebar.is-text .nav-link .nav-text {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar.is-text .nav-link .badge.nav-count {
    position: static; margin-left: auto; border: 0;
}
/* Names are on screen already, so the hover bubbles are switched off. */
.sidebar.is-text .nav-link[data-label]::after,
.sidebar.is-text .nav-signout[data-label]::after,
.sidebar.is-text .nav-theme[data-label]::after,
.sidebar.is-text .nav-shape[data-label]::after { content: none; }
.sidebar.is-text .sidebar-foot { align-items: stretch; }
.sidebar.is-text .who { justify-content: flex-start; align-items: center; gap: 10px; padding: 0 2px; }
.sidebar.is-text .who-mark { flex: 0 0 34px; }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar.is-text .nav-signout,
.sidebar.is-text .nav-theme,
.sidebar.is-text .nav-shape {
    display: flex; align-items: center; justify-content: flex-start;
    gap: 11px; width: 100%; height: 34px; padding: 0 10px; font-size: 14px;
}
.sidebar.is-text .nav-signout > [aria-hidden],
.sidebar.is-text .nav-theme > [aria-hidden],
.sidebar.is-text .nav-shape > [aria-hidden] { flex: 0 0 20px; text-align: center; font-size: 16px; }

.content { flex: 1; padding: 22px 26px 40px; min-width: 0; }

.topbar {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: 18px; gap: 12px; flex-wrap: wrap;
}
.topbar h1 { font-size: 22px; margin: 0; }
.topbar-meta { color: var(--muted); font-size: 13.5px; }

/* ---------------------------------------------------------------- panels */
.panel {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px 18px; margin-bottom: 18px;
}
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-sub { color: var(--muted); font-size: 13px; margin: -6px 0 12px; }
/* Small heading that splits a long form into groups of fields */
.form-subhead { font-size: 14px; margin: 18px 0 10px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 23px; font-weight: 700; margin-top: 4px; }
.stat-foot { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* ---------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #fafbfe; }
tbody tr:hover { background: #f8faff; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot th { background: #f2f5fd; color: var(--ink); font-weight: 700; text-transform: none; letter-spacing: 0; font-size: 13.5px; border-top: 2px solid var(--line); }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

/* ---------------------------------------------------------------- forms */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
    width: 100%; padding: 9px 11px; font: inherit; color: var(--ink);
    background: #fff; border: 1px solid var(--line); border-radius: 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47, 91, 234, .25); border-color: var(--brand); }
.field { margin-bottom: 12px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1 1 160px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 15px; border: 1px solid transparent; border-radius: 9px;
    background: var(--brand); color: #fff; font: inherit; font-weight: 600;
    cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-lg { padding: 13px 18px; font-size: 16px; width: 100%; }
.btn-outline { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-outline:hover { background: #f2f5fd; color: var(--ink); }
.btn-ghost { background: transparent; color: #cfd7ea; border-color: #2a3556; }
.btn-ghost:hover { background: #1a2440; color: #fff; }
.btn-danger { background: var(--bad); }
.btn-danger:hover { background: #b32b2f; }
.btn-good { background: var(--good); }
.btn-good:hover { background: #0d8049; }

/* ---------------------------------------------------------------- misc */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600; background: #e8edfd; color: var(--brand-dark);
}
.badge-good { background: #e2f6ec; color: var(--good); }
.badge-warn { background: #fdf1dc; color: var(--warn); }
.badge-bad  { background: #fce6e7; color: var(--bad); }
.badge-muted { background: #eef1f7; color: var(--muted); }

.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; border: 1px solid; }
.alert-success { background: #e9f8f0; border-color: #bfe8d3; color: #0e6c41; }
.alert-error   { background: #fdeced; border-color: #f5c4c6; color: #9d2226; }
.alert-info    { background: #eaf0fe; border-color: #c8d6fb; color: #1f43bb; }
.alert-warning { background: #fdf4e3; border-color: #f3ddb2; color: #8a5800; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Language quick-switcher in the top bar */
.lang-switcher { display: inline-flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.lang-switcher select { width: auto; min-width: 130px; padding: 5px 9px; font-size: 13px; border-radius: 8px; }
.topbar-date { display: block; }

.stack-top { margin-top: 14px; }

/* Small explanatory paragraph under a panel */
.note { background: #f7f9ff; border: 1px dashed var(--line); border-radius: 10px;
    padding: 10px 12px; font-size: 13px; color: var(--muted); margin: 14px 0 0; }

/* Key/value table used on the Settings page */
.info-table { font-size: 14px; }
.info-table th {
    width: 190px; background: #fafbfe; text-transform: none;
    letter-spacing: 0; font-size: 13.5px; color: var(--muted); font-weight: 600;
}
.info-table tbody tr:hover { background: transparent; }

/* Logo preview on the Settings page */
.settings-logo-preview { margin-bottom: 14px; }
.settings-logo-preview p { margin: 0 0 6px; font-size: 13px; }
.settings-logo-preview img {
    max-width: 220px; max-height: 120px;
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 8px; background: #fff;
}

/* Background colour picker on the Settings page */
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="color"] {
    width: 56px; height: 38px; padding: 2px; cursor: pointer;
    border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
.color-text { max-width: 130px; text-transform: lowercase; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.swatch {
    width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
    border: 1px solid var(--line); box-shadow: inset 0 0 0 2px #fff;
}
.swatch.is-active { border-color: var(--brand); box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px rgba(47, 91, 234, .25); }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: radial-gradient(1200px 600px at 20% -10%, #dae3ff 0%, var(--bg) 55%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line);
    border-radius: 16px; box-shadow: var(--shadow); padding: 26px 24px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-logo { display: block; max-width: 170px; max-height: 90px; margin: 0 auto 14px; object-fit: contain; }
.login-hint { background: #f7f9ff; border: 1px dashed var(--line); border-radius: 10px;
    padding: 10px 12px; font-size: 12.5px; color: var(--muted); margin-top: 14px; }

/* ---------------------------------------------------------------- POS */
.pos-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr); gap: 16px; align-items: start; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.product-card {
    border: 1px solid var(--line); border-radius: 11px; padding: 10px 11px;
    background: #fff; text-align: left; cursor: pointer; font: inherit; color: inherit;
    display: flex; flex-direction: column; gap: 3px; min-height: 96px;
}
.product-card:hover { border-color: var(--brand); box-shadow: 0 4px 14px rgba(47, 91, 234, .12); }
.product-card:disabled { opacity: .5; cursor: not-allowed; }
.product-card .p-name { font-weight: 600; font-size: 13.5px; line-height: 1.3; }
.product-card .p-sku { font-size: 11.5px; color: var(--muted); }
.product-card .p-price { margin-top: auto; font-weight: 700; color: var(--brand-dark); }
.product-card .p-stock { font-size: 11.5px; color: var(--muted); }
.product-card .p-stock-low { color: var(--warn); font-weight: 600; }
.product-card .p-image {
    display: block; width: 100%; height: 84px; margin-bottom: 4px;
    object-fit: cover; border-radius: 8px; background: #f2f5fb; border: 1px solid var(--line);
}
.product-card .p-image-empty {
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 700; color: #b9c2d8; text-transform: uppercase;
}

/* ------------------------------------------------- images & low stock */
.thumb, .thumb-empty {
    width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--line);
    object-fit: cover; background: #f2f5fb; display: block;
}
.thumb-empty {
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; color: #b9c2d8; text-transform: uppercase;
}
.thumb-lg {
    width: 86px; height: 86px; border-radius: 10px; border: 1px solid var(--line);
    object-fit: cover; background: #f2f5fb; display: block;
}
.product-image-edit { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.inline-check input { width: auto; margin: 0; }

.low-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.low-card {
    display: flex; align-items: center; gap: 10px;
    border: 1px solid #f3d9a6; background: #fffaf0; border-radius: 10px; padding: 9px 11px;
}
.low-card.is-out { border-color: #f0c0c2; background: #fff5f5; }
.low-card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.low-card-body strong { font-size: 13.5px; }
.low-card-body span { font-size: 12px; color: var(--muted); }
.low-card-body .low-now { color: var(--warn); font-weight: 600; }

.cart-line-qty { width: 62px; padding: 5px 7px; text-align: center; }
.totals { border-top: 2px solid var(--line); margin-top: 10px; padding-top: 10px; font-size: 14px; }
.totals-row { display: flex; justify-content: space-between; padding: 3px 0; }
.totals-row.grand { font-size: 19px; font-weight: 700; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.change-due { font-size: 15px; font-weight: 700; color: var(--good); }
.quick-cash { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* ---------------------------------------------------------------- bars */
.bar-row { display: grid; grid-template-columns: 110px 1fr 96px; gap: 10px; align-items: center; margin-bottom: 7px; font-size: 13.5px; }
.bar-track { background: #eef1f8; border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--brand); height: 100%; border-radius: 999px; }

/* ------------------------------------------------------------- donut chart */
.donut-wrap { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin-bottom: 14px; }
.donut { width: 160px; height: 160px; flex: 0 0 160px; }
.donut-base { stroke: #dfe4f0; }
.donut-slice { stroke-linecap: butt; }
.donut-total { font-size: 20px; font-weight: 700; fill: var(--ink); }
.donut-unit { font-size: 11px; fill: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1 1 200px; font-size: 13.5px; }
.donut-legend li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center;
    padding: 3px 0; }
.donut-key { width: 12px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .18); }
.donut-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Colour-blind-safe sequence: alternating hue AND lightness so neighbouring
   slices stay distinct in deuteranopia/protanopia and in greyscale print. */
.donut-tone-1 { stroke: #16418f; background: #16418f; }
.donut-tone-2 { stroke: #d55e00; background: #d55e00; }
.donut-tone-3 { stroke: #0f7b6c; background: #0f7b6c; }
.donut-tone-4 { stroke: #7bb0f0; background: #7bb0f0; }
.donut-tone-5 { stroke: #9c1c72; background: #9c1c72; }
.donut-tone-6 { stroke: #8a6a00; background: #8a6a00; }
.donut-tone-7 { stroke: #4a5563; background: #4a5563; }

/* ---------------------------------------------------------------- receipt */
.receipt { max-width: 340px; margin: 24px auto; background: #fff; padding: 18px 20px;
    border: 1px solid var(--line); border-radius: 10px; font-family: "Courier New", monospace; font-size: 13px; }
.receipt h2 { text-align: center; margin: 0 0 2px; font-size: 16px; }
.receipt .center { text-align: center; }
.receipt hr { border: none; border-top: 1px dashed #999; margin: 9px 0; }
.receipt table { font-size: 12.5px; }
.receipt th, .receipt td { border: none; padding: 2px 0; }
.receipt-actions { max-width: 340px; margin: 0 auto 30px; display: flex; gap: 8px; }
.receipt-logo-wrap { margin: 0 0 6px; }
.receipt-logo { max-width: 150px; max-height: 80px; object-fit: contain; }

/* ---------------------------------------------------------------- barcodes */
.barcode { display: block; height: auto; max-width: 100%; image-rendering: crisp-edges; }
.barcode-cell { width: 1%; white-space: nowrap; }
.barcode-cell a { display: inline-block; border: 1px solid var(--line); border-radius: 6px;
    padding: 3px 5px; background: #fff; }
.barcode-cell a:hover { border-color: var(--brand); }
.barcode-preview { display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
    border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; }

.label-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.label { border: 1px dashed #b9c1d4; border-radius: 8px; padding: 10px; background: #fff;
    display: flex; flex-direction: column; gap: 5px; text-align: center; page-break-inside: avoid; }
.label-name { font-weight: 600; font-size: 13.5px; line-height: 1.25; }
.label-meta { font-size: 11.5px; }
.label-code { display: flex; justify-content: center; align-items: center; min-height: 58px; }
.label-price { font-weight: 700; font-size: 17px; letter-spacing: .2px; margin-top: auto; }
.label-foot { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center;
    border-top: 1px solid var(--line); padding-top: 6px; }

/* --------------------------------------------------------------- dark mode
   Switched on by the moon button in the sidebar, which sets data-theme="dark"
   on <html>. Wrapped in "screen" so printed pages always stay light on white. */
@media screen {
    html[data-theme="dark"] {
        --bg: #0f1420;
        --panel: #161d2c;
        --ink: #e7ecf7;
        --muted: #9aa6c0;
        --line: #2a3446;
        --brand: #6d92ff;
        --brand-dark: #a8c0ff;
        --good: #3fce8f;
        --warn: #f0b34a;
        --bad: #ff7076;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
    }

    /* Tables */
    html[data-theme="dark"] th { background: #1b2436; }
    html[data-theme="dark"] tbody tr:hover { background: #1e2839; }
    html[data-theme="dark"] tfoot th { background: #1f2a3d; color: var(--ink); }
    html[data-theme="dark"] .info-table th { background: #1b2436; }

    /* Fields and buttons */
    html[data-theme="dark"] input,
    html[data-theme="dark"] select,
    html[data-theme="dark"] textarea { background: #101725; color: var(--ink); }
    html[data-theme="dark"] input:focus,
    html[data-theme="dark"] select:focus,
    html[data-theme="dark"] textarea:focus { outline-color: rgba(109, 146, 255, .35); }
    html[data-theme="dark"] .btn { color: #0d1220; }
    html[data-theme="dark"] .btn:hover { color: #0d1220; }
    html[data-theme="dark"] .btn-outline { background: #101725; color: var(--ink); }
    html[data-theme="dark"] .btn-outline:hover { background: #1e2839; color: var(--ink); }
    html[data-theme="dark"] .btn-ghost { background: transparent; color: #cfd7ea; }
    html[data-theme="dark"] .btn-danger,
    html[data-theme="dark"] .btn-good { color: #0d1220; }
    html[data-theme="dark"] input[type="color"],
    html[data-theme="dark"] .swatch { background: #101725; }

    /* Badges and alerts keep their meaning but on dark, readable fills */
    html[data-theme="dark"] .badge { background: #24304a; color: #b9caff; }
    html[data-theme="dark"] .badge-good { background: #17372a; color: #6fe0a8; }
    html[data-theme="dark"] .badge-warn { background: #3a2d12; color: #f5c775; }
    html[data-theme="dark"] .badge-bad { background: #3b1d20; color: #ff9ba0; }
    html[data-theme="dark"] .badge-muted { background: #232b3b; color: var(--muted); }
    html[data-theme="dark"] .alert-success { background: #14301f; border-color: #24583a; color: #85e3b0; }
    html[data-theme="dark"] .alert-error   { background: #351a1d; border-color: #6b2b31; color: #ffa8ac; }
    html[data-theme="dark"] .alert-info    { background: #17233d; border-color: #2c4079; color: #a9c0ff; }
    html[data-theme="dark"] .alert-warning { background: #33280f; border-color: #5f4a1c; color: #f3ce85; }

    /* Cards, notes and other light surfaces */
    html[data-theme="dark"] .note,
    html[data-theme="dark"] .login-hint { background: #141b29; }
    html[data-theme="dark"] .login-wrap {
        background: radial-gradient(1200px 600px at 20% -10%, #1b2748 0%, var(--bg) 55%);
    }
    html[data-theme="dark"] .login-card,
    html[data-theme="dark"] .product-card,
    html[data-theme="dark"] .barcode-cell a,
    html[data-theme="dark"] .barcode-preview,
    html[data-theme="dark"] .label,
    html[data-theme="dark"] .settings-logo-preview img { background: var(--panel); }
    html[data-theme="dark"] .product-card:hover { box-shadow: 0 4px 14px rgba(109, 146, 255, .18); }
    html[data-theme="dark"] .product-card .p-image,
    html[data-theme="dark"] .thumb, html[data-theme="dark"] .thumb-empty,
    html[data-theme="dark"] .thumb-lg { background: #101725; }
    html[data-theme="dark"] .product-card .p-image-empty,
    html[data-theme="dark"] .thumb-empty { color: #5d6a86; }
    html[data-theme="dark"] .low-card { border-color: #5f4a1c; background: #2b2312; }
    html[data-theme="dark"] .low-card.is-out { border-color: #6b2b31; background: #2c1a1c; }
    html[data-theme="dark"] .label { border-color: #3a465e; }

    /* Charts */
    html[data-theme="dark"] .bar-track { background: #232d40; }
    html[data-theme="dark"] .donut-base { stroke: #29334a; }
    html[data-theme="dark"] .donut-key { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
    /* Slightly lifted tones so the darkest slices stay visible on a dark card */
    html[data-theme="dark"] .donut-tone-1 { stroke: #4d82e8; background: #4d82e8; }
    html[data-theme="dark"] .donut-tone-2 { stroke: #f08a2e; background: #f08a2e; }
    html[data-theme="dark"] .donut-tone-3 { stroke: #35b3a0; background: #35b3a0; }
    html[data-theme="dark"] .donut-tone-4 { stroke: #bcd8ff; background: #bcd8ff; }
    html[data-theme="dark"] .donut-tone-5 { stroke: #e262b0; background: #e262b0; }
    html[data-theme="dark"] .donut-tone-6 { stroke: #ceac3c; background: #ceac3c; }
    html[data-theme="dark"] .donut-tone-7 { stroke: #97a3b6; background: #97a3b6; }

    /* The receipt stays paper-white so it matches what the printer produces */
    html[data-theme="dark"] .receipt { background: #fff; color: #14181f; border-color: #cfd5e0; }
}

@media print {
    body { background: #fff; }
    .label-sheet { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
    .label { border: 1px dashed #999; padding: 7px; }
    .label-name { font-size: 11.5px; }
    .label-meta { font-size: 10px; color: #000; }
    .label-price { font-size: 14px; color: #000; }
    .barcode { width: 100% !important; }
    .receipt { border: none; box-shadow: none; margin: 0; max-width: none; }
    .receipt-actions, .no-print { display: none !important; }
    .receipt-logo { max-width: 120px; max-height: 60px; }
    .lang-switcher { display: none !important; }
    .sidebar, .topbar-meta, .alert { display: none !important; }
    .layout { display: block; }
    .content { padding: 0; }
    .panel { border: none; box-shadow: none; padding: 0 0 14px; page-break-inside: avoid; }
    table { font-size: 11px; }
    th, td { padding: 5px 6px; }
    .badge { border: 1px solid #ccc; background: none !important; color: #000 !important; }
}

@media (max-width: 1080px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .pos-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .layout { flex-direction: column; }
    .sidebar {
        width: 100%; flex: none;
        flex-direction: row; align-items: center; justify-content: space-between;
        flex-wrap: wrap; gap: 10px; padding: 10px 14px;
    }
    .brand { width: auto; padding: 0; border-bottom: 0; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; width: auto; justify-content: center; }
    .sidebar-foot {
        margin-top: 0; width: auto; flex-direction: row; align-items: center;
        border-top: 0; padding-top: 0;
    }
    /* On a narrow screen the rail is a top bar, so it keeps its compact shape
       whichever mode is chosen; only the names come along. */
    .sidebar.is-text {
        width: 100%; flex: none; align-items: center; padding: 10px 14px;
    }
    .sidebar.is-text nav { align-items: center; }
    .sidebar.is-text .sidebar-foot { align-items: center; }
    .sidebar.is-text .who { padding: 0; }
    .sidebar.is-text .who-name { display: none; }
    .sidebar.is-text .nav-signout,
    .sidebar.is-text .nav-theme,
    .sidebar.is-text .nav-shape { width: auto; }
    /* Tooltips flip below the icon once the rail is horizontal. */
    .nav-link[data-label]::after,
    .nav-signout[data-label]::after {
        left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
    }
    .nav-theme[data-label]::after,
    .nav-shape[data-label]::after {
        left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
    }
    .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .content { padding: 16px; }
}
