:root {
  --bg: #f4f8f6;
  --panel: #ffffffd9;
  --line: #d7e4df;
  --text: #13302a;
  --muted: #58756c;
  --primary: #0f8f73;
  --primary-soft: #dbf2eb;
  --alert: #d9533f;
  --warn: #9a6f00;
  --radius: 18px;
  --shadow: 0 14px 32px rgba(24, 74, 64, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Pretendard", "SUIT", "Noto Sans KR", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 18% 12%, #e9fff6 0%, transparent 45%),
    radial-gradient(circle at 88% 8%, #fff6e7 0%, transparent 38%), var(--bg);
  min-height: 100vh;
}

.bg-orb {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(8px);
  opacity: 0.45;
  pointer-events: none;
}

.orb-a {
  width: 280px;
  height: 280px;
  background: #c6ffe9;
  top: -80px;
  left: -60px;
}

.orb-b {
  width: 320px;
  height: 320px;
  background: #ffe8bf;
  right: -120px;
  bottom: -100px;
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100vw - 32px));
  margin: 26px auto 32px;
  display: grid;
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  animation: reveal 0.35s ease both;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.controls-panel {
  display: grid;
  gap: 8px;
  min-width: 340px;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: clamp(1.25rem, 1.6vw, 1.8rem);
  margin-top: 4px;
}

h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.trend-meta {
  margin: -4px 0 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

h3 {
  font-size: 0.95rem;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.range-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 8px;
  align-items: end;
}

.range-controls label {
  display: grid;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.actions-row {
  justify-content: flex-end;
  align-items: center;
}

.refresh-select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 0.9rem;
}

select,
input[type="date"] {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 0.9rem;
  color: var(--text);
  background: #fff;
}

select {
  border-radius: 999px;
}

button {
  appearance: none;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 0.9rem;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.period-btn.active,
.refresh-btn,
.apply-btn {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(135deg, #0f8f73, #1ea786);
}

.message {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.92rem;
}

.error {
  background: #ffe5e0;
  border: 1px solid #f0b5ac;
  color: #8a2c1f;
}

.warning {
  background: #fff2cf;
  border: 1px solid #e7d08a;
  color: #6d4b00;
}

.hidden {
  display: none;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.health-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.health-grid span {
  font-size: 0.78rem;
  color: var(--muted);
}

.health-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.8rem;
}

.health-pill.pending {
  background: #eef3f2;
  color: #5f7570;
}

.health-pill.ok {
  background: #dff7ee;
  color: #0f6f59;
}

.health-pill.error {
  background: #ffe5e0;
  color: #8a2c1f;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.kpi-item,
.secondary-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #f7fcfa);
}

.kpi-label,
.secondary-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.kpi-value {
  font-size: 1.32rem;
  font-weight: 700;
  margin-top: 8px;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.comparison-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.comparison-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.comparison-empty {
  margin: 0;
  font-size: 0.85rem;
}

.comparison-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
}

.comparison-list li {
  display: grid;
  gap: 3px;
  font-size: 0.85rem;
}

.delta-up {
  color: #0d7c5f;
}

.delta-down {
  color: #b54a39;
}

.delta-flat {
  color: #536e67;
}

.secondary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.secondary-value {
  margin-top: 6px;
  font-weight: 600;
}

.drilldown-card {
  display: grid;
  gap: 12px;
}

.drilldown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.drilldown-legend {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.drilldown-hint {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.drilldown-section {
  display: grid;
  gap: 8px;
}

.drilldown-section h3 {
  font-size: 0.88rem;
  color: var(--muted);
}

.drilldown-table td small {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}

.drilldown-table .thumb-header,
.drilldown-table .thumb-cell {
  text-align: center;
}

.thumb-link {
  display: inline-flex;
  width: 56px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  background: #f8fbfa;
}

.thumb-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 56px;
  padding: 0 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.72rem;
}

.recommendation-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.76rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.reco-keep {
  background: #edf2f0;
  color: #46605a;
  border-color: #d0ddd8;
}

.reco-scale {
  background: #dff7ee;
  color: #0f6f59;
  border-color: #a8e1cc;
}

.reco-pause {
  background: #ffe5e0;
  color: #8a2c1f;
  border-color: #f0b5ac;
}

.alerts-card,
.anomalies-card {
  border-left: 4px solid var(--primary);
}

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

.badge {
  border-radius: 999px;
  background: var(--primary-soft);
  color: #0d6e58;
  padding: 4px 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.badge.alert {
  background: #ffe5e0;
  color: #8a2c1f;
}

.anomaly-summary {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.alerts-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.anomalies-card .alerts-list {
  padding-left: 0;
  list-style: none;
}

.anomalies-card .alerts-list li {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.anomaly-pill {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.severity-critical {
  color: #8a2c1f;
  background: #ffe5e0;
}

.severity-warning {
  color: #7b5600;
  background: #fff2cf;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:last-child,
td:last-child {
  text-align: left;
}

.table-empty {
  color: var(--muted);
}

.status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
  border: 1px solid var(--line);
}

.status-live {
  background: #e1f8ef;
  color: #0f6f59;
  border-color: #a8e1cc;
}

.status-history {
  background: #fff2cf;
  color: #6d4b00;
  border-color: #e7d08a;
}

.status-unavailable {
  background: #f2f4f4;
  color: #60716c;
}

@media (max-width: 980px) {
  .topbar {
    flex-direction: column;
  }

  .controls-panel {
    width: 100%;
    min-width: 0;
  }

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

  .actions-row {
    justify-content: flex-start;
  }

  .health-grid,
  .comparison-grid,
  .kpi-grid,
  .secondary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .drilldown-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .layout {
    width: min(1180px, calc(100vw - 20px));
    margin-top: 14px;
    gap: 10px;
  }

  .card {
    border-radius: 14px;
    padding: 12px;
  }

  .health-grid,
  .comparison-grid,
  .kpi-grid,
  .secondary-grid {
    grid-template-columns: 1fr;
  }

  .drilldown-legend {
    width: 100%;
  }

  .anomalies-card .alerts-list li {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  button {
    padding: 8px 12px;
  }

  .thumb-link,
  .thumb-fallback {
    width: 48px;
    min-width: 48px;
    height: 48px;
  }
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
