:root {
  color-scheme: light;
  --header-bg: #101d33;
  --header-border: #1f2f4d;
  --surface-1: #ffffff;
  --page-bg: #f2f3f5;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border-hairline: rgba(11, 11, 11, 0.12);
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;

  --series-1: #2a78d6; /* NS1 */
  --series-2: #eb6834; /* NS2 */
  --series-3: #1baf7a; /* NS3 */
  --series-4: #eda100; /* NS4 */
  --series-5: #e87ba4; /* NS5 */
  --series-6: #008300; /* NS6 */

  --accent-blue: #2a78d6;
  --accent-blue-dark: #184f95;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Malgun Gothic", system-ui, -apple-system, sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  height: 46px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.menu-btn {
  height: 100%;
  display: block;
  border: 0;
  cursor: pointer;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 14px;
  min-width: 0;
}

.brand-logo {
  height: 40px;
  display: block;
}

.brand-title {
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 10px;
}

.welcome-text {
  color: #dfe4ee;
  font-size: 13px;
  white-space: nowrap;
}

.logout-btn {
  height: 26px;
  display: block;
  cursor: pointer;
}

/* ---------- Mode switch ---------- */
.mode-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}

.mode-switch-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}

.mode-btn {
  appearance: none;
  border: 1px solid var(--border-hairline);
  background: #f5f6f8;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.mode-btn:hover {
  background: #eaf1fb;
}

.mode-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #ffffff;
}

/* ---------- Chat area ---------- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 8px;
  display: flex;
  justify-content: center;
}

.chat-panel {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-panel-wide {
  max-width: 1240px;
}

.chat-panel[hidden] {
  display: none;
}

.response-card {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  padding: 20px 22px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-primary);
}

.response-card h3.card-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
}

.response-card h4.section-title {
  margin: 16px 0 6px;
  font-size: 13.5px;
  font-weight: 700;
}

.response-card h4.section-title:first-of-type {
  margin-top: 0;
}

.bullet-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.bullet-list > li {
  position: relative;
  padding-left: 14px;
  margin-bottom: 4px;
}

.bullet-list > li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--text-secondary);
}

.bullet-list.nested {
  margin-top: 6px;
  padding-left: 18px;
}

.bullet-list.nested > li {
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.quote-line {
  font-weight: 700;
  margin: 4px 0 8px;
}

.body-text {
  margin: 0;
  color: var(--text-secondary);
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.dl-btn {
  appearance: none;
  border: 1px solid var(--border-hairline);
  background: #f5f6f8;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
}

.dl-btn:hover {
  background: #eaeaea;
}

/* ---------- Chart card ---------- */
.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  padding: 16px 20px 8px;
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.chart-card-title {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
}

.chart-card-icons {
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  gap: 10px;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 0 4px;
  flex-wrap: wrap;
}

.chart-legend .legend-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 2px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.legend-more {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 13px;
}

.chart-unit {
  font-size: 11px;
  color: var(--text-muted);
  margin: 2px 0 0 4px;
}

.chart-svg-wrap {
  position: relative;
}

.chart-svg-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-svg-wrap-lg svg {
  min-height: 320px;
}

/* ---------- Two-up pie layout ---------- */
.pie-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 8px;
}

.pie-col-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

@media (max-width: 720px) {
  .pie-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Insight text ---------- */
.insight-text {
  margin: 14px 0 4px;
  padding: 10px 14px;
  background: #f5f6f8;
  border-left: 3px solid var(--accent-blue);
  border-radius: 4px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.axis-line {
  stroke: var(--baseline);
  stroke-width: 1;
}

.grid-line {
  stroke: var(--gridline);
  stroke-width: 1;
}

.axis-label {
  fill: var(--text-muted);
  font-size: 10px;
}

.x-axis-label {
  fill: var(--text-muted);
  font-size: 9.5px;
}

.series-line {
  fill: none;
  stroke-width: 2;
}

.series-marker {
  stroke: var(--surface-1);
  stroke-width: 1;
}

.series-end-label {
  font-size: 10px;
  font-weight: 600;
}

.chart-crosshair {
  stroke: var(--baseline);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0;
  pointer-events: none;
}

.chart-hover-target {
  fill: transparent;
  pointer-events: all;
}

.chart-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background: #ffffff;
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 11.5px;
  line-height: 1.5;
  opacity: 0;
  transform: translate(-9999px, -9999px);
  transition: opacity 0.1s ease;
  z-index: 5;
  white-space: nowrap;
}

.chart-tooltip .tt-title {
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.chart-tooltip .tt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.chart-tooltip .tt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-tooltip .tt-val {
  margin-left: auto;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ---------- Composer ---------- */
.composer-wrap {
  flex-shrink: 0;
  padding: 10px 24px 50px;
  display: flex;
  justify-content: center;
  background: var(--page-bg);
}

.composer {
  width: 100%;
  max-width: 900px;
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  padding: 12px 54px 12px 16px;
}

.composer textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text-primary);
  background: transparent;
  height: 22px;
}

.send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, #2f5fa8, #16264a);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(22, 38, 74, 0.35);
}

.send-btn svg {
  width: 15px;
  height: 15px;
}

/* ---------- Bar chart ---------- */
.bar-rect {
  transition: opacity 0.1s ease;
}

.bar-rect-hover {
  opacity: 0.82;
}

.bar-value-label {
  fill: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- Pie chart ---------- */
.pie-wrap {
  max-width: 520px;
  margin: 0 auto;
}

.pie-slice {
  stroke: var(--surface-1);
  stroke-width: 2;
  transition: opacity 0.1s ease;
}

.pie-slice-hover {
  opacity: 0.82;
}

.pie-leader {
  stroke: var(--baseline);
  stroke-width: 1;
}

.pie-label {
  fill: var(--text-primary);
  font-size: 11.5px;
  font-weight: 700;
}

.pie-pct-label {
  fill: var(--text-secondary);
  font-size: 10.5px;
}

/* ---------- Rank list ---------- */
.rank-card {
  padding-bottom: 16px;
}

.rank-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rank-row {
  display: grid;
  grid-template-columns: 22px 140px 1fr 48px;
  align-items: center;
  gap: 12px;
}

.rank-no {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #eceef1;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rank-1 .rank-no {
  background: var(--accent-blue);
  color: #ffffff;
}

.rank-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-name em {
  font-style: normal;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11.5px;
  margin-left: 2px;
}

.rank-bar-track {
  height: 10px;
  border-radius: 6px;
  background: #eceef1;
  overflow: hidden;
}

.rank-bar {
  display: block;
  height: 100%;
  border-radius: 6px;
  background: var(--text-muted);
}

.rank-1 .rank-bar {
  background: var(--accent-blue);
}

.rank-value {
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ---------- Data table ---------- */
.table-wrap {
  margin-top: 8px;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-hairline);
  white-space: nowrap;
}

.data-table th {
  background: #f5f6f8;
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 12px;
}

.data-table td {
  color: var(--text-primary);
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table tbody tr:hover {
  background: #f9fafb;
}

.data-table .legend-dot {
  margin-right: 6px;
  vertical-align: middle;
}
