:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d232b; --muted: #6b7480; --line: #e2e5ea;
  --accent: #e8700f; --accent-ink: #fff; --block: #c62828; --block-bg: #fdecec;
  --warn: #a15c00; --warn-bg: #fff4e0; --ok: #2e7d32; --ok-bg: #e8f5e9;
  --series: #d9650a; /* 차트 단일 계열 — dataviz validate_palette 통과 (light, #fff) */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b; --panel: #1d2127; --text: #e6e8eb; --muted: #9aa3ad; --line: #2e343c;
    --block: #ff8a80; --block-bg: #3a1d1d; --warn: #ffc266; --warn-bg: #3a2e14; --ok: #81c784; --ok-bg: #1b2e1d;
    --series: #d9701f; /* dark 표면(#1d2127) 기준 통과 */
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 "Pretendard", "Malgun Gothic", system-ui, sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; }
.brand::before { content: ""; display: inline-block; width: 10px; height: 10px; background: var(--accent); margin-right: 8px; border-radius: 2px; }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav a { padding: 8px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); white-space: nowrap; }
nav a.active { color: var(--text); background: var(--bg); font-weight: 600; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 20px; margin: 0 0 16px; display: flex; align-items: center; gap: 12px; }
h2 { font-size: 15px; margin: 24px 0 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }
.stat.block .n { color: var(--block); } .stat.warn .n { color: var(--warn); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge.block { background: var(--block-bg); color: var(--block); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.mute { background: var(--bg); color: var(--muted); }
.issue { padding: 8px 12px; border-radius: 6px; margin: 4px 0; }
.issue.block { background: var(--block-bg); color: var(--block); }
.issue.warn { background: var(--warn-bg); color: var(--warn); }
button, .btn { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
h1 button, h1 input, h2 button { font-size: 14px; font-weight: 500; }
h1 a { text-decoration: none; }
button.small { padding: 3px 10px; font-size: 12px; }
input, select { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); min-width: 0; }
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--panel); color: var(--text); width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#modal-body { padding: 20px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form .full { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.muted { color: var(--muted); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }
h1 { flex-wrap: wrap; row-gap: 10px; }

/* ---------- 공용 컴포넌트 ---------- */
.small-text { font-size: 12px; font-weight: 400; }
.filters { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
button:disabled { opacity: .45; cursor: default; }
.issue.ok { background: var(--ok-bg); color: var(--ok); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 12px 0; }
.more { width: 100%; margin-top: 8px; background: transparent; border-style: dashed; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { padding: 4px 10px; border-radius: 14px; font-size: 12px; background: var(--panel); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
h1 a.btn { font-size: 14px; font-weight: 500; color: var(--text); }
#tot { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.stat .n.sm { font-size: 20px; white-space: nowrap; } .stat .n small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.picker { min-height: 150px; margin-top: 6px; }
#tip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; line-height: 1.4;
       padding: 6px 9px; border-radius: 6px; opacity: 0; transition: opacity .12s; max-width: 240px; }
#tip.show { opacity: 1; }

/* ---------- 실시간 대시보드 ---------- */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on { color: var(--ok); } .live.on i { background: var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }
.stats-6 { grid-template-columns: repeat(6, 1fr); }
.stat.accent .n { color: var(--series); }
.stat.bump { animation: bump .7s ease-out; }
@keyframes bump { 0% { box-shadow: 0 0 0 2px var(--series); } 100% { box-shadow: 0 0 0 0 transparent; } }
.meter { height: 4px; border-radius: 2px; background: var(--bg); margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--series); border-radius: 2px; transition: width .6s; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 0 20px; }
.feed { list-style: none; margin: 0; padding: 4px 0; max-height: 260px; overflow-y: auto; }
.feed li { display: flex; gap: 8px; align-items: baseline; padding: 6px 12px; font-size: 13px; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed li span:last-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.feed time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.feed li.new { animation: slidein .5s ease-out; }
@keyframes slidein { from { background: color-mix(in srgb, var(--series) 18%, transparent); transform: translateY(-4px); } to { background: transparent; } }
.badge.info { background: var(--bg); color: var(--text); }
.chart { padding: 12px 14px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 140px; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; cursor: default; }
.bar { width: 100%; max-width: 22px; background: var(--series); border-radius: 4px 4px 0 0; min-height: 1px; transition: height .5s; }
.bar-col:hover .bar { filter: brightness(1.15); }
.bar-val { font-size: 11px; color: var(--text); font-weight: 600; min-height: 15px; }
.bar-x { font-size: 10px; color: var(--muted); margin-top: 4px; border-top: 1px solid var(--line); width: 100%; text-align: center; padding-top: 2px; }
.bar-x.today { color: var(--text); font-weight: 700; }
.hbar { display: grid; grid-template-columns: 76px 1fr 44px; gap: 8px; align-items: center; padding: 3px 0; font-size: 13px; }
.hbar-l { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 10px; }
.hbar-track i { display: block; height: 100%; background: var(--series); border-radius: 0 4px 4px 0; transition: width .5s; min-width: 1px; }
.hbar-v { text-align: right; font-variant-numeric: tabular-nums; }
.mini { display: inline-block; width: 44px; height: 6px; background: var(--bg); border-radius: 3px; margin-right: 8px; vertical-align: middle; overflow: hidden; }
.mini i { display: block; height: 100%; background: var(--series); border-radius: 3px; }
tr.flash td { animation: rowflash 1.4s ease-out; }
@keyframes rowflash { from { background: color-mix(in srgb, var(--series) 22%, transparent); } to { background: transparent; } }

/* ---------- 챗봇 ---------- */
#chat-fab { position: fixed; right: 20px; bottom: 20px; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 12px 18px;
            border-radius: 28px; background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
#chat-fab.hide { display: none; }
#chat { position: fixed; right: 20px; bottom: 20px; z-index: 30; width: 400px; height: min(620px, calc(100vh - 100px)); display: none;
        flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.22); overflow: hidden; }
#chat.open { display: flex; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chat-head .muted { font-size: 12px; }
button.icon { width: 30px; padding: 0; }
#chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 14px; overflow-wrap: anywhere; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 4px 0 6px; padding-left: 20px; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.err { border-color: var(--block); color: var(--block); }
.msg.pending { color: var(--muted); }
.msg code { background: var(--bg); padding: 0 4px; border-radius: 4px; }
.md-table { overflow-x: auto; margin: 6px 0; }
.md-table table { font-size: 12px; } .md-table th, .md-table td { padding: 4px 8px; }
.tools { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.tool { font-size: 11px; color: var(--muted); background: var(--bg); padding: 1px 6px; border-radius: 8px; }
.suggest { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 8px; }
.suggest .chip { text-align: left; white-space: normal; }
.dots { display: inline-flex; gap: 3px; margin-right: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }
#chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
#chat-form textarea { flex: 1; resize: none; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); max-height: 120px; }
#chat-form.busy button { opacity: .5; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- 태블릿 (641–1024px) ---------- */
@media (max-width: 1024px) {
  header { padding: 0 16px; gap: 16px; }
  main { padding: 20px 16px 48px; }
  th, td { padding: 8px 10px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stats-6 { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

td.wrap { white-space: normal; min-width: 160px; }
@media (min-width: 641px) and (max-width: 1024px) { .opt { display: none; } }

/* ---------- 모바일 (≤640px) ---------- */
@media (max-width: 640px) {
  :root { --nav-h: 60px; }
  header { height: 48px; justify-content: center; }
  /* 상단 내비 → 하단 탭바 */
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
        padding: 0 4px env(safe-area-inset-bottom); background: var(--panel); border-top: 1px solid var(--line); gap: 0; overflow: visible; }
  nav a { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; padding: 6px 2px; font-size: 13px;
          border-radius: 0; white-space: normal; line-height: 1.25; word-break: keep-all; }
  nav a.active { background: none; color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }
  main { padding: 16px 16px calc(var(--nav-h) + 32px); }
  #toast { bottom: calc(var(--nav-h) + 16px); }

  h1 { font-size: 18px; }
  h1 .spacer { flex-basis: 100%; height: 0; }          /* 제목 아래 줄로 버튼 내림 */
  h1 > button, h1 > input { flex: 1 1 auto; }
  .row > input, .row > select { flex: 1 1 140px; }
  button, input, select { min-height: 40px; font-size: 16px; } /* 터치 크기, iOS 확대 방지 */
  button.small { min-height: 32px; font-size: 13px; }

  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px; } .stat .n { font-size: 22px; }
  .kv { grid-template-columns: repeat(2, 1fr); padding: 12px; }

  /* 표 → 카드 목록 */
  .card.stack { overflow: visible; }
  .stack thead { display: none; }
  .stack table, .stack tbody, .stack tr, .stack td { display: block; width: 100%; }
  .stack tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .stack tr:last-child { border-bottom: 0; }
  .stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 3px 0;
              border: 0; white-space: normal; text-align: right; overflow-wrap: anywhere; }
  .stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex-shrink: 0; }
  .stack td[data-label=""]::before, .stack td.empty::before { content: none; }
  .stack td[data-label=""] { justify-content: flex-end; padding-top: 6px; }
  .stack td:first-child { font-weight: 600; }
  tr.click:hover td { background: none; } tr.click:active { background: var(--bg); }

  /* 모달 → 하단 시트 */
  dialog { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 14px 14px 0 0; border-bottom: 0; }
  #modal-body { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
  .form { grid-template-columns: 1fr; }
  .actions button { flex: 1; }

  .stats-6 { grid-template-columns: repeat(2, 1fr); }
  /* 챗봇: 전체화면, 플로팅 버튼은 하단 탭바 위 */
  #chat-fab { right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); padding: 12px 14px; }
  #chat-fab span { display: none; }
  #chat { inset: 0; width: auto; height: auto; border-radius: 0; border: 0; z-index: 40; }
  #chat-form { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .msg { max-width: 94%; }
  .pager { gap: 8px; }
  .picker { min-height: 180px; }
  .hbar { grid-template-columns: 70px 1fr 40px; }
}

/* 버전·환경 표시 */
.ver { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.env-badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 8px; margin-left: 4px; }
.env-badge.preview { background: var(--warn-bg); color: var(--warn); }
.env-badge.local { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
@media (max-width: 640px) { .brand { display: block !important; font-size: 15px; } }
