:root {
  color-scheme: dark;
  --bg: #0f1318;
  --panel: #171d24;
  --panel-strong: #1f2731;
  --panel-soft: #131920;
  --border: #2b3541;
  --text: #e8eef5;
  --muted: #95a3b3;
  --muted-strong: #bac4cf;
  --accent: #38a6e8;
  --accent-soft: #0f3349;
  --green: #40c463;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
  background: #121820;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 8px;
  font-size: 24px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 12px;
  font-size: 15px;
  color: var(--muted-strong);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #1b80bd;
  border-radius: 6px;
  background: var(--accent);
  color: #061018;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.button.secondary {
  display: inline-flex;
  align-items: center;
  border-color: var(--border);
  background: var(--panel-strong);
  color: var(--text);
}

.button.compact,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.shell {
  padding: 20px clamp(12px, 3vw, 32px) 32px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-grid article {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.metric-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-grid strong {
  overflow-wrap: anywhere;
  font-size: 22px;
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(360px, 0.95fr) minmax(420px, 1.2fr);
  min-height: calc(100vh - 190px);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-soft);
  box-shadow: var(--shadow);
}

.filters {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: #121820;
}

.upload-panel {
  display: grid;
  gap: 12px;
  min-width: 0;
  overflow: hidden;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c1117;
}

.upload-panel.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-panel strong {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: var(--text);
  font-size: 14px;
  line-height: 1.25;
}

.upload-panel p {
  overflow-wrap: anywhere;
  word-break: break-word;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.upload-panel p.is-error {
  color: #ff9f9f;
}

.upload-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.upload-actions .button {
  width: 100%;
}

#csvInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0c1117;
  color: var(--text);
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.filter-meta {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.results-panel {
  min-width: 0;
  border-right: 1px solid var(--border);
}

.table-wrap {
  max-height: calc(100vh - 190px);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel-strong);
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted-strong);
  font-size: 12px;
}

td {
  color: #d7e0ea;
  font-size: 13px;
}

th:nth-child(1),
td:nth-child(1) {
  width: 92px;
}

th:nth-child(3),
td:nth-child(3),
th:nth-child(5),
td:nth-child(5) {
  width: 64px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.is-selected {
  background: var(--accent-soft);
}

.cell-title {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-subtitle,
.cell-prompt {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.detail-panel {
  min-width: 0;
  max-height: calc(100vh - 190px);
  overflow: auto;
  background: #10161d;
}

.detail-empty {
  display: grid;
  min-height: 100%;
  padding: 40px 28px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.detail-content {
  padding: 22px;
}

.detail-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.detail-heading p {
  color: var(--muted);
  line-height: 1.5;
}

.pill,
.output-pill {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.output-pill {
  border-color: #1e6634;
  background: #0f2b1a;
  color: var(--green);
}

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

.meta-list div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}

.meta-list dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.meta-list dd {
  overflow: hidden;
  margin: 0;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content-section {
  margin-top: 18px;
}

.content-section p,
.prompt-text,
.explanation-text {
  color: #d6dee7;
  line-height: 1.55;
}

.explanation-text {
  color: var(--muted);
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.code-block {
  overflow: auto;
  max-height: 360px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #090d12;
  color: #b9e8ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
}

.steps-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 24px;
  color: #d6dee7;
  line-height: 1.5;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 240px minmax(320px, 1fr);
  }

  .detail-panel {
    grid-column: 1 / -1;
    max-height: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-grid,
  .workspace,
  .meta-list {
    grid-template-columns: 1fr;
  }

  .filters,
  .results-panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .table-wrap,
  .detail-panel {
    max-height: none;
  }

  th:nth-child(1),
  td:nth-child(1),
  th:nth-child(3),
  td:nth-child(3),
  th:nth-child(5),
  td:nth-child(5) {
    width: auto;
  }

  th:nth-child(4),
  td:nth-child(4) {
    display: none;
  }

  .detail-heading {
    flex-direction: column;
  }
}
