:root {
  color-scheme: light;
  --ink: var(--ci-text);
  --muted: var(--ci-text-muted);
  --paper: var(--ci-bg);
  --surface: var(--ci-surface);
  --line: var(--ci-border);
  --green: var(--ci-accent);
  --green-dark: var(--ci-accent-hover);
  --coral: var(--ci-danger);
  --gold: var(--ci-amber);
  --blue: var(--ci-blue);
  --radius: var(--ci-radius-sm);
  font-family: var(--ci-font-sans);
  font-synthesis: none;
}

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

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.ci-logout-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  color: #fff;
  background: transparent;
  border: 1px solid rgb(255 255 255 / 34%);
  border-radius: var(--radius);
  cursor: pointer;
}
.ci-logout-button:hover { border-color: #fff; }
.ci-logout-button svg { width: 15px; height: 15px; }

.topbar {
  min-height: var(--ci-topbar-height);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-direction: row;
  gap: 11px;
  padding: 0 var(--ci-space-8);
  color: #fff;
  background: var(--ci-ink);
  border-bottom: 3px solid var(--green);
}

.topbar strong { display: block; font-size: 18px; line-height: 1.2; font-weight: 750; letter-spacing: 0; }
.topbar small { display: block; color: #dce7e1; font-size: 13px; margin-top: 4px; }
.topbar .ci-brand { flex: 1; }
.topbar .ci-brand > div:last-child { min-width: 0; }
.topbar strong, .topbar small { overflow-wrap: anywhere; }
.topbar .ci-topbar-meta { flex-shrink: 0; }

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 3px;
  background: #fff;
  border-radius: var(--ci-radius-md);
}

.brand-mark img { display: block; width: 32px; height: 32px; }

.connection {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--ci-space-2);
  color: #e8f2ee;
  font-size: 14px;
  white-space: nowrap;
}

.connection::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #5ed197; }

.tool-nav { min-height: var(--ci-tabs-height); display: flex; align-items: stretch; gap: var(--ci-space-4); padding: 0 var(--ci-space-8); background: var(--surface); border-bottom: 1px solid var(--line); }
.tool-nav a { display: flex; align-items: center; gap: 8px; padding: 0 4px; border-bottom: 2px solid transparent; color: var(--muted); text-decoration: none; font-size: 14px; }
.tool-nav a[aria-current="page"] { border-bottom-color: var(--green); color: var(--ink); font-weight: 700; }
.tool-nav svg { width: 18px; height: 18px; color: currentColor; }

main { width: min(var(--ci-content-width), calc(100vw - 48px)); margin: 0 auto; padding: var(--ci-space-10) 0 56px; }
.workspace, .results { background: var(--surface); border-bottom: 1px solid var(--line); }
.workspace { padding: var(--ci-space-8); }
.results { margin-top: 18px; }

.login-page {
  min-height: 100vh;
  background: var(--paper);
}
.login-shell {
  min-height: 100vh;
  width: min(100% - 32px, 480px);
  display: grid;
  place-items: center;
  margin: 0 auto;
  padding: 48px 0;
}
.login-panel {
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
  padding: var(--ci-space-8);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.login-panel { display: grid; gap: 18px; }
.login-mark {
  width: 58px;
  height: 58px;
  margin-bottom: 2px;
}
.login-panel h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}
.login-message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.login-panel label {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}
.login-panel input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-top: 8px;
}

.section-heading {
  min-height: 46px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.compact-heading { min-height: 42px; }
.eyebrow { margin: 0 0 8px; color: var(--green); font-size: 12px; line-height: 1.2; font-weight: 800; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 18px; line-height: 1.25; }

.icon-button {
  width: 43px;
  height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.icon-button:hover { color: var(--ink); border-color: #aeb5b1; }
.icon-button svg { width: 16px; height: 16px; }

.input-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, 0.85fr);
  gap: 32px;
  margin-top: 18px;
}

.dropzone {
  min-height: 236px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px dashed #aeb6b1;
  background: var(--ci-surface-muted);
  cursor: pointer;
  transition: border-color 130ms ease, background 130ms ease;
}

.dropzone:hover, .dropzone.dragging { border-color: var(--green); background: var(--ci-accent-faint); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone svg { width: 31px; height: 31px; color: var(--green); }
.dropzone > span { font-size: 16px; font-weight: 750; }
.dropzone small { color: var(--muted); font-size: 13px; text-align: center; padding: 0 15px; }

.file-list { margin-top: 8px; display: grid; gap: 6px; }
.file-row {
  min-height: 58px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto 28px;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--ci-radius-md);
  background: #fff;
}
.file-row > svg { width: 15px; color: var(--blue); }
.file-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.file-row small { color: var(--muted); font-size: 12px; }
.file-row button {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.file-row button:hover { color: var(--ink); border-color: var(--line); background: var(--ci-surface-muted); }
.file-row button svg { width: 14px; height: 14px; }

.settings { display: flex; flex-direction: column; gap: 18px; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend, .number-field > span:first-child { display: block; margin-bottom: 8px; color: var(--ink); font-size: 14px; font-weight: 700; }

.segment-control {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.segment-control.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.segment-control label { min-width: 0; border-right: 1px solid var(--line); }
.segment-control label:last-child { border-right: 0; }
.segment-control input { position: absolute; opacity: 0; pointer-events: none; }
.segment-control span { min-height: 43px; height: 100%; display: flex; align-items: center; justify-content: center; padding: 0 8px; font-size: 13px; cursor: pointer; text-align: center; }
.segment-control input:checked + span { color: var(--milo-selected-text); background: var(--milo-selected-bg); font-weight: 750; }
.segment-control input:focus-visible + span { outline: 2px solid var(--milo-selected-bg); outline-offset: -3px; }
.topbar .ci-topbar-meta { width: auto; margin-left: auto; }
.normalization-section:has(#normalizationResult[hidden]) { display: none; }
.status { overflow-wrap: anywhere; }

.number-field { display: block; }
.number-input { min-height: 48px; display: grid; grid-template-columns: 1fr 52px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.number-input input { min-width: 0; padding: 0 12px; border: 0; color: var(--ink); outline: none; font-size: 18px; }
.number-input b { display: flex; align-items: center; justify-content: center; color: var(--muted); background: var(--ci-surface-muted); border-left: 1px solid var(--line); font-size: 13px; font-weight: 750; }

.primary-button, .secondary-button {
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.primary-button { color: var(--milo-selected-text); background: var(--green); border: 1px solid var(--green); }
.primary-button:hover:not(:disabled) { background: var(--green-dark); }
.primary-button:disabled { color: var(--muted); background: var(--ci-accent-soft); border-color: transparent; cursor: not-allowed; opacity: 1; }
.secondary-button { color: var(--ink); background: #fff; border: 1px solid var(--ci-border-strong); }
.secondary-button:hover { border-color: var(--ink); }
.primary-button svg, .secondary-button svg { width: 16px; height: 16px; }
.status { min-height: 18px; color: var(--muted); font-size: 11px; }
.status.error { color: var(--coral); }

.result-band {
  min-height: 122px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, .7fr) auto;
  align-items: center;
  gap: 28px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--ci-surface-muted);
}
.result-value { display: flex; align-items: baseline; gap: 8px; }
.result-value strong { font-size: 42px; line-height: 44px; letter-spacing: 0; }
.result-value span { color: var(--muted); font-size: 14px; font-weight: 700; }
.exact-value { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.target-readout { padding-left: 22px; border-left: 3px solid var(--gold); }
.target-readout span { display: block; color: var(--muted); font-size: 11px; }
.target-readout strong { display: block; margin-top: 5px; font-size: 18px; }
.target-readout strong.over { color: var(--coral); }
.target-readout strong.ok { color: var(--milo-success); }
.report-actions { display: flex; gap: 8px; }

.normalization-section { padding: 20px 28px; border-bottom: 1px solid var(--line); }
.normalization-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.normalization-heading > div { min-width: 0; }
.normalization-summary { font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
.normalization-downloads { display: flex; flex-wrap: wrap; gap: 8px; }
.normalization-downloads a { min-width: 130px; }
.peak-warning { color: var(--gold); font-size: 12px; line-height: 1.6; margin: 12px 0; overflow-wrap: anywhere; }
#gainPreview { line-height: 1.6; }
button:disabled { cursor: not-allowed; }
.dropzone.busy { pointer-events: none; opacity: .6; }

.result-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(260px, .85fr); }
.analysis-section { min-width: 0; padding: 24px 28px 27px; border-bottom: 1px solid var(--line); }
.analysis-section + .analysis-section { border-left: 1px solid var(--line); }

.spectrum { height: 178px; display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 7px; align-items: end; padding-top: 13px; border-bottom: 1px solid var(--line); }
.spectrum-bar { height: 100%; display: grid; grid-template-rows: 1fr 18px; gap: 5px; align-items: end; min-width: 0; }
.spectrum-track { height: 100%; display: flex; align-items: flex-end; background: var(--ci-surface-muted); border: 1px solid var(--line); border-bottom: 0; }
.spectrum-fill { width: 100%; min-height: 2px; background: var(--milo-chart-1); transition: height 300ms ease; }
.spectrum-bar:nth-child(8n+2) .spectrum-fill { background: var(--milo-chart-2); }
.spectrum-bar:nth-child(8n+3) .spectrum-fill { background: var(--milo-chart-3); }
.spectrum-bar:nth-child(8n+4) .spectrum-fill { background: var(--milo-chart-4); }
.spectrum-bar:nth-child(8n+5) .spectrum-fill { background: var(--milo-chart-5); }
.spectrum-bar:nth-child(8n+6) .spectrum-fill { background: var(--milo-chart-6); }
.spectrum-bar:nth-child(8n+7) .spectrum-fill { background: var(--milo-chart-7); }
.spectrum-bar:nth-child(8n+8) .spectrum-fill { background: var(--milo-chart-8); }
.spectrum-label { overflow: hidden; text-align: center; color: var(--muted); font-size: 9px; white-space: nowrap; }

.metadata { margin: 11px 0 0; }
.metadata > div { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.metadata > div:last-child { border-bottom: 0; }
.metadata dt { color: var(--muted); font-size: 10px; font-weight: 700; }
.metadata dd { margin: 0; overflow-wrap: anywhere; font-size: 11px; }

.channel-section { padding: 24px 28px 28px; }
.channel-table-wrap { overflow-x: auto; border: 1px solid var(--line); }
table { width: 100%; min-width: 720px; border-collapse: collapse; font-size: 11px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); }
th { color: #fff; background: var(--ink); font-size: 10px; }
th:first-child, td:first-child { text-align: left; }
tbody tr:nth-child(even) { background: var(--ci-surface-muted); }
tbody tr:last-child td { border-bottom: 0; }
.share-cell { display: grid; grid-template-columns: minmax(80px, 1fr) 42px; gap: 8px; align-items: center; }
.share-track { height: 7px; overflow: hidden; background: var(--ci-surface-muted); border: 1px solid var(--line); border-radius: 999px; }
.share-fill { height: 100%; background: var(--green); }

button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 0;
  box-shadow: var(--ci-shadow-focus);
}

@media (max-width: 820px) {
  main { width: min(100% - 24px, var(--ci-content-width)); padding: var(--ci-space-5) 0 34px; }
  .topbar, .tool-nav { padding-inline: var(--ci-space-4); }
  .workspace { padding: var(--ci-space-5); }
  .input-grid, .result-grid { grid-template-columns: 1fr; }
  .input-grid { gap: 22px; }
  .analysis-section + .analysis-section { border-left: 0; }
  .result-band { grid-template-columns: 1fr 1fr; gap: 18px; padding: 20px 18px; }
  .report-actions { grid-column: 1 / -1; }
  .report-actions a { flex: 1; }
  .analysis-section, .channel-section { padding: 21px 18px 23px; }
  .normalization-section { padding: 20px 18px; }
}

@media (max-width: 520px) {
  .topbar .ci-topbar-meta { flex-direction: column; align-items: flex-end; gap: 4px; }
  .connection { display: none; }
  .segment-control { height: auto; grid-template-columns: repeat(3, 1fr); border: 0; gap: 5px; overflow: visible; }
  .segment-control label { min-height: 43px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
  .segment-control.compact { grid-template-columns: repeat(2, 1fr); }
  .result-band { grid-template-columns: 1fr; }
  .target-readout { padding-left: 13px; }
  .report-actions { grid-column: auto; }
  .spectrum { gap: 3px; height: 150px; }
  .spectrum-label { font-size: 8px; }
  .normalization-heading .primary-button { width: 100%; }
  .normalization-downloads a { flex: 1; }
}
