:root {
    --primary: #059669;
    --primary-dark: #047857;
    --primary-light: #ecfdf5;
    --accent: #03ca80;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #0f172a;
    --muted: #64748b;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -8px rgba(16, 24, 40, .10);
    --header-h: 64px;
    --bottom-nav-h: 64px;
    --sidebar-w: 240px;
    --overlay: rgba(15, 18, 30, .45);
    /* Categorical chart series (expense-category breakdown etc.) — a fixed,
       CVD-safe hue order, never cycled/reassigned per filter. Used only as
       hand-rolled .hbar-fill bar colors (see reports/index.php), never as UI
       chrome, so unlike --primary/--danger/etc. these don't need a semantic
       meaning of their own. */
    --chart-1: #2a78d6;
    --chart-2: #eb6834;
    --chart-3: #1baf7a;
    --chart-4: #eda100;
    --chart-5: #e87ba4;
    --chart-6: #008300;
    --chart-7: #4a3aa7;
    --chart-8: #e34948;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --primary: #10b981;
    --primary-dark: #34d399;
    --primary-light: rgba(16, 185, 129, .16);
    --accent: #00e6a3;
    --bg: #0a1420;
    --surface: #121e2e;
    --border: #263349;
    --text: #e6edf3;
    --muted: #8b9bb0;
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, .14);
    --success: #4ade80;
    --success-bg: rgba(74, 222, 128, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -8px rgba(0, 0, 0, .5);
    --overlay: rgba(0, 0, 0, .6);
    --chart-1: #3987e5;
    --chart-2: #d95926;
    --chart-3: #199e70;
    --chart-4: #c98500;
    --chart-5: #d55181;
    --chart-6: #008300;
    --chart-7: #9085e9;
    --chart-8: #e66767;
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --primary: #10b981;
        --primary-dark: #34d399;
        --primary-light: rgba(16, 185, 129, .16);
        --accent: #00e6a3;
        --bg: #0a1420;
        --surface: #121e2e;
        --border: #263349;
        --text: #e6edf3;
        --muted: #8b9bb0;
        --danger: #f87171;
        --danger-bg: rgba(248, 113, 113, .14);
        --success: #4ade80;
        --success-bg: rgba(74, 222, 128, .14);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -8px rgba(0, 0, 0, .5);
        --overlay: rgba(0, 0, 0, .6);
        --chart-1: #3987e5;
        --chart-2: #d95926;
        --chart-3: #199e70;
        --chart-4: #c98500;
        --chart-5: #d55181;
        --chart-6: #008300;
        --chart-7: #9085e9;
        --chart-8: #e66767;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, Roboto, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    transition: background-color .2s ease, color .2s ease;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
p { margin: 0; }
.muted { color: var(--muted); font-size: .92rem; }

.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;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 11px 18px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform .06s ease, background .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 7px 12px; font-size: .85rem; }
.btn-block { width: 100%; }
/* An <a>-as-button with no href (see debt-reminder.js: SMS/WhatsApp links
   with no phone number on the customer) — :disabled doesn't apply to
   anchors, so this is the aria-disabled equivalent. */
.btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
    width: 100%;
    font: inherit;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.field-row { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 560px) {
    .field-row { grid-template-columns: 1fr 1fr; }
}

/* ---------- Alerts ---------- */
.alert { border-radius: var(--radius-sm); padding: 12px 14px; font-size: .9rem; margin-bottom: 14px; font-weight: 500; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-info { background: var(--primary-light); color: var(--primary-dark); }

/* ---------- Auth layout ---------- */
.auth-body { min-height: 100vh; display: flex; flex-direction: column; }
.auth-topbar { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding: 16px 20px; }
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 28px;
}
.auth-card.center { text-align: center; margin: 60px auto; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-logo {
    height: 42px; width: auto;
    margin: 0 auto 14px;
}
.auth-brand h1 { font-size: 1.25rem; }
.auth-brand p { margin-top: 4px; }

/* ---------- Lang switcher ---------- */
.lang-switcher { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.lang-switcher form { margin: 0; }
.lang-btn {
    border: none; background: transparent; padding: 6px 12px; border-radius: 999px;
    font-size: .78rem; font-weight: 700; color: var(--muted); cursor: pointer;
}
.lang-btn.active { background: var(--primary); color: #fff; }

/* ---------- Theme-aware logo swap ---------- */
/* logo-dark.png has dark navy text — shown on light backgrounds. */
/* logo-light.png has white text — shown on dark backgrounds. */
img.logo-for-light-theme { display: block; }
img.logo-for-dark-theme { display: none; }
:root[data-theme="dark"] img.logo-for-light-theme { display: none; }
:root[data-theme="dark"] img.logo-for-dark-theme { display: block; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) img.logo-for-light-theme { display: none; }
    :root:not([data-theme="light"]) img.logo-for-dark-theme { display: block; }
}

/* ---------- Attendance clock-in/out (dashboard page-head) ---------- */
.attendance-form { display: flex; margin: 0; }
.attendance-btn-dashboard.clocked-in {
    background: var(--success-bg); color: var(--success);
    border: 1px solid var(--success);
}
.attendance-btn-dashboard.clocked-in:hover { background: var(--success-bg); opacity: .85; }

/* ---------- Theme toggle button ---------- */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--muted); cursor: pointer; flex-shrink: 0;
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { display: none; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
    gap: 10px;
}
.topbar-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.role-badge {
    background: var(--primary-light); color: var(--primary-dark);
    font-size: .78rem; font-weight: 700; padding: 5px 10px; border-radius: 999px;
    white-space: nowrap;
}
.shop-name-label {
    font-size: .85rem; font-weight: 700; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: none;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: .88rem; font-weight: 600; }
.user-chip .user-name { display: none; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem; text-transform: uppercase;
}

.content { flex: 1; padding: 18px 16px calc(var(--bottom-nav-h) + 24px); }

.page-head { margin-bottom: 18px; }

/* ---------- Side nav (desktop) ---------- */
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 10px; }
.side-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    font-size: .92rem; font-weight: 600; color: var(--text);
}
.side-link.active { background: var(--primary-light); color: var(--primary-dark); }
.side-link.disabled { color: var(--muted); cursor: default; }
.side-icon svg { width: 19px; height: 19px; }
.side-link .badge {
    margin-left: auto; font-size: .68rem; font-weight: 700;
    background: var(--border); color: var(--muted); padding: 2px 7px; border-radius: 999px;
}
.side-link .badge-locked { background: var(--danger-bg); color: var(--danger); }
.brand { display: flex; align-items: center; padding: 16px; }
.brand-logo { height: 26px; width: auto; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; height: var(--bottom-nav-h);
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; z-index: 20;
}
.bottom-link {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: .66rem; font-weight: 600; color: var(--muted);
    border: none; background: none; font-family: inherit; cursor: pointer; padding: 0;
}
.bottom-link.active { color: var(--primary); }
.bottom-link.disabled { opacity: .45; }
.bottom-icon svg { width: 21px; height: 21px; }

/* ---------- Mobile "more" drawer ---------- */
.mobile-drawer {
    display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 40;
}
.mobile-drawer.open { display: flex; align-items: flex-end; }
.mobile-drawer-sheet {
    background: var(--surface); width: 100%; max-height: 75vh; overflow-y: auto;
    border-radius: 18px 18px 0 0; padding: 14px 10px calc(env(safe-area-inset-bottom, 0px) + 14px);
}
.mobile-drawer-sheet:focus { outline: none; }
.drawer-link {
    display: flex; align-items: center; gap: 12px; padding: 14px 12px;
    border-radius: var(--radius-sm); font-weight: 600; font-size: .95rem; color: var(--text);
}
.drawer-link.active { background: var(--primary-light); color: var(--primary-dark); }
.drawer-link.disabled { color: var(--muted); }
.drawer-link .side-icon svg { width: 20px; height: 20px; }
.drawer-link .badge-locked { margin-left: auto; }

@media (min-width: 900px) {
    .mobile-drawer { display: none !important; }
}

/* ---------- Cards / grid ---------- */
.card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px;
}
.card-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
.module-card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 18px 14px;
    display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.module-icon { font-size: 1.6rem; }
.module-title { font-weight: 700; font-size: .95rem; }
.module-badge {
    font-size: .7rem; font-weight: 700; color: var(--muted);
    background: var(--bg); padding: 2px 8px; border-radius: 999px;
}
.module-card { transition: transform .1s ease, box-shadow .1s ease; }
.module-card:not(.module-card-disabled):hover { transform: translateY(-2px); box-shadow: 0 4px 16px -4px rgba(16, 24, 40, .18); }
.module-card-disabled { cursor: default; }
.module-card-disabled .module-badge { color: var(--muted); }

/* ---------- Search bar ---------- */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input {
    flex: 1; font: inherit; padding: 10px 13px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); outline: none;
}
.search-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.stock-value-tile {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.stock-value-amount { font-size: 1.15rem; }

/* ---------- Filter tabs ---------- */
.filter-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.filter-tab {
    padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); font-size: .82rem; font-weight: 700; color: var(--muted);
}
.filter-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Date filter bar (expenses / reports) ---------- */
.date-filter-bar {
    display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 18px;
}
.date-filter-bar .field { flex: 0 0 auto; }
.date-filter-bar input[type="date"] {
    font: inherit; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.date-filter-bar select { min-width: 160px; }
.date-filter-bar .field-grow { flex: 1 1 220px; }
.date-filter-bar .field-actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* ---------- Net profit hero tile ---------- */
.net-profit-tile {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px; border-radius: var(--radius); box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.net-profit-positive { background: var(--success-bg); }
.net-profit-negative { background: var(--danger-bg); }
.net-profit-amount { font-size: 1.5rem; font-weight: 800; }
.net-profit-positive .net-profit-amount { color: var(--success); }
.net-profit-negative .net-profit-amount { color: var(--danger); }

/* ---------- Hand-rolled daily revenue bar chart ---------- */
.bar-chart {
    display: flex; align-items: flex-end; gap: 4px; height: 180px;
    overflow-x: auto; padding: 16px 4px 0;
}
.bar-col {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
    height: 100%; flex: 1; min-width: 14px;
}
.bar {
    width: 100%; max-width: 26px; min-height: 3px;
    background: var(--primary); border-radius: 4px 4px 0 0;
    position: relative; cursor: default;
}
.bar:hover, .bar:focus { background: var(--primary-dark); outline: none; }
.bar:focus-visible { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary); }
.bar[data-tooltip]:hover::after, .bar[data-tooltip]:focus::after {
    content: attr(data-tooltip);
    position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
    background: #0f172a; color: #fff; font-size: .7rem; font-weight: 600;
    padding: 4px 9px; border-radius: 6px; white-space: nowrap; margin-bottom: 6px;
    z-index: 5; pointer-events: none;
}
.bar-label { font-size: .64rem; color: var(--muted); margin-top: 6px; white-space: nowrap; }

/* ---------- Hand-rolled horizontal breakdown bars ---------- */
.hbar-list { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.hbar-row { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 10px; }
.hbar-label { font-size: .82rem; font-weight: 700; color: var(--muted); }
.hbar-track { background: var(--bg); border-radius: 999px; height: 14px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; transition: width .3s ease; }
.hbar-value { font-size: .85rem; font-weight: 700; white-space: nowrap; min-width: 90px; text-align: right; }

@media (max-width: 520px) {
    .hbar-row { grid-template-columns: 56px 1fr; }
    .hbar-value { grid-column: 1 / -1; text-align: left; min-width: 0; }
}

/* Wide-label variant of .hbar-row for lists with variable-length labels
   (expense categories) rather than the fixed 4-character payment-type labels
   the base 64px column was sized for. Same bars/tracks, just a wider,
   truncating label column. */
.hbar-row-wide { grid-template-columns: minmax(84px, 150px) 1fr auto; }
.hbar-row-wide .hbar-label {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 520px) {
    .hbar-row-wide { grid-template-columns: 1fr; row-gap: 4px; }
    .hbar-row-wide .hbar-label { white-space: normal; }
    .hbar-row-wide .hbar-value { grid-column: auto; text-align: left; }
}

/* ---------- Period-comparison delta (reports page) ---------- */
.delta-badge { font-weight: 700; font-size: .82rem; white-space: nowrap; }
.delta-up { color: var(--success); }
.delta-down { color: var(--danger); }
.delta-flat { color: var(--muted); }

/* ---------- Employees / permissions ---------- */
.field-label-standalone { display: block; font-size: .88rem; font-weight: 600; color: var(--muted); }
.permission-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 480px) {
    .permission-grid { grid-template-columns: 1fr 1fr; }
}
.permission-check {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: .88rem; font-weight: 600; cursor: pointer;
}
.permission-check:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }
.permission-check input { accent-color: var(--primary); width: 18px; height: 18px; }

.perm-badge {
    display: inline-block; font-size: .72rem; font-weight: 700;
    background: var(--primary-light); color: var(--primary-dark);
    padding: 3px 9px; border-radius: 999px; margin: 2px 4px 2px 0;
}

.invite-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 0; border-top: 1px solid var(--border);
}
.invite-row:first-child { border-top: none; }
.invite-row form { margin: 0; }

.invite-link-box {
    font-family: 'SFMono-Regular', Consolas, monospace; font-size: .84rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 12px 14px; word-break: break-all;
}

/* ---------- Page head / cards with actions ---------- */
.page-head-row {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
}
.card-header-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-bottom: 12px;
}
.form-card { max-width: 480px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- Stat tiles ---------- */
.stat-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px;
}
.stat-tile {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px; text-align: center;
}
.stat-value { font-size: 1.5rem; font-weight: 800; color: var(--primary-dark); }
.stat-label { font-size: .78rem; color: var(--muted); font-weight: 600; margin-top: 2px; }

/* ---------- Tables ---------- */
.table-card { padding: 8px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 560px; }
.table th, .table td { text-align: left; padding: 12px; white-space: nowrap; }
.table thead th { color: var(--muted); font-weight: 700; font-size: .75rem; text-transform: uppercase; letter-spacing: .02em; }
.table tbody tr { border-top: 1px solid var(--border); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions form { margin: 0; }

/* Below 720px, tables render as stacked cards instead of a scrolling grid. */
@media (max-width: 720px) {
    .table-wrap { overflow-x: visible; }
    .table { min-width: 0; }
    .table thead { display: none; }
    .table tbody tr {
        display: block;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        margin: 10px;
        padding: 2px 14px;
    }
    .table td {
        display: flex; align-items: center; justify-content: space-between;
        gap: 12px; padding: 10px 0; white-space: normal;
        border-top: 1px solid var(--border);
        text-align: right;
    }
    .table td:first-child {
        display: block; text-align: left;
        font-weight: 700; font-size: .95rem;
        padding: 12px 0 10px; border-top: none;
    }
    .table td::before {
        content: attr(data-label);
        font-size: .7rem; font-weight: 700; color: var(--muted);
        text-transform: uppercase; letter-spacing: .02em; text-align: left;
    }
    .table td:first-child::before { content: none; }
    .table td:last-child { padding-bottom: 12px; }
    .table .row-actions { justify-content: flex-end; width: 100%; }
}

.status-pill { font-size: .74rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.status-active { background: var(--success-bg); color: var(--success); }
.status-blocked { background: var(--danger-bg); color: var(--danger); }

/* ---------- Credentials display ---------- */
.cred-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 0; border-bottom: 1px solid var(--border);
}
.cred-row:last-of-type { border-bottom: none; }
.cred-label { font-weight: 600; color: var(--muted); font-size: .85rem; }
.cred-value { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 1.05rem; font-weight: 700; color: var(--primary-dark); }

/* ---------- Desktop breakpoint ---------- */
@media (min-width: 900px) {
    .sidebar {
        display: block; width: var(--sidebar-w); flex-shrink: 0;
        background: var(--surface); border-right: 1px solid var(--border);
        position: sticky; top: 0; height: 100vh; overflow-y: auto;
    }
    .bottom-nav { display: none; }
    .content { padding: 24px 32px 32px; }
    .user-chip .user-name { display: inline; }
    .shop-name-label { display: block; max-width: 220px; }
    .card-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 520px) {
    .stat-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .stat-tile { padding: 12px 8px; }
    .stat-value { font-size: 1.2rem; }
}

@media (min-width: 1200px) {
    .card-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Point of sale (kassa) ---------- */
.pos-layout { display: flex; flex-direction: column; gap: 16px; }
.pos-search {
    width: 100%; font: inherit; padding: 12px 14px; margin-bottom: 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); outline: none;
}
.pos-search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.pos-product-list { display: flex; flex-direction: column; gap: 8px; max-height: 65vh; overflow-y: auto; }
.pos-product {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    width: 100%; text-align: left; font: inherit; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 12px 14px;
}
.pos-product:hover { border-color: var(--primary); }
.pos-product-name { font-weight: 600; }
.pos-product-meta { font-size: .78rem; color: var(--muted); white-space: nowrap; margin-left: 10px; }

.pos-cart { position: static; }
.cart-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; max-height: 38vh; overflow-y: auto; }
.cart-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.cart-row-main { flex: 1; min-width: 0; }
.cart-row-name { font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-row-price { font-size: .74rem; color: var(--muted); }
.qty-stepper { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.qty-stepper button {
    width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-weight: 700; cursor: pointer; font-size: 1rem; line-height: 1;
}
.qty-stepper span { min-width: 24px; text-align: center; font-weight: 600; font-size: .85rem; }
.qty-stepper-fractional .qty-direct-input {
    width: 58px; min-width: 0; text-align: center; font: inherit; font-weight: 600; font-size: .85rem;
    padding: 4px 2px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text); outline: none;
}
.qty-stepper-fractional .qty-direct-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.cart-row-subtotal { font-weight: 700; font-size: .85rem; min-width: 76px; text-align: right; flex-shrink: 0; }
.cart-remove { background: none; border: none; color: var(--danger); font-size: 1rem; cursor: pointer; padding: 4px; flex-shrink: 0; }

.cart-totals { margin: 14px 0; }
.cart-total-row { display: flex; justify-content: space-between; align-items: center; font-size: 1.15rem; margin-top: 10px; }

.discount-input-row { display: flex; gap: 8px; align-items: stretch; }
.discount-input-row input { flex: 1; min-width: 0; }
.discount-mode-toggle { display: flex; flex-shrink: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.discount-mode-btn {
    border: none; background: var(--surface); color: var(--muted); font-weight: 700; font-size: .82rem;
    padding: 0 12px; cursor: pointer;
}
.discount-mode-btn.active { background: var(--primary); color: #fff; }

.payment-types { display: flex; gap: 8px; margin: 14px 0; }
.payment-btn {
    flex: 1; padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--surface); font-weight: 700; font-size: .85rem; cursor: pointer; color: var(--muted);
}
.payment-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.radio-pill {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    font-weight: 700; font-size: .85rem; color: var(--muted); cursor: pointer;
}
.radio-pill input { accent-color: var(--primary); }
.radio-pill:has(input:checked) { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); }

#debt-fields { margin-bottom: 14px; padding-top: 10px; border-top: 1px dashed var(--border); }
/* Credit-limit-exceeded warning inside #debt-remaining-label (see sale.js) */
.credit-limit-exceeded { color: var(--danger); font-weight: 700; }

@media (min-width: 900px) {
    .pos-layout { flex-direction: row; align-items: flex-start; }
    .pos-products { flex: 1.4; min-width: 0; }
    .pos-cart { flex: 1; position: sticky; top: calc(var(--header-h) + 20px); max-width: 380px; }
}

/* ---------- Receipt / chek ---------- */
/* Always white paper + dark ink, independent of the app theme — this is printed on physical thermal paper. */
.receipt {
    max-width: 360px; margin: 0 auto; background: #fff; color: #1f2333;
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 22px; font-size: .86rem;
}
.receipt-58 { max-width: 240px; font-size: .78rem; }
.receipt-header { text-align: center; }
.receipt-shop-name { font-weight: 800; font-size: 1.05rem; }
.receipt-meta { color: #6b7280; font-size: .76rem; margin-top: 3px; }
.receipt-items { width: 100%; border-collapse: collapse; margin: 12px 0; }
.receipt-items th, .receipt-items td { padding: 4px 0; text-align: left; font-size: .82rem; }
.receipt-items th:last-child, .receipt-items td:last-child { text-align: right; }
.receipt-divider { border: none; border-top: 1px dashed #d1d5db; margin: 10px 0; }
.receipt-line { display: flex; justify-content: space-between; font-size: .84rem; padding: 2px 0; }
.receipt-total-row { display: flex; justify-content: space-between; font-weight: 800; font-size: 1.05rem; margin-top: 6px; }

@media print {
    .sidebar, .topbar, .bottom-nav, .no-print { display: none !important; }
    body, .content { padding: 0 !important; margin: 0 !important; background: #fff !important; }
    .receipt { box-shadow: none; border-radius: 0; margin: 0; padding: 6px; max-width: 100%; }
    @page { margin: 4mm; }
    /* Printed report page (/reports/print): flat white cards on paper instead
       of the themed surface + drop shadow, and dark-mode text tokens don't
       carry over onto white paper. */
    .print-report { color: #1f2333; background: #fff; }
    .print-report .card {
        box-shadow: none; border: 1px solid #d1d5db; break-inside: avoid;
    }
    .print-report .stat-tile { box-shadow: none; border: 1px solid #d1d5db; }
    .print-report .net-profit-tile { box-shadow: none; border: 1px solid #d1d5db; }
}

/* ---------- Low-stock dashboard tile / badge ---------- */
.low-stock-tile {
    display: flex; align-items: center; gap: 12px;
    border-left: 3px solid var(--danger);
    margin-bottom: 16px;
}
.low-stock-tile-icon { font-size: 1.4rem; flex-shrink: 0; }
.low-stock-tile-body { flex: 1; min-width: 0; }
.low-stock-tile-title { font-weight: 700; }
.low-stock-tile-arrow { color: var(--muted); font-size: 1.2rem; flex-shrink: 0; }

.stock-low-badge {
    display: inline-block; margin-left: 6px; font-size: .7rem; font-weight: 700;
    padding: 2px 8px; border-radius: 999px; background: var(--danger-bg); color: var(--danger);
    white-space: nowrap;
}

/* ---------- Purchase line-item entry table ---------- */
.purchase-items-wrap { overflow-x: auto; margin: 14px 0; }
.purchase-items-table { width: 100%; border-collapse: collapse; min-width: 680px; }
.purchase-items-table th, .purchase-items-table td { padding: 8px 6px; text-align: left; vertical-align: top; }
.purchase-items-table th {
    font-size: .7rem; color: var(--muted); text-transform: uppercase;
    font-weight: 700; letter-spacing: .02em;
}
.purchase-items-table input, .purchase-items-table select {
    width: 100%; font: inherit; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); outline: none;
}
.purchase-items-table input:focus, .purchase-items-table select:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.purchase-item-remove { background: none; border: none; color: var(--danger); font-size: 1.1rem; cursor: pointer; padding: 6px; }
.purchase-pack-hint { font-size: .7rem; color: var(--muted); margin-top: 3px; }
.purchase-item-subtotal { font-weight: 700; white-space: nowrap; }

@media (max-width: 720px) {
    .purchase-items-table { min-width: 560px; }
}

/* ---------- CSV import preview ---------- */
.import-summary-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.import-format-hint {
    font-family: 'SFMono-Regular', Consolas, monospace; font-size: .82rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 12px 14px; word-break: break-all; margin: 10px 0;
}

/* ---------- Barcode camera scan ---------- */
.scan-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; flex-shrink: 0; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); cursor: pointer;
}
.scan-btn svg { width: 19px; height: 19px; }
.scan-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.scan-btn:disabled { opacity: .4; cursor: not-allowed; }
.scan-input-row { display: flex; gap: 8px; align-items: stretch; }
.scan-input-row input { flex: 1; min-width: 0; }

.scan-modal {
    display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 60;
    align-items: center; justify-content: center; padding: 16px;
}
.scan-modal.open { display: flex; }
.scan-modal-card {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px; max-width: 420px; width: 100%;
}
.scan-modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.scan-modal-header h2 { font-size: 1rem; }
.scan-modal-close {
    background: none; border: none; font-size: 1.3rem; line-height: 1;
    color: var(--muted); cursor: pointer; padding: 4px;
}
.scan-modal-video { width: 100%; border-radius: var(--radius-sm); background: #000; max-height: 60vh; display: block; }
.scan-modal-hint { margin-top: 10px; }

/* ---------- POS variant picker ---------- */
.pos-variant-list {
    display: flex; flex-direction: column; gap: 6px;
    margin: 0 0 8px; padding: 8px 0 0 10px; border-left: 2px solid var(--border);
}
.pos-variant-btn {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    width: 100%; text-align: left; font: inherit; cursor: pointer;
    padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text);
}
.pos-variant-btn:hover { border-color: var(--primary); }
.pos-variant-btn:disabled { opacity: .5; cursor: not-allowed; }
.pos-variant-toggle-hint { font-size: .74rem; color: var(--primary-dark); font-weight: 600; margin-left: 8px; }

/* ---------- Product variant management (edit page) ---------- */
.variant-row-card { margin-bottom: 12px; }
.variant-row-card form { margin: 0; }

/* ---------- Dashboard onboarding banner ---------- */
.onboarding-banner {
    display: flex; align-items: flex-start; gap: 14px;
    background: var(--primary-light); border: 1px solid var(--primary);
    border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px;
}
.onboarding-banner-icon { font-size: 1.6rem; flex-shrink: 0; line-height: 1; }
.onboarding-banner-body { flex: 1; min-width: 0; }
.onboarding-banner-title { font-weight: 700; color: var(--primary-dark); margin-bottom: 4px; }
.onboarding-banner-text { color: var(--text); font-size: .9rem; margin-bottom: 10px; }
.onboarding-banner-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Help / FAQ accordion ---------- */
.faq-card { padding: 6px 0; }
.faq-item {
    padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.faq-item:last-child { border-bottom: none; }
.faq-item summary {
    cursor: pointer; font-weight: 600; list-style: none;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: '+'; color: var(--muted); font-weight: 400; font-size: 1.2rem; flex-shrink: 0; }
.faq-item[open] summary::after { content: '−'; }
.faq-item p { margin: 10px 0 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }
