:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --accent: #2f6f64;
  --accent-2: #6ba3a8;
  --text: #1f2a30;
  --muted: #4f5b62;
  --border: #d9d7d2;
  --danger: #d64545;
  --success: #2f6f5e;
  --sand: #e8e3da;
  --frost: #dfe7ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  background:
    radial-gradient(circle at 20% 10%, rgba(47, 111, 100, 0.12), transparent 22%),
    radial-gradient(circle at 80% 0%, rgba(107, 163, 168, 0.08), transparent 24%),
    linear-gradient(135deg, #f8f6f2 0%, #eef2f3 65%, #f4f7f7 100%);
  color: var(--text);
  letter-spacing: -0.01em;
}

.page {
  width: 98vw;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.landing {
  max-width: 1180px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

a.brand:visited,
a.brand:active {
  color: inherit;
  text-decoration: none;
}

a.brand:hover {
  opacity: 0.8;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: conic-gradient(from 120deg, rgba(47, 111, 100, 0.2), rgba(107, 163, 168, 0.65), rgba(47, 111, 100, 0.2));
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.brand-mark::after {
  content: "";
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 8px;
  opacity: 0.7;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.03em;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
  margin: 2px 0 0;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.ghost-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.ghost-link:hover {
  color: var(--text);
  border-color: var(--border);
  background: rgba(47, 111, 100, 0.06);
}

.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
  align-items: center;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: var(--muted);
}

.hero-title {
  font-size: clamp(32px, 5vw, 46px);
  line-height: 1.05;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.04em;
}

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

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.hero-chip-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(47, 111, 100, 0.05);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}

.data-card {
  background: linear-gradient(145deg, #ffffff, #f7f6f3);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 14px 34px rgba(12, 26, 37, 0.08);
  display: grid;
  gap: 12px;
}

.data-card h3 {
  margin: 0;
  font-size: 16px;
}

.stat-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stat-chip {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 4px;
}

.stat-sub {
  font-size: 13px;
  color: var(--muted);
}

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

.section-title h2,
.section-title h3 {
  margin: 0;
  font-size: 20px;
}

.section-title .muted {
  font-size: 12px;
}

.surface {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(12, 26, 37, 0.06);
  padding: 18px !important;
}

.search-input {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  width: 200px;
  transition: all 0.15s;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.connection-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.connection-link:hover {
  text-decoration: underline;
  color: var(--accent);
}

.connection-link:visited {
  color: var(--muted);
  text-decoration: line-through;
  opacity: 0.7;
}

header {
  margin-bottom: 8px;
  flex-shrink: 0;
}

p.lead {
  margin: 0 0 12px;
  color: var(--muted);
  max-width: 720px;
  font-size: 13px;
}

.surface.narrow {
  max-width: 680px;
}

.surface.ghost {
  background: rgba(255, 255, 255, 0.7);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.left-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.right-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

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

.card {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
}

.card .label {
  font-size: 11px;
}

.card .value {
  font-size: 16px;
  font-weight: 600;
  margin-top: 2px;
}

.card .muted {
  font-size: 11px;
}

.label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.value {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 700;
}

.hero-number {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.04em;
  margin-top: 4px;
  line-height: 1;
}

.canvas-wrap canvas,
canvas {
  background: #f0f2f4;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 8px;
}

#chart {
  max-height: 120px !important;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0;
  font-size: 14px;
}

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

th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: #f0f2f4;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

tr:hover td {
  background: rgba(47, 111, 100, 0.04);
}

.surface-table {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pill.male {
  background: rgba(47, 111, 100, 0.12);
  color: #2f6f64;
}

.pill.female {
  background: rgba(107, 163, 168, 0.16);
  color: #3a7d77;
}

.pill.nonbinary {
  background: rgba(230, 180, 84, 0.16);
  color: #c07a1f;
}

.pill.unknown {
  background: rgba(79, 91, 98, 0.1);
  color: #4f5b62;
}

.unknown-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.unknown-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.close-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.close-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.unknown-name {
  font-weight: 600;
}

.button {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  border: none;
  color: #f6f8f7;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 15px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
  box-shadow: 0 14px 34px rgba(47, 111, 100, 0.18);
}

.button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow: 0 16px 40px rgba(47, 111, 100, 0.24);
}

.button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.button.ghost:hover {
  background: rgba(47, 111, 100, 0.08);
}

.button.small {
  padding: 6px 12px;
  font-size: 13px;
  box-shadow: none;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.5);
  transform: none;
}

.mini-btn {
  border: none;
  border-radius: 8px;
  padding: 4px 11px;
  font-weight: 700;
  cursor: pointer;
  font-size: 16px;
  color: #0b1222;
  transition: all 0.15s ease;
  line-height: 1.2;
}

.mini-btn.female {
  background: linear-gradient(135deg, #c084fc, #a855f7);
}

.mini-btn.male {
  background: linear-gradient(135deg, #67e8f9, #38bdf8);
}

.mini-btn.nonbinary {
  background: linear-gradient(135deg, #facc15, #eab308);
}

.action-group {
  display: flex;
  gap: 4px;
}

.action-group .mini-btn {
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  padding: 4px 8px;
}

.action-group .mini-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.action-group .mini-btn.active {
  color: #0b1222;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.action-group .mini-btn.active.female {
  background: linear-gradient(135deg, #c084fc, #a855f7);
}

.action-group .mini-btn.active.male {
  background: linear-gradient(135deg, #67e8f9, #38bdf8);
}

.action-group .mini-btn.active.nonbinary {
  background: linear-gradient(135deg, #facc15, #eab308);
}

.action-group .mini-btn.active.unknown {
  background: #94a3b8;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.dropzone {
  border: 1.5px dashed rgba(79, 91, 98, 0.35);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
  border-radius: 12px;
  background: #fff;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(47, 111, 100, 0.08);
}

.dropzone h3 {
  margin: 6px 0 6px;
  font-size: 18px;
}

.dropzone p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.scrollable-table-container {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.error {
  color: var(--danger);
  margin-top: 8px;
}

.stacked-bars-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.stacked-bar {
  display: flex;
  height: 24px;
  border-radius: 8px;
  overflow: hidden;
  background: #e3e7e9;
  border: 1px solid var(--border);
}

.stacked-bar .empty {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 0, 0, 0.35);
  font-size: 11px;
}

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

.bar-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 14px;
}

.legend-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  justify-content: center;
}

.legend-row .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.footer {
  text-align: center;
  padding: 40px 20px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

.footer a {
  color: inherit;
  text-decoration: underline;
}

@media (max-width: 640px) {
  h1 {
    font-size: 24px;
  }

  .value {
    font-size: 26px;
  }

  .dropzone {
    padding: 20px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: #0f1f25;
  color: #fff;
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
  min-width: 300px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-success {
  border-left: 4px solid #10b981;
}

.toast-error {
  border-left: 4px solid #ef4444;
}

.toast-info {
  border-left: 4px solid #3b82f6;
}

.privacy-badge {
  position: fixed;
  bottom: 20px;
  left: 20px;
  padding: 8px 16px;
  border-radius: 50px;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  pointer-events: none;
  opacity: 0.9;
}

.privacy-badge.safe {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.privacy-badge.warning {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}