:root {
  color-scheme: dark;
  --page: #07111f;
  --page-deep: #040b14;
  --panel: #0d1b2d;
  --panel-raised: #11243b;
  --panel-soft: #0a1727;
  --border: #21405d;
  --border-bright: #2e5a7d;
  --accent: #42d7ff;
  --accent-strong: #13bfe9;
  --accent-soft: rgba(66, 215, 255, 0.12);
  --text: #f5f9fd;
  --muted: #9eb2c8;
  --muted-strong: #c3d1df;
  --success: #66e6bd;
  --warning: #ffc66d;
  --error: #ff8292;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.24);
  --radius-lg: 18px;
  --radius-md: 13px;
  --radius-sm: 9px;
  --focus: 0 0 0 3px rgba(66, 215, 255, 0.34);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page-deep);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -8%, rgba(28, 119, 162, 0.2), transparent 30rem),
    linear-gradient(180deg, var(--page) 0%, var(--page-deep) 100%);
  line-height: 1.5;
}

button,
input,
progress {
  font: inherit;
}

button {
  color: inherit;
}

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

h1,
h2,
h3,
h4,
p,
dl,
dd,
ol,
ul {
  margin-top: 0;
}

ul,
ol {
  padding: 0;
}

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

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  color: #00131b;
  background: var(--accent);
  border-radius: var(--radius-sm);
  font-weight: 800;
  transform: translateY(-160%);
  transition: transform 140ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 22px;
  align-items: center;
  padding: 20px 22px;
  background: rgba(13, 27, 45, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand-block,
.header-actions,
.action-buttons,
.pair-controls,
.result-actions {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
  gap: 13px;
}

.brand-logo {
  flex: 0 0 auto;
  filter: drop-shadow(0 7px 16px rgba(66, 215, 255, 0.18));
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  margin-bottom: 1px;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  letter-spacing: -0.025em;
}

.brand-copy p,
.panel-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.privacy-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 9px 12px;
  color: var(--muted-strong);
  background: rgba(102, 230, 189, 0.07);
  border: 1px solid rgba(102, 230, 189, 0.22);
  border-radius: 999px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.privacy-indicator span {
  color: var(--success);
  font-size: 0.62rem;
}

.header-actions,
.action-buttons,
.pair-controls,
.result-actions {
  gap: 9px;
}

.button,
.icon-button,
.drag-handle,
.result-download {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 750;
  transition:
    transform 130ms ease,
    border-color 130ms ease,
    background-color 130ms ease,
    box-shadow 130ms ease,
    opacity 130ms ease;
}

.button {
  padding: 10px 15px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.button-primary {
  color: #00141d;
  background: linear-gradient(135deg, #70e6ff, var(--accent-strong));
  box-shadow: 0 8px 20px rgba(19, 191, 233, 0.15);
}

.button-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(19, 191, 233, 0.24);
}

.button-secondary,
.icon-button,
.result-download {
  color: var(--text);
  background: #12263d;
  border-color: var(--border);
}

.button-secondary:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.result-download:hover:not([aria-disabled="true"]) {
  background: #18334f;
  border-color: var(--border-bright);
}

button:disabled,
.button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
  box-shadow: none;
  transform: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
.file-dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  box-shadow: var(--focus);
}

.statistics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.stat-item {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 9px;
  align-items: baseline;
  min-width: 0;
  padding: 11px 14px;
  background: rgba(13, 27, 45, 0.72);
  border: 1px solid rgba(33, 64, 93, 0.78);
  border-radius: var(--radius-md);
}

.stat-item dt {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.79rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-item dd {
  margin-bottom: 0;
  color: var(--text);
  font-size: 1.06rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(520px, 1.35fr);
  gap: 14px;
  align-items: start;
}

.panel,
.results-panel,
.action-bar,
.notification-shell {
  min-width: 0;
  background: rgba(13, 27, 45, 0.84);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.16);
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.panel-heading h2,
.results-panel h2 {
  margin-bottom: 2px;
  font-size: 1rem;
  letter-spacing: -0.012em;
}

.count-badge,
.pair-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
}

.count-badge {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(66, 215, 255, 0.22);
}

.file-dropzone {
  position: relative;
  min-height: 360px;
  padding: 12px;
  background: rgba(4, 11, 20, 0.36);
  border: 1px dashed var(--border-bright);
  border-radius: var(--radius-md);
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.file-dropzone.is-dragover {
  background: rgba(66, 215, 255, 0.075);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(66, 215, 255, 0.35);
}

.pdf-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  gap: 10px;
  min-height: 70px;
  margin: 0;
  list-style: none;
}

.empty-state {
  position: absolute;
  inset: 50% auto auto 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(250px, calc(100% - 32px));
  color: var(--muted);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

.empty-state strong {
  margin: 9px 0 2px;
  color: var(--muted-strong);
  font-size: 0.9rem;
}

.empty-state span:last-child {
  font-size: 0.8rem;
}

.empty-state-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 58px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(66, 215, 255, 0.28);
  border-radius: 8px 8px 14px 8px;
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.pdf-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 9px 24px rgba(0, 0, 0, 0.18);
  list-style: none;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.pdf-card:hover {
  border-color: var(--border-bright);
}

.pdf-card.is-loading {
  opacity: 0.78;
}

.pdf-preview {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(66, 215, 255, 0.07), transparent 55%),
    #081523;
  border-bottom: 1px solid var(--border);
}

.pdf-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #e6edf3;
}

.preview-placeholder,
.preview-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 12px;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.preview-placeholder strong {
  color: var(--warning);
  font-size: 0.78rem;
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(158, 178, 200, 0.24);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.pdf-card-body {
  min-width: 0;
  padding: 11px;
}

.pdf-name {
  display: -webkit-box;
  min-height: 2.55em;
  margin-bottom: 7px;
  overflow: hidden;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 780;
  line-height: 1.28;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.pdf-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 9px;
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.move-select {
  width: 100%;
  min-height: 38px;
  margin-top: 9px;
  padding: 7px 9px;
  color: var(--text);
  background: #12263d;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  cursor: pointer;
  transition:
    border-color 130ms ease,
    background-color 130ms ease;
}

.move-select:hover:not(:disabled),
.move-select:focus-visible {
  background: #18334f;
  border-color: var(--border-bright);
}

.move-select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.drag-handle,
.icon-button {
  display: grid;
  place-items: center;
  padding: 0;
}

.drag-handle {
  position: absolute;
  z-index: 2;
  top: 7px;
  left: 7px;
  width: 44px;
  min-height: 44px;
  color: var(--text);
  background: rgba(4, 11, 20, 0.82);
  border-color: rgba(158, 178, 200, 0.28);
  cursor: grab;
  touch-action: none;
  backdrop-filter: blur(8px);
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-handle.keyboard-picked {
  color: #00141d;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.drag-dots {
  display: grid;
  grid-template-columns: repeat(2, 3px);
  gap: 3px;
}

.drag-dots i {
  display: block;
  width: 3px;
  height: 3px;
  background: currentColor;
  border-radius: 50%;
}

.remove-file-button {
  position: absolute;
  z-index: 2;
  top: 7px;
  right: 7px;
  width: 44px;
  min-height: 44px;
  color: #ffd8dd;
  background: rgba(67, 20, 31, 0.88);
  border-color: rgba(255, 130, 146, 0.26);
  backdrop-filter: blur(8px);
}

.remove-file-button:hover:not(:disabled) {
  background: rgba(111, 28, 44, 0.94);
  border-color: rgba(255, 130, 146, 0.5);
}

.pairs-list {
  display: grid;
  gap: 12px;
  margin: 0;
  list-style: none;
}

.pair-card {
  min-width: 0;
  padding: 13px;
  background: rgba(4, 11, 20, 0.34);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.pair-card-header {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  margin-bottom: 11px;
}

.pair-card-header h3 {
  margin: 0;
  font-size: 0.92rem;
}

.pair-controls {
  justify-content: flex-end;
}

.pair-controls .button {
  min-height: 44px;
  padding: 7px 10px;
  font-size: 0.74rem;
}

.pair-status-ready {
  color: var(--success);
  background: rgba(102, 230, 189, 0.09);
  border: 1px solid rgba(102, 230, 189, 0.22);
}

.pair-status-partial {
  color: var(--warning);
  background: rgba(255, 198, 109, 0.09);
  border: 1px solid rgba(255, 198, 109, 0.22);
}

.pair-status-empty {
  color: var(--muted);
  background: rgba(158, 178, 200, 0.07);
  border: 1px solid rgba(158, 178, 200, 0.16);
}

.pair-positions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.pair-slot {
  min-width: 0;
  padding: 9px;
  background: rgba(13, 27, 45, 0.72);
  border: 1px dashed var(--border-bright);
  border-radius: 11px;
}

.pair-slot h4 {
  margin-bottom: 7px;
  color: var(--muted-strong);
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.pair-slot-list {
  position: relative;
  display: block;
  min-height: 194px;
  margin: 0;
  list-style: none;
}

.pair-slot-list:empty::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  color: var(--muted);
  border: 1px solid rgba(33, 64, 93, 0.35);
  border-radius: 9px;
  content: "Drop PDF here";
  font-size: 0.76rem;
  text-align: center;
}

.pair-slot-list.sortable-drag-over:empty::after {
  color: var(--accent);
  border-color: var(--accent);
}

.pair-plus {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(66, 215, 255, 0.2);
  border-radius: 50%;
  font-size: 1.2rem;
  font-weight: 500;
}

.action-bar {
  margin-top: 14px;
  padding: 14px;
}

.action-buttons {
  flex-wrap: wrap;
}

.naming-control {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.naming-control label {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
}

#naming-select {
  min-height: 44px;
  padding: 9px 11px;
  color: var(--text);
  background: #12263d;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    border-color 130ms ease,
    background-color 130ms ease;
}

#naming-select:hover:not(:disabled),
#naming-select:focus-visible {
  background: #18334f;
  border-color: var(--border-bright);
}

#naming-select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#naming-select:invalid {
  border-color: var(--border-bright);
  color: var(--muted-strong);
}

.merge-progress {
  margin-top: 13px;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
  color: var(--muted-strong);
  font-size: 0.78rem;
}

progress {
  display: block;
  width: 100%;
  height: 8px;
  overflow: hidden;
  accent-color: var(--accent);
  background: #07111f;
  border: 0;
  border-radius: 999px;
}

progress::-webkit-progress-bar {
  background: #07111f;
  border-radius: 999px;
}

progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  border-radius: 999px;
}

.notification-shell {
  min-height: 48px;
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(8, 21, 35, 0.82);
}

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

.notification-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  min-width: 0;
  color: var(--muted-strong);
  font-size: 0.78rem;
}

.notification-item::before {
  flex: 0 0 auto;
  color: var(--accent);
  content: "•";
  font-size: 1rem;
  line-height: 1.1;
}

.notification-item[data-kind="success"]::before {
  color: var(--success);
}

.notification-item[data-kind="warning"]::before {
  color: var(--warning);
}

.notification-item[data-kind="error"]::before {
  color: var(--error);
}

.results-panel {
  margin-top: 14px;
  padding: 18px;
}

.results-empty {
  margin: 6px 0 0;
  padding: 22px;
  color: var(--muted);
  background: rgba(4, 11, 20, 0.28);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  text-align: center;
}

.results-list {
  display: grid;
  gap: 9px;
  margin: 0;
  list-style: none;
}

.result-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-width: 0;
  padding: 13px 14px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.result-card-copy {
  min-width: 0;
}

.result-name {
  display: block;
  margin-bottom: 3px;
  overflow: hidden;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.result-sources,
.result-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  overflow-wrap: anywhere;
}

.result-meta {
  margin-top: 3px;
}

.result-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  color: var(--text);
  font-size: 0.78rem;
  text-decoration: none;
  white-space: nowrap;
}

.sortable-ghost {
  opacity: 0.3;
}

.sortable-chosen {
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(19, 191, 233, 0.18);
}

.sortable-drag {
  transform: rotate(1deg) scale(1.015);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.38);
}

.app-is-busy .pdf-card,
.app-is-busy .pair-card {
  transition: none;
}

.app-unavailable .workspace-grid,
.app-unavailable .action-bar,
.app-unavailable .statistics,
.app-unavailable .results-panel {
  opacity: 0.54;
}

.noscript-message {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 100;
  margin: 0;
  padding: 14px 18px;
  color: #24050a;
  background: var(--error);
  border-radius: var(--radius-md);
  font-weight: 800;
  text-align: center;
}

@media (max-width: 1080px) {
  .app-header {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .privacy-indicator {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: start;
  }

  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .file-dropzone {
    min-height: 270px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 10px;
  }

  .app-header {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 16px;
  }

  .header-actions {
    grid-column: 1;
    width: 100%;
  }

  .header-actions .button {
    flex: 1 1 0;
  }

  .privacy-indicator {
    grid-column: 1;
    grid-row: auto;
    white-space: normal;
  }

  .statistics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel,
  .results-panel {
    padding: 14px;
  }

  .pair-card-header {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .pair-controls {
    grid-column: 1 / -1;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .pair-positions {
    grid-template-columns: 1fr;
  }

  .pair-plus {
    justify-self: center;
  }

  .pair-slot-list {
    min-height: 186px;
  }

  .result-card {
    grid-template-columns: 1fr;
  }

  .result-download {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .pdf-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-buttons .button {
    flex: 1 1 calc(50% - 9px);
  }

  .naming-control {
    flex: 1 1 100%;
  }

  .stat-item {
    gap: 6px;
    padding: 10px;
  }

  .stat-item dt {
    font-size: 0.7rem;
  }
}

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