:root {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-muted: #f8faf8;
  --ink: #1d2823;
  --ink-soft: #66726c;
  --line: #d8ded9;
  --line-strong: #c3ccc6;
  --green: #14775a;
  --green-soft: #dcefe7;
  --orange: #c25e2c;
  --orange-soft: #f7e6dd;
  --blue: #365f78;
  --danger: #a23d37;
  --shadow: 0 8px 24px rgba(28, 43, 35, 0.07);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
}

button, input { font: inherit; }
button, label[for] { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand-lockup, .dataset-name, .header-actions, .download-actions, .toolbar-filters {
  display: flex;
  align-items: center;
}

.brand-lockup { gap: 11px; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--green);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
  font-weight: 800;
}
.brand-lockup h1 { margin: 0; font-size: 18px; line-height: 1.15; letter-spacing: 0; }
.brand-lockup p { margin: 3px 0 0; color: var(--ink-soft); font-size: 11px; letter-spacing: 0; }

main { width: 100%; }

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0;
  white-space: nowrap;
}
.button-primary { color: #fff; background: var(--green); }
.button-primary:hover { background: #0f664d; }
.button-secondary { color: #fff; background: var(--blue); }
.button-secondary:hover { background: #2c5067; }
.button-quiet { color: var(--ink); background: var(--surface); border-color: var(--line-strong); }
.button-quiet:hover { background: var(--surface-muted); }
.button:focus-visible, .segment:focus-visible, .icon-button:focus-visible, input:focus-visible, .drop-zone:focus-within {
  outline: 3px solid rgba(20, 119, 90, .22);
  outline-offset: 2px;
}

.upload-stage {
  width: min(760px, calc(100% - 36px));
  min-height: calc(100vh - 132px);
  margin: 0 auto;
  display: grid;
  place-items: center;
}
.drop-zone {
  width: 100%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px dashed #aebbb4;
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); background: #fbfdfb; transform: translateY(-1px); }
.drop-zone strong { font-size: 17px; }
.drop-zone > span:last-child { color: var(--ink-soft); font-size: 13px; }
.file-glyph {
  width: 58px;
  height: 68px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-top: 7px solid var(--green);
  border-radius: 4px;
  color: var(--green);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 900;
}
.file-glyph-small { width: 34px; height: 40px; border-top-width: 5px; font-size: 9px; flex: 0 0 auto; }

.workspace { padding-bottom: 50px; }
.dataset-strip, .control-band, .view-toolbar, .comparison-section, .table-section, .method-note {
  padding-left: clamp(18px, 4vw, 52px);
  padding-right: clamp(18px, 4vw, 52px);
}
.dataset-strip {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.dataset-name { gap: 10px; min-width: 0; }
.dataset-name > div { min-width: 0; }
.dataset-name strong, .dataset-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dataset-name strong { font-size: 14px; }
.dataset-name span { margin-top: 4px; color: var(--ink-soft); font-size: 12px; }
.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.icon-button:hover { color: var(--danger); background: #fbefee; }

.control-band {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 28px;
  border-bottom: 1px solid var(--line);
  background: #eef2ef;
}
.field-control, .readout { display: flex; flex-direction: column; gap: 5px; }
.field-control span, .readout span { color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.field-control input {
  width: 154px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--ink);
  background: var(--surface);
}
.readout { min-width: 90px; }
.readout strong { font-size: 14px; }
.download-actions { gap: 8px; margin-left: auto; }

.view-toolbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(106px, auto);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #eef1ef;
}
.segment {
  min-height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 3px;
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.segment:hover { color: var(--ink); }
.segment.active { color: var(--ink); background: var(--surface); box-shadow: 0 1px 4px rgba(28,43,35,.11); }
.segmented-small { grid-auto-columns: minmax(72px, auto); }
.segmented-small .segment { min-height: 30px; padding: 0 10px; font-size: 12px; }
.toolbar-filters { gap: 10px; }

.comparison-section, .table-section { padding-top: 26px; }
.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}
.section-heading p { margin: 0 0 5px; color: var(--green); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.section-heading h2 { margin: 0; font-size: 19px; letter-spacing: 0; }
.section-heading > span { color: var(--ink-soft); font-size: 12px; text-align: right; }
.compact-heading { align-items: center; }

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.metric-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.metric-card-header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
.metric-card-header strong { font-size: 16px; }
.metric-card-header span { color: var(--ink-soft); font-size: 11px; white-space: nowrap; }
.vendor-bar + .vendor-bar { margin-top: 14px; }
.bar-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-size: 12px; }
.bar-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }
.bar-label strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; overflow: hidden; border-radius: 2px; background: #e9eeea; }
.bar-fill { height: 100%; min-width: 2px; border-radius: 2px; background: var(--green); }
.vendor-bar:nth-child(3) .bar-fill { background: var(--orange); }
.winner-note { min-height: 18px; margin: 15px 0 0; color: var(--ink-soft); font-size: 11px; }
.winner-note strong { color: var(--ink); }

.table-section { padding-bottom: 20px; }
.table-shell {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
table { width: 100%; min-width: 820px; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 11px 12px; border-bottom: 1px solid #e7ebe8; text-align: left; font-size: 12px; letter-spacing: 0; }
th { position: sticky; top: 0; z-index: 1; color: var(--ink-soft); background: #f5f7f5; font-size: 11px; font-weight: 800; }
td { font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfb; }
.vendor-cell { font-weight: 750; }
.vendor-dot { width: 7px; height: 7px; display: inline-block; margin-right: 7px; border-radius: 50%; background: var(--green); vertical-align: 1px; }
tr.vendor-second .vendor-dot { background: var(--orange); }
.value-strong { font-size: 13px; font-weight: 800; }
.date-list { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }
.empty-table { padding: 36px; text-align: center; color: var(--ink-soft); }

.method-note {
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 12px;
}
.method-note summary { width: fit-content; cursor: pointer; color: var(--ink); font-weight: 700; }
.method-note p { max-width: 920px; line-height: 1.75; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(440px, calc(100vw - 44px));
  padding: 12px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.toast.error { color: var(--danger); border-color: #e4c2bf; background: #fff8f7; }

@media (max-width: 840px) {
  .control-band { flex-wrap: wrap; gap: 16px 24px; padding-top: 14px; padding-bottom: 14px; }
  .download-actions { width: 100%; margin-left: 0; }
  .view-toolbar { align-items: flex-start; flex-direction: column; padding-top: 14px; padding-bottom: 14px; }
  .comparison-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .app-header { min-height: 62px; padding: 10px 14px; }
  .brand-lockup p { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .button { padding: 0 11px; }
  .dataset-strip, .control-band, .view-toolbar, .comparison-section, .table-section, .method-note { padding-left: 14px; padding-right: 14px; }
  .upload-stage { width: calc(100% - 28px); }
  .drop-zone { min-height: 230px; }
  .control-band { align-items: flex-end; }
  .field-control { flex: 1 1 150px; }
  .field-control input { width: 100%; }
  .readout { flex: 1 1 88px; }
  .download-actions .button { flex: 1 1 0; }
  .view-toolbar > .segmented { width: 100%; grid-auto-columns: 1fr; }
  .toolbar-filters { width: 100%; align-items: stretch; flex-direction: column; }
  .toolbar-filters .segmented { width: 100%; grid-auto-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .section-heading > span { text-align: left; }
  .comparison-section, .table-section { padding-top: 20px; }
  .metric-card { padding: 14px; }
  .toast { right: 14px; bottom: 14px; max-width: calc(100vw - 28px); }
}

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