/* 라이트 기본, prefers-color-scheme(dark)와 사용자 토글(data-theme) 둘 다 반영 — dataviz 스킬 palette.md 기준 */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f1f0ec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-blue: #2a78d6;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --success-text: #006300;
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232320;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255,255,255,0.10);
    --grid: #2c2c2a;
    --baseline: #383835;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --series-blue: #3987e5;
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;
    --success-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232320;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: rgba(255,255,255,0.10);
  --grid: #2c2c2a;
  --baseline: #383835;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --series-blue: #3987e5;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --success-text: #0ca30c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background-color .15s ease, color .15s ease;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  flex-wrap: wrap;
  gap: 10px;
}
header.topbar .brand { font-weight: 700; font-size: 16px; }
header.topbar .brand small { color: var(--text-muted); font-weight: 400; margin-left: 8px; }
header.topbar .right { display: flex; align-items: center; gap: 4px; }
header.topbar nav a {
  color: var(--text-secondary);
  text-decoration: none;
  margin-left: 4px;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 7px;
}
header.topbar nav a:hover { color: var(--text-primary); background: var(--surface-2); }
header.topbar nav a.active { color: var(--accent-ink); background: var(--accent); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  margin-left: 12px;
}
.theme-toggle:hover { color: var(--text-primary); }

main { max-width: 1140px; margin: 0 auto; padding: 24px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.card h2 { margin: 0 0 12px; font-size: 13px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.card h3 { margin: 0; font-size: 15px; }

/* 서비스 헬스 리스트 */
.svc-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 13.5px; }
.svc-row:last-child { border-bottom: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.dot.up { background: var(--status-good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-good) 20%, transparent); }
.dot.down { background: var(--status-critical); box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-critical) 20%, transparent); }

.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-muted); font-weight: 600; }
.pill.real { background: color-mix(in srgb, var(--status-good) 16%, transparent); color: var(--status-good); }
.pill.mock { background: color-mix(in srgb, var(--status-warning) 20%, transparent); color: #9a6a00; }
:root[data-theme="dark"] .pill.mock { color: #ffce6b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.mock { color: #ffce6b; } }

/* 스탯 타일 */
.stat-tile { text-align: center; }
.stat-tile .kpi-num { font-size: 30px; font-weight: 700; font-variant-numeric: proportional-nums; }
.stat-tile .kpi-label { color: var(--text-muted); font-size: 12.5px; margin-top: 4px; }
.stat-tile .kpi-sub { font-size: 12px; margin-top: 6px; }

/* 미터 (서비스 정상률) */
.meter-track { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.meter-fill { height: 100%; background: var(--status-good); border-radius: 6px; transition: width .3s ease; }

/* 바 차트 (가로 막대) */
.bar-chart { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 128px 1fr 46px; align-items: center; gap: 10px; font-size: 12.5px; }
.bar-row .bar-label { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 16px; background: var(--surface-2); border-radius: 4px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; border-radius: 4px; min-width: 3px; transition: width .4s ease; }
.bar-row .bar-value { text-align: right; color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600; }
.bar-row.suppressed .bar-value { color: var(--text-muted); font-weight: 400; font-style: italic; }
.bar-row.suppressed .bar-track { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 4px, var(--border) 4px, var(--border) 5px); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--grid); }
th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: var(--surface-2); }

button, .btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
button.secondary { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:hover:not(:disabled) { filter: brightness(1.08); }
input, textarea, select {
  width: 100%;
  background: var(--page);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 4px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-size: 12.5px; color: var(--text-muted); display: block; margin-top: 10px; }
.muted { color: var(--text-muted); }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; line-height: 1.55; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.active { background: color-mix(in srgb, var(--status-good) 15%, transparent); color: var(--status-good); }
.badge.proposed { background: color-mix(in srgb, var(--status-warning) 22%, transparent); color: #8a5c00; }
.badge.revoked, .badge.deleted { background: color-mix(in srgb, var(--status-critical) 15%, transparent); color: var(--status-critical); }
:root[data-theme="dark"] .badge.proposed { color: #ffce6b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.proposed { color: #ffce6b; } }

.timeline-item { border-left: 2px solid var(--grid); padding: 3px 0 12px 16px; margin-left: 6px; position: relative; font-size: 13px; }
.timeline-item::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); position: absolute; left: -5.5px; top: 6px; box-shadow: 0 0 0 3px var(--surface-1); }
.timeline-item .t { color: var(--text-muted); font-size: 11.5px; margin-bottom: 2px; }
.timeline-item .icon-label { font-weight: 600; }

/* 채팅 UI */
.chat-shell { display: flex; flex-direction: column; height: 460px; }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; padding: 4px 4px 8px; }
.msg-row { display: flex; gap: 9px; align-items: flex-end; max-width: 92%; }
.msg-row.citizen { align-self: flex-end; flex-direction: row-reverse; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; background: var(--surface-2); border: 1px solid var(--border); }
.avatar.ai { background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
.msg { padding: 11px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; }
.msg.ai { background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.citizen { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.system { background: transparent; border: 1px dashed var(--border); color: var(--text-muted); align-self: center; font-size: 11.5px; padding: 6px 12px; max-width: 100%; }
.msg .card-mini { background: var(--surface-1); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; margin-top: 8px; font-size: 12.5px; }
.msg .card-mini .row { display: flex; justify-content: space-between; padding: 2px 0; }
.msg .card-mini .row .k { color: var(--text-muted); }
.msg .typing-dots { display: inline-flex; gap: 3px; align-items: center; }
.msg .typing-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: blink 1.2s infinite ease-in-out; }
.msg .typing-dots span:nth-child(2) { animation-delay: .2s; }
.msg .typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.actions-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.actions-row button { flex: 1; min-width: 130px; padding: 9px 12px; font-size: 12.5px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.chat-input-row { display: flex; gap: 8px; margin-top: 10px; }
.chat-input-row input { margin-top: 0; }

.center-box { max-width: 480px; margin: 60px auto; text-align: center; }
.center-box h1 { font-size: 22px; margin-bottom: 8px; }
.footer-note { text-align: center; color: var(--text-muted); font-size: 12px; margin: 32px 0 8px; }

@media (max-width: 720px) {
  .grid.cols-2 { grid-template-columns: 1fr; }
  main { padding: 16px; }
}
