:root {
  color-scheme: dark;
  --bg: #0b0c0e;
  --panel: #181b1f;
  --panel-2: #111317;
  --border: #2f333a;
  --border-soft: #242830;
  --text: #d8d9da;
  --muted: #9fa7b3;
  --faint: #6b7280;
  --orange: #ff9830;
  --orange-strong: #f97316;
  --blue: #5794f2;
  --green: #73bf69;
  --yellow: #f2cc0c;
  --red: #f2495c;
  --purple: #b877d9;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #fbfcfe;
  --border: #d8dde6;
  --border-soft: #e6e9ef;
  --text: #1f2329;
  --muted: #667085;
  --faint: #8a93a3;
  --orange: #ff9830;
  --orange-strong: #f97316;
  --blue: #2563eb;
  --green: #16a34a;
  --yellow: #ca8a04;
  --red: #dc2626;
  --purple: #7c3aed;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

#project-pill {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 9px;
  color: var(--text);
  background: var(--panel);
}

.theme-toggle {
  min-height: 30px;
  padding: 0 10px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
}

.ask-panel,
.panel,
.kpi-card {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
}

.ask-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
  padding: 12px;
}

form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

textarea {
  width: 100%;
  min-height: 74px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--panel-2);
  line-height: 1.4;
}

textarea:focus {
  border-color: var(--orange);
  outline: 2px solid rgba(255, 152, 48, 0.18);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 14px;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
}

button[type="submit"] {
  border-color: #b85f17;
  color: #111317;
  background: var(--orange);
  font-weight: 700;
}

button:hover {
  border-color: var(--orange-strong);
}

button:disabled {
  opacity: 0.58;
  cursor: wait;
}

.status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.status.error {
  color: var(--red);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.kpi-card {
  min-height: 118px;
  padding: 12px;
}

.kpi-card p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.kpi-card strong {
  display: block;
  width: max-content;
  margin-left: auto;
  border-radius: 7px;
  padding: 7px 11px;
  color: #ffffff;
  background: #1db954;
  font-size: 24px;
  font-weight: 650;
  line-height: 1;
}

.kpi-card strong.negative {
  background: var(--red);
}

.kpi-card strong.positive {
  background: #1db954;
}

.stat-body {
  display: grid;
  grid-template-columns: minmax(108px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.stat-value {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.stat-value span {
  color: var(--green);
  font-size: 14px;
  white-space: nowrap;
}

.stat-value span.negative {
  color: var(--red);
}

.sparkline {
  width: 100%;
  height: 54px;
  background: transparent;
}

.spark-grid {
  stroke: var(--faint);
  stroke-dasharray: 2 3;
  stroke-width: 1;
  opacity: 0.8;
}

.spark-path {
  fill: none;
  stroke: var(--red);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.spark-empty {
  fill: var(--muted);
  font-size: 13px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.panel {
  min-width: 0;
  padding: 12px;
}

.panel-wide {
  grid-column: span 2;
}

.adhoc-panel {
  margin-top: 10px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  margin-bottom: 8px;
}

.panel-header span,
#row-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.result-wrap {
  min-height: 420px;
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  overflow: hidden;
  background: var(--panel-2);
}

svg {
  display: block;
  width: 100%;
  height: 420px;
  background: var(--panel-2);
}

.axis {
  stroke: #59606b;
  stroke-width: 1;
}

.grid {
  stroke: #303640;
  stroke-width: 1;
}

.label {
  fill: var(--muted);
  font-size: 12px;
}

.line {
  fill: none;
  stroke: var(--blue);
  stroke-width: 2.2;
}

.area {
  stroke: none;
}

.bar {
  fill: var(--blue);
}

.empty {
  fill: var(--muted);
  font-size: 14px;
}

.text-result {
  display: grid;
  min-height: 420px;
  place-content: center;
  text-align: center;
}

.text-result p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
}

.text-result strong {
  color: var(--text);
  font-size: 58px;
  line-height: 1;
}

.table-result {
  max-height: 420px;
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--border-soft);
  padding: 9px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  color: var(--muted);
  background: var(--panel);
  font-weight: 700;
}

td {
  color: var(--text);
}

.empty-table {
  margin: 24px;
  color: var(--muted);
}

.details {
  margin-top: 12px;
  color: var(--muted);
}

summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

pre {
  overflow: auto;
  margin: 10px 0 0;
  max-height: 260px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-wide {
    grid-column: span 2;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .ask-panel,
  form {
    grid-template-columns: 1fr;
  }

  .topbar,
  .ask-panel {
    display: grid;
  }

  .actions {
    flex-direction: row;
  }

  .kpi-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .panel-wide {
    grid-column: span 1;
  }
}
