/* Self-hosted (no external CDN calls — this app runs on internal/offline
   networks) to match the delvorinsurance.com brand: Raleway for headings/
   wordmark, Open Sans for body text. */
@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/OpenSans-400.ttf") format("truetype");
}
@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/OpenSans-600.ttf") format("truetype");
}
@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/OpenSans-700.ttf") format("truetype");
}
@font-face {
  font-family: "Raleway";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/Raleway-400.ttf") format("truetype");
}
@font-face {
  font-family: "Raleway";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/Raleway-600.ttf") format("truetype");
}
@font-face {
  font-family: "Raleway";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/Raleway-700.ttf") format("truetype");
}

:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --border: #dde1e6;
  --text: #1a1d21;
  --text-muted: #5b6470;
  --text-faint: #8b93a0;
  /* Delvor Insurance brand palette (sampled from delvorinsurance.com):
     navy header/accent + orange highlight. */
  --accent: #005c99;
  --accent-soft: #e3edf4;
  --brand-orange: #e17a00;
  --danger: #b3261e;
  --danger-soft: #fbeae9;
  --ok: #1e7a4c;
  --ok-soft: #e7f5ee;
  --warn: #9a6300;
  --warn-soft: #fbf2e0;
  --radius: 6px;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "Open Sans", -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --heading: "Raleway", var(--sans);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  /* Always reserve the scrollbar's width, whether or not the page actually
     needs to scroll — otherwise a short result set (e.g. one country with
     few matches) removes the scrollbar, frees ~15-17px, and the whole page
     (including the fixed-width table) grows to fill it, then shrinks back
     the moment a longer result set needs scrolling again. */
  overflow-y: scroll;
  scrollbar-gutter: stable;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Nav */
header.topnav {
  background: var(--accent);
  padding: 0 24px;
}
.topnav-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 56px;
}
.brand {
  font-family: var(--heading);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: #ffffff;
}
.brand:hover { text-decoration: none; }
nav.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}
nav.nav-links a {
  color: rgba(255, 255, 255, 0.75);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
}
nav.nav-links a:hover { background: rgba(255, 255, 255, 0.1); color: #ffffff; text-decoration: none; }
nav.nav-links a.active { color: #ffffff; background: transparent; border-bottom-color: var(--brand-orange); }
.nav-group { display: flex; align-items: center; gap: 2px; }
.logout-btn {
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: transparent;
  color: #ffffff;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--sans);
  cursor: pointer;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.12); border-color: #ffffff; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

h1 {
  font-family: var(--heading);
  font-weight: 600;
  font-size: 23px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
h2 {
  font-size: 15px;
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.page-lede {
  color: var(--text-muted);
  margin: 0 0 20px;
}

/* Toolbar (search/filters) */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}
.toolbar input[type="search"],
.toolbar select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13.5px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
}
.toolbar input[type="search"] { min-width: 220px; flex: 1 1 220px; }
.toolbar .result-count {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  /* Fixed width so "16,735 entities" vs "3 entities" doesn't change this
     element's box size — the search input next to it is flex-grow, so any
     size change here gets absorbed as extra input width, which shifts the
     filter buttons that follow it in the row. */
  min-width: 110px;
  text-align: right;
  flex: 0 0 auto;
}

/* Checkbox filter dropdown */
.filter-dropdown { position: relative; }
.filter-dropdown-toggle {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13.5px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Fixed width so the label changing ("All countries" -> "countries: N
     selected") never resizes the button — that resize was reflowing the
     whole flex toolbar (shrinking the search input) and shifting everything
     next to it on every checkbox click. */
  width: 160px;
  text-align: left;
  flex: 0 0 auto;
}
.filter-dropdown-toggle:hover { border-color: var(--accent); }
.filter-dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 10;
  min-width: 200px;
  max-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  padding: 8px;
}
.filter-dropdown-actions {
  display: flex;
  gap: 6px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.filter-dropdown-actions button {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--text);
}
.filter-dropdown-actions button:hover { background: var(--accent-soft); border-color: var(--accent); }
.filter-dropdown-options {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
}
.filter-checkbox:hover { background: var(--accent-soft); }
.filter-checkbox input { cursor: pointer; }

/* Tables */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
}
.table-wrap.is-loading {
  opacity: 0.5;
  pointer-events: none;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--accent-soft); }
tbody tr.clickable { cursor: pointer; }
td.num, th.num { font-variant-numeric: tabular-nums; }

/* Some source fields (e.g. license permissions) occasionally contain a huge
   blob of text or embedded JSON — without this, one such row would blow out
   to hundreds of lines tall and dominate the whole table. */
.cell-clamp {
  max-height: 140px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Fixed column widths so the table doesn't resize itself based on whatever
   data the current filter/page happens to contain. Long content wraps
   (word-break) rather than being clipped, so nothing is hidden. */
table.fixed-layout {
  table-layout: fixed;
}
table.fixed-layout td {
  word-wrap: break-word;
  overflow-wrap: break-word;
}
table.fixed-layout .col-name { width: 32%; }
table.fixed-layout .col-country { width: 26%; }
table.fixed-layout .col-status { width: 12%; }
table.fixed-layout .col-confidence { width: 10%; }
table.fixed-layout .col-lei { width: 20%; }

/* Insurer entities table has an extra Type column, so it gets its own set
   of widths rather than reusing (and skewing) the broker table's above. */
table.fixed-layout .col-i-name { width: 28%; }
table.fixed-layout .col-i-country { width: 22%; }
table.fixed-layout .col-i-type { width: 14%; }
table.fixed-layout .col-i-status { width: 10%; }
table.fixed-layout .col-i-confidence { width: 8%; }
table.fixed-layout .col-i-lei { width: 18%; }
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-active, .badge-current { background: var(--ok-soft); color: var(--ok); }
.badge-candidate, .badge-unverified, .badge-discovered { background: var(--warn-soft); color: var(--warn); }
.badge-inactive, .badge-rejected, .badge-conflicting, .badge-historical { background: var(--danger-soft); color: var(--danger); }
.badge-merged, .badge-archived { background: #eceef1; color: var(--text-muted); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 13.5px;
}
.pagination button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.pagination button:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.pagination button:disabled { color: var(--text-faint); cursor: not-allowed; }
.pagination .page-indicator { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Detail pages */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.detail-title { font-family: var(--heading); font-weight: 600; font-size: 23px; margin: 0 0 4px; letter-spacing: -0.01em; }
.detail-subtitle { color: var(--text-muted); font-family: var(--mono); font-size: 13px; }
.back-link { display: inline-block; margin-bottom: 12px; font-size: 13px; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 28px;
}
.field-grid dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin: 0 0 3px;
}
.field-grid dd {
  margin: 0;
  font-size: 13.5px;
  word-break: break-word;
}
.field-grid dd.empty { color: var(--text-faint); }

section.detail-block { margin-bottom: 28px; }
section.detail-block h2 { display: flex; align-items: baseline; gap: 8px; }
section.detail-block h2 .count {
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-faint);
  font-size: 12px;
}

.loading, .error-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}
.error-state { color: var(--danger); }

/* Login page */
.login-body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
}
.login-card {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  padding: 32px 32px 28px;
  width: 100%;
  max-width: 340px;
}
.login-brand {
  font-family: var(--heading);
  font-weight: 600;
  font-size: 20px;
  color: var(--accent);
  margin-bottom: 4px;
}
.login-title {
  font-family: var(--heading);
  font-weight: 600;
  font-size: 18px;
  margin: 0 0 20px;
  color: var(--text);
}
.login-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin: 14px 0 4px;
}
.login-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--sans);
  color: var(--text);
  background: var(--surface);
}
.login-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-submit {
  width: 100%;
  margin-top: 20px;
  padding: 10px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
}
.login-submit:hover { opacity: 0.92; }
.login-error {
  margin-top: 14px;
  padding: 8px 10px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius);
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
