:root {
  --ink: #172033;
  --muted: #596579;
  --surface: #ffffff;
  --surface-alt: #f4f6f8;
  --line: #d8dde5;
  --line-strong: #aeb7c4;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --accent: #d97706;
  --danger: #b42318;
  --success: #087443;
  --focus: #f59e0b;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--surface-alt); }
body { margin: 0; color: var(--ink); background: var(--surface-alt); font-family: var(--sans); font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, label[for] { cursor: pointer; }

.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; padding: 8px 12px; color: #fff; background: var(--ink); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }

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

.topbar { display: flex; min-height: 64px; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand-block, .topbar-actions, .toolbar-group, .dialog-heading, .dialog-actions { display: flex; align-items: center; }
.brand-block { gap: 10px; min-width: 0; }
.brand-mark { display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; border-radius: 4px; color: #fff; background: var(--primary); font: 700 12px var(--mono); }
h1, h2, p { margin: 0; }
h1 { font-size: 17px; line-height: 1.2; }
.brand-block p { margin-top: 2px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { gap: 10px; }
.engine-status { min-width: 64px; color: var(--muted); font: 600 12px var(--mono); text-align: right; }
.engine-status.ready { color: var(--success); }
.engine-status.failed { color: var(--danger); }

.workbench { width: 100%; max-width: 1680px; min-height: calc(100vh - 64px); margin: 0 auto; padding: 16px 20px 24px; }
.toolbar-band { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.toolbar-group { gap: 8px; flex-wrap: wrap; }
.button { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); background: var(--surface); font-weight: 650; text-decoration: none; transition: background 160ms ease, border-color 160ms ease, color 160ms ease; }
.button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.button.primary { border-color: var(--primary); color: #fff; background: var(--primary); }
.button.primary:hover:not(:disabled) { color: #fff; background: var(--primary-hover); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.icon-button { width: 36px; padding: 6px; font-size: 16px; }
.checkbox-label { display: inline-flex; min-height: 36px; align-items: center; gap: 7px; color: var(--muted); font-weight: 600; }
.checkbox-label input { width: 16px; height: 16px; accent-color: var(--primary); }
.number-control { display: inline-flex; min-height: 36px; align-items: center; gap: 7px; color: var(--muted); font-weight: 600; }
.number-control input { width: 90px; min-height: 34px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); background: var(--surface); }
.number-control input:disabled { cursor: not-allowed; opacity: .45; }

.drop-zone { display: flex; min-height: 190px; align-items: center; justify-content: center; gap: 18px; margin-top: 16px; padding: 28px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); text-align: left; }
.drop-zone.dragging { border-color: var(--primary); background: #eff6ff; }
.drop-glyph { display: grid; width: 58px; height: 58px; flex: 0 0 58px; place-items: center; border: 1px solid #93c5fd; border-radius: 4px; color: var(--primary); background: #eff6ff; font: 750 13px var(--mono); }
.drop-zone h2 { font-size: 18px; }
.drop-zone p { margin-top: 5px; color: var(--muted); }

.data-panel { margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.summary-strip { display: flex; min-height: 38px; align-items: center; gap: 20px; padding: 7px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font: 12px var(--mono); }
.summary-strip strong { color: var(--ink); }
#preview-note { margin-left: auto; color: var(--accent); }
.filter-strip, .column-strip { display: flex; gap: 8px; padding: 9px 12px; overflow-x: auto; background: var(--surface-alt); scrollbar-width: thin; }
.filter-strip { border-bottom: 1px solid var(--line); }
.column-strip { align-items: center; border-top: 1px solid var(--line); }
.filter-control { display: grid; min-width: 150px; grid-template-columns: 1fr; gap: 4px; }
.filter-control label { overflow: hidden; color: var(--muted); font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.filter-control select, .filter-control input, .export-controls select, .export-controls input { min-height: 34px; min-width: 0; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); background: var(--surface); }
.filter-control select, .filter-control input { padding: 6px 8px; font-size: 12px; }
.table-scroll { max-width: 100%; min-height: 300px; max-height: calc(100vh - 310px); overflow: auto; }
table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font: 12px var(--mono); }
th, td { height: 36px; padding: 7px 11px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; color: #fff; background: #24324a; }
th:last-child, td:last-child { border-right: 0; }
tbody tr:nth-child(even) td { background: #f8fafc; }
tbody tr:hover td { background: #fff7ed; }
.sort-button { min-width: 100%; padding: 0; border: 0; color: inherit; background: transparent; font: inherit; font-weight: 750; text-align: left; }
.sort-button:hover { color: #fde68a; }
.row-number { color: var(--muted); background: var(--surface-alt); text-align: right; }
.column-toggle { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.column-toggle input { accent-color: var(--primary); }

.message, .error, .warning { min-height: 20px; margin-top: 10px; padding: 0 2px; font-size: 13px; }
.message { color: var(--success); }
.error { color: var(--danger); font-weight: 650; }
.warning { color: #92400e; font-weight: 650; }

dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--ink); background: var(--surface); }
dialog::backdrop { background: rgb(15 23 42 / .55); }
.dialog-shell { display: grid; gap: 12px; padding: 18px; }
.dialog-heading { justify-content: space-between; gap: 16px; }
.dialog-heading h2 { font-size: 17px; }
.dialog-heading p { margin-top: 3px; color: var(--muted); font-size: 12px; }
.dialog-shell > label, .export-controls label { color: var(--muted); font-size: 12px; font-weight: 700; }
textarea { width: 100%; min-width: 0; padding: 10px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); background: var(--surface-alt); font: 12px/1.55 var(--mono); resize: vertical; }
.dialog-actions { justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.export-controls { display: grid; grid-template-columns: auto minmax(130px, 1fr) auto minmax(130px, 1fr); align-items: center; gap: 8px; }
.export-controls select, .export-controls input { padding: 6px 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 780px) {
  .topbar { padding: 9px 12px; }
  .brand-block p { max-width: 52vw; }
  .workbench { padding: 12px; }
  .toolbar-band { align-items: stretch; flex-direction: column; }
  .toolbar-group { width: 100%; }
  .toolbar-group .button { flex: 1 1 auto; }
  .drop-zone { min-height: 160px; align-items: flex-start; flex-direction: column; gap: 12px; }
  .summary-strip { align-items: flex-start; flex-wrap: wrap; gap: 8px 16px; }
  #preview-note { width: 100%; margin-left: 0; }
  .table-scroll { max-height: calc(100vh - 350px); }
  .export-controls { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
