:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #2a78d6;
  --accent-soft: #e8f1fc;
  --danger: #d6453d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", system-ui, sans-serif;
  line-height: 1.5;
}

.top, main { max-width: 860px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 24px; }
.top h1 { margin: 0; font-size: 1.5rem; }
.sub { margin: 4px 0 16px; color: var(--muted); }

/* 요약 */
.summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat.wide { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 8px; }
.label { font-size: 0.75rem; color: var(--muted); }
.stat strong { font-size: 0.95rem; overflow-wrap: anywhere; }

.notice {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff6e0;
  color: #7a5a00;
  font-size: 0.9rem;
}
.notice.error { background: #fdecea; color: #9b2c25; }

/* 탭 */
.tabs { display: flex; gap: 4px; margin: 16px 0 0; }
.tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.tab.active { background: var(--card); color: var(--accent); font-weight: 700; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
  padding: 16px;
  margin-bottom: 32px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }

button {
  padding: 9px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
button:disabled { opacity: 0.5; cursor: default; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.small { padding: 4px 8px; font-size: 0.85rem; }
button.danger { color: var(--danger); }

input {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  min-width: 0;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 채팅 */
.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 46vh;
  min-height: 240px;
  overflow-y: auto;
  padding: 4px;
}
.empty { margin: auto; color: var(--muted); text-align: center; }
.bubble { max-width: 82%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--accent-soft); border-bottom-left-radius: 4px; }
.bubble.loading { color: var(--muted); }
.bubble.loading::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.chat-form { display: flex; gap: 8px; margin-top: 12px; }
.chat-form input { flex: 1; }

/* 데이터 */
.data-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.data-form label { display: flex; flex-direction: column; font-size: 0.8rem; color: var(--muted); gap: 2px; }
.data-form .grow { flex: 1; min-width: 140px; }

.table-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: var(--card); color: var(--muted); font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
tr.editing { background: var(--accent-soft); }

/* 대화 기록 */
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.history .info { flex: 1; min-width: 0; }
.history .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .meta { font-size: 0.8rem; color: var(--muted); }
.history li.current { border-color: var(--accent); }

@media (max-width: 560px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .bubble { max-width: 92%; }
}
