/* ============================================================
   MERCADO duBAIRRO — Dashboard Styles
   Adapted from the legacy public/css/style.css: visual language kept,
   Excel-import styles dropped (no longer part of the data flow).
   ============================================================ */

:root {
    --yellow: #FFC107;
    --dark: #2D2D2D;
    --gray: #666666;
    --green: #27AE60;
    --red: #E74C3C;
    --blue: #2E86C1;
    --light-gray: #F5F5F5;
    --orange: #F39C12;
    --green-dark: #1E8449;
    --green-light: #82E0AA;
    --yellow-light: #F9E79F;
    --red-light: #F5B7B1;
    --sidebar-width: 260px;

    /* Semantic tokens for TEXT and thin lines. Every one passes WCAG AA on its background
       (measured 2026-09-11); the brand colors above stay for fills, where 3:1 is enough. */
    --text-muted: #6B6B6B;     /* 5.3:1 on white — was #999 (2.9:1) */
    --positive: #1E8449;       /* 4.7:1 — was #27AE60 (2.9:1) */
    --negative: #C0392B;       /* 5.4:1 — was #E74C3C (3.8:1) */
    --warn-text: #8A5A00;      /* 5.9:1 — was orange #F39C12 */
    --amber: #B7791F;          /* 3.6:1 — yellow lines / outline of yellow bars (#FFC107 is 1.6:1) */
    --link: #1F6FA8;           /* 5.4:1 */
    --sidebar-muted: #A0A0A0;  /* 5.3:1 on --dark — was #666 (2.4:1) */

    /* Plain neutral surfaces/borders (not contrast-critical, unlike the block above) —
       named so each shade only needs to change in one place. */
    --border: #ddd;             /* light-mode input/card borders */
    --divider: #e0e0e0;         /* light-mode dividers — a touch lighter than --border */
    --surface-muted: #eee;      /* light-mode neutral fill (secondary buttons, muted badges) */
    --sidebar-line: #444;       /* dark-sidebar borders/fills, resting state */
    --sidebar-line-hover: #555; /* dark-sidebar borders/fills, hover/active state */
    --sidebar-text: #ccc;       /* dark-sidebar primary text (brighter than --sidebar-muted) */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: #FAFAFA;
    color: var(--dark);
    min-height: 100vh;
}

.hidden { display: none !important; }
/* The hidden attribute must win over component display rules (popover, backdrop). */
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.sidebar :focus-visible, .period-popover :focus-visible { outline-color: var(--yellow); }

/* Keyboard-only: invisible until focused, jumps past the sidebar straight to #content. */
.skip-link {
    position: absolute; top: -48px; left: 8px; z-index: 1000;
    background: var(--dark); color: #fff; padding: 10px 16px; border-radius: 0 0 8px 8px;
    text-decoration: none; font-weight: 600; font-size: 14px; transition: top 0.15s;
}
.skip-link:focus { top: 0; }

/* Utility spacing/sizing used instead of inline style="" (blocked by CSP style-src 'self') */
.mt-16 { margin-top: 16px; }
.mt-8 { margin-top: 8px; }
.w-full { width: 100%; }
.periodo-badge.muted { background: var(--divider); }
.btn-row { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.btn-wide { width: auto !important; padding: 10px 20px; }
.table-scroll-sm { max-height: 280px; }
.table-scroll-md { max-height: 200px; }
.table-scroll-tall { max-height: 70vh; margin-top: 12px; }
.chart-box { height: 280px; }
/* Fixed pixel heights for ECharts containers (echarts.init needs a real clientHeight;
   the old SVG charts self-sized via viewBox, these don't) — CSP blocks style="", so
   sizes come from classes, not inline styles. Named for the height they replace. */
.chart-h-290 { height: 290px; }
.chart-h-330 { height: 330px; }
.chart-h-360 { height: 360px; }
.chart-h-380 { height: 380px; }
.chart-h-400 { height: 400px; }
.chart-h-460 { height: 460px; }
.chart-h-520 { height: 520px; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-screen {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dark);
}

.login-card {
    background: white;
    border-radius: 12px;
    padding: 36px 32px;
    width: 320px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.login-card img { width: 72px; margin-bottom: 12px; }
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-card p { font-size: 13px; color: var(--gray); margin-bottom: 20px; }

.login-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 12px;
}

.login-input:focus { border-color: var(--amber); }

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--yellow);
    color: var(--dark);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover { background: #FFB300; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    padding: 8px 16px;
    background: var(--surface-muted);
    color: var(--dark);
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary:hover { background: var(--border); }

.form-error {
    color: var(--negative);
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 16px;
}

.form-success {
    color: var(--positive);
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 16px;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--dark);
    color: white;
    padding: 16px;
    position: fixed;
    top: 0;
    left: 0;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

/* Compact brand row — the old full-width square logo took ~250px of the sidebar's height. */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 44px; height: 44px; border-radius: 8px; flex: none; }
.brand-text { flex: 1; min-width: 0; }
.brand-name { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--sidebar-muted); }
.sidebar-close {
    display: none; flex: none; align-items: center; justify-content: center;
    width: 40px; height: 40px; border: none; border-radius: 8px;
    background: rgba(255, 255, 255, 0.08); color: #fff; font-size: 18px; cursor: pointer;
}

.sidebar hr { border: none; border-top: 1px solid var(--sidebar-line); margin: 12px 0; }

.nav-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 4px;
    /* Never `all`: it would also animate the visibility inherited from the drawer, leaving the
       link 'hidden' (unfocusable) at the moment openNav() moves focus into it. */
    transition: background-color 0.2s, color 0.2s;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.1); color: white; }
.nav-item.active { background: var(--yellow); color: var(--dark); font-weight: 600; }

.sidebar-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--sidebar-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 16px 0 8px 4px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    font-size: 11px;
    color: var(--sidebar-muted);
    text-align: center;
}

.sim-label { font-size: 12px; color: var(--sidebar-muted); margin: 4px 0 4px 4px; display: block; }

.sim-input {
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--sidebar-line-hover);
    background: #333;
    color: white;
    font-size: 13px;
    margin-bottom: 4px;
}

.sim-input:focus { border-color: var(--yellow); }
.sim-help { font-size: 11px; color: var(--sidebar-muted); margin: 2px 0 2px 4px; line-height: 1.4; }
.sim-status { font-size: 12px; min-height: 16px; margin: 2px 0 0 4px; line-height: 1.4; }
.sim-status.ok { color: #7DDE9E; }
.sim-status.error { color: #F5A39A; }

/* Inline Lucide icons (web/assets/icons.js) replacing the old emoji glyphs —
   currentColor lets them follow the surrounding text color automatically. */
.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
.nav-item .icon, .btn-icon .icon { vertical-align: -4px; margin-right: 6px; }

/* Status dot used for ABC/severity indicators instead of colored emoji circles. */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot-red { background: var(--red); }
.dot-yellow { background: var(--yellow); }
.dot-green { background: var(--green); }
.dot-gray { background: var(--light-gray); border: 1px solid var(--gray); }

/* Screen-reader-only data table alternative for canvas (ECharts) charts. */
.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; }

/* ============================================================
   MAIN CONTENT + TOP BAR (period selector lives here, always in view)
   ============================================================ */
.main-col { margin-left: var(--sidebar-width); min-width: 0; }

.main-content {
    padding: 24px 32px;
    min-width: 0;
}

.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 10px 32px;
    background: #fff;
    border-bottom: 1px solid #e6e6e6;
}
.topbar-menu, .period-step {
    min-width: 40px; min-height: 40px;
    border: 1px solid var(--border); border-radius: 8px; background: #fff;
    color: var(--dark); font-size: 20px; line-height: 1; cursor: pointer;
}
.topbar-menu { display: none; align-items: center; justify-content: center; }
.topbar-menu:hover, .period-step:hover:not(:disabled) { background: #f3f3f3; }
.period-step:disabled { opacity: 0.35; cursor: not-allowed; }
.period-control { position: relative; display: flex; align-items: center; gap: 4px; }
.period-current {
    min-height: 40px; padding: 0 16px;
    border: none; border-radius: 20px;
    background: var(--yellow); color: var(--dark);
    font-size: 14px; font-weight: 700; cursor: pointer;
    font-variant-numeric: tabular-nums;
}
.period-current:hover:not(:disabled) { background: #FFB300; }
.period-current .caret { font-size: 11px; margin-left: 2px; }
.period-popover {
    position: absolute; top: calc(100% + 8px); left: 0; z-index: 60;
    width: 272px; padding: 12px;
    background: var(--dark); border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.period-popover .month-grid { margin-bottom: 0; }
.topbar .period-status { padding: 0; font-size: 12px; color: var(--text-muted); text-align: left; }

.nav-backdrop { position: fixed; inset: 0; z-index: 150; background: rgba(0, 0, 0, 0.45); }

.page-title { font-size: 24px; font-weight: 700; color: var(--dark); margin-bottom: 4px; }
.page-subtitle { font-size: 14px; color: var(--gray); font-style: italic; margin-bottom: 12px; }

.periodo-badge {
    display: inline-block;
    background: var(--yellow);
    color: var(--dark);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 12px;
    margin-right: 8px;
}

.divider { border: none; border-top: 1px solid var(--divider); margin: 16px 0; }

/* ============================================================
   DISCLOSURE / RECONCILIATION BANNER
   ============================================================ */
.disclosure-banner {
    border-left: 4px solid var(--blue);
    background: #EAF3FB;
    color: #1B4F72;
    padding: 10px 16px;
    border-radius: 0 8px 8px 0;
    font-size: 13px;
    margin-bottom: 16px;
    line-height: 1.5;
}

.disclosure-banner.warn { border-left-color: var(--orange); background: #FDF2E3; color: #7E5109; }
.disclosure-banner.error { border-left-color: var(--red); background: #FDEDEC; color: #922B21; }

/* ============================================================
   KPI CARDS
   ============================================================ */
.kpi-grid { display: grid; gap: 12px; margin-bottom: 16px; }
.kpi-grid-4 { grid-template-columns: repeat(4, 1fr); }
.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-grid-2 { grid-template-columns: repeat(2, 1fr); }

.kpi-card {
    background: white;
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border-left: 4px solid var(--yellow);
}

.kpi-title { font-size: 13px; color: var(--gray); margin-bottom: 4px; font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--dark); line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-subtitle { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.kpi-positive { color: var(--positive) !important; }
.kpi-negative { color: var(--negative) !important; }
.kpi-neutral { color: var(--warn-text) !important; }
.kpi-unavailable { color: var(--text-muted) !important; font-style: italic; font-size: 18px !important; }

/* M/M and A/A comparison chips on a kpi-card — see backend/api.py comparison_for() */
.kpi-deltas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.delta-chip { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: #f0f0f0; color: #5E5E5E; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta-chip.delta-positive { background: #D5F5E3; color: #17693A; }
.delta-chip.delta-negative { background: #FADBD8; color: #943126; }

/* Actionable per-product warnings on Resumo Executivo — see backend/api.py dashboard() alerts */
.alert-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.alert-card {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap;
    padding: 10px 14px; border-radius: 8px; border-left: 4px solid var(--orange);
    background: #FDF2E3; color: #7E5109; font-size: 13px; line-height: 1.5;
}
.alert-card > span { flex: 1 1 320px; }
.alert-card.severity-high { border-left-color: var(--red); background: #FDEDEC; color: #922B21; }
.alert-action { flex: none; color: inherit; font-weight: 700; white-space: nowrap; }

.btn-link { background: none; border: none; padding: 0; margin-top: 6px; display: block; color: var(--link); font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: underline; }
.btn-link:hover { color: var(--dark); }

/* ============================================================
   SECTION HEADERS / LAYOUT
   ============================================================ */
.section-header {
    font-size: 18px;
    font-weight: 600;
    color: var(--dark);
    border-bottom: 2px solid var(--yellow);
    padding-bottom: 6px;
    margin: 24px 0 12px 0;
}

.row { display: flex; gap: 20px; margin-bottom: 16px; }
.col-60 { flex: 3; min-width: 0; }
.col-40 { flex: 2; min-width: 0; }
.col-50 { flex: 1; min-width: 0; }

/* ============================================================
   DATA TABLES
   ============================================================ */
.data-table-container {
    max-height: 420px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid var(--divider);
}

.data-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.data-table th {
    background: var(--dark);
    color: white;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}
.data-table td { padding: 8px 12px; border-bottom: 1px solid #f0f0f0; }
.data-table tr:hover td { background: #f8f8f8; }
.data-table tr:nth-child(even) td { background: #fafafa; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table tbody tr td.cell-alert { background: #FDEDEC; color: #922B21; font-weight: 700; }
.th-sort { background: none; border: none; padding: 0; color: inherit; font: inherit; font-weight: 600; text-align: inherit; cursor: pointer; }
.th-sort::after { content: ' ↕'; opacity: 0.5; }
th[aria-sort="ascending"] .th-sort::after { content: ' ▲'; opacity: 1; }
th[aria-sort="descending"] .th-sort::after { content: ' ▼'; opacity: 1; }

/* Produtos & Estoque: search + quick filters (the page lists ~700 products) */
.estoque-toolbar { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--dark); margin-bottom: 4px; }
.search-input {
    width: 100%; max-width: 420px; min-height: 40px; padding: 8px 12px;
    border: 1px solid #bbb; border-radius: 8px; font-size: 14px;
}
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    min-height: 36px; padding: 6px 12px; border: 1px solid #ccc; border-radius: 18px;
    background: #fff; color: var(--dark); font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--amber); }
.chip.active { background: var(--dark); border-color: var(--dark); color: #fff; }
.chip-count {
    display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 9px;
    background: var(--surface-muted); color: var(--dark); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.chip.active .chip-count { background: var(--yellow); }
.result-count { font-size: 12px; color: var(--text-muted); margin: 6px 0 8px; }

/* ============================================================
   CHART CONTAINERS
   ============================================================ */
.chart-container { background: white; border-radius: 8px; padding: 8px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04); }
.chart-empty { padding: 40px 0; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ============================================================
   INSIGHT PAGES — story, "como interpretar", tabs, action plan
   (visual language of the legacy public/css/style.css)
   ============================================================ */
.story-box {
    background: #FFF9E6;
    border-left: 3px solid var(--yellow);
    padding: 12px 16px;
    border-radius: 0 8px 8px 0;
    margin: 8px 0 16px 0;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.section-note { color: var(--gray); font-size: 13px; margin: -4px 0 12px 0; line-height: 1.5; }

.kpi-grid-5 { grid-template-columns: repeat(5, 1fr); }
.kpi-value-sm { font-size: 18px; }

.tooltip-box { margin: 8px 0; }
.tooltip-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--gray);
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: all 0.2s;
}
.tooltip-toggle:hover { border-color: var(--yellow); color: var(--dark); }
.tooltip-content {
    display: none;
    background: white;
    border: 1px solid var(--divider);
    border-radius: 0 0 6px 6px;
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
}
.tooltip-content.open { display: block; }
.tooltip-content strong { color: var(--dark); }

.tabs { display: flex; gap: 0; }
.tab-btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-bottom: none;
    background: var(--light-gray);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px 8px 0 0;
    color: var(--gray);
    transition: all 0.2s;
}
.tab-btn.active { background: white; color: var(--dark); font-weight: 600; border-bottom: 2px solid var(--yellow); }
.tab-content { display: none; border: 1px solid var(--border); border-top: none; padding: 16px; background: white; border-radius: 0 0 8px 8px; }
.tab-content.active { display: block; }

.action-title { font-size: 16px; margin: 4px 0 8px 0; }
.action-list { list-style: none; padding: 0; }
.action-list li { padding: 8px 0; font-size: 14px; border-bottom: 1px solid #f0f0f0; line-height: 1.5; }
.action-list li:last-child { border-bottom: none; }

/* ============================================================
   CHARTS — hover tooltip shared by every ECharts mount (echarts-charts.js);
   the chart body itself is Canvas, drawn/styled entirely from JS, not CSS.
   ============================================================ */
.chart-tip {
    position: fixed; z-index: 1000; pointer-events: none;
    background: rgba(45, 45, 45, 0.95); color: white;
    padding: 8px 10px; border-radius: 6px; font-size: 12px; line-height: 1.45;
    white-space: pre-line; max-width: 320px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

/* ============================================================
   LOADING
   ============================================================ */
.loading { display: flex; align-items: center; justify-content: center; height: 60vh; font-size: 18px; color: var(--gray); }
.loading-spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--divider);
    border-top: 4px solid var(--yellow);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Page-switch skeleton (renderPage()'s inline loading state) — reuses .kpi-grid-4's own
   responsive breakpoints instead of a bespoke grid. Kept separate from #loading above,
   the app's one-time boot spinner (nothing to mimic the shape of yet at that point). */
.skeleton-page { padding-top: 2px; }
.skeleton-line, .skeleton-card, .skeleton-block {
    background: linear-gradient(90deg, #ececec 25%, #f6f6f6 50%, #ececec 75%);
    background-size: 200% 100%; animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 8px;
}
.skeleton-line { height: 14px; margin-bottom: 10px; }
.skeleton-title { width: 220px; height: 24px; margin-bottom: 6px; }
.skeleton-sub { width: 340px; }
.skeleton-card { height: 92px; border-radius: 12px; }
.skeleton-block { height: 240px; margin-top: 20px; }
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
    .skeleton-line, .skeleton-card, .skeleton-block { animation: none; background: #ececec; }
}

/* ============================================================
   BADGES
   ============================================================ */
.badge-success { display: inline-block; background: #D5F5E3; color: var(--green-dark); padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.badge-info { display: inline-block; background: #D6EAF8; color: #1B5E8C; padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.badge-warning { display: inline-block; background: #FDEBD0; color: #7A4F00; padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.badge-error { display: inline-block; background: #FADBD8; color: #943126; padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.badge-muted { display: inline-block; background: var(--surface-muted); color: var(--text-muted); padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; }

/* ============================================================
   PERIOD SELECTOR
   ============================================================ */
.period-tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.tab-btn-period {
    flex: 1; min-width: 50px; padding: 8px;
    background: var(--sidebar-line); color: var(--sidebar-text); border: none; border-radius: 4px;
    cursor: pointer; font-weight: 600; transition: all 0.2s; font-size: 12px;
}
.tab-btn-period:hover { background: var(--sidebar-line-hover); }
.tab-btn-period.active { background: var(--yellow); color: var(--dark); }

.month-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.month-btn {
    min-height: 40px; padding: 8px; background: var(--sidebar-line); color: var(--sidebar-text); border: none; border-radius: 4px;
    cursor: pointer; font-size: 12px; font-weight: 500; transition: all 0.15s;
}
.month-btn:hover:not(:disabled) { background: var(--yellow); color: var(--dark); }
.month-btn.active { background: var(--yellow); color: var(--dark); font-weight: 700; }
.month-btn:disabled { opacity: 0.35; cursor: not-allowed; }
/* Synced, but Mobne has no sales for the period (e.g. before onboarding) — distinct from
   "not yet synced" (.month-btn:disabled): still clickable, so the reason stays reachable. */
.month-btn-empty { background: #2c2c2c; color: #9a9a9a; font-style: italic; text-decoration: line-through; }
.month-btn-empty.active { background: var(--sidebar-line-hover); color: #ddd; }

.period-status { font-size: 11px; color: var(--text-muted); text-align: center; padding: 6px; }

/* ============================================================
   SYNC STATUS
   ============================================================ */
.sync-status { font-size: 12px; color: var(--sidebar-text); padding: 8px 12px; background: rgba(255, 255, 255, 0.05); border-radius: 6px; margin-bottom: 8px; line-height: 1.4; }

.loading-status {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; background: rgba(46, 134, 193, 0.1);
    border: 1px solid rgba(46, 134, 193, 0.3); border-radius: 6px;
    font-size: 12px; color: var(--blue); margin-bottom: 12px;
}

.spinner-mini {
    display: inline-block; width: 12px; height: 12px;
    border: 2px solid rgba(46, 134, 193, 0.3);
    border-top-color: var(--blue); border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.jobs-list { display: flex; flex-direction: column; gap: 8px; }
.job-row {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; background: white; padding: 10px 14px; border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04); font-size: 13px;
}
.job-row .job-detail { color: var(--gray); font-size: 12px; }
.job-row .job-error { color: var(--negative); font-size: 12px; }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-tabs {
    display: flex; gap: 6px; overflow-x: auto; margin: 18px 0;
    padding-bottom: 4px;
}
.settings-tab {
    flex: 0 0 auto; padding: 9px 13px; border: 1px solid var(--border);
    border-radius: 18px; background: #fff; color: var(--dark);
    font-size: 13px; font-weight: 600; text-decoration: none;
}
.settings-tab:hover { border-color: var(--amber); }
.settings-tab.active { background: var(--dark); border-color: var(--dark); color: #fff; }
.settings-panel {
    background: #fff; border-radius: 12px; padding: 22px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.06);
}
.settings-panel h2 { font-size: 18px; margin-bottom: 6px; }
.settings-panel p { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.settings-heading {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; margin-bottom: 18px;
}
.settings-form, .settings-block { max-width: 900px; }
.settings-block { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--divider); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; }
.form-grid-wide { grid-column: 1 / -1; }
.settings-actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.settings-actions .btn-primary { width: auto; padding-left: 22px; padding-right: 22px; }
.inline-form {
    display: flex; align-items: end; gap: 10px; flex-wrap: wrap;
}
.inline-form > div { min-width: 180px; flex: 1; }
.inline-form .login-input { margin-bottom: 0; }
.table-wrap { width: 100%; overflow-x: auto; margin: 12px 0; }
.settings-panel table { width: 100%; border-collapse: collapse; font-size: 13px; }
.settings-panel th {
    padding: 9px 10px; background: var(--surface-muted); text-align: left;
}
.settings-panel td { padding: 9px 10px; border-bottom: 1px solid var(--divider); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
    .kpi-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .kpi-grid-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 901px) {
    .nav-backdrop { display: none !important; }
}
/* Below 900px the sidebar becomes an off-canvas drawer (body.nav-open, see app.js openNav).
   visibility:hidden keeps its links out of the tab order while it is closed. */
@media (max-width: 900px) {
    .sidebar {
        width: min(84vw, 300px); z-index: 200;
        transform: translateX(-100%); visibility: hidden;
        transition: transform 0.2s ease, visibility 0s linear 0.2s;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }
    body.nav-open .sidebar { transform: none; visibility: visible; transition: transform 0.2s ease; }
    body.nav-open { overflow: hidden; }
    .sidebar-close { display: inline-flex; }
    .main-col { margin-left: 0; }
    .topbar { padding: 8px 16px; }
    .topbar-menu { display: inline-flex; }
    .main-content { padding: 16px; }
    .row { flex-direction: column; }
    .kpi-grid-4, .kpi-grid-3, .kpi-grid-5 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .topbar .period-status { flex-basis: 100%; }
    .kpi-grid-4, .kpi-grid-3, .kpi-grid-2, .kpi-grid-5 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid-wide { grid-column: auto; }
    .settings-panel { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
