/* ------------------------------------------------------------------
   Design tokens
   ------------------------------------------------------------------ */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #171a21;
  --muted: #667085;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8effd;
  --accent-text: #ffffff;
  --success: #15803d;
  --danger: #dc2626;
  --warning-bg: #fff7e6;
  --warning-border: #f5c76a;
  --warning-text: #7a4b00;

  --type-integer: #2563eb;
  --type-number: #2563eb;
  --type-date: #7c3aed;
  --type-boolean: #15803d;
  --type-string: #64748b;
  --type-empty: #b91c1c;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 6px 20px -8px rgba(16, 24, 40, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --topbar-h: 56px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1015;
    --surface: #161922;
    --surface-2: #1d212c;
    --text: #e7e9ee;
    --muted: #8b93a7;
    --border: #262b38;
    --border-strong: #353b4b;
    --accent: #5b8def;
    --accent-hover: #7aa2f7;
    --accent-soft: #1b2a4a;
    --accent-text: #ffffff;
    --success: #4ade80;
    --danger: #f87171;
    --warning-bg: #2b2411;
    --warning-border: #6b4f0e;
    --warning-text: #f5d38a;
    --type-integer: #7aa2f7;
    --type-number: #7aa2f7;
    --type-date: #c084fc;
    --type-boolean: #4ade80;
    --type-string: #9aa4b8;
    --type-empty: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -8px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1015;
  --surface: #161922;
  --surface-2: #1d212c;
  --text: #e7e9ee;
  --muted: #8b93a7;
  --border: #262b38;
  --border-strong: #353b4b;
  --accent: #5b8def;
  --accent-hover: #7aa2f7;
  --accent-soft: #1b2a4a;
  --accent-text: #ffffff;
  --success: #4ade80;
  --danger: #f87171;
  --warning-bg: #2b2411;
  --warning-border: #6b4f0e;
  --warning-text: #f5d38a;
  --type-integer: #7aa2f7;
  --type-number: #7aa2f7;
  --type-date: #c084fc;
  --type-boolean: #4ade80;
  --type-string: #9aa4b8;
  --type-empty: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -8px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------------
   Base
   ------------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Let the `hidden` attribute win over any class that sets `display`. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

main {
  flex: 1;
  width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.accent {
  color: var(--accent);
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.icon--fill {
  fill: currentColor;
  stroke: none;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius);
  z-index: 100;
}

.skip-link:focus {
  top: 12px;
}

/* ------------------------------------------------------------------
   Buttons & controls
   ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--muted);
  text-decoration: none;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}

.btn--ghost:hover {
  border-color: transparent;
  background: var(--surface-2);
}

.btn--sm {
  padding: 5px 10px;
  border-radius: 8px;
  min-width: 34px;
  justify-content: center;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn .icon--moon,
.icon-btn[data-mode="dark"] .icon--sun {
  display: none;
}

.icon-btn[data-mode="dark"] .icon--moon {
  display: block;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 0.9rem;
  transition: background-color 0.15s, border-color 0.15s;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

select,
input[type="search"],
textarea {
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

input[type="search"]::-webkit-search-cancel-button {
  cursor: pointer;
}

/* ------------------------------------------------------------------
   Top bar
   ------------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand:hover {
  text-decoration: none;
}

.brand__logo {
  width: 28px;
  height: 28px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ------------------------------------------------------------------
   Landing
   ------------------------------------------------------------------ */
.landing {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(32px, 8vh, 88px) 20px 48px;
  text-align: center;
}

.landing h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin: 0 0 14px;
}

.lede {
  font-size: 1.1rem;
  color: var(--muted);
  max-width: 600px;
  margin: 0 auto 32px;
}

.dropzone {
  position: relative;
  padding: 44px 24px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, transform 0.15s;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone.is-dragover {
  transform: scale(1.01);
}

.dropzone__icon {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 8px;
}

.dropzone__text {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

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

.dropzone .muted {
  margin: 0;
  font-size: 0.9rem;
}

.samples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 22px 0 8px;
}

.paste {
  margin: 18px auto 0;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.paste summary {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}

.paste[open] summary {
  border-bottom: 1px solid var(--border);
}

.paste textarea {
  display: block;
  width: 100%;
  margin: 12px 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  resize: vertical;
}

.paste > :not(summary) {
  margin-left: 14px;
  margin-right: 14px;
}

.paste .btn {
  margin-bottom: 14px;
}

.features {
  list-style: none;
  margin: 40px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px 24px;
  text-align: left;
  color: var(--muted);
  font-size: 0.95rem;
}

.features strong {
  color: var(--text);
}

/* ------------------------------------------------------------------
   Workspace
   ------------------------------------------------------------------ */
.workspace {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 20px 40px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 14px;
}

.file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.file-meta__name {
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta .muted {
  font-size: 0.875rem;
}

.toolbar__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
}

.search {
  position: relative;
  flex: 1 1 320px;
  max-width: 560px;
  display: flex;
  align-items: center;
}

.search__icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  padding-left: 38px;
  padding-right: 40px;
}

.search__help {
  position: absolute;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.search__help:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.notice {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 0.9rem;
}

.notice ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.notice p {
  margin: 4px 0 0;
}

.notice .btn {
  color: inherit;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.tabs [role="tab"] {
  padding: 8px 14px;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 500;
}

.tabs [role="tab"]:hover {
  color: var(--text);
}

.tabs [role="tab"][aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Grid */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - var(--topbar-h) - 230px);
  min-height: 240px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.grid th,
.grid td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
  padding: 0;
}

.grid thead th.grid__rownum {
  padding: 8px 12px;
  color: var(--muted);
  font-weight: 500;
}

.grid__sort {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: none;
  font-weight: 600;
  text-align: left;
}

.grid th.num .grid__sort {
  flex-direction: row-reverse;
  text-align: right;
}

.grid__sort:hover {
  background: var(--accent-soft);
}

.grid__colname {
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid__arrow {
  font-size: 0.7em;
  color: var(--accent);
  width: 1em;
}

.grid tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}

.grid tbody tr:hover {
  background: var(--accent-soft);
}

.grid tbody tr:last-child td {
  border-bottom: 0;
}

.grid td.num {
  text-align: right;
}

.grid td.null {
  color: var(--muted);
  font-style: italic;
}

.grid td.bool--true {
  color: var(--success);
}

.grid td.bool--false {
  color: var(--muted);
}

.grid .grid__rownum {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.5;
  color: var(--badge-color, var(--muted));
  background: color-mix(in srgb, var(--badge-color, var(--muted)) 14%, transparent);
}

.badge--integer { --badge-color: var(--type-integer); }
.badge--number { --badge-color: var(--type-number); }
.badge--date { --badge-color: var(--type-date); }
.badge--boolean { --badge-color: var(--type-boolean); }
.badge--string { --badge-color: var(--type-string); }
.badge--empty { --badge-color: var(--type-empty); }

/* Pager */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  font-size: 0.9rem;
}

.pager__controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pager__size {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 8px;
}

.pager__size select {
  padding: 5px 8px;
}

.pager__page {
  min-width: 100px;
  text-align: center;
  color: var(--muted);
}

/* Summary cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  min-width: 0;
}

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

.card__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card__meta {
  margin: -6px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 0;
  font-size: 0.875rem;
}

.stats__item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
  min-width: 0;
}

.stats dt {
  color: var(--muted);
  white-space: nowrap;
}

.stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Charts */
.chart {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart__bar {
  fill: var(--accent);
  opacity: 0.85;
  transition: opacity 0.15s;
}

.chart__bar:hover {
  opacity: 1;
}

.chart__axis {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.chart__label {
  fill: var(--muted);
  font-size: 10px;
  font-family: var(--font);
}

.chart-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
}

.bars__row {
  display: grid;
  grid-template-columns: minmax(60px, 38%) 1fr auto;
  align-items: center;
  gap: 10px;
}

.bars__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bars__track {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}

.bars__fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  opacity: 0.85;
}

.bars__count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: right;
}

.bars__row--other {
  color: var(--muted);
  font-style: italic;
}

/* Dialog */
.dialog {
  max-width: 560px;
  width: calc(100% - 32px);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(10, 12, 18, 0.5);
  backdrop-filter: blur(2px);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.dialog p {
  margin: 0 0 12px;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.help-table td {
  padding: 6px 8px 6px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.help-table td:first-child {
  white-space: nowrap;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

/* Toast */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}

.toast-host.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  max-width: min(90vw, 520px);
}

.toast--error {
  background: var(--danger);
  color: #fff;
}

.toast--success {
  background: var(--success);
  color: #fff;
}

/* Footer */
.footer {
  padding: 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------------
   Responsive & motion
   ------------------------------------------------------------------ */
@media (max-width: 720px) {
  .topbar {
    padding: 0 14px;
  }

  .brand__name {
    display: none;
  }

  .workspace {
    padding: 14px 14px 32px;
  }

  .toolbar__controls {
    justify-content: stretch;
  }

  .search {
    flex-basis: 100%;
    max-width: none;
  }

  .table-wrap {
    max-height: none;
  }

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

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