@import url("https://fonts.googleapis.com/css2?family=Fraunces:wght@600;700&family=JetBrains+Mono:wght@400;600&family=Spline+Sans:wght@400;600&display=swap");

:root {
  color-scheme: light;
  --ink: #122226;
  --muted: #4b5d63;
  --paper: #f6f1e8;
  --surface: #ffffff;
  --line: rgba(18, 34, 38, 0.14);
  --accent: #e07a3d;
  --accent-strong: #b1521b;
  --teal: #2f6f72;
  --shadow: 0 16px 40px rgba(18, 34, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Spline Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #f6efe6 0%, #eef6f2 45%, #f4efe3 100%);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(18, 34, 38, 0.08) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.35;
  pointer-events: none;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.hero {
  padding: 28px 32px;
  border-radius: 24px;
  background: linear-gradient(140deg, #fff8ec, #f8f8f6 60%, #edf6f2 100%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: rise 0.7s ease both;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.7rem;
  color: var(--muted);
  margin: 0 0 12px;
}

h1 {
  font-family: "Fraunces", "Times New Roman", serif;
  font-weight: 700;
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0 0 8px;
}

.lede {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 640px;
}

.status-row {
  display: flex;
  gap: 16px;
  align-items: center;
  font-weight: 600;
  color: var(--teal);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 4px rgba(47, 111, 114, 0.18);
}

.status[data-state="busy"]::before {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(224, 122, 61, 0.18);
}

.status[data-state="error"]::before {
  background: #b0352c;
  box-shadow: 0 0 0 4px rgba(176, 53, 44, 0.18);
}

.elapsed {
  color: var(--muted);
  font-size: 0.95rem;
}

.grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1.1fr);
  gap: 20px;
  margin-top: 28px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(18, 34, 38, 0.08);
  animation: rise 0.7s ease both;
}

.panel:nth-of-type(1) {
  animation-delay: 0.06s;
}

.panel:nth-of-type(2) {
  animation-delay: 0.12s;
}

.panel:nth-of-type(3) {
  animation-delay: 0.18s;
}

.panel:nth-of-type(4) {
  animation-delay: 0.24s;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

h2 {
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: 1.2rem;
  margin: 0;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(47, 111, 114, 0.12);
  color: var(--teal);
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  font-weight: 600;
}

.field input,
.field select,
textarea {
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  background: #fbfbf9;
}

.field input:focus,
.field select:focus,
textarea:focus {
  outline: 2px solid rgba(224, 122, 61, 0.25);
  border-color: rgba(224, 122, 61, 0.6);
}

.field-inline {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.dataset-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dataset-controls select {
  flex: 1;
}

.controls {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.history-panel {
  grid-column: 1 / -1;
}

.history-controls {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.history-error {
  color: #b0352c;
}

.history-summary {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(47, 111, 114, 0.25);
  background: rgba(47, 111, 114, 0.08);
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
}

.history-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.history-summary-label {
  color: var(--muted);
  font-weight: 600;
}

.history-summary-value {
  font-weight: 600;
  color: var(--ink);
}

.history-visuals {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 16px;
}

.history-chart-block {
  display: grid;
  gap: 6px;
}

.history-chart-title {
  font-weight: 600;
  color: var(--muted);
}

.history-chart {
  width: 100%;
  min-height: 120px;
  border-radius: 14px;
  border: 1px solid rgba(47, 111, 114, 0.2);
  background: rgba(47, 111, 114, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.history-chart svg {
  width: 100%;
  height: 120px;
}

.history-chart-path {
  fill: none;
  stroke: #2f6f72;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-chart-dot {
  fill: #e07a3d;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.history-band {
  stroke: rgba(47, 111, 114, 0.5);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.history-chart-point {
  fill: transparent;
  stroke: transparent;
  pointer-events: all;
}

.history-chart-point:hover {
  fill: #2f6f72;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.history-anomaly-dot {
  fill: #b0352c;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.history-insights {
  display: grid;
  gap: 8px;
}

.history-anomalies {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.history-anomalies-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.history-anomalies-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.history-anomaly-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.history-insight {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(18, 34, 38, 0.08);
  background: #f9f6f0;
}

.history-insight-label {
  color: var(--muted);
  font-weight: 600;
}

.history-insight-value {
  font-weight: 600;
  color: var(--ink);
}

.compare-panel {
  grid-column: 1 / -1;
}

.compare-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px;
  align-items: end;
}

.compare-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.compare-visuals {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 16px;
}

.compare-chart-block {
  display: grid;
  gap: 6px;
}

.compare-chart-title {
  font-weight: 600;
  color: var(--muted);
}

.compare-chart {
  width: 100%;
  min-height: 120px;
  border-radius: 14px;
  border: 1px solid rgba(47, 111, 114, 0.2);
  background: rgba(47, 111, 114, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.compare-chart svg {
  width: 100%;
  height: 120px;
}

.compare-chart-path-a {
  fill: none;
  stroke: #2f6f72;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.compare-chart-path-b {
  fill: none;
  stroke: #e07a3d;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.compare-band-a {
  stroke: rgba(47, 111, 114, 0.45);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.compare-band-b {
  stroke: rgba(224, 122, 61, 0.45);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.compare-chart-dot-a {
  fill: #2f6f72;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.compare-chart-dot-b {
  fill: #e07a3d;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.compare-chart-point-a,
.compare-chart-point-b {
  fill: transparent;
  stroke: transparent;
  pointer-events: all;
}

.compare-chart-point-a:hover {
  fill: #2f6f72;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.compare-chart-point-b:hover {
  fill: #e07a3d;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.compare-anomaly-dot-a {
  fill: #2f6f72;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.compare-anomaly-dot-b {
  fill: #e07a3d;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.compare-insights {
  display: grid;
  gap: 8px;
}

.compare-anomalies {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.compare-anomalies-block {
  display: grid;
  gap: 6px;
}

textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  line-height: 1.45;
  background: #f9f6f0;
}

.hint {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}

.hidden {
  display: none;
}

.banner {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  font-weight: 600;
}

.banner-error {
  background: rgba(176, 53, 44, 0.12);
  border: 1px solid rgba(176, 53, 44, 0.4);
  color: #7a2720;
}

.diagnostics {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px dashed rgba(18, 34, 38, 0.2);
  background: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  color: var(--muted);
}

.diagnostics summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--teal);
}

.diagnostics pre {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f7f3ea;
  color: var(--ink);
  white-space: pre-wrap;
}

.diagnostics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 16px;
  margin-top: 10px;
}

.diagnostics-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.diagnostics-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.diagnostics-value {
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
}

.diagnostics-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.diagnostics-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  grid-column: 1 / -1;
}

.pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(47, 111, 114, 0.16);
  color: var(--teal);
  font-size: 0.75rem;
  font-weight: 700;
}

.mono {
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  font-size: 0.85rem;
}

button.small {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.warning-banner {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(224, 122, 61, 0.14);
  border: 1px solid rgba(224, 122, 61, 0.4);
  color: #7a3a12;
  font-size: 0.9rem;
}

.warning-title {
  font-weight: 700;
}

.warning-details {
  margin-top: 6px;
}

.warning-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent-strong);
}

.warning-details-body {
  margin-top: 6px;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: pre-wrap;
}

button {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

button.primary {
  background: var(--accent);
  color: #fffaf3;
  box-shadow: 0 8px 18px rgba(224, 122, 61, 0.35);
}

button.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(224, 122, 61, 0.4);
}

button.ghost {
  background: #f0eee7;
  color: var(--accent-strong);
}

.advanced-panel {
  grid-column: 1 / -1;
}

.advanced-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.advanced-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.advanced-value {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 4px;
}

.advanced-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.results-panel {
  grid-column: 1 / -1;
}

.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 12px;
}

.results {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: auto;
  max-height: 60vh;
  background: #fffefc;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95rem;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(18, 34, 38, 0.08);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f7f3ea;
  font-weight: 700;
}

.error {
  display: none;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(176, 53, 44, 0.08);
  border: 1px solid rgba(176, 53, 44, 0.3);
  color: #7a2720;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  white-space: pre-wrap;
}

.error.show {
  display: block;
}

.tips ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .history-visuals {
    grid-template-columns: 1fr;
  }

  .history-controls {
    grid-template-columns: 1fr;
  }

  .compare-controls {
    grid-template-columns: 1fr;
  }

  .compare-visuals {
    grid-template-columns: 1fr;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .dataset-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .results-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
}

@media (max-width: 600px) {
  .history-insights {
    display: none;
  }

  .compare-insights {
    display: none;
  }

  .history-anomalies {
    display: none;
  }

  .compare-anomalies {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
