/* ── Merchant reports kit (phase 124) ─────────────────────────────────────────
   Shared by reports.php (the hub) and every rk-* report page. Everything is scoped under
   .rk so it cannot leak into the rest of the portal. Colours are tokens on .rk; chart colours
   follow the data-viz reference palette (one blue series, a grey previous period, a sequential
   blue ramp for magnitude, a fixed status palette that always ships with an icon + label). */
.rk {
    --rk-surface: #fcfcfb;
    --rk-plane: #f4f5f7;
    --rk-ink: #0b0b0b;
    --rk-ink-2: #52514e;
    --rk-muted: #898781;
    --rk-grid: #e1e0d9;
    --rk-border: rgba(11, 11, 11, .10);
    --rk-accent: #2a78d6;
    --rk-accent-ink: #1c5cab;
    --rk-good: #006300;
    --rk-bad: #b42318;
    --rk-status-good: #0ca30c;
    --rk-status-warning: #fab219;
    --rk-status-serious: #ec835a;
    --rk-status-critical: #d03b3b;
    --rk-seq-1: #cde2fb;
    --rk-seq-2: #86b6ef;
    --rk-seq-3: #3987e5;
    --rk-seq-4: #1c5cab;
    --rk-seq-5: #0d366b;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--rk-ink);
    padding: 8px 4px 32px;
}
.rk *, .rk *::before, .rk *::after { box-sizing: border-box; }
.content-area.rk-host { overflow: visible !important; min-width: 0; }
.rk { min-width: 0; max-width: 100%; }

/* Page header */
.rk-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.rk-title { font-size: 22px; font-weight: 700; margin: 0; line-height: 1.2; }
.rk-sub { color: var(--rk-ink-2); font-size: 13.5px; margin: 4px 0 0; max-width: 720px; }
.rk-crumb { font-size: 12px; color: var(--rk-muted); margin-bottom: 4px; }
.rk-crumb a { color: var(--rk-accent-ink); }

/* Controls row: filters left, actions right */
.rk-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.rk-controls .rk-spacer { flex: 1 1 auto; }
.rk-btn, .rk-range, .rk-select, .rk-input {
    height: 36px; border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; color: var(--rk-ink);
    font-size: 13.5px; padding: 0 12px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
}
.rk-range { min-width: 250px; }
.rk-range .fa { color: var(--rk-muted); }
.rk-select { padding-right: 28px; cursor: pointer; }
.rk-input { cursor: text; }
.rk-btn:hover, .rk-range:hover { border-color: #9aa3b0; }
.rk-btn:focus-visible, .rk-range:focus-visible, .rk-select:focus-visible, .rk-input:focus-visible, .rk-chip:focus-visible,
.rk-th-sort:focus-visible { outline: 2px solid var(--rk-accent); outline-offset: 2px; }
.rk-btn-primary { background: var(--rk-accent); border-color: var(--rk-accent); color: #fff; }
.rk-btn-primary:hover { background: var(--rk-accent-ink); border-color: var(--rk-accent-ink); }
.rk-btn[disabled] { opacity: .55; cursor: default; }

/* Cards */
.rk-card { background: var(--rk-surface); border: 1px solid var(--rk-border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.rk-card h3 { font-size: 15px; font-weight: 700; margin: 0 0 2px; }
.rk-card .rk-card-sub { font-size: 12.5px; color: var(--rk-muted); margin: 0 0 12px; }
.rk-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.rk-grid { display: grid; gap: 16px; }
.rk-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.rk-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.rk-grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 991px) { .rk-grid-2, .rk-grid-3, .rk-grid-2-1 { grid-template-columns: minmax(0, 1fr); } }
.rk-grid > .rk-card { margin-bottom: 0; }
.rk-grid + .rk-card, .rk-grid + .rk-grid { margin-top: 16px; }

/* KPI tiles */
.rk-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.rk-kpi { background: var(--rk-surface); border: 1px solid var(--rk-border); border-radius: 12px; padding: 14px 16px; min-height: 96px; }
.rk-kpi-label { font-size: 12px; color: var(--rk-ink-2); font-weight: 600; letter-spacing: .2px; }
.rk-kpi-value { font-size: 24px; font-weight: 700; margin: 6px 0 4px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rk-kpi-value.l { font-size: 20px; }
.rk-kpi-value.xl { font-size: 17px; }
.rk-kpi-foot { font-size: 12px; color: var(--rk-muted); }
.rk-delta { font-weight: 600; white-space: nowrap; }
.rk-delta.up-good, .rk-delta.down-good { color: var(--rk-good); }
.rk-delta.up-bad, .rk-delta.down-bad { color: var(--rk-bad); }
.rk-delta.flat { color: var(--rk-muted); }
.rk-kpi.rk-kpi-hero { border-left: 4px solid var(--rk-accent); }

/* Charts */
.rk-chart { width: 100%; height: 280px; }
.rk-chart-sm { height: 220px; }
.rk-chart-tall { height: 340px; }
.rk-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--rk-ink-2); }
.rk-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.rk-legend i.dash { background: repeating-linear-gradient(90deg, #898781 0 4px, transparent 4px 7px); }

/* Horizontal share bars (payment types, tills, cashiers...) */
.rk-bars { display: flex; flex-direction: column; gap: 10px; }
.rk-bar-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.rk-bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--rk-ink); }
.rk-bar-track { display: block; height: 10px; background: #eef0f3; border-radius: 4px; overflow: hidden; }
.rk-bar-fill { display: block; height: 100%; background: var(--rk-accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.rk-bar-val { font-variant-numeric: tabular-nums; color: var(--rk-ink-2); white-space: nowrap; text-align: right; }
.rk-bar-val b { color: var(--rk-ink); font-weight: 600; }

/* Aging strip */
.rk-strip { display: flex; height: 18px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--rk-surface); margin: 8px 0 10px; }
.rk-strip span { display: block; height: 100%; min-width: 3px; }
.rk-strip-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 16px; font-size: 12.5px; }
.rk-strip-legend div { display: flex; flex-direction: column; }
.rk-strip-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.rk-strip-legend b { font-size: 15px; font-variant-numeric: tabular-nums; }

/* Tables */
.rk-table-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.rk-table-tools .rk-input { min-width: 220px; flex: 0 1 280px; }
.rk-table-tools .rk-count { font-size: 12.5px; color: var(--rk-muted); margin-left: auto; }
.rk-table-wrap { overflow-x: auto; border: 1px solid var(--rk-border); border-radius: 10px; }
.rk-table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
.rk-table th { position: sticky; top: 0; background: #f6f7f9; color: var(--rk-ink-2); font-weight: 600; font-size: 12px;
    text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--rk-grid); white-space: nowrap; z-index: 1; }
.rk-table td { padding: 8px 10px; border-bottom: 1px solid #f0f0ee; vertical-align: middle; white-space: nowrap; }
.rk-table td.rk-wrap { white-space: normal; min-width: 160px; }
.rk-table tbody tr:hover td { background: #f7faff; }
.rk-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rk-table tfoot td { font-weight: 700; background: #f6f7f9; border-top: 1px solid var(--rk-grid); border-bottom: 0; }
.rk-th-sort { cursor: pointer; user-select: none; }
.rk-th-sort::after { content: "\2195"; color: #c3c2b7; margin-left: 4px; font-size: 11px; }
.rk-th-sort.asc::after { content: "\2191"; color: var(--rk-ink-2); }
.rk-th-sort.desc::after { content: "\2193"; color: var(--rk-ink-2); }
.rk-table .muted { color: var(--rk-muted); }
.rk-table .neg { color: var(--rk-bad); }
.rk-pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 10px; font-size: 12.5px; color: var(--rk-ink-2); flex-wrap: wrap; }
.rk-pager .rk-btn { height: 30px; padding: 0 10px; }
.rk-empty { text-align: center; color: var(--rk-muted); padding: 28px 12px !important; }

/* Chips: status / filters */
.rk-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.rk-chip { border: 1px solid #cfd4dc; background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 12.5px; cursor: pointer; color: var(--rk-ink); display: inline-flex; align-items: center; gap: 6px; }
.rk-chip b { font-variant-numeric: tabular-nums; }
.rk-chip.on { border-color: var(--rk-accent); background: #eaf2fc; color: var(--rk-accent-ink); }
.rk-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.rk-pill .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.rk-pill .fa { font-size: 12px; }

/* Notes, states */
.rk-note { font-size: 12.5px; color: var(--rk-ink-2); background: #f6f7f9; border-radius: 8px; padding: 10px 12px; margin: 0 0 16px; }
.rk-note b { color: var(--rk-ink); }
.rk-state { padding: 36px 12px; text-align: center; color: var(--rk-muted); font-size: 13.5px; }
.rk-state.err { color: var(--rk-bad); }
.rk-skel { background: linear-gradient(90deg, #eef0f3 25%, #f6f7f9 50%, #eef0f3 75%); background-size: 200% 100%; animation: rk-sh 1.2s infinite; border-radius: 6px; }
@keyframes rk-sh { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .rk-skel { animation: none; } }

/* Heatmap (weekday x hour) */
.rk-heat { display: grid; grid-template-columns: 38px repeat(24, minmax(14px, 1fr)); gap: 2px; font-size: 10.5px; color: var(--rk-muted); min-width: 460px; }
.rk-heat div { height: 20px; border-radius: 3px; }
.rk-heat .lbl { background: none; display: flex; align-items: center; height: auto; }
.rk-heat .hl { background: none; text-align: center; height: auto; }
.rk-heat-wrap { overflow-x: auto; }

/* Hub */
.rk-hub-group { margin-bottom: 22px; }
.rk-hub-group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--rk-ink-2); margin: 0 0 10px; font-weight: 700; }
.rk-hub { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.rk-tile { display: flex; flex-direction: column; gap: 6px; background: var(--rk-surface); border: 1px solid var(--rk-border); border-radius: 12px;
    padding: 14px 16px; color: var(--rk-ink) !important; text-decoration: none !important; transition: border-color .15s, box-shadow .15s; min-height: 118px; }
.rk-tile:hover, .rk-tile:focus-visible { border-color: var(--rk-accent); box-shadow: 0 2px 10px rgba(42, 120, 214, .12); outline: none; }
.rk-tile-top { display: flex; align-items: center; gap: 10px; }
.rk-tile-ic { width: 34px; height: 34px; border-radius: 9px; background: #eaf2fc; color: var(--rk-accent-ink); display: flex; align-items: center; justify-content: center; font-size: 15px; flex: none; }
.rk-tile-name { font-weight: 700; font-size: 14.5px; }
.rk-tile-q { font-size: 12.5px; color: var(--rk-ink-2); line-height: 1.4; }
.rk-badge { font-size: 10.5px; font-weight: 700; letter-spacing: .3px; color: var(--rk-accent-ink); background: #eaf2fc; border-radius: 999px; padding: 2px 8px; margin-left: auto; }
.rk-hub-search { margin-bottom: 18px; }
.rk-hub-search .rk-input { width: 100%; max-width: 420px; }

/* Print: just the report */
@media print {
    #sidebar, .navbar, .header, .app-header, .rk-controls, .rk-table-tools, .rk-pager, .rk-noprint, footer, .footer { display: none !important; }
    .content-area, .rk { padding: 0 !important; margin: 0 !important; }
    .rk-card, .rk-kpi { break-inside: avoid; border-color: #ccc; }
    .rk-table-wrap { overflow: visible; border: 0; }
    .rk-table th { position: static; }
}
@media (max-width: 575px) {
    .rk-title { font-size: 19px; }
    .rk-range { min-width: 0; width: 100%; }
    .rk-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .rk-kpi { padding: 12px; min-height: 0; }
    .rk-kpi-value, .rk-kpi-value.l { font-size: 17px; }
    .rk-kpi-value.xl { font-size: 15px; }
    .rk-bar-row { grid-template-columns: minmax(70px, 38%) 1fr auto; }
}
