/* Mahasamut Car Wash — Dashboard theme
   Brand: deep green #183D2E, orange #F28C28, peach #F6C8B2, cream #FFF7ED
   Chart marks (validated, distinct from UI brand hues): see app.js CHART_COLORS */

:root {
  --bg: #FFF7ED;
  --surface: #FFFFFF;
  --surface-2: #FCEFE1;
  --border: #EFE0CC;
  --text-primary: #183D2E;
  --text-secondary: #52685D;
  --text-tertiary: #92A296;
  --brand-orange: #F28C28;
  --brand-orange-ink: #C96A12;
  --shadow: 0 1px 2px rgba(24,61,46,0.05), 0 10px 24px -16px rgba(24,61,46,0.18);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --good: #147A4E;
  --critical: #B3261E;

  --chart-green: #147A4E;
  --chart-orange: #F28C28;
  --chart-terracotta: #C1613F;
}

:root[data-theme="dark"] {
  --bg: #0E211A;
  --surface: #15291F;
  --surface-2: #1B3226;
  --border: #223B2D;
  --text-primary: #F5EFE6;
  --text-secondary: #B9C9BE;
  --text-tertiary: #7E9086;
  --brand-orange: #F2A854;
  --brand-orange-ink: #F2A854;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 12px 28px -16px rgba(0,0,0,0.5);
  --good: #3FBE8B;
  --critical: #E37A72;

  --chart-green: #1E9463;
  --chart-orange: #CC6E1A;
  --chart-terracotta: #B8542E;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E211A;
    --surface: #15291F;
    --surface-2: #1B3226;
    --border: #223B2D;
    --text-primary: #F5EFE6;
    --text-secondary: #B9C9BE;
    --text-tertiary: #7E9086;
    --brand-orange: #F2A854;
    --brand-orange-ink: #F2A854;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 12px 28px -16px rgba(0,0,0,0.5);
    --good: #3FBE8B;
    --critical: #E37A72;

    --chart-green: #1E9463;
    --chart-orange: #CC6E1A;
    --chart-terracotta: #B8542E;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Noto Sans Thai', 'Prompt', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  overflow-x: hidden;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 60px;
}

/* Header */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-name {
  font-family: 'Prompt', sans-serif;
  font-weight: 700;
  font-size: 19px;
  color: var(--text-primary);
}

.brand-name-en {
  color: var(--brand-orange-ink);
}

.brand-sub {
  font-size: 12px;
  color: var(--text-tertiary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--good);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 rgba(20,122,78,0.5);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(20,122,78,0.45); }
  70% { box-shadow: 0 0 0 6px rgba(20,122,78,0); }
  100% { box-shadow: 0 0 0 0 rgba(20,122,78,0); }
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text-primary); }

.updated-bar {
  font-size: 12.5px;
  color: var(--text-tertiary);
  padding-bottom: 18px;
}

/* Layout */

.content { display: flex; flex-direction: column; gap: 20px; }

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

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.section-header { padding-top: 6px; }
.section-header h2 {
  font-family: 'Prompt', sans-serif;
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

/* KPI cards */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 720px) {
  .kpi-row { grid-template-columns: 1fr; }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.kpi-icon { font-size: 18px; margin-bottom: 6px; }

.kpi-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
}

.kpi-value {
  font-family: 'Prompt', sans-serif;
  font-size: 30px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.kpi-value.positive { color: var(--good); }
.kpi-value.negative { color: var(--critical); }

.kpi-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.card-title {
  font-family: 'Prompt', sans-serif;
  font-size: 14.5px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--text-primary);
}

.takeaway-title { margin-top: 18px; margin-bottom: 8px; }

/* 100%-stacked share bar (part-to-whole) */

.stackbar {
  display: flex;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
  margin-bottom: 10px;
}

.stackbar-seg {
  height: 100%;
  border-right: 2px solid var(--surface);
  transition: width 0.4s ease;
}
.stackbar-seg:last-child { border-right: none; }

.stackbar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* Tables */

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

.data-table th, .data-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--text-tertiary);
  font-weight: 500;
  font-size: 12px;
}

.data-table td { color: var(--text-primary); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr.total-row td { font-weight: 700; }
.data-table tr:last-child td { border-bottom: none; }
.data-table.compact th, .data-table.compact td { padding: 6px; font-size: 12.5px; }

.insight {
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 12px 0 0;
}

.empty-note {
  font-size: 12.5px;
  color: var(--text-tertiary);
  text-align: center;
  padding: 10px 0 2px;
}

.takeaways {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Mini bar charts */

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

@media (max-width: 520px) {
  .chart-pair { grid-template-columns: 1fr; }
}

.mini-chart-title {
  font-size: 11.5px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.mini-chart svg { overflow: visible; }

.bar-group { cursor: default; }
.bar-rect { transition: opacity 0.15s ease; }
.bar-group:hover .bar-rect { opacity: 0.75; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--bg);
  font-size: 11.5px;
  padding: 5px 8px;
  border-radius: 6px;
  white-space: nowrap;
  transform: translate(-50%, -110%);
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 5;
}

.chart-tooltip.visible { opacity: 1; }

.mini-chart-wrap { position: relative; }

.axis-label {
  font-size: 9.5px;
  fill: var(--text-tertiary);
}

.page-footer {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-tertiary);
  padding-top: 28px;
}
