* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f4f7fb;
  color: #1f2937;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

.hero,
.panel,
.card {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px;
  margin-bottom: 20px;
}

.hero-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
  justify-content: center;
}

.hero-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.hero-actions form {
  margin: 0;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #2563eb;
}

.subtitle {
  color: #4b5563;
  max-width: 720px;
}

.badge {
  height: fit-content;
  padding: 10px 14px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 700;
}

.link {
  color: #2563eb;
  font-weight: 700;
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1f2937;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  border-color: #94a3b8;
}

.btn.secondary {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
}

.btn.primary {
  border-color: #2563eb;
  background: #2563eb;
  color: #ffffff;
}

.btn.primary:hover {
  border-color: #1d4ed8;
  background: #1d4ed8;
}

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-page {
  width: min(420px, calc(100% - 40px));
  margin: 0;
  padding: 0;
}

.login-panel h1 {
  margin: 0 0 8px;
}

.login-panel .subtitle {
  margin-top: 0;
}

.login-panel .error {
  margin-top: 0;
  margin-bottom: 4px;
}

.login-panel .btn.primary {
  margin-top: 4px;
  width: 100%;
}

.form button {
  font: inherit;
}

.btn.danger {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.row.actions.inline {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form input,
.form textarea,
.form select {
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font: inherit;
}

.form textarea {
  min-height: 180px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9rem;
}

.flash {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
}

.flash-success {
  background: #dcfce7;
  color: #166534;
}

.flash-error {
  background: #fee2e2;
  color: #991b1b;
}

.merge-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-new {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-conflict {
  background: #ffedd5;
  color: #c2410c;
}

.status-identical {
  background: #e5e7eb;
  color: #374151;
}

.status-duplicate {
  background: #f3e8ff;
  color: #6b21a8;
}

.merge-table td,
.merge-table th {
  vertical-align: top;
}

.merge-rule {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.muted {
  color: #6b7280;
  font-size: 0.9rem;
}

.merge-table select {
  min-width: 160px;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font: inherit;
  background: #ffffff;
}

.panel {
  padding: 24px;
  margin-bottom: 20px;
}

.filters {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.filters-nav-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.filters-nav {
  width: 100%;
  min-height: 44px;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
}

.filters-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
}

.filters-fields label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 160px;
  min-width: 0;
}

.filters-fields input,
.filters-fields button {
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font: inherit;
}

.filters-fields button {
  flex: 0 0 auto;
  width: auto;
  min-width: 120px;
  background: #2563eb;
  color: white;
  border-color: #2563eb;
  cursor: pointer;
  font-weight: 700;
}

.error {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #fee2e2;
  color: #991b1b;
}

.error-retrying {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.error-body {
  min-width: 0;
}

.error-retry-hint {
  margin-top: 6px;
  font-size: 0.9rem;
  opacity: 0.85;
}

.spinner {
  flex-shrink: 0;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 2px;
  border: 2px solid rgba(153, 27, 27, 0.25);
  border-top-color: #991b1b;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.card {
  padding: 22px;
}

.card span {
  display: block;
  color: #6b7280;
  margin-bottom: 10px;
}

.card strong {
  font-size: 28px;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.chart-wrap {
  position: relative;
  min-height: 320px;
}

.facts {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px 18px;
  margin: 0;
}

.facts dt {
  font-weight: 700;
}

.facts dd {
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
}

th {
  color: #6b7280;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}


.positive {
  color: #15803d;
}

.negative {
  color: #b91c1c;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: #f8fafc;
}

.clickable-row:focus {
  outline: 2px solid #93c5fd;
  outline-offset: -2px;
}

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-dialog {
  position: relative;
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  margin: 24px auto;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 20px 24px;
  border-bottom: 1px solid #e5e7eb;
}

.modal-subtitle {
  margin: 0;
  color: #6b7280;
}

.modal-close {
  border: 0;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  color: #6b7280;
}

.modal-body {
  padding: 0 24px 24px;
  overflow: auto;
  max-height: calc(100vh - 180px);
}

small {
  color: #6b7280;
}

@media (max-width: 720px) {
  .page {
    padding: 16px 12px 32px;
  }

  .hero,
  .panel,
  .card {
    padding: 18px 16px;
  }

  .hero {
    flex-direction: column;
  }

  .hero-right,
  .hero-actions {
    width: 100%;
    align-items: stretch;
  }

  .hero-actions {
    flex-direction: column;
  }

  .hero-actions .btn,
  .hero-actions form,
  .hero-actions button {
    width: 100%;
  }

  .badge {
    align-self: flex-start;
  }

  .filters-nav {
    white-space: normal;
    padding-left: 10px;
    padding-right: 10px;
    font-size: 0.95rem;
  }

  .filters-fields {
    flex-direction: column;
    align-items: stretch;
  }

  .filters-fields label {
    flex: none;
    width: 100%;
  }

  .filters-fields button {
    width: 100%;
    min-width: 0;
  }

  .two-column {
    grid-template-columns: 1fr;
  }

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

  .cards {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .card strong {
    font-size: 22px;
  }

  .chart-wrap {
    min-height: 260px;
  }

  .modal-dialog {
    width: calc(100vw - 16px);
    margin: 8px auto;
    max-height: calc(100vh - 16px);
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
