:root {
  --navy: #013c58;
  --deep: #00537a;
  --steel: #a8e8f9;
  --teal: #00537a;
  --aqua: #a8e8f9;
  --sky: #ffba42;
  --mist: #a8e8f9;
  --sun: #f5a201;
  --gold: #ffd35b;
  --page: #013c58;
  --panel: rgba(1, 60, 88, 0.74);
  --panel-solid: #013c58;
  --panel-soft: rgba(168, 232, 249, 0.1);
  --ink: #f7fdff;
  --muted: #b2d8e3;
  --soft: #e2f8fd;
  --line: rgba(168, 232, 249, 0.2);
  --line-strong: rgba(255, 211, 91, 0.34);
  --shadow: 0 24px 70px rgba(1, 25, 42, 0.38);
  --radius: 8px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 211, 91, 0.92) 0%, rgba(255, 186, 66, 0.84) 18%, rgba(0, 83, 122, 0.94) 48%, rgba(1, 60, 88, 0.98) 100%),
    var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(141, 216, 233, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(141, 216, 233, 0.045) 1px, transparent 1px);
  background-size: 38px 38px;
  content: "";
}

button, textarea, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 268px;
  gap: 16px;
  width: min(1480px, calc(100% - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
  padding: 16px;
  border: 1px solid rgba(141, 216, 233, 0.24);
  border-radius: 16px;
  background: rgba(1, 60, 88, 0.68);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.side-panel,
.workspace,
.insight-panel { min-width: 0; }
.side-panel,
.insight-panel { display: grid; align-content: start; gap: 14px; }
.workspace { display: grid; align-content: start; gap: 14px; }

.brand-lockup,
.project-nav,
.schema-card,
.composer,
.answer-card,
.status,
.signal-card,
.examples button,
.studio-bar,
.hero-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 15, 32, 0.22);
  backdrop-filter: blur(14px);
}

.brand-lockup {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(141, 216, 233, 0.36);
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--gold), var(--deep));
  color: white;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25), 0 10px 20px rgba(0, 20, 44, 0.3);
}
.brand-mark-text { font-weight: 950; }
.brand-main { display: grid; gap: 3px; min-width: 0; }
.brand-title { color: var(--ink); font-size: 20px; font-weight: 950; line-height: 1; }
.brand-company { overflow: hidden; color: var(--muted); font-size: 12px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }

.project-nav { display: grid; overflow: hidden; background: var(--panel-solid); }
.project-nav a {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  color: var(--soft);
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
}
.project-nav a:last-child { border-bottom: 0; }
.project-nav a span { display: grid; place-items: center; height: 100%; color: var(--sky); font-size: 11px; font-weight: 950; }
.project-nav a:hover,
.project-nav a.is-active { background: rgba(141, 216, 233, 0.12); color: white; }
.project-nav a.is-active span { color: var(--gold); }

.schema-card { overflow: hidden; }
.schema-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 15px; }
.schema-kicker,
.eyebrow,
.hero-kicker,
.report-header p { margin: 0; color: var(--mist); font-size: 11px; font-weight: 950; letter-spacing: 0.08em; text-transform: uppercase; }
.schema-title { margin: 4px 0 0; color: var(--ink); font-size: 21px; font-weight: 950; }
.schema-body { max-height: 390px; overflow: auto; border-top: 1px solid var(--line); background: rgba(0, 29, 57, 0.46); }
.schema-card pre,
#sql { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.58 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.schema-card pre { padding: 14px; color: var(--soft); font-weight: 700; }

.studio-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 12px 16px;
  background: linear-gradient(90deg, rgba(1,60,88,0.88), rgba(245,162,1,0.28));
}
.studio-bar p { margin: 0 0 3px; color: var(--mist); font-size: 11px; font-weight: 950; letter-spacing: 0.08em; text-transform: uppercase; }
.studio-bar strong { color: var(--ink); font-size: 14px; }
.studio-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.studio-actions span { display: inline-flex; align-items: center; min-height: 28px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: rgba(0,29,57,0.3); color: var(--soft); font-size: 12px; font-weight: 850; }

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  overflow: hidden;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(1, 60, 88, 0.96) 0%, rgba(0, 83, 122, 0.92) 54%, rgba(245, 162, 1, 0.78) 100%);
  color: white;
}
.hero-copy { display: grid; align-content: center; gap: 13px; min-width: 0; }
.hero-kicker { color: var(--gold); }
.hero-copy h1 { margin: 0; max-width: 760px; color: white; font-size: 43px; font-weight: 950; line-height: 1.08; letter-spacing: 0; }
.hero-copy p:last-child { margin: 0; max-width: 680px; color: rgba(242,251,253,0.86); font-size: 15px; font-weight: 700; line-height: 1.62; }
.hero-stats { display: grid; gap: 10px; margin: 0; }
.hero-stats div { padding: 13px; border: 1px solid rgba(141,216,233,0.28); border-radius: var(--radius); background: rgba(141,216,233,0.1); }
.hero-stats dt { color: rgba(242,251,253,0.7); font-size: 11px; font-weight: 950; letter-spacing: 0.06em; text-transform: uppercase; }
.hero-stats dd { margin: 5px 0 0; color: white; font-size: 14px; font-weight: 950; }

.examples { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.examples button {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 126px;
  appearance: none;
  padding: 14px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.42;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}
.examples button span { color: var(--mist); font-size: 11px; font-weight: 950; letter-spacing: 0.04em; text-transform: uppercase; }
.examples button:nth-child(2) span { color: var(--sky); }
.examples button:nth-child(3) span { color: var(--aqua); }
.examples button:nth-child(4) span { color: var(--mist); }
.examples button:nth-child(3) { background: rgba(245,162,1,0.18); }
.examples button:hover { transform: translateY(-2px); border-color: rgba(141,216,233,0.48); background: rgba(141,216,233,0.14); }

.composer { display: grid; gap: 12px; padding: 16px; background: var(--panel-solid); }
.composer-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.composer-header h2 { margin: 4px 0 0; color: var(--ink); font-size: 25px; font-weight: 950; }
.composer-badge { display: inline-flex; align-items: center; min-height: 30px; padding: 6px 11px; border: 1px solid rgba(141,216,233,0.42); border-radius: 999px; background: rgba(141,216,233,0.12); color: var(--mist); font-size: 12px; font-weight: 950; }
textarea { width: 100%; min-height: 136px; resize: vertical; padding: 14px 15px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: rgba(0,29,57,0.46); color: var(--ink); line-height: 1.55; }
textarea::placeholder { color: #8bb5c5; }
textarea:focus { outline: none; border-color: rgba(141,216,233,0.72); box-shadow: 0 0 0 4px rgba(141,216,233,0.12); }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.query-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; color: var(--muted); font-size: 11px; line-height: 1.2; }
.query-flow span { display: inline-flex; align-items: center; min-height: 28px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; background: rgba(0,29,57,0.34); color: var(--soft); font-weight: 900; white-space: nowrap; }
.query-flow span[data-flow-step="question"], .query-flow span[data-flow-step="clickhouse"] { color: var(--mist); }
.query-flow span.flow-warning, .query-flow span.flow-export { color: var(--sky); }
.query-flow span.flow-active { border-color: rgba(255,211,91,0.72); background: rgba(245,162,1,0.16); color: var(--gold); }
.query-flow span.flow-done { border-color: rgba(168,232,249,0.55); background: rgba(168,232,249,0.12); color: var(--mist); }
.query-flow span.flow-error { border-color: rgba(255,150,150,0.38); background: rgba(255,150,150,0.1); color: #ffc0c0; }
.query-flow b { color: var(--steel); font-weight: 950; }

button[type="submit"], .secondary-button, .chart-type-button, .export-link { min-height: 34px; border: 1px solid var(--line-strong); border-radius: 999px; background: rgba(0,29,57,0.3); color: var(--ink); cursor: pointer; font-weight: 950; text-decoration: none; }
button[type="submit"] { min-width: 128px; padding: 9px 18px; border-color: rgba(141,216,233,0.5); background: linear-gradient(135deg, var(--sun), var(--gold)); color: var(--navy); box-shadow: 0 10px 22px rgba(0, 29, 57, 0.22); }
button[type="submit"]:hover { filter: brightness(1.04); }
button[type="submit"]:disabled { cursor: wait; opacity: 0.7; }
.secondary-button, .chart-type-button { padding: 7px 11px; }
.secondary-button:hover, .chart-type-button:hover, .chart-type-button.active { border-color: rgba(141,216,233,0.58); color: var(--mist); background: rgba(141,216,233,0.12); }
.compact-button { flex: 0 0 auto; min-height: 28px; padding: 5px 9px; font-size: 12px; }
.export-row { display: flex; justify-content: flex-start; margin-top: -4px; }
.export-link { display: inline-flex; align-items: center; padding: 7px 11px; color: var(--mist); }
.export-link[aria-busy="true"] { cursor: wait; opacity: 0.7; }
.status { padding: 13px 15px; color: var(--soft); font-weight: 850; background: var(--panel-solid); }

.result { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.result > .briefing-card, .result > #chart-card { grid-column: 1 / -1; }
.answer-card { display: grid; gap: 12px; min-width: 0; padding: 16px; background: var(--panel-solid); }
.report-card { gap: 0; overflow: hidden; padding: 0; }
.report-header, .card-header.report-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); background: rgba(0,29,57,0.28); }
.report-header h2, .chart-card-header h2 { margin: 4px 0 0; color: var(--ink); font-size: 24px; font-weight: 950; }
.chart-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.chart-type-controls { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.chart-type-button { min-height: 29px; padding: 6px 9px; font-size: 12px; }
.chart-type-button:disabled { cursor: wait; opacity: 0.62; }
#chart { width: 100%; height: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--navy); }

#answer { display: grid; gap: 12px; padding: 18px; color: var(--soft); font-size: 14px; line-height: 1.68; }
#answer p, #answer h2, #answer h3, #answer h4, #answer ul, #answer ol { margin: 0; }
#answer h2 { color: var(--ink); font-size: 28px; font-weight: 950; line-height: 1.12; }
#answer h3 { margin-top: 4px; padding-left: 11px; border-left: 4px solid var(--mist); color: var(--ink); font-size: 17px; font-weight: 950; }
#answer .answer-heading-yellow { border-left-color: var(--sky); color: var(--mist); }
#answer h4 { color: var(--ink); font-size: 15px; font-weight: 950; }
#answer ul, #answer ol { display: grid; gap: 8px; padding-left: 0; list-style: none; }
#answer ol { counter-reset: briefing-list; }
#answer li { position: relative; padding-left: 18px; color: var(--soft); }
#answer li::before { position: absolute; top: 0.72em; left: 0; width: 6px; height: 6px; border-radius: 50%; background: var(--mist); content: ""; }
#answer ol li { counter-increment: briefing-list; padding-left: 30px; }
#answer ol li::before { top: 0.1em; display: inline-grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--line); border-radius: 50%; background: rgba(141,216,233,0.13); color: var(--ink); content: counter(briefing-list); font-size: 11px; font-weight: 950; }
#answer strong { color: var(--ink); font-weight: 950; }
.answer-action-detail { display: grid; gap: 9px; }
.answer-action-detail summary { cursor: pointer; color: var(--ink); font-weight: 950; outline: none; }
.answer-action-detail summary::marker { color: var(--mist); }
.answer-action-detail[open] summary { color: var(--mist); }
.answer-action-body { display: grid; gap: 8px; margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(0,29,57,0.34); }
.answer-action-body strong { color: var(--mist); font-size: 13px; }
#answer .answer-action-body li { color: var(--soft); font-size: 13px; line-height: 1.58; padding-left: 16px; }
#answer .answer-action-body li::before { top: 0.72em; width: 5px; height: 5px; background: var(--sky); border: 0; }

.markdown-table-wrap, .report-card > .table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(0,29,57,0.34); }
.report-card > .table-wrap, .report-card > #sql { margin: 16px; }
.report-card > #sql { max-height: 420px; overflow: auto; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(0,29,57,0.34); color: var(--soft); }
.table-wrap { overflow: auto; }
.empty-result { margin: 0; color: var(--muted); }
.result-section { display: grid; gap: 8px; min-width: 720px; margin-bottom: 18px; }
.result-section:last-child { margin-bottom: 0; }
.result-section h3 { margin: 0; color: var(--mist); font-size: 14px; font-weight: 950; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: rgba(141,216,233,0.13); color: var(--ink); font-weight: 950; }
.answer-inline-image, .result-table-image { width: 50px; max-width: 50px; height: auto; border: 1px solid var(--line); border-radius: 6px; vertical-align: middle; }
.result-table-image { display: block; }

.signal-card { display: grid; gap: 12px; padding: 15px; background: var(--panel-solid); }
.score-card { background: linear-gradient(145deg, rgba(123,189,232,0.18), rgba(0,29,57,0.2)), var(--panel-solid); }
.score-card strong { color: var(--ink); font-size: 66px; font-weight: 950; line-height: 0.9; }
.score-card span { color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; }
.queue-list { display: grid; gap: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.queue-list div { display: flex; justify-content: space-between; gap: 10px; padding: 10px; border-bottom: 1px solid var(--line); background: rgba(0,29,57,0.24); }
.queue-list div:last-child { border-bottom: 0; }
.queue-list b { color: var(--ink); font-size: 13px; }
.queue-list span { color: var(--mist); font-size: 12px; font-weight: 950; text-transform: uppercase; }
.bar-meter { display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; gap: 8px; height: 120px; border-bottom: 1px solid var(--line); }
.bar-meter span { min-height: 16px; border-radius: 999px 999px 0 0; background: linear-gradient(180deg, var(--mist), rgba(141,216,233,0.26)); }
.bar-meter span:nth-child(2), .bar-meter span:nth-child(4) { background: linear-gradient(180deg, var(--sun), rgba(245,162,1,0.26)); }
.bar-meter span:nth-child(3), .bar-meter span:nth-child(5) { background: linear-gradient(180deg, var(--gold), rgba(255,211,91,0.24)); }
.note-card p:last-child { margin: 0; color: var(--soft); font-size: 13px; font-weight: 750; line-height: 1.58; }

@media (max-width: 1180px) {
  .shell { grid-template-columns: 230px minmax(0, 1fr); }
  .insight-panel { grid-column: 1 / -1; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hero-panel { grid-template-columns: 1fr; }
  .hero-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .examples { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; width: min(100% - 12px, 1180px); margin: 6px auto; padding: 12px; border-radius: 14px; }
  .side-panel { order: 2; }
  .workspace { order: 1; }
  .insight-panel { order: 3; grid-template-columns: 1fr; }
  .studio-bar, .controls, .chart-card-header { align-items: stretch; flex-direction: column; }
  .studio-actions, .chart-type-controls { justify-content: flex-start; }
  .hero-panel { padding: 20px; }
  .hero-copy h1 { font-size: 31px; }
  .hero-stats, .examples, .result { grid-template-columns: 1fr; }
  button[type="submit"] { width: 100%; }
}
