/* ---------------------------------------------------------------
   Design tokens (light default, dark override)
--------------------------------------------------------------- */
:root {
  --page-plane: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border-hairline: rgba(11, 11, 11, 0.1);

  --series-1: #2a78d6; /* jull        - blue   */
  --series-2: #1baf7a; /* jullapp     - aqua   */
  --series-3: #eda100; /* luvreapp    - yellow */
  --series-4: #008300; /* matinkim    - green  */

  --seq-100: #cde2fb;
  --seq-400: #3987e5;
  --seq-500: #256abf;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --radius-card: 12px;
  --radius-control: 8px;
  --font-sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-plane: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border-hairline: rgba(255, 255, 255, 0.1);

    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --series-4: #008300;

    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;
  }
}

:root[data-theme='light'] {
  color-scheme: light;
}
:root[data-theme='dark'] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* ---------------------------------------------------------------
   Header
--------------------------------------------------------------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}

.page-header .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

.header-meta {
  text-align: right;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.6;
}

/* ---------------------------------------------------------------
   Filters row
--------------------------------------------------------------- */
.filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.filter-presets {
  display: flex;
  gap: 6px;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-control);
  padding: 4px;
}

.filter-presets button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.filter-presets button:hover {
  background: var(--gridline);
}

.filter-presets button.active {
  background: var(--series-1);
  color: #fff;
  font-weight: 600;
}

/* ---------------------------------------------------------------
   Cards
--------------------------------------------------------------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-bottom: 20px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-head h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.card-head .card-note {
  color: var(--text-muted);
  font-size: 12px;
}

/* ---------------------------------------------------------------
   KPI row
--------------------------------------------------------------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-tile {
  min-width: 0; /* 그리드 트랙이 내용 때문에 뷰포트보다 넓어지는 것을 방지 */
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  padding: 16px;
}

.kpi-label {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.kpi-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  min-width: 0;
}

.kpi-delta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.kpi-foot svg {
  flex: none;
  width: 64px;
  height: 24px;
}

/* ---------------------------------------------------------------
   Toggle group (합계 / 일평균)
--------------------------------------------------------------- */
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-control);
  overflow: hidden;
}

.toggle-group button {
  border: none;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
}

.toggle-group button.active {
  background: var(--series-1);
  color: #fff;
  font-weight: 600;
}

/* ---------------------------------------------------------------
   Tables
--------------------------------------------------------------- */
.table-scroll {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

table.data-table th,
table.data-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

table.data-table th:first-child,
table.data-table td:first-child {
  text-align: left;
  font-variant-numeric: normal;
}

table.data-table thead th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--baseline);
  white-space: nowrap;
}

table.data-table tbody tr:hover {
  background: var(--gridline);
}

table.data-table tr.total-row {
  font-weight: 700;
}

table.data-table tr.total-row td {
  border-top: 1px solid var(--baseline);
  border-bottom: none;
}

.adv-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.adv-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

/* ---------------------------------------------------------------
   Trend section controls
--------------------------------------------------------------- */
.trend-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.trend-controls label {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.trend-controls select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border-hairline);
  background: var(--surface-1);
  color: var(--text-primary);
}

.adv-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.adv-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.adv-checkbox input {
  accent-color: var(--series-1);
}

.spacer {
  flex: 1;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 0;
}

.chart-wrap {
  position: relative;
  height: 320px;
}

/* ---------------------------------------------------------------
   Custom HTML chart tooltip (Chart.js external tooltip target)
--------------------------------------------------------------- */
.chart-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.08s ease;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 12px;
  min-width: 140px;
}

.chart-tooltip-title {
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 6px;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.chart-tooltip-key {
  width: 10px;
  height: 2px;
  border-radius: 1px;
  flex: none;
}

.chart-tooltip-value {
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.chart-tooltip-name {
  color: var(--text-secondary);
}

/* ---------------------------------------------------------------
   Tabs
--------------------------------------------------------------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--gridline);
  padding-bottom: 12px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius-control);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-btn:hover {
  background: var(--gridline);
}

.tab-btn.active {
  background: var(--surface-1);
  color: var(--text-primary);
  font-weight: 700;
  box-shadow: 0 0 0 1px var(--border-hairline) inset;
}

/* ---------------------------------------------------------------
   Footer
--------------------------------------------------------------- */
.page-footer {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.7;
  margin-top: 32px;
  border-top: 1px solid var(--gridline);
  padding-top: 16px;
}

.page-footer code {
  background: var(--gridline);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

/* ---------------------------------------------------------------
   Empty / loading / error states
--------------------------------------------------------------- */
.state-banner {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.state-banner.error {
  color: var(--status-critical);
}

/* ---------------------------------------------------------------
   Responsive
--------------------------------------------------------------- */
@media (max-width: 960px) {
  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .page {
    padding: 16px 12px 48px;
  }
  .kpi-row {
    grid-template-columns: 1fr 1fr;
  }
  .header-meta {
    text-align: left;
  }
}
