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

body {
  font-family: 'Inter', sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  font-size: 13px
}

:root {
  --primary: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-dark: #1e3a8a;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0891b2;
  --neutral: #64748b;
  --card: #ffffff;
  --border: #e2e8f0;
  --text-muted: #94a3b8;
  --bg: #f1f5f9
}

/* ─── Layout ─────────────────────────────────────────────── */
.app-header {
  background: var(--primary-dark);
  color: #fff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25)
}

.app-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .3px
}

.app-header .subtitle {
  font-size: 11px;
  color: #93c5fd;
  margin-top: 1px
}

.sticky-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08)
}

.filter-bar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px
}

.filter-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--neutral);
  white-space: nowrap
}

.btn-group {
  display: flex;
  gap: 2px
}

.btn-period {
  border: 1px solid var(--border);
  background: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s
}

.btn-period:hover {
  border-color: var(--primary);
  color: var(--primary)
}

.btn-period.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary)
}

select.filter-select {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-family: inherit;
  background: #fff;
  cursor: pointer;
  outline: none
}

select.filter-select:focus {
  border-color: var(--primary)
}

/* ─── Nav Tabs ───────────────────────────────────────────── */
.nav-tabs {
  display: flex;
  background: #fff;
  border-bottom: 2px solid var(--border);
  padding: 0 24px;
  gap: 0;
  overflow-x: auto
}

.nav-tab {
  padding: 10px 18px;
  font-size: 12px;
  font-weight: 500;
  color: var(--neutral);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 6px
}

.nav-tab:hover {
  color: var(--primary);
  background: #f8fafc
}

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600
}

.nav-tab .tab-icon {
  font-size: 14px
}

/* ─── Pages ──────────────────────────────────────────────── */
.page {
  display: none;
  padding: 20px 24px
}

.page.active {
  display: block
}

/* ─── Section ────────────────────────────────────────────── */
.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--neutral);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border)
}

/* ─── KPI Cards ──────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px
}

.kpi-card {
  background: var(--card);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
  border-radius: 10px 0 0 10px
}

.kpi-card.success::before {
  background: var(--success)
}

.kpi-card.warning::before {
  background: var(--warning)
}

.kpi-card.danger::before {
  background: var(--danger)
}

.kpi-card.info::before {
  background: var(--info)
}

.kpi-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--neutral);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1;
  margin-bottom: 6px
}

.kpi-unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--neutral);
  margin-left: 2px
}

.kpi-compare {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px
}

.kpi-compare .up {
  color: var(--success)
}

.kpi-compare .down {
  color: var(--danger)
}

.kpi-compare .neutral {
  color: var(--neutral)
}

/* ─── Grid layouts ───────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px
}

.grid-3 {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px
}

.grid-1-2 {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 16px;
  margin-bottom: 20px
}

@media(max-width:900px) {

  .grid-2,
  .grid-3,
  .grid-1-2 {
    grid-template-columns: 1fr
  }
}

/* ─── Chart card ─────────────────────────────────────────── */
.chart-card {
  background: var(--card);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
  border: 1px solid var(--border)
}

.chart-card h3 {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between
}

.chart-card h3 .badge {
  font-size: 10px;
  font-weight: 400;
  background: #f1f5f9;
  color: var(--neutral);
  padding: 2px 8px;
  border-radius: 20px
}

.chart-container {
  position: relative
}

/* ─── Table ──────────────────────────────────────────────── */
.table-card {
  background: var(--card);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
  border: 1px solid var(--border);
  margin-bottom: 16px
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
  flex-wrap: wrap
}

.table-toolbar h3 {
  font-size: 12px;
  font-weight: 600;
  color: #334155
}

.search-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-family: inherit;
  outline: none;
  width: 200px
}

.search-input:focus {
  border-color: var(--primary)
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px
}

.data-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--neutral);
  padding: 7px 10px;
  text-align: right;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0
}

.data-table th:first-child,
.data-table th:nth-child(2) {
  text-align: left
}

.data-table th:hover {
  background: #f1f5f9;
  color: var(--primary)
}

.data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #f1f5f9;
  text-align: right;
  vertical-align: middle
}

.data-table td:first-child,
.data-table td:nth-child(2) {
  text-align: left
}

.data-table tr:hover {
  background: #f8fafc
}

.table-wrapper {
  max-height: 400px;
  overflow-y: auto;
  border-radius: 6px;
  border: 1px solid var(--border)
}

/* ─── Rating badges ──────────────────────────────────────── */
.badge-a {
  background: #dcfce7;
  color: #15803d;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 10px
}

.badge-b {
  background: #dbeafe;
  color: #1d4ed8;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 10px
}

.badge-c {
  background: #fef3c7;
  color: #b45309;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 10px
}

.badge-d1 {
  background: #fee2e2;
  color: #b91c1c;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 10px
}

.badge-d2 {
  background: #f3e8ff;
  color: #7e22ce;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 10px
}

/* ─── Mini chips ─────────────────────────────────────────── */
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 500
}

.chip-open {
  background: #dcfce7;
  color: #15803d
}

.chip-closed {
  background: #fee2e2;
  color: #b91c1c
}

/* ─── Change indicator ───────────────────────────────────── */
.chg-pos {
  color: var(--success);
  font-weight: 500
}

.chg-neg {
  color: var(--danger);
  font-weight: 500
}

.chg-neutral {
  color: var(--neutral)
}

/* ─── Loading overlay ────────────────────────────────────── */
#loading {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, .9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  gap: 12px
}

#loading .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite
}

@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}

#loading p {
  font-size: 13px;
  color: var(--neutral)
}

/* ─── P&L Table special ──────────────────────────────────── */
.pnl-table th {
  min-width: 90px
}

.pnl-section {
  background: #f8fafc;
  font-weight: 600;
  color: #334155
}

.pnl-gross {
  background: #eff6ff
}

.pnl-noi {
  background: #f0fdf4
}

.pnl-alloc {
  background: #fff7ed;
  color: #92400e
}

.pnl-pbt {
  background: #fef3c7;
  font-weight: 700
}

.pnl-ebitda {
  background: #dcfce7;
  font-weight: 700;
  color: #14532d
}

/* stacked value + % in one cell */
.pnl-val {
  line-height: 1.3
}

.pnl-pct {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 1px
}

/* ─── Rating legend ──────────────────────────────────────── */
.rating-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  background: #f8fafc;
  border-radius: 6px;
  margin-top: 8px;
  border: 1px solid var(--border)
}

.rating-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: #475569
}

/* ─── Heatmap ────────────────────────────────────────────── */
#heatmap-canvas {
  display: block;
  margin: auto
}

.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 10px;
  color: var(--neutral)
}

.heatmap-legend-bar {
  width: 120px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #dbeafe, #1e40af)
}

/* ─── Scatter labels ─────────────────────────────────────── */
.tooltip-custom {
  position: absolute;
  background: rgba(15, 23, 42, .9);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11px;
  pointer-events: none;
  white-space: nowrap;
  line-height: 1.6;
  z-index: 1000
}

/* ─── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 12px
}

.empty-state .icon {
  font-size: 32px;
  margin-bottom: 8px
}

/* ─── Store P&L Modal ─────────────────────────────────────── */
#store-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 2000;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto
}

#store-modal-overlay.open {
  display: flex
}

#store-modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 920px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  overflow: hidden;
  margin: auto
}

.modal-header {
  background: var(--primary-dark);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px
}

.modal-header-info h2 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px
}

.modal-header-info .meta {
  font-size: 11px;
  color: #93c5fd;
  display: flex;
  flex-wrap: wrap;
  gap: 10px
}

.modal-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: .8
}

.modal-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, .15)
}

.modal-body {
  padding: 20px
}

.modal-kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 18px
}

@media(max-width:700px) {
  .modal-kpi-row {
    grid-template-columns: repeat(3, 1fr)
  }
}

.modal-kpi {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px
}

.modal-kpi .mk-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--neutral);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 4px
}

.modal-kpi .mk-value {
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.2
}

.modal-kpi .mk-unit {
  font-size: 10px;
  font-weight: 400;
  color: var(--neutral);
  margin-left: 2px
}

.modal-kpi .mk-sub {
  font-size: 10px;
  color: var(--neutral);
  margin-top: 3px
}

.modal-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--neutral);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 16px 0 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px
}

/* KPI Vận hành per-shift */
#modal-kpi-ops {
  margin-bottom: 16px
}

.kpi-ops-grid {
  display: flex;
  flex-direction: column;
  gap: 8px
}

.kpi-ops-dt {
  display: flex;
  gap: 24px;
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px
}

.kpi-ops-dt-label {
  color: var(--neutral);
  font-weight: 500
}

.kpi-ops-dt-val {
  font-weight: 700;
  color: #1e293b;
  font-size: 14px
}

.kpi-ops-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px
}

.kpi-ops-table th {
  background: #f1f5f9;
  color: var(--neutral);
  font-weight: 600;
  padding: 5px 10px;
  text-align: center;
  border: 1px solid var(--border)
}

.kpi-ops-table td {
  padding: 5px 10px;
  text-align: center;
  border: 1px solid var(--border)
}

.kpi-ops-row-label {
  font-weight: 600;
  text-align: left !important;
  color: var(--neutral);
  background: #fafafa
}

.kpi-ops-tc-row td {
  color: var(--text-muted);
  font-style: italic
}

.modal-pnl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-bottom: 4px
}

.modal-pnl-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--neutral);
  padding: 6px 10px;
  text-align: right;
  border-bottom: 2px solid var(--border)
}

.modal-pnl-table th:first-child {
  text-align: left;
  min-width: 160px
}

.modal-pnl-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #f1f5f9;
  text-align: right
}

.modal-pnl-table td:first-child {
  text-align: left;
  padding-left: 12px
}

.modal-pnl-table tr.pnl-gross td {
  background: #eff6ff;
  font-weight: 600
}

.modal-pnl-table tr.pnl-noi td {
  background: #f0fdf4;
  font-weight: 700
}

.modal-pnl-table tr.pnl-section td {
  background: #f8fafc;
  font-weight: 600;
  color: #334155
}

.modal-chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 16px
}

@media(max-width:600px) {
  .modal-chart-row {
    grid-template-columns: 1fr
  }
}

.store-link {
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  background: none;
  border: none;
  font-size: inherit;
  font-family: inherit;
  padding: 0;
  text-align: left
}

.store-link:hover {
  text-decoration: underline
}

/* ── Comparison Tab ─────────────────────────────────────────────── */
.cmp-selectors {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--card);
  border-radius: 8px;
  margin-bottom: 16px;
  align-items: flex-end;
  flex-wrap: wrap
}

.cmp-sel-group {
  display: flex;
  flex-direction: column;
  gap: 4px
}

.cmp-auto-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px
}

.cmp-auto-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px
}

.cmp-auto-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text)
}

.cmp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px
}

.cmp-table th {
  background: var(--card-header);
  padding: 10px 12px;
  text-align: center;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1
}

.cmp-table th.cmp-th-label {
  text-align: left;
  min-width: 160px
}

.cmp-table th.cmp-th-auto {
  background: rgba(234, 179, 8, 0.12)
}

.cmp-table td {
  padding: 7px 12px;
  text-align: right;
  border: 1px solid var(--border);
  white-space: nowrap
}

.cmp-table td.cmp-label {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  white-space: normal
}

.cmp-table tr.cmp-section-row td {
  background: var(--card-header);
  font-weight: 700;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .6px
}

.cmp-best {
  color: var(--success) !important;
  font-weight: 700
}

.cmp-worst {
  color: var(--danger) !important
}

.cmp-null {
  color: var(--text-muted);
  font-style: italic
}

/* ── Aggregate P&L full table ───────────────────────────────────── */
#agg-pnl-table th:first-child,
#agg-pnl-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #f8fafc;
  min-width: 150px;
  border-right: 2px solid var(--border)
}

#agg-pnl-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  white-space: nowrap
}

#agg-pnl-table thead th:first-child {
  z-index: 4
}

#agg-pnl-table td,
#agg-pnl-table th {
  padding: 5px 8px;
  text-align: right;
  border: 1px solid var(--border);
  white-space: nowrap;
  font-size: 11px
}

.agg-pnl-yoy {
  background: #f0fdf4;
  min-width: 70px;
  text-align: center !important
}

.agg-pnl-year-sep {
  border-left: 3px solid var(--primary) !important
}

.agg-pnl-pct {
  display: block;
  font-size: 9px;
  color: var(--neutral);
  line-height: 1.2
}

/* ── Modal mini-comparison ──────────────────────────────────────── */
.modal-best-cmp {
  margin: 0 0 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden
}

.mini-cmp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--card-header);
  font-size: 12px;
  font-weight: 600
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 0
}

.btn-link:hover {
  text-decoration: underline
}

.mini-cmp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px
}

.mini-cmp-table th {
  background: var(--card-header);
  padding: 6px 10px;
  text-align: center;
  border: 1px solid var(--border);
  font-size: 11px
}

.mini-cmp-table th.mcmp-label {
  text-align: left;
  min-width: 100px
}

.mini-cmp-table td {
  padding: 5px 10px;
  text-align: right;
  border: 1px solid var(--border)
}

.mini-cmp-table td.mcmp-label {
  text-align: left;
  color: var(--text-muted);
  background: var(--bg)
}

/* ── 3-Year YoY section ─────────────────────────────────────────── */
#modal-yoy-section {
  margin: 0 0 16px
}

.yoy-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px
}

.yoy-table th {
  background: var(--card-header);
  padding: 7px 10px;
  text-align: center;
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600
}

.yoy-table th.yoy-label {
  text-align: left;
  min-width: 110px
}

.yoy-table th.yoy-yoy {
  background: rgba(99, 102, 241, 0.08);
  font-size: 10px;
  color: var(--text-muted)
}

.yoy-table td {
  padding: 6px 10px;
  text-align: right;
  border: 1px solid var(--border);
  white-space: nowrap
}

.yoy-table td.yoy-label {
  text-align: left;
  color: var(--text-muted);
  background: var(--bg)
}

.yoy-table td.yoy-yoy {
  background: rgba(99, 102, 241, 0.04);
  font-size: 11px
}

.yoy-up {
  color: var(--success);
  font-weight: 600
}

.yoy-dn {
  color: var(--danger);
  font-weight: 600
}

/* ── Comparison brand filter row ───────────────────────────────── */
.cmp-brand-row {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  background: var(--card);
  border-radius: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap
}

.cmp-related-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px
}

.cmp-chip {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  transition: all .15s
}

.cmp-chip:hover {
  border-color: var(--primary);
  color: var(--primary)
}

.cmp-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary)
}

/* ── KPI sub-label ──────────────────────────────────────────────── */
.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px
}

/* ── YoY null cell ──────────────────────────────────────────────── */
.yoy-null {
  color: var(--text-muted);
  font-style: italic
}

/* ── Winning Team + RM History (modal) ──────────────────────────── */
.modal-hr-section {
  margin: 0 0 16px
}

.modal-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px
}

.winning-team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 12px
}

.wt-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px
}

.wt-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 2px
}

.wt-val {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
  line-height: 1.3
}

.wt-code {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  font-family: monospace
}

.wt-phone {
  display: block;
  font-size: 11px;
  color: var(--primary);
  text-decoration: none;
  margin-top: 3px
}

.wt-phone:hover {
  text-decoration: underline
}

.wt-note-badge {
  font-size: 9px;
  background: #fef3c7;
  color: #92400e;
  border-radius: 4px;
  padding: 1px 4px;
  margin-left: 4px;
  font-weight: 500
}

.wt-empty {
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic
}

.rm-acting-badge {
  display: inline-block;
  font-size: 9px;
  background: rgba(234, 179, 8, 0.2);
  color: #92400e;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  font-weight: 700;
  vertical-align: middle
}

/* RM History table */
.rm-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px
}

.rm-history-table th {
  background: var(--card-header);
  padding: 7px 10px;
  text-align: left;
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap
}

.rm-history-table td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  vertical-align: middle
}

.rm-history-table tbody tr:hover {
  background: var(--primary-light)
}

.rm-mini-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  min-width: 60px;
  gap: 1px
}

.rm-mini-bar-seg {
  height: 100%;
  min-width: 2px
}

.rm-mini-bar-seg.seg-a {
  background: #16a34a
}

.rm-mini-bar-seg.seg-b {
  background: #22d3ee
}

.rm-mini-bar-seg.seg-c {
  background: #d97706
}

.rm-mini-bar-seg.seg-d1 {
  background: #f97316
}

.rm-mini-bar-seg.seg-d2 {
  background: #dc2626
}

.trend-up2 {
  color: var(--success);
  font-weight: 700
}

.trend-up1 {
  color: #4ade80;
  font-weight: 600
}

.trend-neu {
  color: var(--text-muted)
}

.trend-dn1 {
  color: #fb923c;
  font-weight: 600
}

.trend-dn2 {
  color: var(--danger);
  font-weight: 700
}

/* ── p7 — RM Analytics ──────────────────────────────────────────── */
#p7 {
  padding: 0
}

.p7-top {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px
}

.p7-top .card {
  flex: 1;
  min-width: 0
}

.p7-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 12px;
  height: calc(100vh - 180px);
  min-height: 400px
}

@media(max-width:960px) {
  .p7-layout {
    grid-template-columns: 1fr
  }
}

.p7-table-wrap {
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid var(--border)
}

.rm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px
}

.rm-table th {
  background: var(--card-header);
  padding: 9px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
  cursor: pointer;
  white-space: nowrap;
  user-select: none
}

.rm-table th:not(:first-child) {
  text-align: center
}

.rm-table th.sort-asc::after {
  content: ' ▲';
  font-size: 9px;
  color: var(--primary)
}

.rm-table th.sort-desc::after {
  content: ' ▼';
  font-size: 9px;
  color: var(--primary)
}

.rm-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle
}

.rm-table td:not(:first-child) {
  text-align: center
}

.rm-table tbody tr {
  cursor: pointer;
  transition: background .1s
}

.rm-table tbody tr:hover {
  background: var(--primary-light)
}

.rm-table tbody tr.rm-selected {
  background: rgba(29, 78, 216, 0.08);
  outline: 2px solid var(--primary) inset
}

.eff-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%
}

.eff-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  min-width: 40px
}

.eff-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--primary)
}

.eff-val {
  font-size: 11px;
  font-weight: 600;
  min-width: 28px;
  text-align: right
}

.rm-turnaround-badge {
  display: inline-block;
  font-size: 9px;
  background: rgba(22, 163, 74, 0.15);
  color: #15803d;
  border-radius: 4px;
  padding: 1px 5px;
  font-weight: 700;
  margin-left: 4px
}

/* RM detail panel */
.rm-detail-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow-y: auto;
  font-size: 12px
}

.rm-detail-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px
}

.rm-detail-meta {
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 12px
}

.rm-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px
}

.rm-kpi-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px
}

.rm-kpi-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px
}

.rm-kpi-val {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px
}

.rm-rating-dist {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  flex-wrap: wrap
}

.rm-rating-dist-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 36px
}

.rm-rating-dist-bar-wrap {
  height: 50px;
  display: flex;
  align-items: flex-end;
  width: 24px
}

.rm-rating-dist-bar {
  width: 100%;
  border-radius: 2px 2px 0 0;
  min-height: 2px
}

.rm-rating-dist-label {
  font-size: 10px;
  font-weight: 600
}

.rm-rating-dist-count {
  font-size: 10px;
  color: var(--text-muted)
}

.rm-store-tenure {
  margin-top: 4px
}

.rm-store-tenure-row {
  padding: 7px 0;
  border-bottom: 1px solid var(--border)
}

.rm-store-tenure-row:last-child {
  border-bottom: none
}

.rm-store-name {
  font-weight: 600;
  margin-bottom: 3px
}

.rm-store-period {
  font-size: 11px;
  color: var(--text-muted)
}

.p7-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  flex-direction: column;
  gap: 8px;
  padding: 40px
}

.p7-empty-icon {
  font-size: 40px;
  opacity: .4
}

/* ── Print / PDF styles ──────────────────────────────────────────── */
#pdf-print-area {
  display: none;
}

@media print {

  /* Hide everything except the dedicated print container */
  body>*:not(#pdf-print-area) {
    display: none !important;
  }

  #pdf-print-area {
    display: block !important;
    overflow: visible !important;
  }

  /* Modal inside print area: remove visual chrome */
  #pdf-print-area #store-modal {
    max-width: 100% !important;
    width: 100% !important;
    overflow: visible !important;
    max-height: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }

  /* Unconstrain all inner containers */
  #pdf-print-area * {
    overflow: visible !important;
    max-height: none !important;
  }

  /* Modal header keep colors */
  #pdf-print-area .modal-header {
    background: #1e3a8a !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Page breaks */
  .modal-pnl-table tr,
  .yoy-table tr {
    page-break-inside: avoid;
  }

  .modal-section-title {
    page-break-after: avoid;
  }

  /* Preserve all colors */
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile / Tablet
   ══════════════════════════════════════════════════════════════ */

/* ── P2 cost charts grid (replaces inline style) ─────────────── */
.grid-cost-charts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

/* ── Nav tab scroll fade indicator ──────────────────────────── */
.nav-tabs-wrap {
  position: relative;
}
.nav-tabs-wrap::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 40px;
  background: linear-gradient(to right, transparent, #fff);
  pointer-events: none;
  z-index: 1;
}

/* Mobile filter toggle button — hidden on desktop */
.filter-toggle-btn {
  display: none;
}

/* ── Tablet (≤900px) ── */
@media (max-width: 900px) {
  /* grid-3 → 2 columns at tablet */
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Tablet (≤768px) ── */
@media (max-width: 768px) {
  .page { padding: 12px 16px; }
  .app-header { padding: 10px 16px; }
  .filter-bar { padding: 6px 16px; gap: 10px; }
  .nav-tabs { padding: 0 8px; -webkit-overflow-scrolling: touch; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

  /* grid-3 → 1 column at tablet */
  .grid-3 { grid-template-columns: 1fr; }

  /* cost charts: 2 cols at tablet */
  .grid-cost-charts { grid-template-columns: repeat(2, 1fr); }

  /* P6 comparison selectors */
  .cmp-selectors {
    flex-wrap: wrap;
  }
  .cmp-sel-group {
    min-width: 180px;
    flex: 1 1 180px;
  }

  /* Modal chart row stacks */
  .modal-chart-row {
    grid-template-columns: 1fr;
  }
}

/* ── Phone (≤480px) ── */
@media (max-width: 480px) {
  body { font-size: 12px; }
  .page { padding: 8px 12px; }

  /* Header */
  .app-header { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
  .app-header h1 { font-size: 13px; }
  .app-header .subtitle { display: none; }
  .app-header > div:last-child { display: none; }

  /* Nav tabs */
  .nav-tabs {
    padding: 0 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tab { padding: 8px 10px; font-size: 11px; white-space: nowrap; }
  .nav-tab .tab-icon { font-size: 13px; }

  /* Filter bar toggle */
  .filter-bar {
    padding: 6px 12px;
    gap: 8px;
  }
  .filter-bar.collapsed { display: none; }
  .filter-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    background: #f1f5f9;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    font-size: 12px;
    font-family: inherit;
    color: #374151;
    cursor: pointer;
    font-weight: 500;
  }

  /* Grids → single column */
  .grid-2,
  .grid-3,
  .grid-1-2,
  .grid-cost-charts {
    grid-template-columns: 1fr;
  }

  /* KPI cards */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 18px; }

  /* Tables */
  .filter-select { font-size: 12px; min-height: 36px; }
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-card { padding: 10px 8px; }
  .search-input { width: 100%; max-width: none; }

  /* P2 P&L sticky column — narrower on mobile */
  .pnl-table td:first-child,
  .pnl-table th:first-child,
  .data-table td:first-child,
  .data-table th:first-child {
    max-width: 110px;
    min-width: 90px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Charts */
  .chart-container { min-height: 160px; }
  .chart-card { padding: 10px; }
  .chart-card h3 { font-size: 11px; }

  /* Cost charts: 1 col on mobile */
  .grid-cost-charts { grid-template-columns: 1fr; }

  /* Modal */
  #store-modal { border-radius: 8px; margin: 0; }
  .modal-body { padding: 12px; }
  .modal-header { padding: 12px 14px; }
  .modal-header-info h2 { font-size: 13px; }
  .modal-kpi-row { grid-template-columns: repeat(2, 1fr); }

  /* Modal buttons — more spacing to avoid mis-taps */
  .modal-header > div:last-child {
    display: flex;
    gap: 10px;
    align-items: center;
  }
  .modal-close {
    padding: 6px 10px;
    font-size: 18px;
    min-width: 36px;
  }
  #modal-pdf-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Modal chart row */
  .modal-chart-row { grid-template-columns: 1fr; }

  /* P6 comparison */
  .cmp-selectors { flex-direction: column; }
  .cmp-sel-group { width: 100%; }
  .cmp-auto-col { display: none; }

  /* Filter bar reset button */
  #btn-reset-filter { margin-top: 4px; }
}