:root {
  color-scheme: light;
  --page: #f3f5f8;
  --surface: #fff;
  --text: #19293a;
  --muted: #526379;
  --line: #d7dfe8;
  --line-strong: #a4b2c2;
  --brand: #142a42;
  --primary: #075496;
  --primary-hover: #064576;
  --focus: #1672b9;
  --tint: #eaf3fb;
  --danger: #a12622;
  --danger-bg: #fff1ef;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-synthesis: none;
}

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

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
}

a { color: var(--primary); }
button, input { font: inherit; }
button, input[type="checkbox"], input[type="radio"] { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.shell { width: min(1056px, calc(100% - 3rem)); margin-inline: auto; }

.masthead {
  min-height: 66px;
  background: var(--brand);
  color: #e3eaf3;
  border-bottom: 3px solid #337db4;
}

.masthead-inner {
  min-height: inherit;
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.wordmark {
  color: white;
  text-decoration: none;
  font-size: 1.45rem;
  font-weight: 780;
  letter-spacing: -.045em;
  line-height: 1;
}

.masthead-product {
  border-inline-start: 1px solid #587089;
  padding-inline-start: 1.1rem;
  font-size: .925rem;
  font-weight: 600;
}

main.shell { padding-block: 2rem 2.5rem; }

h1 {
  margin: 0 0 1.35rem;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  line-height: 1.15;
  font-weight: 730;
  letter-spacing: -.035em;
}

h2, .check-list legend {
  margin: 0;
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 695;
  letter-spacing: -.01em;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  align-items: stretch;
  gap: 1.1rem;
}

.panel {
  min-width: 0;
  padding: clamp(1rem, 2.4vw, 1.65rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

fieldset { min-inline-size: 0; margin: 0; padding: 0; border: 0; }
.source-panel h2 { margin-bottom: .95rem; }

.source-selector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .25rem;
  padding: .25rem;
  background: #eaf0f6;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.source-selector label { position: relative; }

.source-selector input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: 0;
  opacity: 0;
}

.source-selector span {
  display: grid;
  block-size: 100%;
  min-height: 42px;
  padding: .53rem .35rem;
  place-items: center;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 620;
  text-align: center;
  cursor: pointer;
}

.source-selector span:hover { color: var(--primary); }
.source-selector input:checked + span {
  color: var(--brand);
  background: var(--surface);
  border-color: #b6c8d8;
  box-shadow: 0 1px 2px #142a4214;
}
.source-selector input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.source-fields { margin-top: 1.1rem; }
.upload-area {
  min-height: 142px;
  padding: 1.15rem .75rem;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: .55rem;
  color: var(--muted);
  background: #f8fafc;
  border: 1px dashed #91a5ba;
  border-radius: 8px;
}
.upload-area:focus-within, .upload-area.is-dragging {
  background: var(--tint);
  border-color: var(--focus);
}
.upload-area:has(.file-input:focus-visible) .upload-action {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.upload-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  min-height: 44px;
  padding: .55rem .85rem;
  border: 1px solid #91b1cf;
  border-radius: 6px;
  color: var(--primary);
  background: white;
  font-weight: 680;
  cursor: pointer;
}
.upload-action:hover { border-color: var(--focus); background: #eef6fd; }
.drop-text { margin: 0; padding-inline: .5rem; text-align: center; }

.plus-icon {
  position: relative;
  display: block;
  inline-size: .78rem;
  block-size: .78rem;
}
.plus-icon::before, .plus-icon::after {
  content: "";
  position: absolute;
  inset: calc(50% - 1px) 0 auto;
  block-size: 2px;
  background: currentColor;
  border-radius: 1px;
}
.plus-icon::after { transform: rotate(90deg); }

.field-help {
  margin: .52rem 0 0;
  color: var(--muted);
  font-size: .875rem;
}
.field-help + .field-help { margin-top: .25rem; }

.network-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .8rem;
}
.field { display: grid; min-width: 0; gap: .22rem; }
.field span { font-size: .925rem; font-weight: 620; }
.field .field-help { margin: 0; }
.field-wide { grid-column: 1 / -1; }
.field input {
  min-block-size: 45px;
  min-inline-size: 0;
  inline-size: 100%;
  padding: .5rem .65rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}
.field input::placeholder { color: #596a7d; opacity: 1; }

.check-list legend { padding: 0; margin-bottom: .55rem; }
.check-list label {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: .68rem;
  padding: .32rem .25rem;
  border-radius: 5px;
  cursor: pointer;
}
.check-list label:hover { background: #f3f7fb; }
.check-list input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}
.settings-panel .check-list:first-child { padding-bottom: .85rem; border-bottom: 1px solid var(--line); }
.output-list { margin-top: 1.1rem; }
.catalog-note { padding-inline-start: 1.6rem; }

.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .65rem 1rem;
  margin-top: 1rem;
}
.button-primary {
  min-height: 45px;
  padding: .65rem 1rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  font-weight: 680;
}
.button-primary:hover { background: var(--primary-hover); }
.button-primary:disabled { opacity: .7; cursor: wait; }
.form-error {
  margin: 0;
  max-width: 70ch;
  padding: .5rem .7rem;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 6px;
}

.file-list, .download-list { list-style: none; padding: 0; }
.file-list {
  margin: .8rem 0 0;
  max-height: 15rem;
  overflow: auto;
  border-block-start: 1px solid var(--line);
}
.file-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content max-content;
  align-items: center;
  gap: .45rem;
  padding: .35rem .2rem;
  border-bottom: 1px solid var(--line);
}
.file-name { overflow-wrap: anywhere; }
.file-size { color: var(--muted); font-size: .875rem; white-space: nowrap; }
.remove-file {
  display: grid;
  min-inline-size: 40px;
  min-block-size: 40px;
  place-items: center;
  padding: 0;
  color: var(--muted);
  border: 0;
  border-radius: 5px;
  background: transparent;
  font-size: 1.35rem;
}
.remove-file:hover { color: var(--danger); background: var(--danger-bg); }

.task-panel { margin-top: 1.15rem; }
.task-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .5rem 1rem;
}
.task-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem .8rem;
}
.job-link { font-size: .925rem; }
.button-stop {
  min-height: 42px;
  padding: .38rem .72rem;
  border: 1px solid #c78683;
  border-radius: 6px;
  color: var(--danger);
  background: white;
  font-weight: 640;
}
.button-stop:hover { color: #861713; background: var(--danger-bg); }
.button-stop:disabled { opacity: .7; cursor: wait; }
.button-primary:disabled[data-reason="active-stream"] { cursor: not-allowed; }
.stop-error { margin-top: .55rem; }
.task-status { margin: .45rem 0 0; }
.task-status[data-status="failed"] { color: var(--danger); }
.task-panel progress {
  display: block;
  width: min(100%, 28rem);
  height: .8rem;
  margin-top: .8rem;
  accent-color: var(--primary);
}
.download-list { display: flex; flex-wrap: wrap; gap: .55rem .8rem; margin: .8rem 0 0; }
.download-list a {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: .45rem .7rem;
  border: 1px solid #91b1cf;
  border-radius: 6px;
  background: var(--surface);
  text-underline-offset: .15em;
  font-weight: 610;
}
.download-list a:hover { background: var(--tint); }
.history-panel { margin-top: 1.15rem; }
.history-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .55rem 1rem;
}
.history-heading .button-stop { max-width: 100%; font-size: .9rem; }
.history-list { list-style: none; margin: .55rem 0 0; padding: 0; }
.history-row {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) minmax(6.6rem, .5fr) minmax(0, 1.65fr);
  gap: .5rem .85rem;
  align-items: center;
  padding: .65rem 0;
  border-bottom: 1px solid var(--line);
}
.history-row:last-child { padding-bottom: 0; border-bottom: 0; }
.history-job {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  align-self: stretch;
  justify-content: center;
  min-height: 42px;
  text-underline-offset: .15em;
}
.history-kind { font-weight: 670; }
.history-job time { color: var(--muted); font-size: .875rem; }
.history-job[aria-current="true"] .history-kind { color: var(--brand); }
.history-state {
  width: fit-content;
  padding: .18rem .48rem;
  border-radius: 4px;
  background: #edf1f5;
  color: #41566c;
  white-space: normal;
  font-size: .875rem;
  font-weight: 620;
}
.history-state[data-status="running"], .history-state[data-status="active"] {
  background: var(--tint);
  color: #125384;
}
.history-state[data-status="failed"] { background: var(--danger-bg); color: var(--danger); }
.history-downloads {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem .75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.history-downloads a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  text-underline-offset: .15em;
}
.retention { color: var(--muted); font-size: .875rem; margin: 1rem 0 0; }
.history-dialog {
  width: min(31rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: clamp(1rem, 3vw, 1.5rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
}
.history-dialog::backdrop { background: #142a4275; }
.history-dialog p { margin: .65rem 0 .9rem; }
.history-dialog .form-error { margin: .6rem 0 0; }
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1rem;
}
.button-secondary {
  min-height: 45px;
  padding: .55rem .8rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
}
.button-secondary:hover { background: var(--page); }
.button-secondary:disabled { opacity: .65; cursor: wait; }
.button-delete { background: var(--danger); }
.button-delete:hover { background: #861713; }

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

@media (max-width: 740px) {
  .work-grid { grid-template-columns: 1fr; gap: .85rem; }
  .shell { width: min(1056px, calc(100% - 2rem)); }
  main.shell { padding-top: 1.45rem; }
  .source-fields { min-height: auto; }
  .history-row { grid-template-columns: minmax(0, 1fr) auto; gap: .22rem .6rem; }
  .history-downloads { grid-column: 1 / -1; }
}

@media (max-width: 380px) {
  .network-fields { grid-template-columns: 1fr; }
  .file-list li { grid-template-columns: minmax(0, 1fr) max-content; }
  .file-size { display: none; }
  .source-selector span { font-size: .875rem; }
  .form-actions .button-primary { width: 100%; }
}

@media (forced-colors: active) {
  .source-selector input:checked + span { border: 2px solid Highlight; }
  .upload-area.is-dragging { outline: 2px solid Highlight; }
}
