@import url("../design/tokens.css");

:root {
  --app-canvas: var(--ui-color-canvas);
  --app-surface: var(--ui-color-surface);
  --app-surface-muted: var(--ui-color-surface-muted);
  --app-border: var(--ui-color-border);
  --app-border-strong: var(--ui-color-border-strong);
  --app-text: var(--ui-color-text);
  --app-text-secondary: var(--ui-color-text-secondary);
  --app-text-tertiary: var(--ui-color-text-tertiary);
  --app-primary: var(--ui-color-primary);
  --app-primary-hover: var(--ui-color-primary-hover);
  --app-primary-muted: var(--ui-color-primary-muted);
  --app-success: var(--ui-color-success);
  --app-success-muted: var(--ui-color-success-muted);
  --app-warning: var(--ui-color-warning);
  --app-warning-muted: var(--ui-color-warning-muted);
  --app-danger: var(--ui-color-danger);
  --app-danger-muted: var(--ui-color-danger-muted);
  --app-focus: 0 0 0 3px color-mix(in srgb, var(--app-primary) 24%, transparent);
  --app-table-edge: color-mix(in srgb, var(--app-primary) 38%, var(--app-border));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-width: 320px;
  background: var(--app-canvas);
  color: var(--app-text);
  font-family: var(--ui-font-sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body { margin: 0; min-height: 100vh; background: var(--app-canvas); }
button, input, select { font: inherit; }
button, label[for], summary { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, label[role="button"]:focus-visible, .drop-zone:focus-within { outline: none; box-shadow: var(--app-focus); }
button:disabled { cursor: not-allowed; opacity: .48; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
p, li, small { text-wrap: pretty; }
svg { display: block; width: 1.1rem; height: 1.1rem; fill: currentColor; flex: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.app-header {
  position: sticky; top: 0; z-index: 40; height: var(--ui-size-header);
  display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-16);
  padding: 0 clamp(var(--ui-space-16), 4vw, var(--ui-space-40));
  background: color-mix(in srgb, var(--app-surface) 94%, transparent);
  border-bottom: 1px solid var(--app-border);
  backdrop-filter: blur(12px);
}

.brand { display: inline-flex; align-items: center; gap: var(--ui-space-12); color: inherit; text-decoration: none; min-height: 44px; }
.brand-mark { width: 32px; height: 32px; border-radius: 7px; outline: 1px solid rgba(0, 0, 0, .1); outline-offset: -1px; }
.brand span { display: grid; line-height: 1.1; }
.brand strong { font-size: var(--ui-font-size-md); letter-spacing: -.01em; }
.brand small { margin-top: 3px; color: var(--app-text-secondary); font-size: var(--ui-font-size-xs); }
.header-actions { display: flex; align-items: center; gap: var(--ui-space-8); }
.offline-badge { display: inline-flex; align-items: center; gap: 5px; color: var(--app-success); font-size: var(--ui-font-size-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.offline-badge svg { width: 15px; height: 15px; }

.btn, .icon-btn {
  min-height: 40px; border: 0; border-radius: var(--ui-radius-control); cursor: pointer;
  transition-property: background-color, color, box-shadow, transform, opacity;
  transition-duration: 150ms; transition-timing-function: ease-out;
}
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--ui-space-8); padding: 0 14px; font-size: var(--ui-font-size-sm); font-weight: 650; white-space: nowrap; }
.btn:active:not(:disabled), .icon-btn:active:not(:disabled) { transform: scale(.96); }
.btn-primary { color: var(--ui-color-on-primary); background: var(--app-primary); }
.btn-primary:hover:not(:disabled) { background: var(--app-primary-hover); }
.btn-secondary { color: var(--app-primary); background: var(--app-surface); box-shadow: 0 0 0 1px var(--app-border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--app-primary-muted); box-shadow: 0 0 0 1px color-mix(in srgb, var(--app-primary) 38%, var(--app-border)); }
.btn-ghost { color: var(--app-text-secondary); background: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--app-primary); background: var(--app-primary-muted); }
.btn-text { min-height: 40px; padding: 0 var(--ui-space-8); color: var(--app-primary); background: transparent; }
.btn-text:hover:not(:disabled) { background: var(--app-primary-muted); }
.icon-btn { display: grid; place-items: center; width: 40px; padding: 0; color: var(--app-text-secondary); background: transparent; }
.icon-btn:hover { color: var(--app-primary); background: var(--app-primary-muted); }

.app-main { width: min(1440px, calc(100% - 32px)); margin: 0 auto; padding: var(--ui-space-40) 0 var(--ui-space-48); }
.intro { display: flex; align-items: end; justify-content: space-between; max-width: 860px; margin-bottom: var(--ui-space-32); }
.eyebrow { margin-bottom: var(--ui-space-6); color: var(--app-primary); font-size: var(--ui-font-size-xs); font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.intro h1 { max-width: 720px; font-size: clamp(1.65rem, 4vw, 2.35rem); line-height: 1.12; letter-spacing: -.035em; }
.intro p:last-child { max-width: 760px; margin-top: var(--ui-space-12); color: var(--app-text-secondary); line-height: 1.6; }

.upload-section { max-width: 1060px; }
.section-heading, .results-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-16); margin-bottom: var(--ui-space-12); }
.section-heading h2, .results-heading h2 { font-size: var(--ui-font-size-xl); letter-spacing: -.015em; }
.section-heading p { margin-top: var(--ui-space-4); color: var(--app-text-secondary); font-size: var(--ui-font-size-sm); }

.drop-zone {
  display: flex; align-items: center; gap: var(--ui-space-16); min-height: 92px;
  padding: var(--ui-space-16) var(--ui-space-20); border: 1px dashed var(--app-border-strong);
  border-radius: var(--ui-radius-panel); background: color-mix(in srgb, var(--app-surface) 70%, transparent);
  cursor: pointer; transition-property: background-color, border-color, box-shadow, transform; transition-duration: 180ms; transition-timing-function: ease-out;
}
.drop-zone:hover, .drop-zone.is-dragging { border-color: var(--app-primary); background: var(--app-primary-muted); }
.drop-zone.is-dragging { transform: translateY(-2px); }
.drop-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; color: var(--app-primary); background: var(--app-primary-muted); }
.drop-icon svg { width: 22px; height: 22px; }
.drop-copy { display: grid; gap: var(--ui-space-4); flex: 1; }
.drop-copy strong { font-size: var(--ui-font-size-md); }
.drop-copy small { color: var(--app-text-secondary); font-size: var(--ui-font-size-sm); }
.demo-row { display: flex; align-items: center; justify-content: flex-end; gap: var(--ui-space-4); min-height: 40px; color: var(--app-text-tertiary); font-size: var(--ui-font-size-xs); }

.file-workspace { margin-top: var(--ui-space-16); }
.workspace-line { margin-bottom: var(--ui-space-8); color: var(--app-text-secondary); font-size: var(--ui-font-size-sm); font-variant-numeric: tabular-nums; }
.file-list { display: flex; flex-wrap: wrap; gap: var(--ui-space-8); }
.file-chip { display: inline-flex; align-items: center; min-height: 40px; max-width: 100%; padding: 4px 4px 4px 12px; border-radius: var(--ui-radius-pill); background: var(--app-surface); box-shadow: 0 0 0 1px var(--app-border); }
.file-chip.is-reference { box-shadow: 0 0 0 1px color-mix(in srgb, var(--app-primary) 42%, var(--app-border)); }
.file-index { display: grid; place-items: center; width: 24px; height: 24px; margin-right: 8px; border-radius: 50%; color: var(--app-primary); background: var(--app-primary-muted); font-size: var(--ui-font-size-xs); font-weight: 800; font-variant-numeric: tabular-nums; }
.file-name { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--ui-font-size-sm); font-weight: 620; }
.file-role { margin-left: 7px; color: var(--app-text-tertiary); font-size: var(--ui-font-size-xs); }
.chip-actions { display: flex; margin-left: 4px; }
.chip-actions button { position: relative; display: grid; place-items: center; width: 36px; height: 32px; min-height: 32px; padding: 0; border: 0; border-radius: 50%; color: var(--app-text-tertiary); background: transparent; cursor: pointer; transition-property: color, background-color, transform; transition-duration: 150ms; }
.chip-actions button::after { content: ""; position: absolute; inset: -4px 0; }
.chip-actions button:hover { color: var(--app-primary); background: var(--app-primary-muted); }
.chip-actions button:active { transform: scale(.96); }
.chip-actions svg { width: 15px; height: 15px; }
.add-file { margin-top: var(--ui-space-8); }

.settings { margin-top: var(--ui-space-20); border-top: 1px solid var(--app-border); border-bottom: 1px solid var(--app-border); }
.settings summary { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-16); min-height: 48px; cursor: pointer; color: var(--app-primary); font-size: var(--ui-font-size-sm); font-weight: 650; list-style: none; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary::after { content: "+"; font-size: 1.15rem; font-weight: 400; }
.settings[open] summary::after { content: "−"; }
.settings-trace { flex: 1; text-align: right; color: var(--app-text-tertiary); font-size: var(--ui-font-size-xs); font-weight: 500; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(180px, 1fr)) repeat(2, minmax(190px, 1fr)); gap: var(--ui-space-16) var(--ui-space-20); padding: 0 0 var(--ui-space-20); }
.field { display: grid; gap: var(--ui-space-6); color: var(--app-text-secondary); font-size: var(--ui-font-size-xs); font-weight: 650; }
.field select, .field input, .search-field input { min-height: 40px; border: 1px solid var(--app-border-strong); border-radius: var(--ui-radius-control); color: var(--app-text); background: var(--app-surface); }
.field select, .field input { width: 100%; padding: 0 10px; }
.check-field { display: flex; align-items: center; gap: var(--ui-space-8); min-height: 40px; color: var(--app-text-secondary); font-size: var(--ui-font-size-sm); cursor: pointer; }
.check-field input { width: 17px; height: 17px; accent-color: var(--app-primary); }
.primary-action-row { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-16); margin-top: var(--ui-space-20); }
.primary-action-row p { color: var(--app-text-secondary); font-size: var(--ui-font-size-sm); }
.primary-action-row .btn { min-width: 190px; }

.message-area { max-width: 1060px; margin-top: var(--ui-space-16); }
.message { display: flex; align-items: flex-start; gap: var(--ui-space-10, .625rem); padding: var(--ui-space-12) var(--ui-space-16); border-left: 3px solid currentColor; border-radius: 0 var(--ui-radius-control) var(--ui-radius-control) 0; font-size: var(--ui-font-size-sm); }
.message + .message { margin-top: var(--ui-space-8); }
.message.warning { color: var(--app-warning); background: var(--app-warning-muted); }
.message.error { color: var(--app-danger); background: var(--app-danger-muted); }
.message.success { color: var(--app-success); background: var(--app-success-muted); }

.results { margin-top: var(--ui-space-40); scroll-margin-top: calc(var(--ui-size-header) + var(--ui-space-16)); }
.results-heading { margin-bottom: var(--ui-space-16); }
.result-actions { display: flex; gap: var(--ui-space-8); }
.metrics { display: flex; flex-wrap: wrap; gap: var(--ui-space-8) var(--ui-space-24); margin-bottom: var(--ui-space-20); }
.metric { display: grid; gap: 2px; min-width: 100px; }
.metric strong { font-size: var(--ui-font-size-display); line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric span { color: var(--app-text-secondary); font-size: var(--ui-font-size-xs); }

.result-toolbar { position: sticky; top: var(--ui-size-header); z-index: 20; display: flex; align-items: end; flex-wrap: wrap; gap: var(--ui-space-8); padding: var(--ui-space-12) 0; background: var(--app-canvas); }
.compact-field { min-width: 190px; }
.type-filters { display: flex; flex: 1; flex-wrap: wrap; gap: var(--ui-space-6); min-height: 40px; align-items: center; }
.filter-pill { min-height: 32px; padding: 0 11px; border: 1px solid var(--app-border-strong); border-radius: var(--ui-radius-pill); color: var(--app-text-secondary); background: var(--app-surface); cursor: pointer; font-size: var(--ui-font-size-xs); font-weight: 650; transition-property: color, background-color, border-color, transform; transition-duration: 150ms; }
.filter-pill:hover { border-color: var(--app-primary); color: var(--app-primary); }
.filter-pill[aria-pressed="true"] { border-color: var(--app-primary); color: var(--app-primary); background: var(--app-primary-muted); }
.filter-pill:active { transform: scale(.96); }
.search-field { position: relative; display: flex; align-items: center; min-width: min(300px, 100%); }
.search-field svg { position: absolute; left: 11px; color: var(--app-text-tertiary); pointer-events: none; }
.search-field input { width: 100%; padding: 0 12px 0 35px; }
.filter-summary { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-16); min-height: 40px; color: var(--app-text-secondary); font-size: var(--ui-font-size-sm); font-variant-numeric: tabular-nums; }

.table-panel { overflow: hidden; border: 1px solid var(--app-border); border-radius: var(--ui-radius-panel); background: var(--app-surface); }
.table-wrap { max-height: min(68vh, 820px); overflow: auto; }
.diff-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--ui-font-size-sm); }
.diff-table th { position: sticky; top: 0; z-index: 10; padding: 12px; color: var(--app-primary); background: var(--app-surface); box-shadow: inset 0 -2px 0 var(--app-table-edge), inset 0 2px 0 var(--app-surface); text-align: left; font-size: var(--ui-font-size-xs); font-weight: 750; letter-spacing: .025em; white-space: nowrap; }
.diff-table td { max-width: 340px; padding: 11px 12px; border-bottom: 1px solid var(--app-border); vertical-align: top; }
.diff-table tbody tr { cursor: pointer; transition-property: background-color; transition-duration: 120ms; }
.diff-table tbody tr:hover { background: var(--app-surface-muted); }
.diff-table tbody tr:focus-visible { outline: 2px solid var(--app-primary); outline-offset: -2px; }
.diff-table tbody tr:last-child td { border-bottom: 0; }
.cell-address { color: var(--app-primary); font-family: var(--ui-font-mono); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sheet-name { font-weight: 620; white-space: nowrap; }
.cell-value { display: block; max-height: 4.4em; overflow: hidden; color: var(--app-text); font-family: var(--ui-font-mono); font-size: var(--ui-font-size-xs); line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; }
.cell-value.is-empty { color: var(--app-text-tertiary); font-family: var(--ui-font-sans); font-style: italic; }
.value-formula { display: block; margin-top: 3px; color: var(--app-text-tertiary); font-family: var(--ui-font-mono); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: var(--ui-radius-pill); font-size: var(--ui-font-size-xs); font-weight: 700; white-space: nowrap; }
.kind-text, .kind-type { color: var(--app-primary); background: var(--app-primary-muted); }
.kind-number { color: var(--app-success); background: var(--app-success-muted); }
.kind-empty, .kind-row { color: var(--app-danger); background: var(--app-danger-muted); }
.kind-formula, .kind-format { color: var(--app-warning); background: var(--app-warning-muted); }
.matched-row { display: block; margin-top: 3px; color: var(--app-text-tertiary); font-size: 10px; }
.empty-result { display: grid; place-items: center; gap: var(--ui-space-6); min-height: 260px; color: var(--app-text-secondary); text-align: center; }
.empty-result svg { width: 34px; height: 34px; color: var(--app-success); }
.empty-result span { font-size: var(--ui-font-size-sm); }
.load-more-row { display: flex; justify-content: center; padding: var(--ui-space-12); border-top: 1px solid var(--app-border); background: var(--app-surface-muted); }

.privacy-note { display: flex; align-items: flex-start; gap: var(--ui-space-12); max-width: 840px; margin-top: var(--ui-space-40); color: var(--app-text-secondary); }
.privacy-note > svg { width: 22px; height: 22px; color: var(--app-success); }
.privacy-note h2 { margin-bottom: 3px; color: var(--app-text); font-size: var(--ui-font-size-sm); }
.privacy-note p { font-size: var(--ui-font-size-xs); line-height: 1.55; }
.app-footer { padding: var(--ui-space-20); border-top: 1px solid var(--app-border); color: var(--app-text-tertiary); text-align: center; font-size: var(--ui-font-size-xs); }

.comparison-dialog { width: min(96vw, 1600px); height: min(92vh, 980px); max-width: none; max-height: none; padding: 0; border: 0; border-radius: 12px; color: var(--app-text); background: var(--app-surface); box-shadow: 0 24px 70px rgba(14, 30, 45, .28); }
.comparison-dialog::backdrop { background: rgba(14, 30, 45, .52); backdrop-filter: blur(3px); }
.comparison-dialog:fullscreen { width: 100vw; height: 100vh; border-radius: 0; }
.dialog-shell { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; height: 100%; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-16); min-height: 64px; padding: var(--ui-space-12) var(--ui-space-16); border-bottom: 1px solid var(--app-border); }
.dialog-header h2 { font-size: var(--ui-font-size-xl); }
.dialog-actions { display: flex; gap: var(--ui-space-4); }
.dialog-toolbar { display: flex; align-items: end; flex-wrap: wrap; gap: var(--ui-space-12); padding: var(--ui-space-12) var(--ui-space-16); background: var(--app-surface-muted); border-bottom: 1px solid var(--app-border); }
.dialog-cell-info { margin-left: auto; align-self: center; color: var(--app-text-secondary); font-family: var(--ui-font-mono); font-size: var(--ui-font-size-xs); font-variant-numeric: tabular-nums; }
.comparison-panes { display: grid; grid-template-columns: repeat(var(--pane-count, 2), minmax(0, 1fr)); min-height: 0; overflow: hidden; }
.comparison-pane { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; border-right: 1px solid var(--app-border); }
.comparison-pane:last-child { border-right: 0; }
.pane-title { padding: 9px 12px; overflow: hidden; color: var(--app-primary); background: var(--app-primary-muted); font-size: var(--ui-font-size-xs); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.sheet-grid-wrap { overflow: auto; }
.sheet-grid { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-family: Calibri, var(--ui-font-sans); font-size: 11px; }
.sheet-grid th, .sheet-grid td { min-width: 82px; height: 26px; padding: 4px 7px; border-right: 1px solid var(--app-border); border-bottom: 1px solid var(--app-border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sheet-grid th { position: sticky; top: 0; z-index: 2; color: var(--app-primary); background: var(--app-surface); box-shadow: inset 0 -2px 0 var(--app-table-edge); font-weight: 700; }
.sheet-grid .row-head { position: sticky; left: 0; z-index: 1; min-width: 48px; width: 48px; color: var(--app-primary); background: var(--app-surface-muted); text-align: right; font-weight: 650; }
.sheet-grid thead .row-head { z-index: 3; }
.sheet-grid td.is-target { position: relative; background: var(--app-warning-muted) !important; box-shadow: inset 0 0 0 2px var(--app-warning); }
.dialog-footer { min-height: 44px; padding: var(--ui-space-12) var(--ui-space-16); border-top: 1px solid var(--app-border); color: var(--app-text-secondary); background: var(--app-surface-muted); font-size: var(--ui-font-size-xs); }
.toast { position: fixed; right: var(--ui-space-20); bottom: var(--ui-space-20); z-index: 100; max-width: min(420px, calc(100vw - 40px)); padding: 12px 16px; border-radius: var(--ui-radius-panel); color: white; background: var(--app-text); box-shadow: 0 12px 34px rgba(14, 30, 45, .22); font-size: var(--ui-font-size-sm); animation: toast-in 220ms ease-out both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); filter: blur(4px); } to { opacity: 1; transform: translateY(0); filter: blur(0); } }

@media (max-width: 900px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-toolbar { position: static; }
  .search-field { width: 100%; }
  .comparison-panes { overflow-x: auto; grid-template-columns: repeat(var(--pane-count, 2), minmax(560px, 1fr)); }
}

@media (max-width: 640px) {
  .app-header { padding: 0 var(--ui-space-12); }
  .brand small, .offline-badge, #downloadToolBtn { display: none; }
  .app-main { width: min(100% - 24px, 1440px); padding-top: var(--ui-space-24); }
  .intro { margin-bottom: var(--ui-space-24); }
  .intro h1 { font-size: 1.7rem; }
  .drop-zone { align-items: flex-start; flex-wrap: wrap; }
  .drop-zone > .btn { width: 100%; }
  .demo-row { justify-content: center; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-trace { display: none; }
  .primary-action-row, .results-heading { align-items: stretch; flex-direction: column; }
  .primary-action-row .btn, .result-actions .btn { flex: 1; }
  .result-actions { width: 100%; }
  .metrics { gap: var(--ui-space-16); }
  .diff-table th, .diff-table td { padding: 9px; }
  .privacy-note { margin-top: var(--ui-space-24); }
  .comparison-dialog { width: 100vw; height: 100vh; border-radius: 0; }
  .dialog-cell-info { width: 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Tool-family shell: shared visual language with sas-db-analyzer and model-tools. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  position: relative;
  top: auto;
  z-index: 40;
  display: block;
  height: auto;
  padding: 0;
  background: var(--app-surface);
  backdrop-filter: none;
  margin-bottom: 1.25rem;
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: var(--ui-size-header);
  padding: .5rem 1.5rem;
  gap: 1rem;
}

.app-title {
  color: var(--app-text);
  font-size: var(--ui-font-size-xl);
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -.02em;
  text-decoration: none;
}

.app-title:focus-visible {
  border-radius: var(--ui-radius-control);
  outline: none;
  box-shadow: var(--app-focus);
}

.app-header-context {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .6rem;
  flex-wrap: wrap;
}

.app-context-note {
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-sm);
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}

.app-main {
  flex: 1 0 auto;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 1.5rem 3rem;
}

.upload-section {
  max-width: none;
}

.upload-section:not(.has-files) {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 4.5rem 1rem 3rem;
}

.upload-section:not(.has-files) .drop-zone {
  width: 100%;
  max-width: 35rem;
  background: var(--app-surface);
}

.upload-section:not(.has-files) .drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 14.25rem;
  padding: 2.5rem;
  border: 1px solid var(--app-border);
  border-radius: var(--ui-radius-panel);
  text-align: center;
  background: var(--app-surface);
  cursor: default;
}

.upload-section:not(.has-files) .drop-zone:hover,
.upload-section:not(.has-files) .drop-zone.is-dragging {
  border-color: var(--app-primary);
  background: var(--app-primary-muted);
}

.upload-section:not(.has-files) .drop-icon {
  display: inline-grid;
  width: auto;
  height: auto;
  margin-bottom: .75rem;
  border-radius: 0;
  color: var(--app-primary);
  background: transparent;
}

.drop-target {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  cursor: pointer;
}

.upload-section:not(.has-files) .drop-icon svg {
  width: 1.25rem;
  height: 1.25rem;
}

.upload-section:not(.has-files) .drop-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: none;
  gap: .25rem;
}

.upload-section:not(.has-files) .drop-copy strong {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -.01em;
}

.upload-section:not(.has-files) .drop-copy small {
  max-width: 22rem;
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-sm);
  line-height: 1.45;
}

.upload-section:not(.has-files) .demo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  width: auto;
  min-height: 0;
  margin-top: 1rem;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.upload-section:not(.has-files) .demo-row .btn {
  min-height: 2rem;
  padding: 0 .75rem;
}

.upload-section.has-files {
  padding-top: 1.25rem;
}

.file-workspace {
  margin-top: 0;
}

.workspace-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
  padding: .1rem 0 .15rem;
  border: 0;
  background: transparent;
}

.workspace-panel-copy {
  min-width: 0;
}

.workspace-program-label {
  color: var(--app-text);
  font-size: var(--ui-font-size-md);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -.01em;
}

.workspace-panel-selection {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .35rem;
  margin-top: .15rem;
  color: var(--app-text-secondary);
  font-size: .75rem;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

.workspace-panel-quiet-btn,
.footer-action {
  position: relative;
  padding: 0;
  border: 0;
  color: var(--app-text-secondary);
  background: transparent;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  transition: color 150ms ease-out;
}

.workspace-panel-quiet-btn::before,
.footer-action::before {
  content: "";
  position: absolute;
  inset: -.5rem -.35rem;
}

.workspace-panel-quiet-btn:hover,
.footer-action:hover {
  color: var(--app-primary);
  text-decoration: underline;
  text-underline-offset: .18em;
}

.workspace-actions {
  display: flex;
  align-items: center;
  flex: none;
  gap: .5rem;
}

.workspace-actions .btn {
  min-height: 2rem;
  padding: 0 .75rem;
}

.files-section-heading {
  margin-top: .9rem;
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-xs);
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.files-strip {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .45rem;
  overflow: hidden;
}

.file-list {
  display: flex;
  flex-flow: row nowrap;
  gap: .5rem;
  width: 100%;
  overflow-x: auto;
  padding: 1px 1px .35rem;
}

.file-chip {
  display: flex;
  flex: none;
  align-items: center;
  min-height: 2.25rem;
  max-width: min(27rem, 80vw);
  padding: .15rem .2rem .15rem .65rem;
  border: 1px solid var(--app-border);
  border-radius: var(--ui-radius-control);
  background: var(--app-surface);
  box-shadow: none;
  transition-property: border-color, background-color;
  transition-duration: 150ms;
}

.file-chip.is-reference {
  border-color: color-mix(in srgb, var(--app-primary) 35%, var(--app-border));
  box-shadow: none;
}

.file-index {
  width: 1.25rem;
  height: 1.25rem;
  margin-right: .45rem;
  border-radius: var(--ui-radius-pill);
  font-size: .625rem;
}

.file-name {
  max-width: 15rem;
  font-size: var(--ui-font-size-sm);
  font-weight: 600;
}

.file-role {
  margin-left: .5rem;
  padding: .1rem .5rem;
  border-radius: var(--ui-radius-pill);
  color: var(--app-primary);
  background: var(--app-primary-muted);
  font-size: .68rem;
  font-weight: 650;
}

.chip-actions button {
  width: 2rem;
  height: 1.9rem;
}

.settings {
  margin-top: .75rem;
  border-top: 1px solid var(--app-border);
  border-bottom: 1px solid var(--app-border);
}

.settings summary {
  min-height: 2.75rem;
}

.settings-grid {
  padding-bottom: 1rem;
}

.results {
  margin-top: 2rem;
  scroll-margin-top: 1rem;
}

.message-area {
  max-width: none;
}

.metrics {
  gap: .5rem 1.75rem;
  margin-bottom: 1.1rem;
}

.metric {
  min-width: 5.25rem;
}

.metric strong {
  font-size: 1.25rem;
  font-weight: 650;
}

.result-toolbar {
  position: static;
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: .5rem .75rem;
  padding: 0 0 .75rem;
  background: transparent;
}

.result-toolbar .field > span {
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-xs);
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.result-toolbar .field select {
  min-height: 2rem;
}

.type-filters {
  min-height: 2rem;
}

.filter-pill {
  min-height: 1.75rem;
  padding: 0 .65rem;
}

.result-toolbar #resetFiltersBtn {
  min-height: 2rem;
  margin-left: auto;
}

.table-panel {
  overflow: hidden;
  border: 1px solid var(--app-border);
  border-radius: var(--ui-radius-panel);
  background: var(--app-surface);
  box-shadow: none;
}

.result-tabs-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1.25rem;
  min-height: 3.5rem;
  padding: .65rem 1rem .65rem .75rem;
  border-radius: var(--ui-radius-panel) var(--ui-radius-panel) 0 0;
  background: var(--app-surface);
  box-shadow: inset 0 -1px 0 var(--app-border);
}

.result-title-group {
  display: flex;
  align-items: baseline;
  gap: .65rem;
  min-width: 0;
}

.result-title-group h2 {
  color: var(--app-text);
  font-size: var(--ui-font-size-md);
  font-weight: 650;
  letter-spacing: -.01em;
}

#filterSummary {
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-left: auto;
}

.result-actions .btn {
  min-height: 2rem;
  padding: 0 .7rem;
}

.result-actions .btn-ghost {
  color: var(--app-text-secondary);
}

.search-field {
  width: 13.75rem;
  min-width: 0;
}

.search-field input {
  min-height: 2rem;
  padding-left: 2rem;
}

.search-field svg {
  left: .6rem;
  width: .9rem;
  height: .9rem;
}

.diff-table {
  width: max-content;
  min-width: 100%;
  font-size: var(--ui-font-size-md);
}

.diff-table th {
  padding: .65rem .75rem;
  font-size: var(--ui-font-size-sm);
  font-weight: 600;
  letter-spacing: 0;
  box-shadow: inset 0 -2px 0 var(--app-table-edge);
}

.diff-table td {
  padding: .55rem .75rem;
}

.load-more-row {
  padding: .75rem 1rem;
  background: var(--app-surface);
}

.app-footer {
  flex-shrink: 0;
  margin-top: auto;
  padding: 0;
  border-top: 1px solid var(--app-border);
  color: var(--app-text-secondary);
  background: var(--app-surface);
  text-align: left;
}

.app-footer-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .3rem;
  min-height: 2.4rem;
  padding: .35rem 1.5rem;
  font-size: var(--ui-font-size-xs);
}

@media (max-width: 760px) {
  .app-header-inner,
  .app-main,
  .app-footer-inner {
    padding-left: .75rem;
    padding-right: .75rem;
  }

  .app-header-context {
    display: none;
  }

  .upload-section:not(.has-files) {
    padding: 2rem 0 2.5rem;
  }

  .upload-section:not(.has-files) .drop-zone {
    align-items: center;
    flex-wrap: nowrap;
    padding-right: 1.25rem;
    padding-left: 1.25rem;
  }

  .upload-section:not(.has-files) .drop-zone > .btn {
    width: auto;
  }

  .workspace-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace-actions {
    width: 100%;
  }

  .workspace-actions .btn {
    flex: 1;
  }

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

  .result-toolbar #resetFiltersBtn {
    margin-left: 0;
  }

  .result-tabs-bar,
  .result-actions {
    align-items: stretch;
  }

  .result-title-group,
  .result-actions {
    width: 100%;
  }

  .result-actions {
    flex-wrap: wrap;
    margin-left: 0;
  }

  .search-field {
    order: 3;
    width: 100%;
  }

  .result-actions .btn {
    flex: 1;
  }

  .app-footer-inner {
    min-height: auto;
    padding-top: .9rem;
    padding-bottom: .9rem;
  }
}

/* Family-aligned patterns for settings, feedback, pagination and dialogs. */
.workspace-actions #compareBtn {
  min-width: 10.5rem;
}

.btn[aria-busy="true"] > svg {
  display: none;
}

.btn[aria-busy="true"]::before,
.footer-action[aria-busy="true"]::after {
  content: "";
  width: .8rem;
  height: .8rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: control-spin 700ms linear infinite;
}

.footer-action[aria-busy="true"]::after {
  display: inline-block;
  margin-left: .35rem;
  vertical-align: -.1rem;
}

@keyframes control-spin {
  to { transform: rotate(360deg); }
}

.settings summary::after {
  content: "";
  width: .45rem;
  height: .45rem;
  margin: 0 .25rem 0 .5rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition-property: transform;
  transition-duration: 160ms;
  transition-timing-function: ease-out;
}

.settings[open] summary::after {
  content: "";
  transform: rotate(225deg) translate(-1px, -1px);
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.25rem;
  padding: .15rem 0 .8rem;
}

.settings[open] .settings-grid,
.settings[open] .settings-footer {
  animation: settings-enter 180ms ease-out both;
}

.settings[open] .settings-footer {
  animation-delay: 35ms;
}

@keyframes settings-enter {
  from { opacity: 0; transform: translateY(-6px); filter: blur(2px); }
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

.settings-group {
  min-width: 0;
  padding: .15rem .55rem .35rem;
  border-radius: var(--ui-radius-control);
}

.settings-group-label,
.result-settings-group-label {
  margin: 0 0 .35rem;
  color: var(--app-text-secondary);
  font-size: .68rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.settings-group .field {
  margin-bottom: .35rem;
  max-width: 22rem;
}

.settings-group .field select,
.settings-group .field input {
  min-height: 2rem;
}

.settings-group .check-field {
  min-height: 2.25rem;
  padding: .15rem .35rem;
  border-radius: var(--ui-radius-control);
  transition-property: background-color;
  transition-duration: 150ms;
}

.settings-group .check-field:hover {
  background: rgba(26, 35, 50, .04);
}

.settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  padding: .65rem .55rem .8rem;
  border-top: 1px solid var(--app-border);
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-xs);
}

.message {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 2rem;
  align-items: center;
  min-height: 2.75rem;
  padding: .55rem .45rem .55rem .9rem;
  border-radius: 0 var(--ui-radius-control) var(--ui-radius-control) 0;
  animation: message-enter 180ms ease-out both;
  transition-property: opacity, transform, filter;
  transition-duration: 150ms;
  transition-timing-function: ease-in;
}

.message > svg {
  width: .95rem;
  height: .95rem;
}

.message.is-leaving {
  opacity: 0;
  transform: translateY(-8px);
  filter: blur(2px);
}

.message-close {
  position: relative;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: var(--ui-radius-control);
  color: currentColor;
  background: transparent;
  cursor: pointer;
  opacity: .62;
  transition-property: opacity, background-color, transform;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}

.message-close::after {
  content: "";
  position: absolute;
  inset: -4px 0;
}

.message-close:hover {
  background: rgba(255, 255, 255, .45);
  opacity: 1;
}

.message-close:active {
  transform: scale(.96);
}

.message-close svg {
  width: .8rem;
  height: .8rem;
}

@keyframes message-enter {
  from { opacity: 0; transform: translateY(6px); filter: blur(2px); }
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

.result-actions .btn,
.result-settings > summary {
  position: relative;
}

.result-actions .btn::before,
.result-settings > summary::before {
  content: "";
  position: absolute;
  inset: -4px 0;
}

.result-settings {
  position: relative;
  flex: none;
}

.result-settings > summary {
  list-style: none;
  color: var(--app-text-secondary);
}

.result-settings > summary::-webkit-details-marker {
  display: none;
}

.result-settings > summary::after {
  content: "";
  width: .38rem;
  height: .38rem;
  margin-left: .15rem;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: rotate(45deg) translateY(-1px);
}

.result-settings[open] > summary {
  color: var(--app-text);
  background: var(--app-surface-muted);
}

.result-settings-menu {
  position: absolute;
  top: calc(100% + .45rem);
  right: 0;
  z-index: 40;
  width: 20rem;
  max-width: calc(100vw - 2rem);
  padding: .5rem;
  border: 1px solid var(--app-border);
  border-radius: var(--ui-radius-panel);
  background: var(--app-surface);
  box-shadow: 0 .35rem 1rem rgba(26, 35, 50, .1);
  animation: settings-menu-enter 150ms ease-out both;
}

@keyframes settings-menu-enter {
  from { opacity: 0; transform: translateY(-4px); filter: blur(2px); }
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

.result-settings-group {
  padding: .15rem .05rem;
}

.result-settings-group + .result-settings-group {
  margin-top: .35rem;
  padding-top: .5rem;
  border-top: 1px solid var(--app-border);
}

.result-settings-group-label {
  padding: .1rem .55rem .2rem;
}

.result-settings-field {
  display: block;
  padding: .1rem .55rem .35rem;
}

.result-settings-field select {
  width: 100%;
  min-height: 2rem;
  padding: 0 .55rem;
  border: 1px solid var(--app-border-strong);
  border-radius: var(--ui-radius-control);
  color: var(--app-text);
  background: var(--app-surface);
  font-size: var(--ui-font-size-sm);
}

.result-settings-option {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 2.5rem;
  padding: .35rem .55rem;
  border-radius: var(--ui-radius-control);
  cursor: pointer;
  font-size: var(--ui-font-size-sm);
  transition-property: background-color;
  transition-duration: 150ms;
}

.result-settings-option:hover {
  background: rgba(26, 35, 50, .04);
}

.result-settings-option input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--app-primary);
}

.diff-table .is-column-hover {
  background: rgba(26, 35, 50, .025);
}

.diff-table tbody tr:hover > .is-column-hover {
  background: rgba(26, 35, 50, .045);
}

.results.hide-formulas .value-formula {
  display: none;
}

.results.compact-results .diff-table td {
  padding-top: .35rem;
  padding-bottom: .35rem;
}

.results.compact-results .kind-badge {
  min-height: 1.25rem;
}

.empty-result {
  min-height: 0;
  padding: 3rem 1rem;
}

.empty-result svg {
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: .25rem;
}

.empty-result strong {
  color: var(--app-text);
  font-size: var(--ui-font-size-md);
}

.load-more-row {
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-xs);
  font-variant-numeric: tabular-nums;
}

.load-more-row .btn {
  min-height: 2rem;
}

.results:not([hidden]) .metrics,
.results:not([hidden]) .result-toolbar,
.results:not([hidden]) .table-panel {
  animation: result-enter 220ms ease-out both;
}

.results:not([hidden]) .result-toolbar { animation-delay: 45ms; }
.results:not([hidden]) .table-panel { animation-delay: 90ms; }

@keyframes result-enter {
  from { opacity: 0; transform: translateY(6px); filter: blur(2px); }
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

.comparison-dialog {
  border-radius: var(--ui-radius-panel);
  box-shadow: 0 1.5rem 4.5rem rgba(14, 30, 45, .28);
}

.dialog-heading h2 {
  font-size: var(--ui-font-size-xl);
  font-weight: 650;
  letter-spacing: -.015em;
}

.dialog-heading p {
  margin-top: .15rem;
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-xs);
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.dialog-footer .btn {
  min-height: 2rem;
}

.confirm-dialog {
  width: min(30rem, calc(100vw - 2rem));
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: var(--ui-radius-panel);
  color: var(--app-text);
  background: var(--app-surface);
  box-shadow: 0 1.5rem 4.5rem rgba(14, 30, 45, .28);
}

.confirm-dialog::backdrop {
  background: rgba(14, 30, 45, .48);
  backdrop-filter: blur(2px);
}

.confirm-dialog-shell {
  display: grid;
}

.confirm-dialog-header,
.confirm-dialog-footer {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
}

.confirm-dialog-header {
  justify-content: space-between;
  min-height: 3.5rem;
  border-bottom: 1px solid var(--app-border);
}

.confirm-dialog-header h2 {
  font-size: var(--ui-font-size-xl);
  font-weight: 650;
  letter-spacing: -.015em;
}

.confirm-dialog-body {
  display: grid;
  gap: .5rem;
  padding: 1rem;
  color: var(--app-text-secondary);
  font-size: var(--ui-font-size-sm);
  line-height: 1.5;
}

.confirm-dialog-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--app-border);
  background: var(--app-surface-muted);
}

.confirm-dialog-footer .btn {
  min-height: 2rem;
}

.toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: .6rem;
  min-width: min(19rem, calc(100vw - 2rem));
  padding: .7rem .8rem;
  border: 1px solid var(--app-border);
  border-radius: var(--ui-radius-panel);
  color: var(--app-text);
  background: var(--app-surface);
  box-shadow: 0 .35rem 1rem rgba(26, 35, 50, .12);
  opacity: 0;
  transform: translateY(8px);
  filter: blur(3px);
  animation: none;
  transition-property: opacity, transform, filter;
  transition-duration: 160ms;
  transition-timing-function: cubic-bezier(.2, 0, 0, 1);
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

.toast > svg {
  width: 1rem;
  height: 1rem;
  color: var(--app-success);
}

.toast.is-progress > svg {
  color: var(--app-primary);
}

.toast-progress {
  grid-column: 1 / -1;
  height: .18rem;
  overflow: hidden;
  border-radius: var(--ui-radius-pill);
  background: var(--app-primary-muted);
}

.toast-progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--app-primary);
  transition-property: width;
  transition-duration: 160ms;
  transition-timing-function: ease-out;
}

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

  .settings-group .field {
    max-width: none;
  }

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

  .result-settings-menu {
    right: auto;
    left: 0;
  }

  .load-more-row {
    align-items: stretch;
    flex-direction: column;
  }

  .load-more-row .btn {
    width: 100%;
  }

  .toast {
    right: .75rem;
    bottom: .75rem;
    left: .75rem;
    max-width: none;
  }

  .comparison-dialog {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }
}
