:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #020617;
  color: #e2e8f0;
  
  /* Spacing scale (4px base) for consistent gaps between panes */
  --space-1: 4px;    /* 0.25rem - Tiny gaps */
  --space-2: 8px;    /* 0.5rem - Small gaps */
  --space-3: 12px;   /* 0.75rem - Medium gaps */
  --space-4: 16px;   /* 1rem - Standard gaps */
  --space-5: 20px;   /* 1.25rem - Large gaps */
  --space-6: 24px;   /* 1.5rem - Extra large gaps */
  --space-8: 32px;   /* 2rem - Section spacing */
  --space-12: 48px;  /* 3rem - Major section spacing */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #0f172a, #020617 60%);
}

.page {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero {
  margin-bottom: 24px;
}

.hero h1 {
  margin: 0 0 var(--space-2);
  font-size: clamp(2rem, 4vw, 3rem);
}

.eyebrow,
.meta-label {
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

.hero-copy {
  max-width: 70ch;
  color: #cbd5e1;
}

.grid {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.two-columns {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.card {
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.3);
}

.card-compact {
  padding: 14px 16px;
}

.upload-form,
.stack,
.dataset-list,
.legend,
.meta-grid,
.summary-grid,
.filter-grid,
.conversion-grid,
.control-field {
  display: grid;
  gap: var(--space-3);
}

.upload-form label {
  display: grid;
  gap: var(--space-2);
  color: #cbd5e1;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.9);
  color: #f8fafc;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
  color: #02111f;
  font-weight: 700;
}

button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.dataset-item {
  width: 100%;
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  flex-wrap: wrap;
}

.dataset-item.active {
  outline: 2px solid #22c55e;
}

.dataset-item.drag-over {
  border-color: rgba(96, 165, 250, 0.8);
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
}

.dataset-item-copy {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.dataset-item-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.dataset-drag-handle {
  cursor: grab;
  user-select: none;
}

.dataset-drag-handle:active {
  cursor: grabbing;
}

.dataset-focus-button.active {
  border-color: rgba(34, 197, 94, 0.45);
  color: #bbf7d0;
}

.dataset-visibility-control {
  display: grid;
  gap: var(--space-2);
  justify-items: end;
}

.dataset-visibility-control.disabled {
  opacity: 0.55;
}

.toggle-switch {
  position: relative;
  display: inline-flex;
  width: 46px;
  height: 28px;
}

.toggle-switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.toggle-switch input:disabled {
  cursor: not-allowed;
}

.toggle-slider {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: rgba(51, 65, 85, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.24);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #e2e8f0;
  transition: transform 0.2s ease, background 0.2s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
  border-color: transparent;
}

.toggle-switch input:checked + .toggle-slider::after {
  transform: translateX(18px);
  background: #02111f;
}

.toggle-switch input:disabled + .toggle-slider {
  opacity: 0.5;
}

.section-toggle {
  width: auto;
  padding: 8px 12px;
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.section-toggle:hover {
  background: rgba(51, 65, 85, 0.95);
}

.summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.meta-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.meta-grid > div {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.meta-grid .meta-label {
  flex-shrink: 0;
}

.meta-grid strong {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.summary-card,
.card-row,
.section-header,
.chart-meta,
.legend-item,
.pager,
.row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.filter-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  flex: 1;
}

.control-field {
  min-width: 0;
}

.control-field-inline {
  width: auto;
  min-width: 140px;
}

.conversion-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: var(--space-4);
}

.actions-row {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-4);
}

.chart-options-card {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-4);
  padding: var(--space-4);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.chart-options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
}

.checkbox-field {
  align-content: start;
}

.checkbox-control {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.9);
  color: #f8fafc;
}

.checkbox-input {
  width: auto;
  margin: 0;
}

.meta-inline {
  color: #94a3b8;
  font-size: 0.85rem;
}

.pager,
.row-actions {
  justify-content: flex-end;
}

.table-shell {
  overflow-x: auto;
  margin-top: var(--space-4);
}

.data-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  vertical-align: top;
}

.data-table th {
  color: #94a3b8;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.data-table tbody tr:hover {
  background: rgba(15, 23, 42, 0.55);
}

button.button-secondary,
button.button-ghost {
  width: auto;
  padding: 8px 12px;
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.24);
}

button.button-secondary {
  background: rgba(30, 41, 59, 0.85);
}

button.button-ghost {
  background: transparent;
}

.range-caption {
  color: #94a3b8;
  margin-top: 0;
}

.banner {
  padding: var(--space-3) 14px;
  border-radius: 14px;
  margin-bottom: var(--space-4);
}

.banner-error {
  background: rgba(127, 29, 29, 0.35);
  border: 1px solid rgba(248, 113, 113, 0.4);
}

.banner-info {
  background: rgba(8, 47, 73, 0.4);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.badge {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.badge-error {
  background: rgba(220, 38, 38, 0.18);
  color: #fecaca;
}

.badge-warning {
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
}

.badge-info {
  background: rgba(56, 189, 248, 0.18);
  color: #bae6fd;
}

.empty-state {
  color: #94a3b8;
  padding: 12px 0;
}

.metric-chart {
  width: 100%;
  height: auto;
  margin-top: var(--space-4);
  background: rgba(2, 6, 23, 0.55);
  border-radius: 14px;
}

.legend-panel {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.chart-note {
  margin: 0;
}

.legend {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.legend-item {
  align-items: center;
  justify-content: flex-start;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 12px;
  padding: 10px 12px;
}

.legend-copy {
  display: grid;
  gap: var(--space-2);
}

.legend-line {
  width: 28px;
  height: 4px;
  border-radius: 999px;
  display: inline-block;
}

p {
  margin: var(--space-2) 0 0;
  color: #cbd5e1;
}

strong {
  color: #f8fafc;
}

.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.login-page .hero {
  text-align: center;
}

.login-card {
  width: min(400px, 100%);
}

.login-form {
  display: grid;
  gap: var(--space-4);
}

.login-form label {
  display: grid;
  gap: var(--space-2);
  color: #cbd5e1;
}

.hero-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.user-form {
  margin-bottom: var(--space-5);
}

.badge-user {
  background: rgba(56, 189, 248, 0.18);
  color: #bae6fd;
}

.badge-admin {
  background: rgba(34, 197, 94, 0.18);
  color: #bbf7d0;
}

.button-danger {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.4);
}

.button-danger:hover {
  background: rgba(127, 29, 29, 0.35);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(2, 6, 23, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  width: min(900px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}

.modal-body {
  flex: 1;
}

.clickable-suggestion {
  cursor: pointer;
  padding: 12px;
  border-radius: 12px;
  transition: background 0.2s;
  border: 1px solid transparent;
}

.clickable-suggestion:hover {
  background: rgba(30, 41, 59, 0.6);
  border-color: rgba(148, 163, 184, 0.2);
}

.clickable-suggestion .meta-label {
  display: block;
  margin-top: var(--space-2);
  color: #0ea5e9;
}

.heatmap-label-row {
  display: flex;
  justify-content: space-between;
  color: #94a3b8;
  font-size: 11px;
}

.heatmap-cell {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.heatmap-cell:hover {
  transform: translateY(-1px);
}

/* Findings Highlighting */
.row-finding-error {
  background: rgba(239, 68, 68, 0.1) !important;
}

.row-finding-warning {
  background: rgba(245, 158, 11, 0.1) !important;
}

.row-finding-info {
  background: rgba(56, 189, 248, 0.1) !important;
}

.row-finding-error:hover {
  background: rgba(239, 68, 68, 0.2) !important;
}

.row-finding-warning:hover {
  background: rgba(245, 158, 11, 0.2) !important;
}

.row-finding-info:hover {
  background: rgba(56, 189, 248, 0.2) !important;
}

/* Negative/Zero Value Styling */
.value-negative {
  color: #ef4444;
  font-weight: 600;
}

.value-zero {
  color: #ef4444;
  font-weight: 600;
}

.row-zero-value {
  background: rgba(239, 68, 68, 0.08);
}

.row-zero-value:hover {
  background: rgba(239, 68, 68, 0.16) !important;
}
