/* ==================== Design tokens ==================== */
:root {
  --header-main-height: 72px;
  --header-spectrum-height: 4px;
  --header-total-height: calc(var(--header-main-height) + var(--header-spectrum-height));
  --sidebar-width: 264px;

  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-surface-muted: #eef2f6;
  --color-border: #e3e8ee;
  --color-text: #1b2430;
  --color-text-muted: #67707c;
  --color-text-faint: #9ba4af;

  --color-primary: #2f6fed;
  --color-primary-soft: #e8f0fe;

  --color-pm10: #7c6fee;      --color-pm10-soft: #efedfd;
  --color-pm25: #ef5b5b;      --color-pm25-soft: #fdecec;
  --color-co2: #4fa9e0;       --color-co2-soft: #eaf5fc;
  --color-tvoc: #f2994a;      --color-tvoc-soft: #fdf0e4;
  --color-temp: #22b573;      --color-temp-soft: #e8f8f0;
  --color-humidity: #2fb6c0;  --color-humidity-soft: #e7f7f8;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --font-sans: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
    'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ==================== Header ==================== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.header__spectrum {
  height: var(--header-spectrum-height);
  width: 100%;
  background: linear-gradient(
    90deg,
    var(--color-temp),
    var(--color-co2),
    var(--color-tvoc),
    var(--color-pm25)
  );
}

.header__inner {
  height: var(--header-main-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 28px;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header__brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #fff;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.header__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.header__brand-text strong { font-size: 15px; font-weight: 800; }
.header__brand-text span { font-size: 11px; color: var(--color-text-muted); }

/* Segmented nav */
.header__nav.main-buttons {
  display: flex;
  gap: 4px;
  background: var(--color-surface-muted);
  padding: 4px;
  border-radius: var(--radius-md);
}

.text-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.header__nav .text-btn {
  padding: 8px 18px;
  border-radius: calc(var(--radius-md) - 2px);
}
.header__nav .text-btn:hover { color: var(--color-text); }
.main-buttons__btn.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.header__meta {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-shrink: 0;
}

.header__clock {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.menu-toggle {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 20px;
  height: 14px;
  cursor: pointer;
}
.menu-toggle__bar {
  width: 100%;
  height: 2px;
  background-color: var(--color-text-muted);
  border-radius: 2px;
  transition: background-color 0.2s ease;
}
.menu-toggle.active .menu-toggle__bar,
.menu-toggle:hover .menu-toggle__bar {
  background-color: var(--color-primary);
}

/* ==================== Sidebar ==================== */
.sidebar {
  position: fixed;
  top: var(--header-total-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100% - var(--header-total-height));
  background-color: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 18px 12px;
  overflow-y: auto;
  transition: transform 0.25s ease;
  z-index: 900;
}
.sidebar.hidden { transform: translateX(-100%); }

.sidebar__menu { list-style: none; margin: 0; padding: 0; }
.menu-group { display: flex; flex-direction: column; margin-bottom: 8px; }

.menu-group__title {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 14px 12px 6px;
  color: var(--color-text-faint);
}

.submenu { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.submenu__btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.submenu__btn:hover { background: var(--color-surface-muted); }

.submenu__btn.active {
  background: var(--color-primary-soft);
  border-left-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 700;
}

.submenu__btn--soon {
  color: var(--color-text-faint);
  cursor: not-allowed;
}
.submenu__btn--soon:hover { background: none; }

.submenu__tag {
  font-size: 10px;
  font-weight: 600;
  background: var(--color-surface-muted);
  color: var(--color-text-faint);
  padding: 2px 6px;
  border-radius: var(--radius-full);
}

/* ==================== Main content ==================== */
.main-content {
  margin-top: var(--header-total-height);
  margin-left: var(--sidebar-width);
  padding: 32px;
  min-height: calc(100vh - var(--header-total-height));
  transition: margin-left 0.25s ease;
}

/* 사이드바가 닫혔을 때 React state(sidebarHidden)로 토글되는 클래스 */
.main-content.main-content--full {
  margin-left: 0;
}

/* Page header */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}
.page-header__title { font-size: 22px; font-weight: 800; margin: 0; }
.page-header__subtitle { font-size: 13px; color: var(--color-text-muted); margin: 6px 0 0; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  box-shadow: var(--shadow-sm);
}
.status-pill__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-temp);
  box-shadow: 0 0 0 0 rgba(34, 181, 115, 0.5);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 181, 115, 0.45); }
  70%  { box-shadow: 0 0 0 6px rgba(34, 181, 115, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 181, 115, 0); }
}

/* ==================== Stat cards ==================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-card__icon svg { width: 22px; height: 22px; }

.stat-card__label { font-size: 13px; font-weight: 600; color: var(--color-text-muted); }

.stat-card__value-row { display: flex; align-items: baseline; gap: 6px; }
.stat-card__value { font-size: 30px; font-weight: 800; line-height: 1; }
.stat-card__unit { font-size: 12px; font-weight: 600; color: var(--color-text-faint); }

.stat-card--pm10 .stat-card__icon { background: var(--color-pm10-soft); color: var(--color-pm10); }
.stat-card--pm25 .stat-card__icon { background: var(--color-pm25-soft); color: var(--color-pm25); }
.stat-card--co2 .stat-card__icon { background: var(--color-co2-soft); color: var(--color-co2); }
.stat-card--tvoc .stat-card__icon { background: var(--color-tvoc-soft); color: var(--color-tvoc); }
.stat-card--temp .stat-card__icon { background: var(--color-temp-soft); color: var(--color-temp); }
.stat-card--humidity .stat-card__icon { background: var(--color-humidity-soft); color: var(--color-humidity); }

/* ==================== Summary (IAQ) card ==================== */
.summary-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-top: 24px;
}
.summary-card__header h3 { margin: 0 0 4px; font-size: 16px; font-weight: 800; }
.summary-card__header p { margin: 0; font-size: 13px; color: var(--color-text-muted); }

.summary-card__grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--color-border);
}
.summary-item { flex: 1; min-width: 150px; text-align: center; }
.summary-item__value { font-size: 22px; font-weight: 800; }
.summary-item__label { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.summary-item--highlight .summary-item__value { color: var(--color-primary); }

/* ==================== Compare card ==================== */
.compare-card {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-top: 20px;
}

.compare-card__chart h3 { margin: 0 0 16px; font-size: 15px; font-weight: 800; }

.bar-chart-visuals {
  height: 200px;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 16px;
  padding-top: 10px;
  border-bottom: 2px solid var(--color-border);
}

.bar-chart__bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 44px;
  height: 100%;
}

.bar-chart__value {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.bar-chart__bar {
  width: 100%;
  border-radius: 6px 6px 0 0;
  background: var(--color-primary);
  transition: height 0.5s ease;
}
.bar-chart__bar[data-sensor="pm10"],
.bar-chart__bar[data-sensor="asan_pm10"] { background: var(--color-pm10); }
.bar-chart__bar[data-sensor="pm25"],
.bar-chart__bar[data-sensor="asan_pm25"] { background: var(--color-pm25); }
.bar-chart__bar[data-sensor^="asan_"] { opacity: 0.5; }

.bar-chart__label {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--color-text-muted);
  text-align: center;
}

.compare-card__side { display: flex; flex-direction: column; gap: 12px; }

.small-info-card {
  background: var(--color-surface-muted);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: center;
}
.small-info-card__title { font-size: 12px; font-weight: 700; color: var(--color-text-muted); margin-bottom: 4px; }
.small-info-card__content { font-size: 18px; font-weight: 800; }

.compare-card__note {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin-top: 4px;
}

/* ==================== Chip row (predict / analysis tabs) ==================== */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.chip-row .text-btn {
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text-muted);
}
.chip-row .text-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.chip-row .text-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* Predict card */
.predict-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}
.predict-card h3 { margin: 0 0 16px; font-size: 16px; font-weight: 800; }
.predict-card__image {
  width: 100%;
  max-height: 380px;
  object-fit: contain;
  background: var(--color-surface-muted);
  border-radius: var(--radius-md);
  display: block;
}
.predict-card__footer {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 16px;
}
.predict-card__badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-primary-soft);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}
.predict-card__footer p { margin: 0; font-size: 13px; color: var(--color-text-muted); line-height: 1.6; }

/* Analysis iframe */
.analysis-frame {
  width: 100%;
  height: 720px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

/* ==================== Responsive ==================== */
@media (max-width: 960px) {
  :root { --sidebar-width: 220px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .compare-card { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .header__inner { padding: 0 16px; gap: 12px; }
  .header__brand-text span { display: none; }
  .header__nav .text-btn { padding: 7px 10px; font-size: 12px; }
  .header__clock { display: none; }
  .main-content { padding: 20px; }
  .stat-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
