/* ==========================================================================
   Spare Parts Management System — Design System
   Inspired by Apple / Stripe Dashboard / Linear / Notion
   ========================================================================== */

:root {
    /* Brand palette (indigo → royal → sky → lime) */
    --brand-indigo: #1C0770;
    --brand-royal: #261CC1;
    --brand-sky: #3A9AFF;
    --brand-lime: #F1FF5E;

    --color-primary: #261CC1;
    --color-primary-dark: #1C0770;
    --color-primary-soft: #3A9AFF;
    --color-primary-light: #EAF4FF;
    --color-accent: #F1FF5E;
    --brand-gradient: linear-gradient(135deg, var(--brand-indigo), var(--brand-royal) 55%, var(--brand-sky));
    --brand-stripes: linear-gradient(
        to bottom,
        var(--brand-indigo) 0 41%,
        var(--brand-royal) 41% 67%,
        var(--brand-sky) 67% 85%,
        var(--brand-lime) 85% 100%
    );
    --color-success: #16A34A;
    --color-success-light: #ECFDF5;
    --color-danger: #EF4444;
    --color-danger-light: #FEF2F2;
    --color-warning: #EAB308;
    --color-warning-light: #FEFCE8;
    --color-bg: #F5F7FC;
    --color-card: #FFFFFF;
    --color-border: #DDE3F0;
    --color-text: #0F1225;
    --color-text-muted: #5B6478;
    --color-text-subtle: #8B95A8;

    --sidebar-width: 260px;
    --sidebar-collapsed: 76px;
    --topbar-height: 68px;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 2px rgba(28, 7, 112, 0.05);
    --shadow-md: 0 4px 12px rgba(28, 7, 112, 0.08);
    --shadow-lg: 0 12px 32px rgba(28, 7, 112, 0.12);

    --transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    /* Chart tokens — brand palette, fixed order, never cycled. */
    --chart-surface: #FFFFFF;
    --series-1: #1C0770;
    --series-2: #261CC1;
    --series-3: #3A9AFF;
    --series-4: #F1FF5E;
    --chart-grid: #E6EBF5;
    --chart-axis: #C5CEE0;
    --chart-ink-muted: #5B6478;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #0B0B1A;
        --color-card: #141428;
        --color-border: #2A2A48;
        --color-text: #EEF1FF;
        --color-text-muted: #A0A8C0;
        --color-text-subtle: #6E7794;
        --color-primary: #3A9AFF;
        --color-primary-dark: #261CC1;
        --color-primary-soft: #F1FF5E;
        --color-primary-light: #1A1A3A;
        --color-success-light: #0F2A1A;
        --color-danger-light: #2A1414;
        --color-warning-light: #2A2610;
        --brand-gradient: linear-gradient(135deg, var(--brand-royal), var(--brand-sky));

        --chart-surface: #141428;
        --series-1: #6B8CFF;
        --series-2: #3A9AFF;
        --series-3: #7EC4FF;
        --series-4: #F1FF5E;
        --chart-grid: #222240;
        --chart-axis: #3A3A5C;
        --chart-ink-muted: #A0A8C0;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

html {
    scrollbar-gutter: stable;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, h4, h5, h6 { margin: 0 0 4px; font-weight: 600; letter-spacing: -0.01em; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------- App shell ---------------------------------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ---------------------------------- Sidebar ---------------------------------- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-card);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 40;
    transition: width 0.2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.sidebar-brand .logo-mark {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: var(--brand-stripes);
    display: flex; align-items: center; justify-content: center;
    color: transparent; font-weight: 700; font-size: 15px;
    flex-shrink: 0;
    overflow: hidden;
}
.sidebar-brand .logo-mark img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.sidebar-brand .logo-mark.has-image {
    color: #fff;
    background: var(--color-card);
}

.sidebar-brand .brand-text { font-weight: 700; font-size: 15.5px; white-space: nowrap; overflow: hidden; }
.sidebar-brand .brand-sub { font-size: 11.5px; color: var(--color-text-muted); white-space: nowrap; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 12px;
    scrollbar-gutter: stable;
}
.nav-group-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-subtle);
    font-weight: 700;
    padding: 14px 10px 6px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-size: 13.8px;
    font-weight: 600;
    margin-bottom: 2px;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
    border-left: 3px solid transparent;
}
.nav-item i { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-item span { overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: var(--color-bg); color: var(--color-text); }
.nav-item.active {
    background: var(--color-primary-light);
    color: var(--color-primary);
    border-left-color: var(--color-primary);
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

/* ---------------------------------- Main / topbar ---------------------------------- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.2s ease;
}

.topbar {
    height: var(--topbar-height);
    background: var(--color-card);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 30;
    gap: 16px;
}

.topbar-search {
    flex: 1;
    max-width: 420px;
    position: relative;
}
.topbar-search input {
    width: 100%;
    padding: 9px 14px 9px 38px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    font-size: 13.5px;
    color: var(--color-text);
}
.topbar-search input:focus { outline: none; border-color: var(--color-primary); background: var(--color-card); }
.topbar-search i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--color-text-subtle); }

.topbar-actions { display: flex; align-items: center; gap: 14px; }
.icon-btn {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: var(--color-text-muted);
    position: relative;
    transition: var(--transition);
    cursor: pointer;
}
.icon-btn:hover { background: var(--color-bg); color: var(--color-text); }
.icon-btn .badge-dot {
    position: absolute; top: 6px; right: 7px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--color-danger);
    border: 2px solid var(--color-card);
}

.user-chip { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 6px 4px 4px; border-radius: 30px; transition: var(--transition); }
.user-chip:hover { background: var(--color-bg); }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand-gradient);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-chip .user-meta { line-height: 1.25; }
.user-chip .user-name { font-size: 13.2px; font-weight: 600; }
.user-chip .user-role { font-size: 11px; color: var(--color-text-muted); text-transform: capitalize; }

.page-body { padding: 26px; flex: 1; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 21px; }
.page-header p { color: var(--color-text-muted); font-size: 13.3px; margin: 0; }
.breadcrumb { font-size: 12.5px; color: var(--color-text-subtle); margin-bottom: 6px; }
.breadcrumb a:hover { color: var(--color-primary); }

/* ---------------------------------- Cards ---------------------------------- */
.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
}
.card-header h3 { font-size: 15px; }
.card-body { padding: 20px; }

/* ---------------------------------- Stat cards ---------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.stat-icon {
    width: 40px; height: 40px; border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.stat-icon.blue { background: var(--color-primary-light); color: var(--color-primary); }
.stat-icon.green { background: var(--color-success-light); color: var(--color-success); }
.stat-icon.red { background: var(--color-danger-light); color: var(--color-danger); }
.stat-icon.amber { background: var(--color-warning-light); color: var(--color-warning); }
.stat-trend { font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.stat-trend.up { background: var(--color-success-light); color: var(--color-success); }
.stat-trend.down { background: var(--color-danger-light); color: var(--color-danger); }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }

/* ---------------------------------- Dashboard KPIs ----------------------------------
   Every tile shares one structure so values and labels line up across the row.
   9 cards → 5 + 4 in two rows on desktop. */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}
@media (max-width: 1200px) {
    .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } /* 3 + 3 + 3 */
}
@media (max-width: 900px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
    .kpi-grid { grid-template-columns: 1fr; }
}
.kpi-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-head {
    display: flex; align-items: center; gap: 9px;
    min-height: 20px;
}
.kpi-head .stat-icon {
    width: 30px; height: 30px; border-radius: 9px; font-size: 14px; flex-shrink: 0;
}
.kpi-title {
    font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
    color: var(--color-text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-value {
    font-size: 23px; font-weight: 700; letter-spacing: -0.025em;
    line-height: 1.15;
    margin-top: auto;
}
.kpi-sub { font-size: 11.8px; color: var(--color-text-subtle); min-height: 15px; }

/* Compact counters row — same internal rhythm as the KPI tiles above. */
.mini-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(124px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.mini-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 13px 15px;
    text-align: left;
    transition: var(--transition);
}
.mini-card:hover { border-color: var(--color-primary); }
.mini-value { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.mini-label {
    font-size: 11px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
    color: var(--color-text-muted); margin-top: 3px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------------------------------- Chart chrome ---------------------------------- */
.chart-card { display: flex; flex-direction: column; min-width: 0; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; padding: 0 20px 4px; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.2px; color: var(--color-text-muted); }
.chart-legend-swatch { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.chart-canvas-wrap { padding: 12px 16px 16px; width: 100%; max-width: 100%; min-width: 0; position: relative; }
.chart-canvas-wrap canvas { max-width: 100% !important; }

/* Dashboard / report multi-column chart rows */
.dash-charts-row,
.dash-two-col,
.report-charts {
    display: grid;
    gap: 16px;
    margin-bottom: 20px;
    min-width: 0;
}
.dash-charts-row { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.dash-two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.report-charts { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.report-charts.report-charts-methods { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
.report-charts.report-charts-single { grid-template-columns: minmax(0, 1fr); }
.report-filters {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) auto;
}
.report-filter-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.kpi-grid > *,
.form-row > *,
.dash-charts-row > *,
.dash-two-col > *,
.report-charts > *,
.product-rank-grid > * { min-width: 0; }
.chart-toggle {
    font-size: 11.8px; font-weight: 600; color: var(--color-text-muted);
    background: none; border: 1px solid var(--color-border); border-radius: 20px;
    padding: 4px 11px; cursor: pointer; transition: var(--transition); font-family: inherit;
}
.chart-toggle:hover { background: var(--color-bg); color: var(--color-text); }
.chart-table-view { display: none; }
.chart-table-view.show { display: block; }
.chart-plot.hide { display: none; }

/* ---------------------------------- Buttons ---------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.3px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: 0 1px 2px rgba(28, 7, 112, .28); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { filter: brightness(0.94); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }
.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-bg); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-bg); color: var(--color-text); }
.btn-sm { padding: 6px 11px; font-size: 12.3px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }

/* ---------------------------------- Forms ---------------------------------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.8px; font-weight: 600; margin-bottom: 6px; color: var(--color-text); }
.form-label .required { color: var(--color-danger); }
.form-control, select.form-control, textarea.form-control {
    width: 100%;
    padding: 9.5px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-card);
    color: var(--color-text);
    font-size: 13.5px;
    font-family: inherit;
    transition: var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}
.form-hint { font-size: 11.8px; color: var(--color-text-subtle); margin-top: 5px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group-addon {
    display: flex; align-items: center; padding: 0 12px;
    background: var(--color-bg); border: 1px solid var(--color-border); border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 13px; color: var(--color-text-muted);
}

/* ---------------------------------- Tables ---------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.3px; }
table.data-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 11.8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
table.data-table td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
table.data-table tbody tr { transition: var(--transition); }
table.data-table tbody tr:hover { background: var(--color-bg); }
table.data-table tbody tr:last-child td { border-bottom: none; }

/* ---------------------------------- Badges ---------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11.3px;
    font-weight: 700;
    text-transform: capitalize;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-danger { background: var(--color-danger-light); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-primary { background: var(--color-primary-light); color: var(--color-primary); }
.badge-muted { background: var(--color-bg); color: var(--color-text-muted); }

/* ---------------------------------- Misc ---------------------------------- */
.avatar-sm { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--color-bg); }
.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.fw-600 { font-weight: 600; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mb-0 { margin-bottom: 0 !important; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--color-text-muted); }
.empty-state i { font-size: 42px; color: var(--color-text-subtle); margin-bottom: 14px; display: block; }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-top: 1px solid var(--color-border); flex-wrap: wrap; gap: 10px; }
.pagination-links { display: flex; gap: 6px; }
.pagination-links a, .pagination-links span {
    min-width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); font-size: 12.8px; color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}
.pagination-links a:hover { background: var(--color-bg); }
.pagination-links .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
    display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px;
    backdrop-filter: blur(2px);
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: var(--color-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 520px; max-height: min(92vh, 880px);
    display: flex; flex-direction: column; overflow: hidden;
}
.modal-box.modal-lg { max-width: 760px; }
.modal-box.modal-xl { max-width: 920px; }
.modal-box.modal-invoice { max-width: 780px; }
.modal-header {
    padding: 16px 20px; border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    flex-shrink: 0;
}
.modal-body {
    padding: 18px 20px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.modal-body::-webkit-scrollbar { width: 0; height: 0; display: none; }
.modal-footer {
    padding: 14px 20px; border-top: 1px solid var(--color-border);
    display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0;
    background: var(--color-card);
}
.modal-body-iframe { padding: 0; overflow: hidden; flex: 1 1 auto; min-height: 0; display: flex; }
.modal-body-iframe iframe {
    width: 100%;
    height: min(72vh, 640px);
    border: 0;
    display: block;
    background: var(--color-card);
    flex: 1;
}
body.modal-open { overflow: hidden; }

.dropdown-menu {
    position: absolute; top: calc(100% + 8px); right: 0; min-width: 200px;
    background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg); z-index: 50; padding: 6px; display: none;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a, .dropdown-menu button {
    display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
    padding: 9px 10px; border-radius: var(--radius-sm); font-size: 13px; color: var(--color-text);
    background: none; border: none; cursor: pointer; font-family: inherit;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--color-bg); }
.dropdown-menu hr { border: none; border-top: 1px solid var(--color-border); margin: 6px 0; }

.sidebar-toggle { display: flex; }

/* Desktop collapse: icon rail */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed);
}
body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed);
}
body.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 18px 12px;
}
body.sidebar-collapsed .sidebar-brand > div:not(.logo-mark),
body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .brand-sub,
body.sidebar-collapsed .nav-group-label,
body.sidebar-collapsed .nav-item span,
body.sidebar-collapsed .sidebar-footer .nav-item span {
    display: none;
}
body.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 10px 8px;
    gap: 0;
    border-left-width: 0;
}
body.sidebar-collapsed .nav-item.active {
    border-left-width: 0;
    box-shadow: inset 3px 0 0 var(--color-primary);
}
body.sidebar-collapsed .sidebar-nav {
    padding: 10px 8px;
    scrollbar-gutter: auto;
}
body.sidebar-collapsed .sidebar-footer {
    padding: 10px 8px;
}

@media (max-width: 1024px) {
    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-width);
    }
    body.sidebar-collapsed .main-content {
        margin-left: 0;
    }
    body.sidebar-collapsed .sidebar-brand {
        justify-content: flex-start;
        padding: 20px 22px;
    }
    body.sidebar-collapsed .sidebar-brand > div:not(.logo-mark),
    body.sidebar-collapsed .brand-text,
    body.sidebar-collapsed .brand-sub,
    body.sidebar-collapsed .nav-group-label,
    body.sidebar-collapsed .nav-item span,
    body.sidebar-collapsed .sidebar-footer .nav-item span {
        display: revert;
    }
    body.sidebar-collapsed .nav-item {
        justify-content: flex-start;
        padding: 9px 12px;
        gap: 12px;
        border-left-width: 3px;
    }
    body.sidebar-collapsed .nav-item.active {
        box-shadow: none;
        border-left-color: var(--color-primary);
    }
    body.sidebar-collapsed .sidebar-nav { padding: 14px 12px; scrollbar-gutter: stable; }
    body.sidebar-collapsed .sidebar-footer { padding: 14px; }
}

/* ---------------------------------- Login page ---------------------------------- */
.auth-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at top left, var(--color-primary-light), var(--color-bg) 60%);
    padding: 20px;
}
.auth-card {
    width: 100%; max-width: 380px; background: var(--color-card); border: 1px solid var(--color-border);
    border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); padding: 36px 32px;
}
.auth-logo {
    width: 52px; height: 52px; border-radius: 14px;
    background: var(--brand-stripes);
    display: flex; align-items: center; justify-content: center;
    color: transparent; font-weight: 700; font-size: 22px; margin: 0 auto 18px;
    overflow: hidden;
}
.auth-logo img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.auth-logo.has-image {
    color: #fff;
    background: var(--color-card);
}
.auth-title { text-align: center; font-size: 19px; margin-bottom: 4px; }
.auth-subtitle { text-align: center; color: var(--color-text-muted); font-size: 13px; margin-bottom: 26px; }
.auth-checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--color-text-muted); margin-bottom: 20px; }

/* ---------------------------------- Alerts ---------------------------------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.alert-danger { background: var(--color-danger-light); color: var(--color-danger); }
.alert-success { background: var(--color-success-light); color: var(--color-success); }
.alert-warning { background: var(--color-warning-light); color: var(--color-warning); }

/* ---------------------------------- Responsive ---------------------------------- */
@media (max-width: 1100px) {
    .dash-charts-row,
    .dash-two-col,
    .product-rank-grid,
    .report-charts,
    .report-charts.report-charts-methods {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        transition: transform 0.2s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar-search { display: none; }
}

@media (max-width: 900px) {
    /* Force any inline two/three-column grid layouts (form-row overrides) to stack on tablets/phones. */
    .form-row[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
    .product-rank-grid { grid-template-columns: 1fr !important; }
    .page-header .d-flex { flex-wrap: wrap; gap: 8px; width: 100%; }
    .page-header .d-flex .btn { flex: 1 1 auto; }
}

@media (max-width: 640px) {
    .report-filters { grid-template-columns: 1fr !important; }
    .report-filters > .btn { width: 100%; }
    .page-body { padding: 14px; overflow-x: hidden; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header h1 { font-size: 18px; }
    .page-header > .d-flex { width: 100%; flex-wrap: wrap; }
    .page-header > .d-flex .btn { flex: 1 1 calc(50% - 4px); min-width: 0; justify-content: center; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
    .topbar { padding: 0 12px; }
    table.data-table th, table.data-table td { padding: 9px 10px; font-size: 12.5px; }
    .table-wrap { -webkit-overflow-scrolling: touch; }

    .kpi-card { padding: 12px 13px; gap: 8px; }
    .kpi-value { font-size: 18px; word-break: break-word; }
    .kpi-title { font-size: 10.5px; }
    .kpi-sub { font-size: 11px; line-height: 1.35; min-height: 0; }

    .mini-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .mini-card { padding: 11px 12px; }

    .chart-legend { padding: 0 12px 4px; gap: 10px; }
    .chart-canvas-wrap { padding: 8px 10px 12px; }
    /* Cap tall inline chart heights on phones so cards stay usable */
    .chart-card .chart-canvas-wrap,
    .product-rank-card .chart-canvas-wrap {
        height: min(220px, 48vw) !important;
        min-height: 180px;
    }
    .dash-charts-row .chart-canvas-wrap.chart-plot {
        height: 220px !important;
    }

    .product-rank-table th,
    .product-rank-table td { padding: 7px 6px; font-size: 11.5px; }
    .product-rank-table th:nth-child(3),
    .product-rank-table td:nth-child(3) { width: 58px; }
    .product-rank-table th:nth-child(4),
    .product-rank-table td:nth-child(4) { width: 82px; }
    .product-rank-table .rank-code { font-size: 10px; }

    .stat-value { font-size: 20px; }
    .filters-bar, .toolbar { flex-wrap: wrap; }
}

@media (max-width: 420px) {
    .kpi-grid { gap: 10px; }
    .page-header > .d-flex .btn { flex: 1 1 100%; }
    .product-rank-table th:nth-child(3),
    .product-rank-table td:nth-child(3) { width: 48px; }
    .product-rank-table th:nth-child(4),
    .product-rank-table td:nth-child(4) { width: 72px; }
}

.sidebar-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 39; display: none; }
.sidebar-backdrop.show { display: block; }

/* ---------------------------------- Invoices ---------------------------------- */
.invoice-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 20px; margin-bottom: 28px; flex-wrap: wrap;
}
.invoice-brand { display: flex; align-items: flex-start; gap: 14px; }
.invoice-logo { max-height: 62px; max-width: 180px; object-fit: contain; }
.invoice-company { margin-bottom: 6px; font-size: 20px; }
.invoice-meta { margin: 0; font-size: 12.8px; }

/* Print / Save-as-PDF: strip the app chrome and print only the invoice sheet. */
@media print {
    @page { margin: 14mm; }
    html, body { background: #fff !important; color: #000 !important; }
    .no-print, .sidebar, .topbar, .sidebar-backdrop, .pos-mobile-bar,
    .pos-page, .pos-layout, .pos-page-head { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-body { padding: 0 !important; }
    .modal-overlay { display: none !important; }
    #invoiceModal.show {
        display: block !important;
        position: static !important;
        background: transparent !important;
        padding: 0 !important;
        backdrop-filter: none !important;
    }
    #invoiceModal.show .modal-box.modal-invoice {
        max-width: none !important;
        max-height: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        overflow: visible !important;
    }
    #invoiceModal.show .modal-body {
        overflow: visible !important;
        padding: 0 !important;
    }
    .invoice-sheet, .card, .invoice-sheet-inner {
        border: none !important;
        box-shadow: none !important;
        background: #fff !important;
    }
    .invoice-sheet .card-body { padding: 0 !important; }
    .invoice-company, .invoice-meta, h1, h2, h3, td, th, span, p, div { color: #000 !important; }
    .text-muted { color: #444 !important; }
    table.data-table th {
        background: #f2f2f2 !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    table.data-table th, table.data-table td { border-bottom: 1px solid #ddd !important; }
    .badge {
        border: 1px solid #999 !important;
        color: #000 !important;
        background: transparent !important;
    }
    .badge::before { display: none; }
    a[href]::after { content: none !important; }
}

/* ---------------------------------- POS ---------------------------------- */
/* POS can run Full Screen (no sidebar) or Normal (with sidebar). */
body[data-pos-page="1"] .topbar-search { display: none; }
body[data-pos-page="1"] .main-content {
    height: 100vh;
    overflow: hidden;
}
body[data-pos-page="1"] .page-body {
    padding: 8px 10px 10px;
    height: calc(100vh - var(--topbar-height));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
body[data-pos-page="1"] .page-body > .alert { flex-shrink: 0; margin-bottom: 0; }
body[data-pos-page="1"] .pos-topbar-title {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
body[data-pos-page="1"] .pos-topbar-title strong { font-size: 14.5px; }
body[data-pos-page="1"] .pos-topbar-title span { font-size: 11.5px; }
body[data-pos-page="1"] .pos-exit-btn { display: none; }

/* Full screen POS: hide sidebar and use full width */
body.pos-fullscreen {
    overflow: hidden;
}
body.pos-fullscreen .sidebar,
body.pos-fullscreen .sidebar-backdrop {
    display: none !important;
}
body.pos-fullscreen .main-content {
    margin-left: 0 !important;
    height: 100vh;
    overflow: hidden;
}
body.pos-fullscreen .topbar {
    height: 56px;
    padding: 0 14px;
}
body.pos-fullscreen .page-body {
    padding: 8px 10px 10px;
    height: calc(100vh - 56px);
}
body.pos-fullscreen .user-chip .user-meta { display: none; }
body.pos-fullscreen .sidebar-toggle { display: flex; }
body.pos-fullscreen .pos-exit-btn { display: inline-flex; }

.pos-page {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
}
.pos-page > .alert { flex-shrink: 0; }
.pos-page-head { display: none; }

.pos-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
    gap: 10px;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
}
.pos-left {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 10px;
    overflow: hidden;
}
.product-grid-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 2px 2px;
    min-height: 0;
    scrollbar-width: thin;
}

.pos-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    gap: 8px;
    overflow: hidden;
}
.pos-panel {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.pos-panel-top { padding: 10px; flex-shrink: 0; }
.pos-field { margin-bottom: 7px; }
.pos-field:last-child { margin-bottom: 0; }
.pos-field .form-label { font-size: 11px; margin-bottom: 3px; }
.pos-field .form-control { padding: 7px 10px; font-size: 12.8px; }
.pos-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.pos-cart-panel {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.pos-panel-title {
    display: flex; align-items: center; justify-content: space-between;
    padding: 9px 12px; border-bottom: 1px solid var(--color-border);
    font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.pos-cart-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 0 10px 4px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    scrollbar-width: thin;
}
.pos-cart-body .empty-state { margin: auto; padding: 14px; }
.pos-cart-body .empty-state i { font-size: 26px; margin-bottom: 6px; }

.pos-checkout {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 10px;
    flex-shrink: 0;
}
.pos-checkout .btn-block {
    width: 100%;
    min-height: 44px;
    font-size: 14.5px;
    font-weight: 700;
}
.pos-total-row {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 16.5px; font-weight: 700; letter-spacing: -0.02em;
    padding-top: 6px; margin-bottom: 8px;
    border-top: 1px solid var(--color-border);
}
.pos-cost-warning {
    display: none;
    align-items: center; gap: 6px;
    background: var(--color-danger-light); color: var(--color-danger);
    border-radius: var(--radius-sm);
    padding: 7px 10px; margin-bottom: 8px;
    font-size: 11.8px; font-weight: 600;
}
.pos-cost-warning.show { display: flex; }

@media (min-width: 1101px) and (max-height: 700px) {
    body.pos-fullscreen .topbar { height: 50px; }
    body.pos-fullscreen .page-body { height: calc(100vh - 50px); padding: 6px 8px 8px; }
    body[data-pos-page="1"]:not(.pos-fullscreen) .page-body { padding: 6px 8px 8px; }
    .pos-layout { gap: 8px; }
    .pos-left { padding: 8px; }
    .pos-panel-top { padding: 8px; }
    .pos-checkout { padding: 8px; }
    .pos-checkout .btn-block { min-height: 40px; }
    .cart-line { padding: 6px 0; }
    .product-card { padding: 8px; gap: 5px; }
}

/* POS popups must sit above the mobile cart sheet (z-index 210). */
.pos-modal { z-index: 300; }

.pos-right-close { display: none; }
.pos-right-backdrop { display: none; }
.pos-mobile-bar { display: none; }

/* Mobile / tablet: cart + checkout become a slide-up popup opened via a floating bar. */
@media (max-width: 1100px) {
    body[data-pos-page="1"] .page-body,
    body.pos-fullscreen .page-body {
        height: auto;
        min-height: calc(100vh - 56px);
        overflow: auto;
        padding: 10px;
    }
    body.pos-fullscreen { overflow: auto; }
    body[data-pos-page="1"] .main-content,
    body.pos-fullscreen .main-content { height: auto; min-height: 100vh; overflow: visible; }
    .pos-page { height: auto; min-height: 0; flex: none; }
    .pos-layout { grid-template-columns: 1fr; flex: none; gap: 12px; }
    .pos-left { overflow: visible; padding-bottom: 4px; margin-bottom: 70px; }
    .product-grid-scroll { flex: none; overflow: visible; max-height: none; }

    .pos-right {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        max-height: 88vh;
        overflow-y: auto;
        background: var(--color-bg);
        border-radius: 20px 20px 0 0;
        box-shadow: var(--shadow-lg);
        padding: 14px 14px 22px;
        z-index: 210;
        transform: translateY(100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        gap: 10px;
    }
    .pos-right.show { transform: translateY(0); }
    .pos-cart-panel { flex: none; overflow: visible; min-height: 0; }
    .pos-cart-body { overflow: visible; max-height: 38vh; overflow-y: auto; }

    .pos-right-close {
        display: flex; align-items: center; justify-content: center; gap: 6px;
        width: 100%; padding: 9px; margin-bottom: 2px;
        background: var(--color-card); border: 1px solid var(--color-border);
        border-radius: var(--radius-md); color: var(--color-text-muted);
        font-size: 13px; font-weight: 600; cursor: pointer;
    }
    .pos-right-backdrop {
        display: none;
        position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
        z-index: 205; backdrop-filter: blur(2px);
    }
    .pos-right-backdrop.show { display: block; }

    .pos-mobile-bar {
        display: none;
        position: fixed;
        left: 12px; right: 12px; bottom: 12px;
        background: var(--color-primary);
        color: #fff;
        border-radius: var(--radius-lg);
        padding: 15px 20px;
        align-items: center;
        justify-content: space-between;
        box-shadow: var(--shadow-lg);
        z-index: 150;
        cursor: pointer;
        font-size: 14px;
        font-weight: 600;
    }
    .pos-mobile-bar.show { display: flex; }
}
.pos-search-bar { position: relative; flex-shrink: 0; }
.pos-search-bar input {
    width: 100%;
    padding: 11px 14px 11px 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    font-size: 13.8px;
}
.pos-search-bar input:focus { outline: none; border-color: var(--color-primary); background: var(--color-card); box-shadow: 0 0 0 3px var(--color-primary-light); }
.pos-search-bar i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--color-text-subtle); font-size: 15px; }

.category-chips {
    display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 8px;
    flex-shrink: 0; scrollbar-width: none;
}
.category-chips::-webkit-scrollbar { display: none; }
.category-chip {
    flex-shrink: 0;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12.2px;
    font-weight: 600;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}
.category-chip:hover { background: var(--color-card); color: var(--color-text); }
.category-chip.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
    gap: 10px;
    align-content: start;
}
.product-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 10px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    gap: 7px;
    user-select: none;
    min-width: 0;
}
.product-card:hover { border-color: var(--color-primary); box-shadow: var(--shadow-md); transform: translateY(-1px); background: var(--color-card); }
.product-card:active { transform: scale(0.98); }
.product-card.out-of-stock { opacity: 0.45; cursor: not-allowed; }
.product-card.out-of-stock:hover { transform: none; box-shadow: none; border-color: var(--color-border); background: var(--color-bg); }
.product-card-thumb {
    width: 100%; aspect-ratio: 1.25 / 1; border-radius: var(--radius-sm);
    background: var(--color-card); display: flex; align-items: center; justify-content: center;
    color: var(--color-text-subtle); font-size: 24px; overflow: hidden;
}
.product-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-card-name {
    font-size: 12.4px; font-weight: 600; line-height: 1.3;
    min-height: 2.5em;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.product-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.product-card-price { font-size: 13.5px; font-weight: 700; color: var(--color-primary); }
.product-card-stock { font-size: 10.5px; padding: 2px 6px; border-radius: 10px; background: var(--color-success-light); color: var(--color-success); font-weight: 700; white-space: nowrap; }
.product-card-stock.low { background: var(--color-warning-light); color: var(--color-warning); }
.product-card-stock.out { background: var(--color-danger-light); color: var(--color-danger); }

.cart-line {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 4px 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
}
.cart-line:last-child { border-bottom: none; }
.cart-line-info { min-width: 0; }
.cart-line-name { font-size: 12.4px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-line-price { font-size: 11px; color: var(--color-text-muted); display: flex; align-items: center; gap: 5px; margin-top: 3px; flex-wrap: wrap; }
.cart-line-price .price-label { flex-shrink: 0; }
.cart-line-price-input {
    width: 70px;
    padding: 2px 5px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 11.5px;
    font-weight: 600;
    font-family: inherit;
    -moz-appearance: textfield;
}
.cart-line-price-input::-webkit-outer-spin-button,
.cart-line-price-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cart-line-price-input:focus { outline: none; border-color: var(--color-primary); background: var(--color-card); }
.price-changed {
    font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
    background: var(--color-warning-light); color: var(--color-warning);
    padding: 1px 5px; border-radius: 8px;
}
.cart-line-remove {
    width: 24px; height: 24px; border-radius: 50%;
    border: none; background: none; cursor: pointer;
    color: var(--color-text-subtle); font-size: 11px;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}
.cart-line-remove:hover { background: var(--color-danger-light); color: var(--color-danger); }
.cart-line-controls {
    grid-column: 1 / -1;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.qty-stepper { display: flex; align-items: center; gap: 4px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); }
.qty-stepper button { width: 26px; height: 26px; border: none; background: none; color: var(--color-text); cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.qty-stepper button:hover { color: var(--color-primary); }
.qty-stepper input { width: 30px; border: none; background: none; text-align: center; font-size: 12.5px; font-weight: 600; color: var(--color-text); -moz-appearance: textfield; }
.qty-stepper input::-webkit-outer-spin-button, .qty-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cart-line-total { font-size: 13px; font-weight: 700; text-align: right; flex-shrink: 0; }

/* Top / Lowest product rank cards — identical columns so both sides align */
.product-rank-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.product-rank-card .chart-canvas-wrap { margin-bottom: 4px; }
.product-rank-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
}
.product-rank-table th,
.product-rank-table td {
    padding: 8px 10px;
    border-top: 1px solid var(--color-border);
    vertical-align: middle;
    font-size: 12.5px;
}
.product-rank-table thead th {
    border-top: none;
    color: var(--color-text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding-top: 10px;
    padding-bottom: 6px;
}
.product-rank-table th:nth-child(1),
.product-rank-table td:nth-child(1) { width: 36px; color: var(--color-text-muted); }
.product-rank-table th:nth-child(2),
.product-rank-table td:nth-child(2) { width: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-rank-table th:nth-child(3),
.product-rank-table td:nth-child(3),
.product-rank-table th:nth-child(4),
.product-rank-table td:nth-child(4) { width: 108px; text-align: right; white-space: nowrap; }
.product-rank-table .rank-name { font-weight: 600; color: var(--color-text); }
.product-rank-table .rank-code { display: block; font-size: 11px; font-weight: 500; color: var(--color-text-muted); }

@media (max-width: 640px) {
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
}

/* ---------------------------------- Products page (mobile-first) ---------------------------------- */
.products-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.filters-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.filters-toggle .filters-chevron { transition: transform 0.18s ease; font-size: 12px; }
.filters-toggle.is-open .filters-chevron { transform: rotate(180deg); }
.filters-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--color-primary); display: inline-block;
}
.filters-panel {
    display: none;
    overflow: hidden;
}
.filters-panel.is-open { display: block; }
.filters-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    gap: 12px;
    align-items: end;
}
.filters-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.product-cards { display: none; }
.products-table-wrap { display: block; }
.desktop-only-flex { display: flex; }

.product-card-item {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--color-border);
}
.product-card-item:last-child { border-bottom: none; }
.product-card-main {
    display: flex;
    gap: 12px;
    padding: 14px 14px 14px 16px;
    flex: 1;
    min-width: 0;
    color: inherit;
}
.product-card-thumb {
    width: 56px; height: 56px; border-radius: 10px;
    object-fit: cover; flex-shrink: 0;
    background: var(--color-bg); border: 1px solid var(--color-border);
}
.product-card-thumb-empty {
    display: flex; align-items: center; justify-content: center;
    color: var(--color-text-muted); font-size: 20px;
}
.product-card-body { min-width: 0; flex: 1; }
.product-card-title {
    font-weight: 650; font-size: 14.5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.product-card-meta {
    font-size: 11.5px; color: var(--color-text-muted);
    margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.product-card-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; margin-top: 8px;
}
.product-card-sub { font-size: 11.5px; margin-top: 4px; }
.product-card-actions {
    display: flex; flex-direction: column; justify-content: center;
    gap: 2px; padding: 8px 8px 8px 0; flex-shrink: 0;
}
.product-card-actions form { margin: 0; }

@media (max-width: 900px) {
    .filters-form { grid-template-columns: 1fr; }
    .filters-actions { width: 100%; }
    .filters-actions .btn { flex: 1; justify-content: center; }
    .product-cards { display: block; }
    .products-table-wrap { display: none; }
    .desktop-only-flex { display: none !important; }
    .products-actions { width: 100%; }
    .products-actions .btn { flex: 1; justify-content: center; }
    .btn-label { display: none; }
    .modal-box.modal-xl {
        max-width: 100%;
        max-height: 96vh;
        height: 96vh;
        border-radius: 14px;
    }
    .modal-body-iframe iframe { height: calc(96vh - 58px); }
}

@media (min-width: 901px) {
    .filters-panel { display: block !important; }
    .filters-toggle { display: none; }
    .products-count { display: none; }
}

