:root {
  color-scheme: light;
  font-family: Pretendard, "Segoe UI", sans-serif;
  color: #17211b;
  background: #eef2ef;
  letter-spacing: 0;
  --ink: #17211b;
  --muted: #68746d;
  --line: #d8e0da;
  --surface: #ffffff;
  --surface-soft: #f7faf8;
  --sidebar: #17211b;
  --green: #10784f;
  --green-dark: #0d6040;
  --green-soft: #e5f4ec;
  --amber: #9a6110;
  --amber-soft: #fff4de;
  --red: #b33b36;
  --red-soft: #fbe9e7;
  --blue: #3068a5;
  --chat-font-size: 18px;
  --prompt-font-size: 15px;
  --shadow: 0 12px 32px rgba(27, 43, 34, 0.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 980px; min-height: 680px; height: 100%; overflow: hidden; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.68; }

:where(.sidebar, .view, .chat-timeline, .table-wrap, .sql-panel pre, .prompt-editor, .small-editor, .catalog-table-choice-list, .preview-modal-body) {
  scrollbar-color: #8c9a91 #e3e9e5;
  scrollbar-width: auto;
  scrollbar-gutter: stable;
}
:where(.sidebar, .view, .chat-timeline, .table-wrap, .sql-panel pre, .prompt-editor, .small-editor, .catalog-table-choice-list, .preview-modal-body)::-webkit-scrollbar { width: 11px; height: 11px; }
:where(.sidebar, .view, .chat-timeline, .table-wrap, .sql-panel pre, .prompt-editor, .small-editor, .catalog-table-choice-list, .preview-modal-body)::-webkit-scrollbar-track { background: #e3e9e5; }
:where(.sidebar, .view, .chat-timeline, .table-wrap, .sql-panel pre, .prompt-editor, .small-editor, .catalog-table-choice-list, .preview-modal-body)::-webkit-scrollbar-thumb { background: #8c9a91; border: 2px solid #e3e9e5; border-radius: 6px; }

.app-shell { display: grid; grid-template-columns: 218px minmax(0, 1fr); height: 100vh; }
.sidebar { background: linear-gradient(180deg, #17211b 0%, #202c25 100%); color: #fff; display: flex; flex-direction: column; padding: 22px 14px 14px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border: 1px solid #516158; display: grid; place-items: center; border-radius: 8px; font: 700 13px "IBM Plex Mono", monospace; background: #2c3831; color: #dcf0e5; flex: 0 0 auto; }
.brand strong, .brand span { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand strong { font-size: 15px; line-height: 1.25; }
.brand span { color: #b3c1b8; font-size: 11px; margin-top: 4px; }
.nav-list { display: grid; gap: 5px; }
.nav-item { border: 0; background: transparent; color: #c8d3cc; min-height: 44px; border-radius: 8px; display: flex; align-items: center; gap: 11px; padding: 0 12px; text-align: left; transition: 120ms ease; }
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active { background: #e8f6ee; color: #124b35; font-weight: 800; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12); }
.sidebar-footer { margin-top: auto; border-top: 1px solid #3b4840; padding: 14px 6px 0; display: flex; align-items: center; justify-content: space-between; color: #a8b7ae; font: 12px "IBM Plex Mono", monospace; }
.icon-button { width: 36px; height: 36px; border: 1px solid #4b5a51; color: #e0e8e3; background: transparent; border-radius: 7px; display: grid; place-items: center; }
.icon-button:hover { background: rgba(255, 255, 255, 0.08); }
.icon-button svg { width: 16px; }

.workspace { min-width: 0; min-height: 0; background: #eef2ef; display: grid; grid-template-rows: 86px minmax(0, 1fr); overflow: hidden; }
.topbar { background: rgba(255, 255, 255, 0.92); border-bottom: 1px solid var(--line); padding: 16px 28px; display: flex; justify-content: space-between; align-items: center; backdrop-filter: blur(10px); }
.topbar h1 { margin: 0; font-size: 22px; line-height: 1.2; font-weight: 800; }
.topbar p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.view { display: none; min-width: 0; min-height: 0; height: 100%; padding: 22px 28px 30px; overflow: auto; }
.active-view { display: block; }
#view-chat.active-view { display: grid; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; padding: 0; }
.chat-timeline { min-height: 0; overflow-y: auto; padding: 24px max(24px, calc((100% - 1060px) / 2)) 26px; }
.service-hero { margin-bottom: 18px; padding: 26px 28px; border: 1px solid #dbe4dd; border-radius: 14px; background: linear-gradient(135deg, #ffffff 0%, #f2faf5 100%); box-shadow: var(--shadow); }
.service-hero h2 { margin: 9px 0 0; font-size: 32px; line-height: 1.15; font-weight: 800; color: #101915; }
.service-hero p { margin: 12px 0 0; max-width: 760px; color: #4f5e55; font-size: 16px; line-height: 1.55; }
.section-label { font: 700 11px "IBM Plex Mono", monospace; color: var(--green); letter-spacing: 0.02em; }
.starter-row { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 20px; }
.starter-chip { border: 1px solid #c7d5cc; color: #24362d; background: #fff; border-radius: 999px; padding: 10px 14px; font-size: 14px; font-weight: 700; box-shadow: 0 3px 10px rgba(27, 43, 34, 0.05); }
.starter-chip:hover { border-color: var(--green); color: var(--green); background: #f4fbf7; }

.message { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 18px; padding: 20px 0; }
.message-role { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; padding-top: 14px; }
.message-content { min-width: 0; border: 1px solid #dfe6e1; border-radius: 14px; background: rgba(255, 255, 255, 0.9); box-shadow: 0 8px 22px rgba(27, 43, 34, 0.06); padding: 18px; }
.message.user .message-content { background: #f8fbf9; }
.message.assistant .message-role { color: var(--green); }
.message.error .message-role, .error-text { color: var(--red); }
.message.error .message-content { border-color: #efc3c0; background: #fff6f5; }
.message-content p { margin: 0; line-height: 1.72; font-size: var(--chat-font-size); white-space: pre-wrap; }

.composer { background: var(--surface); border: 1px solid #c8d4cc; border-radius: 16px; margin: 0 max(24px, calc((100% - 1060px) / 2)) 18px; box-shadow: var(--shadow); padding: 12px; }
.composer textarea { border: 0; outline: 0; resize: none; width: 100%; min-height: 64px; padding: 7px; color: var(--ink); font-size: 18px; line-height: 1.5; }
.composer-footer { border-top: 1px solid #edf1ee; padding-top: 10px; display: flex; justify-content: space-between; align-items: center; }
.composer-footer span { color: #86938b; font-size: 12px; }

.preview-card, .image-preview { margin-top: 16px; border: 1px solid #dce5df; border-radius: 14px; background: #fbfdfb; overflow: hidden; }
.preview-card-header, .image-preview-header { min-height: 42px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #e4ebe6; color: #26332c; font-size: 13px; font-weight: 800; }
.preview-card-header small, .image-preview-header small { color: var(--muted); font: 700 11px "IBM Plex Mono", monospace; }
.image-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; padding: 14px; }
.image-card { min-width: 0; display: grid; gap: 8px; color: var(--ink); text-decoration: none; }
.image-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid #d7ded9; border-radius: 10px; background: #e9eeeb; }
.image-card:hover img { border-color: var(--green); box-shadow: 0 0 0 3px rgba(16, 120, 79, 0.14); }
.image-card-caption { min-width: 0; display: grid; gap: 3px; }
.image-card-caption strong, .image-card-caption small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-card-caption strong { font-size: 13px; }
.image-card-caption small { color: var(--muted); font-size: 11px; }
.inline-map-canvas { height: 270px; background: #dfe8e2; }
.map-empty { height: 100%; min-height: 180px; display: grid; place-content: center; padding: 20px; text-align: center; color: var(--muted); font-size: 14px; }
.inline-chart-canvas { max-height: 330px; overflow: auto; padding: 12px; }
.preview-card-footer { border-top: 1px solid #e4ebe6; padding: 10px 12px; display: flex; justify-content: flex-end; }

.collapsible-panel { margin-top: 14px; border-radius: 12px; overflow: hidden; }
.collapsible-panel summary { min-height: 42px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; font-size: 12px; font-weight: 800; user-select: none; }
.collapsible-panel summary::-webkit-details-marker { display: none; }
.collapsible-panel summary::before { content: "보기"; margin-right: 7px; color: var(--green); font-weight: 800; }
.collapsible-panel[open] summary::before { content: "숨김"; color: var(--muted); }
.sql-panel { border: 1px solid #2f3832; background: #1d221f; color: #e4ebe6; }
.sql-panel summary { color: #b9c5bd; }
.sql-panel[open] summary { border-bottom: 1px solid #38413b; }
.sql-panel pre { margin: 0; padding: 15px; overflow-x: auto; font: 13px/1.65 "IBM Plex Mono", monospace; white-space: pre-wrap; }
.agent-trace-panel { border: 1px solid #b9cbc0; background: #f5faf7; color: var(--ink); }
.agent-trace-panel > summary { color: #365043; background: #edf5f0; }
.agent-trace-list { display: grid; gap: 10px; padding: 12px; border-top: 1px solid #d8e4dc; }
.agent-trace-step { border: 1px solid #d6e2da; border-left: 4px solid var(--green); border-radius: 9px; background: #fff; padding: 11px 12px; }
.agent-trace-step.failed { border-left-color: var(--amber); background: #fffaf1; }
.agent-trace-step-head { display: flex; justify-content: space-between; gap: 10px; color: #43534a; font: 700 11px "IBM Plex Mono", monospace; }
.agent-trace-step p { margin: 9px 0 0; display: grid; gap: 3px; color: #526158; font-size: 12px; }
.agent-trace-step p b { color: #7a877f; font: 700 10px "IBM Plex Mono", monospace; text-transform: uppercase; }
.agent-trace-sql { margin-top: 9px; }
.agent-trace-sql summary { cursor: pointer; color: var(--green); font-size: 11px; font-weight: 800; }
.agent-trace-sql pre { margin: 7px 0 0; border-radius: 7px; background: #202823; padding: 10px; overflow-x: auto; color: #dce8df; font: 11px/1.55 "IBM Plex Mono", monospace; white-space: pre-wrap; }
.agent-trace-error { margin-top: 9px; color: #8a4f08; font-size: 11px; line-height: 1.45; }
.validation-line { margin-top: 12px; display: flex; align-items: center; gap: 7px; color: var(--green); font-size: 12px; font-weight: 700; }
.validation-line svg { width: 15px; }
.validation-line.failed { color: #9a5b08; }
.safety-notice { margin-top: 12px; display: grid; gap: 5px; border-left: 4px solid var(--amber); border-radius: 0 9px 9px 0; background: var(--amber-soft); padding: 11px 13px; color: #62430f; font-size: 12px; line-height: 1.5; }
.safety-notice strong { font: 700 11px "IBM Plex Mono", monospace; }
.usage-panel { margin-top: 14px; border-top: 1px solid #e4ebe6; padding-top: 12px; display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted); font-size: 11px; }
.usage-panel div { display: inline-flex; align-items: center; gap: 5px; }
.usage-panel strong { color: #405047; font: 600 11px "IBM Plex Mono", monospace; }
.usage-warning { flex-basis: 100%; color: var(--amber); font-weight: 800; }
.result-meta { margin: 16px 0 8px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.result-details { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.result-details summary { color: #4d5650; background: #f6f9f7; }
.result-details .table-wrap { border: 0; border-top: 1px solid var(--line); border-radius: 0; max-height: 360px; }
.table-wrap { border: 1px solid var(--line); border-radius: 10px; overflow: auto; background: var(--surface); max-height: 360px; }
table { border-collapse: collapse; min-width: 100%; font-size: 13px; }
th { position: sticky; top: 0; z-index: 1; background: #f0f4f1; color: #45524a; text-align: left; font-weight: 800; }
th, td { padding: 10px 12px; border-bottom: 1px solid #e5ebe7; white-space: nowrap; }
td.null { color: #98a19b; font-style: italic; }

.primary-button, .secondary-button { min-height: 38px; border-radius: 9px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 13px; }
.primary-button { border: 1px solid var(--green); background: var(--green); color: #fff; }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { border: 1px solid #c6d0c9; background: #fff; color: #344139; }
.secondary-button:hover { border-color: #90a098; background: #f8faf8; }
.primary-button svg, .secondary-button svg { width: 15px; }
.primary-button.loading svg { animation: spin 0.8s linear infinite; }

.settings-grid { display: grid; gap: 16px; max-width: 1100px; margin: 0 auto; }
.settings-section { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: 0 6px 18px rgba(27, 43, 34, 0.04); }
.section-heading, .action-row, .prompt-toolbar, .catalog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.section-heading h2, .catalog-header h2, .prompt-toolbar h2 { margin: 8px 0 0; font-size: 22px; line-height: 1.2; }
.helper-note { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; font-weight: 500; }
.form-grid { display: grid; gap: 14px; margin-top: 22px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: #56635b; font-size: 12px; font-weight: 800; }
input, .prompt-editor, .small-editor { width: 100%; border: 1px solid #cbd5cf; background: #fff; color: var(--ink); border-radius: 9px; outline: 0; }
input { height: 42px; padding: 0 12px; }
input:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(16, 120, 79, 0.13); }
.small-editor { min-height: 104px; resize: vertical; padding: 12px; font: 13px/1.6 "IBM Plex Mono", monospace; }
.readonly-editor { background: #f7f9f8; color: #4f5a54; }
.action-row { margin-top: 18px; border-top: 1px solid #edf1ee; padding-top: 15px; align-items: center; }
.inline-message { font-size: 12px; color: var(--muted); }
.inline-message.good { color: var(--green); }
.inline-message.bad { color: var(--red); }
.segmented { display: inline-flex; border: 1px solid #cbd5cf; border-radius: 9px; overflow: hidden; background: #fff; margin-top: 20px; }
.segmented button { border: 0; border-right: 1px solid #dce3df; background: transparent; color: #626e67; min-height: 36px; padding: 0 13px; font-size: 12px; font-weight: 800; }
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: #26302a; color: #fff; }
.hidden { display: none !important; }

.status-card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.status-card { border: 1px solid #dce4df; border-radius: 12px; background: #fbfdfb; padding: 16px; display: grid; gap: 8px; }
.status-card span { color: var(--muted); font-size: 12px; font-weight: 800; }
.status-card strong { font-size: 20px; color: var(--ink); }
.status-card.good strong { color: var(--green); }
.status-card.bad strong { color: var(--red); }

#view-prompt.active-view { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 14px; }
.prompt-toolbar { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 17px 19px; }
.toolbar-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.font-size-control { display: flex; grid-template-columns: none; align-items: center; gap: 8px; min-width: 184px; padding: 0 10px; border: 1px solid #c6d0c9; border-radius: 9px; background: #fff; }
.wide-control { min-width: 100%; height: 42px; }
.font-size-control svg { width: 16px; height: 16px; color: #657069; flex: 0 0 auto; }
.font-size-control input[type="range"] { width: 100%; height: 36px; padding: 0; border: 0; box-shadow: none; accent-color: var(--green); }
.font-size-control output { min-width: 40px; color: #465049; font: 700 12px "IBM Plex Mono", monospace; text-align: right; }
.prompt-editor { min-height: 0; height: 100%; resize: none; padding: 18px; font-family: "IBM Plex Mono", monospace; font-size: var(--prompt-font-size); line-height: 1.7; }
.editor-status { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }

.catalog-header { max-width: 1100px; margin: 0 auto 15px; }
.catalog-summary { max-width: 1100px; margin: 0 auto 15px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); background: var(--surface); border-radius: 14px; overflow: hidden; }
.catalog-summary div { padding: 17px; border-right: 1px solid var(--line); }
.catalog-summary div:last-child { border-right: 0; }
.catalog-summary strong, .catalog-summary span { display: block; }
.catalog-summary strong { font-size: 20px; }
.catalog-summary span { color: var(--muted); font-size: 12px; margin-top: 5px; }
.profile-detail { max-width: 1100px; margin: 0 auto 15px; padding: 12px 15px; border-left: 4px solid var(--green); background: var(--green-soft); color: var(--ink); font-size: 13px; border-radius: 0 10px 10px 0; }
.dataset-section { max-width: 1100px; margin: 0 auto; }
.catalog-table-choice-list { min-height: 92px; max-height: 250px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfb; padding: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.catalog-table-choice { display: flex; align-items: center; gap: 9px; min-width: 0; padding: 9px 10px; border: 1px solid #dce3df; border-radius: 9px; background: #fff; font: 12px/1.3 "IBM Plex Mono", monospace; color: var(--ink); }
.catalog-table-choice input { width: auto; height: auto; margin: 0; }
.catalog-table-choice span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-choice { grid-column: 1 / -1; color: var(--muted); font-size: 13px; line-height: 1.5; padding: 8px; }
.preview-toggle-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.toggle-row { display: flex; grid-template-columns: none; align-items: center; gap: 8px; border: 1px solid #dce4df; background: #fbfdfb; border-radius: 10px; padding: 12px; color: #334139; }
.toggle-row input { width: auto; height: auto; }
.budget-status-grid { margin-bottom: 4px; }

.chart-svg { width: 100%; min-width: 680px; height: auto; display: block; }
.chart-axis { stroke: #a8b2ab; stroke-width: 1; }
.chart-bar { fill: var(--green); }
.chart-line { fill: none; stroke: var(--green); stroke-width: 3; }
.chart-point { fill: #fff; stroke: var(--green); stroke-width: 2; }
.chart-value, .chart-label, .chart-tick { fill: #55605a; font-size: 11px; font-family: Pretendard, "Segoe UI", sans-serif; }
.chart-value { font-weight: 800; fill: #2f3a34; }
.chart-legend { display: flex; gap: 12px; flex-wrap: wrap; margin: 0 0 10px; color: #4d5750; font-size: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

.preview-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 28px; }
.preview-modal-backdrop { position: absolute; inset: 0; background: rgba(12, 19, 15, 0.52); }
.preview-modal-panel { position: relative; width: min(1120px, calc(100vw - 56px)); height: min(760px, calc(100vh - 56px)); display: grid; grid-template-rows: auto minmax(0, 1fr); background: #fff; border-radius: 18px; box-shadow: 0 28px 70px rgba(0, 0, 0, 0.28); overflow: hidden; }
.preview-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding: 18px 20px; }
.preview-modal-header h2 { margin: 7px 0 0; font-size: 24px; }
.preview-modal-body { min-height: 0; overflow: auto; padding: 18px; }
.modal-map-layout { height: 100%; min-height: 520px; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; }
.modal-map-canvas { min-height: 520px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #dfe8e2; }
.modal-map-list { min-height: 0; overflow: auto; display: grid; align-content: start; gap: 8px; }
.map-result-item { width: 100%; border: 1px solid #d7ded9; background: #fff; border-radius: 10px; padding: 11px; text-align: left; display: grid; gap: 5px; color: var(--ink); }
.map-result-item:hover, .map-result-item.active { border-color: var(--green); background: #f0f8f4; }
.map-result-item strong { font-size: 13px; }
.map-result-item span { color: var(--muted); font-size: 12px; line-height: 1.45; white-space: normal; }
.modal-chart-wrap { display: grid; gap: 14px; }
.modal-chart-canvas { border: 1px solid var(--line); border-radius: 14px; padding: 14px; overflow: auto; background: #fbfdfb; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: 440px; padding: 12px 15px; border-radius: 10px; background: #212722; color: #fff; box-shadow: var(--shadow); font-size: 13px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: 160ms ease; z-index: 1100; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8f312d; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 198px minmax(0, 1fr); }
  .form-grid.three, .form-grid.two, .preview-toggle-grid, .status-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .service-hero h2 { font-size: 28px; }
}
