:root {
  --bg: #f4f6fb;
  --bg-accent: #eef2ff;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #eef2ff;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --ok-border: #a7f3d0;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --err: #b91c1c;
  --err-bg: #fef2f2;
  --err-border: #fecaca;
  --info: #1d4ed8;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 30px -12px rgba(15, 23, 42, 0.18);
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 10% -10%, #e0e7ff 0%, transparent 60%),
    radial-gradient(900px 400px at 100% 0%, #fae8ff 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--primary-2); text-decoration: none; }

h1 { font-size: 28px; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 18px; font-weight: 750; }
h2 { font-size: 19px; line-height: 1.3; letter-spacing: -0.01em; margin: 32px 0 14px; font-weight: 700; }
h3 { font-size: 16px; margin: 20px 0 10px; }
.muted { color: var(--muted); font-weight: 450; }

/* ---------- header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 26px;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { color: var(--text); }
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px -6px rgba(79, 70, 229, 0.6);
  color: #fff;
  flex: none;
}
.brand-mark svg { width: 18px; height: 18px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text .brand-sub {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 3px;
}
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.topbar nav a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 550;
  padding: 7px 11px;
  border-radius: 9px;
  transition: background .15s ease, color .15s ease;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.userbox { margin-left: auto; display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 14px; }
.userbox .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #eef2ff, #e9d5ff);
  color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px;
}

/* ---------- layout ---------- */
.container { max-width: 1440px; margin: 0 auto; padding: 28px 24px 72px; }
.breadcrumb { margin: 0 0 10px; font-size: 14px; }

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 14px;
  margin: 18px 0 10px;
}
.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
}
.stat:nth-child(2)::before { background: linear-gradient(180deg, #0ea5e9, #2563eb); }
.stat:nth-child(3)::before { background: linear-gradient(180deg, #f59e0b, #d97706); }
.stat:nth-child(4)::before { background: linear-gradient(180deg, #10b981, #047857); }
.stat:nth-child(5)::before { background: linear-gradient(180deg, #ec4899, #be185d); }
.stat:nth-child(6)::before { background: linear-gradient(180deg, #8b5cf6, #6d28d9); }
.stat:nth-child(7)::before { background: linear-gradient(180deg, #14b8a6, #0f766e); }
.stat-value {
  display: block;
  font-size: 26px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-label { display: block; color: var(--muted); font-size: 12.5px; margin-top: 6px; font-weight: 550; }

/* ---------- tables ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 16px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  position: sticky;
  top: 0;
}
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.thumb-cell { width: 58px; padding: 8px 12px; }
.thumb {
  width: 42px; height: 42px; object-fit: cover; border-radius: 9px;
  border: 1px solid var(--border); display: block; background: var(--surface-2);
}
.thumb.placeholder {
  display: flex; align-items: center; justify-content: center;
  color: #94a3b8; font-size: 12px;
}
.unread-row { background: #f5f7ff; }
.unread-row:hover { background: #eef2ff; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.4;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.badge.off { background: var(--err-bg); border-color: var(--err-border); color: var(--err); }
.badge.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }
.badge.info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }
.pill {
  display: inline-block;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  vertical-align: middle;
}

/* ---------- filters / forms ---------- */
.filters {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin: 0 0 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 140px; }
.field.grow { flex: 1 1 260px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check label { font-size: 13px; color: var(--text); }
.field.actions { flex-direction: row; gap: 8px; }

input, select, textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  min-width: 0;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover, select:hover { border-color: #94a3b8; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, transform .12s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--surface-2); border-color: #94a3b8; color: var(--text); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px -8px rgba(79, 70, 229, 0.65);
}
.btn.primary:hover {
  background: linear-gradient(135deg, #4338ca, #6d28d9);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 12px 22px -10px rgba(79, 70, 229, 0.7);
}
.linklike {
  background: none; border: none; color: var(--primary); cursor: pointer;
  padding: 0; font: inherit; font-weight: 600;
}
.linklike:hover { color: var(--primary-2); text-decoration: underline; }

/* ---------- cards / messages ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  max-width: 860px;
}
.card form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

.messages { margin-bottom: 18px; display: flex; flex-direction: column; gap: 10px; }
.message {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.message.success { background: var(--ok-bg); border-color: var(--ok-border); color: #065f46; }
.message.warning { background: var(--warn-bg); border-color: var(--warn-border); color: #92400e; }
.message.error { background: var(--err-bg); border-color: var(--err-border); color: #991b1b; }

/* ---------- pagination ---------- */
.pagination { display: flex; gap: 14px; align-items: center; margin-top: 18px; color: var(--muted); font-size: 14px; }
.pagination a {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.pagination a:hover { background: var(--surface-2); border-color: var(--border-strong); }

/* ---------- login ---------- */
.login-card {
  max-width: 420px;
  margin: 70px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 30px 60px -30px rgba(15, 23, 42, 0.35);
}
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card form { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.login-card label { font-size: 12.5px; color: var(--muted); font-weight: 650; margin-top: 8px; }
.login-card .btn { margin-top: 18px; width: 100%; }

/* ---------- misc ---------- */
.mono { font-variant-numeric: tabular-nums; font-family: "JetBrains Mono", Consolas, monospace; font-size: 12.5px; }
.small { font-size: 12.5px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 18px; }
code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 12.5px;
  color: #334155;
}
.footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  padding: 20px 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.6);
}

/* ---------- matching ---------- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--muted); font-weight: 600;
  font-size: 13.5px; box-shadow: var(--shadow-sm);
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary); }
.match-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 16px; }
.match-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 16px;
}
.match-head { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 10px; flex-wrap: wrap; }
.match-pair { display: grid; grid-template-columns: 1fr 26px 1fr; gap: 8px; align-items: start; }
.match-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.match-photo {
  width: 100%; height: 110px; max-height: 110px; object-fit: contain;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px;
}
.match-photo-lg { height: 240px; max-height: 240px; }
.match-side img { max-width: 100%; }
.match-name { font-weight: 650; font-size: 13.5px; line-height: 1.35; }
.match-arrow { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 18px; padding-top: 54px; }
.reasons { list-style: none; margin: 12px 0 0; padding: 0; font-size: 12.5px; color: var(--muted); }
.reasons li { display: flex; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--border); }
.reason-weight { min-width: 28px; text-align: right; font-weight: 700; color: var(--primary); }
.match-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- vision ---------- */
.photo-zoom {
  align-self: flex-start; margin-top: 4px; padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--primary); font: inherit; font-size: 12px; font-weight: 650; cursor: pointer;
}
.photo-zoom:hover { background: var(--primary-soft); border-color: #c7d2fe; }
.vision-card { max-width: none; }
.vision-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px; margin: 14px 0 18px;
}
.vision-feature {
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  background: var(--surface-2);
}
.vision-head {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 13px; font-weight: 650; margin-bottom: 7px;
}
.vision-bar {
  height: 7px; border-radius: 999px; background: #e2e8f0; overflow: hidden;
}
.vision-bar span {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #4f46e5, #7c3aed);
}
.vision-bar.empty { background: repeating-linear-gradient(90deg, #e2e8f0 0 6px, #eef2f7 6px 12px); }
.vision-feature .small { margin: 7px 0 0; line-height: 1.35; }
.vision-conflicts { margin: 8px 0 16px; padding-left: 18px; color: #92400e; font-size: 13px; }
.vision-explain { margin: 8px 0 16px; padding-left: 18px; color: #065f46; font-size: 13px; }
.photo-overlay {
  position: fixed; inset: 0; z-index: 1000; display: flex;
  align-items: center; justify-content: center; padding: 32px;
  background: rgba(15, 23, 42, 0.78); backdrop-filter: blur(3px);
}
.photo-overlay[hidden] { display: none; }
.photo-overlay img {
  max-width: min(1100px, 92vw); max-height: 86vh; border-radius: 14px;
  background: #fff; box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.6);
}
.photo-overlay-close {
  position: fixed; top: 18px; right: 22px; width: 42px; height: 42px;
  border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(15, 23, 42, 0.6); color: #fff; font-size: 24px; line-height: 1;
  cursor: pointer;
}
body.overlay-open { overflow: hidden; }

/* ---------- scanner ---------- */
.scanner-thumbs {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.scanner-thumb {
  border: 1px solid var(--border); border-radius: 12px; padding: 8px;
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.scanner-thumb img {
  width: 100%; height: 130px; object-fit: contain; background: var(--surface-2);
  border-radius: 8px;
}
.prov {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11px; color: var(--muted); font-weight: 650;
}
.preline { white-space: pre-line; line-height: 1.55; }
@media (max-width: 640px) {
  .scanner-thumbs { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .vision-grid { grid-template-columns: 1fr; }
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .topbar-inner { gap: 12px; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .userbox { margin-left: auto; }
  .container { padding: 20px 16px 60px; }
  h1 { font-size: 23px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .stat-value { font-size: 22px; }
}
