*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:        #1976d2;
  --primary-dark:   #0d47a1;
  --primary-soft:   #e3f2fd;
  --accent:         #43a047;
  --accent-dark:    #2e7d32;
  --bg:             #fafafa;
  --surface:        #ffffff;
  --border:         #e0e0e0;
  --border-light:   #f0f0f0;
  --text:           #212121;
  --text-secondary: #616161;
  --muted:          #9e9e9e;
  --active:         #2e7d32;
  --inactive:       #d32f2f;
  --warning:        #f57c00;
  --tag-asc:        #0d47a1;
  --tag-ai:         #6a1b9a;
  --tag-match:      #2e7d32;
  --radius:         6px;
  --shadow:         0 1px 4px rgba(0,0,0,0.08);
}

body {
  font-family: 'Roboto', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Header ── */
header {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.header-inner { display: flex; align-items: baseline; gap: 20px; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-mark { color: rgba(255,255,255,0.7); font-size: 18px; }
.logo-text { font-size: 17px; font-weight: 700; letter-spacing: 0.3px; }
.header-sub { font-size: 12px; color: rgba(255,255,255,0.6); }

/* ── Stats bar ── */
.stats-bar {
  background: var(--primary-dark);
  display: flex;
  gap: 0;
  padding: 0 24px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 28px;
  border-right: 1px solid rgba(255,255,255,0.1);
  min-width: 130px;
}
.stat-item:last-child { border-right: none; }
.stat-num {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}
.stat-label {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 1px;
}

/* ── Map Panel ── */
.map-panel {
  background: #0d1b2e;
  border-bottom: 2px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  height: 460px;
  min-height: 42px;
  overflow: hidden;
  transition: height 0.25s ease;
  user-select: none;
}
.map-panel.collapsed { height: 42px !important; transition: height 0.25s ease; }
.map-panel.resizing  { transition: none; }

.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  height: 42px;
  flex-shrink: 0;
  gap: 12px;
}
.map-left { display: flex; align-items: center; gap: 10px; }
.map-controls { display: flex; align-items: center; gap: 8px; }

.map-back-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.map-back-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }

.map-breadcrumb { font-size: 13px; color: rgba(255,255,255,0.5); }
.bc-item { color: rgba(255,255,255,0.5); }
.bc-item.bc-active { color: #fff; font-weight: 600; }
.bc-sep { color: rgba(255,255,255,0.3); margin: 0 2px; }
.bc-item[style*="cursor"] { transition: color 0.15s; }
.bc-item[style*="cursor"]:hover { color: #90caf9 !important; }
.bc-item.bc-link { cursor: pointer; transition: color 0.15s; }
.bc-item.bc-link:hover { color: #90caf9; }

/* Zoom buttons */
.map-zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 5px;
  padding: 2px;
}
.map-zoom-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 15px;
  line-height: 1;
  width: 26px;
  height: 24px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  padding: 0;
}
.map-zoom-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }

.map-collapse-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.5);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.map-collapse-btn:hover { color: #fff; border-color: rgba(255,255,255,0.3); }

.map-container {
  position: relative;
  background: #0d1b2e;
  flex: 1;
  overflow: hidden;
}
#mapSvg { width: 100%; height: 100%; display: block; }

/* Resize handle */
.map-resize-handle {
  height: 10px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.03);
  border-top: 1px solid rgba(255,255,255,0.07);
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.map-resize-handle:hover { background: rgba(255,255,255,0.08); }
.resize-grip {
  width: 36px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.18);
}
.map-panel.collapsed .map-resize-handle { display: none; }

.map-tooltip {
  position: fixed;
  background: rgba(13,27,46,0.96);
  border: 1px solid rgba(25,118,210,0.5);
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 9999;
  white-space: nowrap;
  line-height: 1.5;
}
.map-tooltip strong { color: #fff; }

/* ── Layout ── */
main {
  display: flex;
  gap: 0;
  min-height: calc(100vh - 110px);
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-group label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}
.filter-group input,
.filter-group select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.filter-group input:focus,
.filter-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
  background: #fff;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: var(--text) !important;
  cursor: pointer;
  font-weight: 500 !important;
}
.checkbox-label input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--primary); }
.btn-clear {
  margin-top: 4px;
  padding: 7px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-clear:hover { border-color: var(--primary); color: var(--primary); }

/* ── Content ── */
.content { flex: 1; padding: 20px 24px; overflow: hidden; }
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.result-count { font-size: 13px; color: var(--text-secondary); }
.per-page-wrap { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.per-page-wrap select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
}
table { width: 100%; border-collapse: collapse; }
thead { background: var(--primary); }
th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,0.08);
}
th:last-child { border-right: none; }
tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
  cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--primary-soft); }
tbody tr[data-valcre="active"]       { background: #f1f8e9; }
tbody tr[data-valcre="active"]:hover { background: #dcedc8; }
tbody tr[data-valcre="former"]       { background: #fafafa; }
tbody tr[data-valcre="former"]:hover { background: var(--primary-soft); }
td {
  padding: 9px 14px;
  font-size: 13px;
  vertical-align: middle;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.td-name { font-weight: 600; color: var(--primary-dark); }
.td-name:hover { text-decoration: underline; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-active   { background: #c8e6c9; color: #1b5e20; }
.badge-inactive { background: #ffcdd2; color: #b71c1c; }
.badge-asc      { background: #e3f2fd; color: #0d47a1; }
.badge-ai       { background: #ede0f7; color: #4a148c; }
.badge-both     { background: #e8f5e9; color: #1b5e20; }
.badge-match    { background: #c8e6c9; color: #2e7d32; font-size: 10px; }
.badge-nomatch  { background: #f5f5f5; color: #9e9e9e; font-size: 10px; }
.badge-client   { background: #e8f5e9; color: #1b5e20; font-size: 10px; }

.loading { text-align: center; padding: 40px; color: var(--muted); }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.page-btn {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
  font-family: inherit;
}
.page-btn:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-ellipsis { padding: 5px 6px; color: var(--muted); }

/* ── Side Panel ── */
.modal { position: fixed; inset: 0; z-index: 1000; pointer-events: none; }
.modal.hidden .modal-backdrop { opacity: 0; pointer-events: none; }
.modal.hidden .modal-box      { transform: translateX(100%); }
.modal:not(.hidden)           { pointer-events: auto; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(1px);
  opacity: 1;
  transition: opacity 0.25s ease;
}
.modal-box {
  position: absolute;
  top: 0;
  right: 0;
  height: 100vh;
  background: var(--surface);
  box-shadow: -8px 0 32px rgba(0,0,0,0.15);
  width: 560px;
  max-width: 96vw;
  overflow-y: auto;
  z-index: 1;
  transform: translateX(0);
  transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}
.modal-header h2 { font-size: 18px; color: var(--primary-dark); font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px 24px; }

.detail-section { margin-bottom: 20px; }
.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 20px;
}
.detail-field label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 2px;
}
.detail-field span { font-size: 13px; color: var(--text); }
.detail-field a {
  color: var(--primary);
  text-decoration: none;
  font-size: 13px;
}
.detail-field a:hover { text-decoration: underline; }
.detail-field.full { grid-column: 1 / -1; }
.detail-desig {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.desig-chip {
  padding: 2px 10px;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.disc-warning {
  background: #fff8e1;
  border: 1px solid #ffcc02;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12px;
  color: #e65100;
  margin-top: 8px;
}

/* ── Header actions ── */
header { justify-content: space-between; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.btn-header-dup {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.9);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.btn-header-dup:hover { background: rgba(255,255,255,0.22); color: #fff; }

/* ── Duplicates Panel ── */
.dup-panel {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1100;
  display: flex;
  flex-direction: column;
}
.dup-panel.hidden { display: none; }

.dup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.dup-title { display: flex; align-items: center; gap: 12px; font-size: 16px; font-weight: 600; }
.dup-badge {
  background: rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 2px 12px;
  font-size: 12px;
  font-weight: 500;
}
.dup-header-right { display: flex; align-items: center; gap: 8px; }
.btn-dup-merges {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.9);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-dup-merges:hover { background: rgba(255,255,255,0.22); }

.dup-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Left list */
.dup-list {
  width: 300px;
  min-width: 200px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
}
.dup-list-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.1s;
}
.dup-list-item:hover   { background: var(--primary-soft); }
.dup-list-item.selected { background: var(--primary-soft); border-left: 3px solid var(--primary); }
.dup-item-name { font-weight: 600; font-size: 13px; color: var(--text); }
.dup-item-meta { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.dup-loading   { text-align: center; padding: 32px 16px; color: var(--muted); font-size: 13px; }

/* Right detail */
.dup-detail {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}
.dup-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 200px;
  color: var(--muted);
  font-size: 14px;
}
.dup-placeholder-icon { font-size: 36px; opacity: 0.35; }

/* Side-by-side comparison */
.dup-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.dup-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.dup-card-header {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  background: var(--primary);
  color: #fff;
}
.dup-card-body  { padding: 14px; }
.dup-card-name  { font-size: 15px; font-weight: 600; margin-bottom: 10px; color: var(--primary-dark); }
.dup-card-row   { display: flex; align-items: baseline; gap: 6px; margin-bottom: 5px; font-size: 12px; }
.dup-card-label { color: var(--text-secondary); width: 62px; flex-shrink: 0; font-size: 11px; }
.dup-card-id    { font-size: 10px; color: var(--muted); margin-top: 8px; }

/* Action buttons */
.dup-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 4px 0 20px;
  flex-wrap: wrap;
}
.btn-keep {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 9px 18px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-keep:hover { background: var(--primary-dark); }
.btn-skip-pair {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 18px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-skip-pair:hover { background: var(--bg); border-color: #aaa; }

/* Merge history drawer */
.dup-merges-drawer {
  border-top: 2px solid var(--border);
  background: var(--surface);
  max-height: 220px;
  overflow-y: auto;
  flex-shrink: 0;
}
.dup-merges-drawer.hidden { display: none; }
.dup-merges-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.btn-text {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}
.btn-text:hover { text-decoration: underline; }
.merge-row {
  display: flex;
  align-items: center;
  padding: 7px 16px;
  border-bottom: 1px solid var(--border-light);
  gap: 10px;
  font-size: 12px;
}
.merge-row:last-child { border-bottom: none; }
.merge-names  { flex: 1; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.merge-kept   { font-weight: 600; color: var(--text); }
.merge-arrow  { color: var(--muted); }
.merge-gone   { color: var(--text-secondary); text-decoration: line-through; }
.merge-states { color: var(--muted); font-size: 11px; }
.btn-undo {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: inherit;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-undo:hover { background: #ffebee; border-color: #ef9a9a; color: #c62828; }
.btn-undo:disabled { opacity: 0.4; cursor: default; }

/* Dup pagination footer */
.dup-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}
