:root {
  --bg: #f5f5f2;
  --panel: rgba(255, 253, 250, 0.94);
  --ink: #121618;
  --muted: #5f6768;
  --accent: #dd6f4e;
  --accent-2: #0f6b71;
  --line: rgba(40, 55, 57, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.98), transparent 22%),
    linear-gradient(180deg, #fbfbf8 0%, #f6f6f2 42%, #f1f2ef 100%);
  color: var(--ink);
}

.topbar,
.tabs,
.tab-panel {
  position: relative;
  z-index: 1;
}

.topbar,
.filters,
.grid,
.cards {
  width: min(1400px, calc(100% - 32px));
  margin: 16px auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 16px;
  border: 1px solid rgba(40, 55, 57, 0.12);
  background:
    linear-gradient(90deg, rgba(15,107,113,0.16) 0 2.4%, transparent 2.4% 6.5%, rgba(255,255,255,0.78) 6.5% 93%, transparent 93% 97.6%, rgba(221,111,78,0.18) 97.6% 100%),
    linear-gradient(180deg, rgba(255,255,255,0.94), rgba(250,248,243,0.9));
  box-shadow: 0 18px 34px rgba(26, 37, 39, 0.07);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.topbar-copy {
  min-width: 0;
}

.brand-logo {
  width: 220px;
  height: auto;
  flex: 0 0 auto;
  display: block;
  border-radius: 6px;
}

h1 {
  margin: 0 0 4px;
  font-size: 32px;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
}

.button {
  padding: 10px 14px;
  border-radius: 8px;
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.button.secondary {
  background: #d8c3ad;
  color: var(--ink);
}

.tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 4px 0;
}

.tab-button {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.72);
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}

.tab-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  background:
    linear-gradient(90deg, rgba(15,107,113,0.05) 0 1.2%, transparent 1.2% 98.8%, rgba(221,111,78,0.06) 98.8% 100%),
    linear-gradient(180deg, rgba(255,255,255,0.9), rgba(251,248,242,0.82));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  position: relative;
  z-index: 20;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

select,
input[type="date"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  min-width: 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.card {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(251,247,240,0.88));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 16px 28px rgba(26, 37, 39, 0.06);
}

.card h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.card .value {
  font-size: 28px;
  font-weight: 700;
}

.card .subvalue {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.97), rgba(251,247,240,0.9));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 18px 32px rgba(26, 37, 39, 0.06);
  min-width: 0;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.callout-text {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.66);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.chart {
  width: 100%;
  height: 300px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.78), rgba(249,244,236,0.72)),
    linear-gradient(90deg, rgba(15,107,113,0.05) 1px, transparent 1px),
    linear-gradient(rgba(18,22,24,0.04) 1px, transparent 1px);
  background-size: auto, 36px 36px, 36px 36px;
  border-radius: 8px;
}

.chart.tall {
  height: 380px;
}

.table-wrap {
  overflow: auto;
  max-height: 480px;
  position: relative;
  z-index: 1;
}

#tab-storeview .table-wrap {
  max-height: none;
  overflow-x: auto;
  overflow-y: visible;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

th {
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}

td.num,
th.num {
  text-align: right;
}

.store-kpi-table,
.period-matrix-table {
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
}

.store-kpi-table col.store-col,
.period-matrix-table col.entity-col {
  width: 260px;
}

.store-kpi-table col.metric-col,
.period-matrix-table col.metric-col {
  width: 120px;
}

.store-kpi-table th,
.store-kpi-table td,
.period-matrix-table th,
.period-matrix-table td {
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  line-height: 1.2;
}

.store-kpi-table th:first-child,
.store-kpi-table td:first-child,
.period-matrix-table th:first-child,
.period-matrix-table td:first-child {
  text-align: left;
  white-space: normal;
  word-break: break-word;
  position: sticky;
  left: 0;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--line);
  z-index: 3;
}

.store-total-row td,
.period-total-row td {
  font-weight: 700;
  background: #f5ecdf;
}

.store-total-row td:first-child,
.period-total-row td:first-child {
  background: #f5ecdf;
}

.comparison-table {
  table-layout: fixed;
}

.comparison-table th,
.comparison-table td {
  text-align: center;
  vertical-align: middle;
  white-space: normal;
  word-break: break-word;
  line-height: 1.15;
  padding: 7px 5px;
  font-size: 12px;
}

.comparison-table th:first-child,
.comparison-table td:first-child {
  text-align: left;
  width: 26%;
}

.store-view-table {
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
}

.store-view-table col.week-col {
  width: 138px;
}

.store-view-table col.kpi-col {
  width: 74px;
}

.store-view-table col.day-col {
  width: 92px;
}

.store-view-table th,
.store-view-table td {
  text-align: center;
  vertical-align: middle;
  padding: 6px 4px;
  white-space: normal;
  line-height: 1.15;
  border: 1px solid rgba(40, 55, 57, 0.12);
}

.store-view-table th:first-child,
.store-view-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: rgba(255, 253, 250, 0.98);
  box-shadow: 1px 0 0 var(--line);
}

.store-view-table th:nth-child(2),
.store-view-table td:nth-child(2) {
  position: sticky;
  left: 138px;
  z-index: 3;
  background: rgba(255, 253, 250, 0.98);
  box-shadow: 1px 0 0 var(--line);
}

.store-view-weekend-head,
.store-view-weekend-cell {
  background: rgba(255, 244, 228, 0.72);
}

.store-view-summary-head,
.store-view-summary-cell {
  background: rgba(237, 247, 247, 0.72);
}

.store-view-week-id {
  font-weight: 700;
  color: var(--ink);
  font-size: 12px;
}

.store-view-week-range {
  margin-top: 3px;
  font-size: 10px;
  color: var(--muted);
}

.store-view-day-card {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
  padding: 5px 6px;
  border: 1.5px solid rgba(40, 55, 57, 0.22);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(249,245,238,0.92) 100%);
}

.store-view-day-date {
  align-self: flex-end;
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  color: var(--muted);
}

.store-view-day-value {
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.05;
  white-space: nowrap;
}

.delta-positive {
  color: #2f7a3f;
  font-weight: 700;
}

.delta-negative {
  color: #b13c30;
  font-weight: 700;
}

.delta-neutral {
  color: var(--muted);
  font-weight: 700;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

@media (max-width: 960px) {
  .topbar,
  .filters,
  .grid,
  .cards,
  .tabs {
    width: min(100% - 20px, 1400px);
    margin: 10px auto;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    border-radius: 8px;
  }

  .topbar-brand {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .brand-logo {
    width: min(180px, 58vw);
  }

  h1 {
    font-size: 26px;
    line-height: 1.05;
  }

  .topbar-copy p {
    font-size: 13px;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .button {
    width: 100%;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    gap: 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 8px;
  }

  .tab-button {
    flex: 0 0 auto;
  }

  .card .value {
    font-size: 24px;
  }

  .chart,
  .chart.tall {
    height: 320px;
  }

  .table-wrap {
    max-width: 100%;
  }
}
