:root {
  color-scheme: light;
  --background: #f4f7fb;
  --surface: #ffffff;
  --text: #14213d;
  --muted: #5d6b82;
  --border: #d7e0ec;
  --surface-soft: #f8fbff;
  --file-border: #9eb8dc;
  --selector: #eaf2ff;
  --selector-hover: #dceaff;
  --code-text: #244c85;
  --code-background: #edf4ff;
  --accent: #1769e0;
  --accent-hover: #1158bf;
  --focus: #85b6ff;
  --radius: 14px;
  --shadow: 0 18px 50px rgb(33 63 109 / 10%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #0f1724;
  --surface: #172131;
  --text: #eef4ff;
  --muted: #aebbd0;
  --border: #334158;
  --surface-soft: #1c293b;
  --file-border: #4a6588;
  --selector: #243a59;
  --selector-hover: #2d496f;
  --code-text: #b9d7ff;
  --code-background: #223550;
  --accent: #5a9cff;
  --accent-hover: #76adff;
  --focus: #9ec5ff;
  --shadow: 0 20px 56px rgb(0 0 0 / 32%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--background);
  font-size: 16px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.page {
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: clamp(14px, 2vw, 28px);
}

.processor {
  width: min(100%, 1480px);
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(380px, 1fr);
  gap: 20px 30px;
  padding: clamp(24px, 2.5vw, 40px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.processor__header {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 4px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.85rem, 3.2vw, 2.65rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
}

.processor__header p {
  max-width: 54ch;
  margin-bottom: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--muted);
}

.theme-toggle {
  flex: 0 0 auto;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 700;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.theme-toggle:hover {
  border-color: var(--file-border);
  background: var(--selector);
}

.theme-toggle__icon {
  width: 1.1em;
  font-size: 1.05rem;
  line-height: 1;
  text-align: center;
}

.upload-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 18px;
  align-content: start;
}

.profile-catalog,
.reference-panel {
  padding: 20px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.profile-catalog {
  grid-column: 1 / -1;
}

.reference-panel {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
  min-width: 0;
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading h2 {
  margin-bottom: 6px;
  color: var(--text);
  font-size: 1.12rem;
}

.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.select-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 9px 34px 9px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

select:disabled {
  color: var(--muted);
  background: var(--surface-soft);
  cursor: not-allowed;
  opacity: 0.78;
}

.profile-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 0;
}

.profile-summary div {
  padding: 9px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.profile-summary .select-label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.66rem;
}

.profile-summary select {
  min-height: 38px;
  padding: 7px 27px 7px 9px;
  font-size: 0.8rem;
}

.availability {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.merge-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.merge-toggle,
.merge-limit {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.merge-toggle {
  cursor: pointer;
}

.merge-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.merge-toggle span {
  display: grid;
}

.merge-toggle strong,
.merge-limit span {
  font-size: 0.78rem;
  white-space: nowrap;
}

.merge-toggle small {
  color: var(--muted);
  font-size: 0.68rem;
}

.merge-limit {
  justify-content: space-between;
}

.merge-limit input {
  width: 132px;
  flex: 0 0 132px;
  min-height: 34px;
  padding: 5px 7px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.merge-options--disabled {
  opacity: 0.55;
}

.article-catalog {
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.article-hint {
  margin-top: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

@media (min-width: 1081px) {
  .article-hint {
    max-height: 420px;
    overflow: auto;
    scrollbar-width: thin;
  }
}

.article-hint p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.article-hint .article-format {
  color: var(--text);
  font-weight: 700;
}

.article-empty {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem !important;
  line-height: 1.45 !important;
}

.article-selected-brand {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--accent) !important;
  font-size: 0.82rem !important;
  font-weight: 800;
}

.article-patterns {
  margin: 10px 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.25;
}

.article-patterns li + li {
  margin-top: 2px;
}

.article-examples {
  overflow-wrap: anywhere;
}

.article-caveat {
  margin-top: 8px !important;
}

.article-sources {
  margin-top: 10px !important;
  font-size: 0.78rem !important;
}

.article-sources a {
  color: var(--accent);
}

.file-field {
  grid-column: 1 / -1;
  padding: 18px;
  border: 1px dashed var(--file-border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.file-field label {
  display: block;
  margin-bottom: 4px;
  font-size: 1.02rem;
  font-weight: 700;
}

.file-field p {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

input[type="file"] {
  width: 100%;
  padding: 6px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 9px 14px;
  color: var(--accent);
  font-weight: 700;
  background: var(--selector);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 160ms ease;
}

input[type="file"]:hover::file-selector-button {
  background: var(--selector-hover);
}

.file-list {
  max-height: 180px;
  margin-top: 12px;
  padding: 12px;
  overflow: auto;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.78rem;
  scrollbar-width: thin;
}

.file-list strong {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
}

.file-list ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.file-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.file-list li > span:first-child {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-brand {
  flex: 0 0 auto;
  font-weight: 700;
}

.file-brand--ok {
  color: var(--accent);
}

.file-brand--pending {
  color: var(--muted);
}

.requirements {
  grid-column: 1;
  align-self: center;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.requirements h2 {
  margin-bottom: 6px;
  color: var(--text);
  font-size: 1.08rem;
}

.requirements ul {
  margin: 0;
  padding-left: 18px;
}

.requirements li + li {
  margin-top: 4px;
}

code {
  padding: 2px 5px;
  color: var(--code-text);
  background: var(--code-background);
  border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

button[type="submit"] {
  grid-column: 2;
  align-self: center;
  width: 100%;
  min-height: 50px;
  padding: 12px 20px;
  color: #ffffff;
  font-weight: 700;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 11px;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button[type="submit"]:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button[type="submit"]:active {
  transform: translateY(1px);
}

button[type="submit"].is-processing {
  background: linear-gradient(110deg, var(--accent) 10%, #77adff 36%, var(--accent) 62%, #9cc5ff 86%);
  background-size: 240% 100%;
  border-color: transparent;
  cursor: wait;
  animation: processing-shimmer 1.35s linear infinite;
}

button[type="submit"].is-processing:disabled {
  color: #ffffff;
  opacity: 1;
}

@keyframes processing-shimmer {
  from { background-position: 100% 0; }
  to { background-position: -140% 0; }
}

.process-status {
  grid-column: 1 / -1;
  min-height: 1.4em;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.instruction {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.instruction__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 0;
  color: var(--text);
  list-style: none;
  cursor: pointer;
}

.instruction__summary::-webkit-details-marker {
  display: none;
}

.instruction__title {
  display: block;
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.3;
}

.instruction__chevron {
  flex: 0 0 auto;
  color: var(--muted);
  transition: transform 180ms ease, color 180ms ease;
}

.instruction[open] .instruction__chevron {
  color: var(--accent);
  transform: rotate(180deg);
}

.instruction__content {
  padding-top: 16px;
}

.instruction__content > p {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.instruction ol {
  margin: 0;
  padding-left: 24px;
  color: var(--muted);
  columns: 1;
  font-size: 0.84rem;
  line-height: 1.5;
}

.instruction li + li {
  margin-top: 8px;
}

.instruction li {
  break-inside: avoid;
}

.instruction code {
  white-space: nowrap;
}

.catalog-admin {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.catalog-admin__content {
  padding-top: 14px;
}

.catalog-admin__content h3 {
  margin: 0 0 9px;
  font-size: 0.88rem;
}

.catalog-admin__content section + section {
  margin-top: 18px;
}

.admin-alias-form {
  margin-top: 8px;
}

.admin-alias-form select {
  min-width: 0;
  min-height: 40px;
  font-size: 0.78rem;
}

.admin-alias-filter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 10px;
  margin-top: 12px;
}

.admin-alias-filter label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.admin-alias-filter input {
  min-width: 0;
  min-height: 38px;
  padding: 7px 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.admin-alias-filter span {
  align-self: center;
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
}

.admin-login > label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
}

.admin-inline {
  display: flex;
  gap: 8px;
}

.admin-inline input {
  min-width: 0;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.catalog-admin button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 12px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  background: var(--selector);
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
}

.catalog-admin button:hover {
  background: var(--selector-hover);
}

.admin-status {
  min-height: 1.4em;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.catalog-admin ul {
  display: grid;
  gap: 6px;
  max-height: 190px;
  margin: 10px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  scrollbar-width: thin;
}

.catalog-admin li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px 7px 10px;
  color: var(--muted);
  font-size: 0.76rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.catalog-admin li button {
  min-height: 30px;
  padding: 4px 8px;
}

.catalog-admin li > div {
  min-width: 0;
}

.catalog-admin li strong {
  display: block;
  color: var(--text);
}

.admin-aliases {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.7rem;
}

.admin-aliases span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 3px 2px 7px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.admin-aliases span button {
  min-height: 22px;
  padding: 1px 5px;
  border-radius: 999px;
}

input[type="file"]:focus-visible,
select:focus-visible,
button.theme-toggle:focus-visible,
button[type="submit"]:focus-visible,
.catalog-admin button:focus-visible,
.catalog-admin input:focus-visible,
.instruction__summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

@media (max-width: 1080px) {
  .processor {
    display: block;
    min-height: auto;
    padding: 28px;
  }

  .processor__header {
    margin-bottom: 24px;
  }

  .requirements,
  button[type="submit"] {
    grid-column: auto;
  }

  .reference-panel {
    margin-top: 24px;
  }
}

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

  .file-field {
    grid-column: auto;
  }

}

@media (max-width: 600px) {
  .page {
    place-items: start center;
    padding: 0;
  }

  .processor {
    min-height: 100vh;
    padding: 22px 18px 28px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .processor__header {
    align-items: stretch;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 26px;
  }

  .theme-toggle {
    align-self: flex-start;
  }

  .file-field {
    padding: 18px;
  }

  .profile-catalog,
  .reference-panel {
    padding: 18px;
  }

  .profile-summary {
    grid-template-columns: 1fr;
  }

  .merge-options {
    grid-template-columns: 1fr;
  }

  .admin-inline {
    align-items: stretch;
    flex-direction: column;
  }

  input[type="file"] {
    padding: 6px;
    font-size: 0.875rem;
  }

  input[type="file"]::file-selector-button {
    display: block;
    width: 100%;
    margin: 0 0 9px;
  }
}

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

  button[type="submit"].is-processing {
    animation: none;
  }
}
