:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #607080;
  --line: #d9e0e7;
  --surface: #ffffff;
  --band: #f4f7f9;
  --teal: #0f766e;
  --teal-dark: #0b5c55;
  --blue: #2457a6;
  --green: #2f7d47;
  --red: #b13f3f;
  --amber: #a46212;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--band);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.45rem;
  line-height: 1.1;
}

h2 {
  font-size: 1rem;
}

#subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

main {
  display: grid;
  gap: 16px;
  padding: 16px clamp(12px, 3vw, 32px) 32px;
}

.import-band,
.batch-band,
.control-band,
.workspace,
.detail-panel,
.queue-panel {
  border: 1px solid var(--line);
  background: var(--surface);
}

.import-band {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.batch-band {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.batch-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.merge-plan-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.merge-plan-row {
  display: grid;
  grid-template-columns: 32px 72px minmax(180px, 1fr) minmax(140px, 220px) minmax(140px, 220px);
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.merge-plan-row input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.merge-plan-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.merge-plan-title strong,
.merge-plan-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.merge-plan-title span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.merge-plan-row select {
  min-height: 36px;
}

.synology-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(140px, 0.7fr) minmax(150px, 0.7fr) minmax(110px, 0.45fr) minmax(96px, 0.35fr) auto auto;
  gap: 14px;
  align-items: end;
}

.checkbox-label {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.checkbox-label input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.import-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.control-band {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: end;
  padding: 16px;
}

.scan-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px) auto;
  gap: 14px;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

input[type="text"],
input:not([type]),
textarea {
  padding: 9px 10px;
}

input[type="range"] {
  accent-color: var(--teal);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #fff;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  background: var(--teal);
}

.button.primary:hover {
  background: var(--teal-dark);
}

.button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.button.success {
  background: var(--green);
}

.button.danger {
  background: var(--red);
}

.button.warning {
  background: var(--amber);
}

.actions,
.review-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(80px, 1fr));
  gap: 8px;
  min-width: 300px;
}

.stats div {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.stats strong {
  font-size: 1.2rem;
}

.stats span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  min-height: calc(100vh - 190px);
}

.queue-panel {
  border-width: 0 1px 0 0;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading select {
  max-width: 150px;
}

.candidate-list {
  display: grid;
  align-content: start;
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.candidate-card {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 62px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.candidate-card:hover,
.candidate-card.active {
  background: #eef7f6;
}

.score {
  color: var(--blue);
  font-weight: 900;
}

.names {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 750;
}

.status,
.status-pill {
  border-radius: 999px;
  background: #eef1f4;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 850;
  padding: 4px 8px;
  white-space: nowrap;
}

.detail-panel {
  border-width: 0;
  min-width: 0;
}

.empty-state,
.detail-content {
  padding: clamp(16px, 3vw, 28px);
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 420px;
  color: var(--muted);
  text-align: center;
}

.detail-content {
  display: grid;
  gap: 18px;
}

.detail-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.detail-title {
  margin-top: 4px;
  font-size: 1.35rem;
  overflow-wrap: anywhere;
}

.comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

figure {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #0f1720;
}

figure img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #101820;
}

figcaption {
  padding: 10px;
  background: #fff;
  font-size: 0.86rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.notes {
  resize: vertical;
  min-height: 76px;
}

body.busy .button.primary {
  opacity: 0.7;
  pointer-events: none;
}

@media (max-width: 900px) {
  .topbar,
  .synology-form,
  .control-band,
  .scan-form,
  .workspace,
  .comparison,
  .batch-heading,
  .merge-plan-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
  }

  .stats {
    min-width: 0;
  }

  .queue-panel {
    border-width: 0 0 1px 0;
  }

  .candidate-list {
    max-height: 320px;
  }
}

@media (max-width: 520px) {
  .stats,
  .candidate-card {
    grid-template-columns: 1fr;
  }

  .candidate-card {
    gap: 4px;
  }
}
