:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #3b82f6;
  --chip-bg: #eef1f5;
  --chip-active: #3b82f6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1d2026;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #2a2e37;
    --accent: #60a5fa;
    --chip-bg: #262a33;
    --chip-active: #3b82f6;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Noto Sans KR", sans-serif;
  line-height: 1.5;
}

header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
}

header h1 { margin: 0; font-size: 20px; }

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

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 12px;
}
.header-actions-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.muted { color: var(--muted); font-size: 13px; }

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
button:hover { opacity: 0.9; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 28px 60px;
}

section { margin-bottom: 40px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tab {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.tab.active { background: var(--chip-active); color: white; border-color: var(--chip-active); }

.report-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.report-toolbar-actions { display: flex; align-items: center; gap: 8px; }

select {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

.ghost-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.ghost-btn:hover { opacity: 1; border-color: var(--accent); color: var(--accent); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-overlay:not([hidden]) {
  display: flex;
}

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { margin: 0; font-size: 16px; }

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.keyword-category-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

.keyword-category {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.keyword-category .keyword-category-title { margin-bottom: 0; }

.keyword-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 8px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px 4px 12px;
  border-radius: 999px;
  font-size: 12px;
}
.chip-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
}
.chip-remove:hover { color: #dc2626; }

.keyword-add { display: flex; gap: 8px; margin-top: 10px; }
.keyword-add input {
  flex: 1;
  min-width: 140px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.keyword-add input:focus { outline: none; border-color: var(--accent); }
.keyword-add button { padding: 6px 12px; font-size: 12px; }

#reportMeta { margin-bottom: 0; }

.report-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
}

.report-content h1,
.report-content h2,
.report-content h3 {
  margin: 1.4em 0 0.5em;
  line-height: 1.3;
}
.report-content h1:first-child,
.report-content h2:first-child,
.report-content h3:first-child { margin-top: 0; }

.report-content h1 { font-size: 24px; }
.report-content h2 { font-size: 21px; }
.report-content h3 { font-size: 18px; color: var(--muted); }

.report-content p { margin: 0.8em 0; font-size: 18px; line-height: 1.75; }

.report-content ul,
.report-content ol { padding-left: 1.4em; font-size: 18px; line-height: 1.75; }

.report-content a { color: var(--accent); }

.report-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.6em 0;
}

.report-content blockquote {
  margin: 0.8em 0;
  padding: 4px 16px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

/* ---------- 시스템 상태 ---------- */

:root {
  --series-1: #2a78d6;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5;
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-critical: #e66767;
  }
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat-tile-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-tile-value { font-size: 24px; font-weight: 600; margin-bottom: 8px; }
.stat-tile-value .unit { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 2px; }
.stat-tile-sub { font-size: 12px; color: var(--muted); }

.meter {
  height: 6px;
  border-radius: 999px;
  background: var(--chip-bg);
  overflow: hidden;
}
.meter-fill { height: 100%; border-radius: 999px; background: var(--series-1); transition: width 0.4s ease; }
.meter-fill.warning { background: var(--status-warning); }
.meter-fill.critical { background: var(--status-critical); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--muted);
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge.on { color: var(--status-good); }
.badge.on .dot { background: var(--status-good); }

.chart-toolbar { margin-bottom: 12px; }
.range-toggle { display: inline-flex; gap: 6px; }
.range-toggle button {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.range-toggle button.active { background: var(--chip-active); color: white; border-color: var(--chip-active); }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.chart-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  position: relative;
}
.chart-card-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.chart-card svg { display: block; width: 100%; height: 160px; overflow: visible; }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-crosshair { stroke: var(--muted); stroke-width: 1; opacity: 0; pointer-events: none; }
.chart-dot { fill: var(--series-1); stroke: var(--card-bg); stroke-width: 2; opacity: 0; pointer-events: none; }
.chart-gridline { stroke: var(--border); stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 10px; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -110%);
  z-index: 5;
}
.chart-tooltip .value { font-weight: 700; }
.chart-tooltip .time { color: var(--muted); margin-top: 2px; }
