@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ui-page: #080d17;
  --ui-surface: #111927;
  --ui-surface-raised: #151f31;
  --ui-control: #0c1422;
  --ui-text: #e8f0ff;
  --ui-muted: #a8b6cc;
  --ui-subtle: #7f8da5;
  --ui-line: #2b3a52;
  --ui-line-strong: #40516c;
}
body {
  margin: 0;
  color: #0f172a;
  background: #f1f5f9;
  font-family: Arial, Helvetica, sans-serif;
}
:root[data-theme="dark"] body {
  color: var(--ui-text);
  background: var(--ui-page);
}
:root[data-theme="dark"] .registry-app,
:root[data-theme="dark"] .workspace,
:root[data-theme="dark"] .sidebar,
:root[data-theme="dark"] .topbar,
:root[data-theme="dark"] .record-detail,
:root[data-theme="dark"] .profile-dialog,
:root[data-theme="dark"] .export-dialog {
  background: var(--ui-surface) !important;
  color: var(--ui-text) !important;
  border-color: var(--ui-line) !important;
}
:root[data-theme="dark"] .bg-white,
:root[data-theme="dark"] .bg-slate-50,
:root[data-theme="dark"] .bg-slate-100,
:root[data-theme="dark"] .bg-slate-200,
:root[data-theme="dark"] .registry-grid thead,
:root[data-theme="dark"] .registry-grid th,
:root[data-theme="dark"] .registry-grid td,
:root[data-theme="dark"] .detail-section,
:root[data-theme="dark"] .table-footer {
  background: var(--ui-surface-raised) !important;
  border-color: var(--ui-line) !important;
}
:root[data-theme="dark"] .text-slate-900,
:root[data-theme="dark"] .text-slate-700 {
  color: var(--ui-text) !important;
}
:root[data-theme="dark"] .text-slate-600,
:root[data-theme="dark"] .text-slate-500 {
  color: var(--ui-muted) !important;
}
:root[data-theme="dark"] .text-slate-400 {
  color: var(--ui-subtle) !important;
}
:root[data-theme="dark"] .text-slate-50 {
  color: #f8fbff !important;
}
:root[data-theme="dark"] .muted {
  color: var(--ui-muted) !important;
}
:root[data-theme="dark"] .border-slate-100,
:root[data-theme="dark"] .border-slate-200,
:root[data-theme="dark"] .border-slate-300,
:root[data-theme="dark"] .border-slate-400 {
  border-color: var(--ui-line) !important;
}
:root[data-theme="dark"] .bg-blue-50,
:root[data-theme="dark"] .bg-sky-50,
:root[data-theme="dark"] .bg-amber-50 {
  background-color: #10243a !important;
}
:root[data-theme="dark"] .border-blue-200,
:root[data-theme="dark"] .border-blue-300,
:root[data-theme="dark"] .border-sky-200,
:root[data-theme="dark"] .border-amber-200 {
  border-color: #31577e !important;
}
:root[data-theme="dark"] .text-blue-800,
:root[data-theme="dark"] .text-sky-700,
:root[data-theme="dark"] .text-sky-950 {
  color: #b9dcff !important;
}
:root[data-theme="dark"] .text-amber-700,
:root[data-theme="dark"] .text-amber-900,
:root[data-theme="dark"] .text-amber-950 {
  color: #fcd34d !important;
}
:root[data-theme="dark"] .text-red-700,
:root[data-theme="dark"] .text-red-800 {
  color: #fda4af !important;
}
:root[data-theme="dark"] .text-emerald-700 {
  color: #86efac !important;
}
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  color: var(--ui-text);
  background: var(--ui-control);
  border-color: var(--ui-line-strong);
}
:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder {
  color: var(--ui-subtle);
}
:root[data-theme="dark"] button.bg-white,
:root[data-theme="dark"] button.bg-slate-100,
:root[data-theme="dark"] button.bg-slate-200 {
  color: var(--ui-text) !important;
  background-color: var(--ui-surface-raised) !important;
  border-color: var(--ui-line-strong) !important;
}
:root[data-theme="dark"] button.bg-slate-900 {
  color: #fff !important;
  background-color: #2563eb !important;
  border-color: #2563eb !important;
}
.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border: 1px solid currentColor;
  border-radius: 7px;
  color: #475569;
}
.theme-switch select {
  border: 0;
  background: transparent;
  font: inherit;
  color: inherit;
}
:root[data-theme="dark"] .theme-switch {
  color: var(--ui-muted);
  border-color: var(--ui-line-strong);
  background: var(--ui-surface);
}
:root[data-theme="dark"] .theme-switch select {
  color: inherit;
  background: transparent;
}
@media (prefers-reduced-motion: no-preference) {
  .registry-app, .workspace, .sidebar, .topbar, .record-detail, button, a {
    transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  }
  button:hover, a:hover {
    box-shadow: 0 0 14px rgba(37, 99, 235, 0.2);
  }
}
::selection {
  background: #cbd5e1;
  color: #0f172a;
}
:root[data-theme="dark"] ::selection {
  background: #315b96;
  color: #fff;
}
button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}
input,
select {
  caret-color: #0f172a;
}
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  caret-color: #93c5fd;
}
:focus-visible {
  outline: 2px solid #334155;
  outline-offset: 3px;
}
:root[data-theme="dark"] :focus-visible {
  outline-color: #75a8ff;
}
input[type="checkbox"],
input[type="radio"] {
  accent-color: #0f172a;
}
:root[data-theme="dark"] input[type="checkbox"],
:root[data-theme="dark"] input[type="radio"] {
  accent-color: #4d8dff;
}
button {
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
}
.profile-dialog {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(620px, 100%);
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: #fff;
  color: #0f172a;
  box-shadow: -12px 0 36px rgba(15, 23, 42, 0.16);
}
.export-dialog {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100dvh - 40px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: #fff;
  color: #0f172a;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
}
dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}
.registry-table {
  max-height: max(280px, calc(100dvh - 385px));
  overflow: auto;
  scrollbar-color: #94a3b8 #f1f5f9;
}
.registry-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
}
.registry-table table {
  min-width: 1080px;
  table-layout: fixed;
}
.registry-table th:nth-child(2) {
  width: 260px;
}
.registry-table th:last-child {
  width: 160px;
}
.person-identity {
  min-width: 220px;
}
.intersection-table {
  position: relative;
  max-height: 65dvh;
  overflow: auto;
  scrollbar-color: #94a3b8 #f1f5f9;
}
.intersection-table table {
  border-collapse: separate;
  border-spacing: 0;
}
.intersection-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
}
.intersection-table .combination-heading {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 220px;
  min-width: 180px;
  max-width: 260px;
  background: #fff;
}
.intersection-table tbody > tr + tr > * {
  border-top: 1px solid #e2e8f0;
}
.intersection-table thead .combination-heading {
  background: #f8fafc;
}
.dialog-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
}
:root[data-theme="dark"] .dialog-heading {
  background: var(--ui-surface-raised);
  color: var(--ui-text);
  border-color: var(--ui-line) !important;
}
:root[data-theme="dark"] .dialog-heading h1,
:root[data-theme="dark"] .dialog-heading h2,
:root[data-theme="dark"] .dialog-heading h3 {
  color: var(--ui-text);
}
:root[data-theme="dark"] .dialog-heading button {
  color: var(--ui-text) !important;
  background: var(--ui-control) !important;
  border-color: var(--ui-line-strong) !important;
}
:root[data-theme="dark"] .dialog-heading button:hover {
  background: #1b2a42 !important;
  border-color: #75a8ff !important;
}
.registry-table th:first-child,
.registry-table td:first-child {
  position: sticky;
  left: 0;
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  z-index: 2;
  background: #fff;
}
.registry-table th:nth-child(2),
.registry-table td:nth-child(2) {
  position: sticky;
  left: 40px;
  z-index: 2;
  background: #fff;
}
.registry-table thead {
  z-index: 3;
}
.registry-table thead th:first-child,
.registry-table thead th:nth-child(2) {
  background: #f8fafc;
}
@media (max-width: 640px) {
  .person-identity {
    min-width: 170px;
    max-width: 170px;
  }
  .registry-table table {
    min-width: 928px;
  }
  .registry-table th:nth-child(2) {
    width: 194px;
  }
  .registry-table th:last-child {
    width: 124px;
    white-space: normal;
  }
}
@media (pointer: coarse) {
  button,
  nav a {
    min-height: 44px;
  }
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
  }
}
@media (max-width: 640px) {
  .registry-table {
    max-height: 480px;
  }
}
@media (prefers-reduced-motion: no-preference) {
  dialog[open] {
    animation: reveal-panel 180ms ease-out;
  }
  @keyframes reveal-panel {
    from {
      transform: translateY(6px);
      opacity: 0.85;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
}

.source-table {
  position: relative;
  overflow: auto;
  max-height: 480px;
  scrollbar-color: #94a3b8 #f1f5f9;
}
.source-table table {
  border-collapse: separate;
  border-spacing: 0;
}
.source-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
}
.source-table th:first-child {
  position: sticky;
  left: 0;
  min-width: 160px;
  max-width: 220px;
  background: #fff;
  z-index: 1;
  overflow-wrap: anywhere;
}
.source-table thead th:first-child {
  background: #f8fafc;
}
.source-table tbody > tr + tr > * {
  border-top: 1px solid #e2e8f0;
}
