/* Texas Physicians Marketing DB by Resolon.
   Light instrument on Resolon's brand system: warm archival paper ground,
   graphite ink, petrol enamel for everything interactive, amber reserved for
   the one verdict moment (the 3+-corroborated stat). Newsreader carries the
   product title; Schibsted Grotesk does the work; Spline Sans Mono speaks
   only where data must align. Self-hosted fonts, no frameworks, no CDN. */

/* ---------- type (vendored from the Resolon brand, OFL) ---------- */
@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('/static/fonts/newsreader-latin-opsz-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Schibsted Grotesk';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('/static/fonts/schibsted-grotesk-latin-wght-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Spline Sans Mono';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('/static/fonts/spline-sans-mono-latin-wght-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Resolon system: paper / graphite / petrol, amber for verdicts only */
  --paper: #f8f5ee;
  --card: #fdfcf9;
  --ink: #333a45;
  --ink-2: #5c6675;
  --ink-3: #7c8595;
  --line: #e7e1d2;
  --line-strong: #b9b2a0;
  --petrol: #1e606f;
  --petrol-strong: #17505d;
  --petrol-tint: #e2ecee;
  --ring: #2f7f97;
  --amber: #8a6209;
  --amber-bg: #f6ecd4;
  --amber-line: #d9b45e;
  --oxide: #9c4a33;
  --oxide-bg: #f1e5dd;
  --err: #a03a22;

  --sans: 'Schibsted Grotesk', system-ui, 'Segoe UI', Helvetica, sans-serif;
  --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --mono: 'Spline Sans Mono', ui-monospace, Consolas, monospace;

  --topbar-h: 58px;
  --filterbar-h: 54px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 13.5px/1.5 var(--sans);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; gap: 22px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.brand .aperture-mark { display: block; color: var(--ink); }
.brand-text { display: flex; flex-direction: column; line-height: 1.12; }
.brand-title {
  font-family: var(--serif);
  font-size: 19px; font-weight: 560; letter-spacing: -0.012em;
  font-optical-sizing: auto;
}
.brand-by {
  font-size: 10.5px; color: var(--ink-2); letter-spacing: 0.02em;
}
.brand-by .wordmark {
  display: inline-flex; align-items: baseline;
  font-weight: 720; letter-spacing: -0.024em; color: var(--ink);
}
.brand-by .aperture-o {
  display: inline-flex; height: 0.92em; width: 0.92em;
  transform: translateY(0.085em); margin: 0 0.008em;
}
.brand-by .aperture-o svg { height: 100%; width: 100%; overflow: visible; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 12px; color: var(--ink-2); white-space: nowrap;
  font-size: 12px;
}
.chip b {
  color: var(--ink);
  font-family: var(--mono); font-weight: 600; font-size: 13px;
}
/* the verdict stat — the one amber moment on the page */
.chip-green { background: var(--amber-bg); border-color: var(--amber-line); color: var(--amber); }
.chip-green b { color: var(--amber); }

.userbox { margin-left: auto; display: flex; gap: 10px; align-items: center; color: var(--ink-2); font-size: 12.5px; }

/* ---------- controls ---------- */
.btn {
  background: var(--card); border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 5px 13px; cursor: pointer; color: var(--ink);
  transition: border-color .12s, background .12s;
}
.btn:hover { border-color: var(--petrol); color: var(--petrol-strong); }
.btn-accent {
  background: var(--petrol); border-color: var(--petrol); color: #fdfcf9; font-weight: 600;
}
.btn-accent:hover { background: var(--petrol-strong); border-color: var(--petrol-strong); color: #fdfcf9; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--line-strong); }
.btn:disabled { opacity: .4; cursor: default; }

input, select {
  background: var(--card); border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 5px 10px; min-width: 0; color: var(--ink);
}
input::placeholder { color: var(--ink-3); }
input:focus, select:focus { outline: none; border-color: var(--petrol); box-shadow: 0 0 0 3px var(--petrol-tint); }

.filterbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  min-height: var(--filterbar-h);
  padding: 9px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky; top: var(--topbar-h); z-index: 19;
}
.filterbar input:not([type="checkbox"]) { width: 132px; }
#f-q { width: 190px; }
.check { display: flex; gap: 6px; align-items: center; color: var(--ink-2); white-space: nowrap; }
.check input { accent-color: var(--petrol); }
.spacer { flex: 1; }

/* ---------- results table ---------- */
.results { padding: 0 20px 70px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 9px 10px;
  color: var(--ink-2); font-weight: 600;
  text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--line-strong);
  position: sticky; top: calc(var(--topbar-h) + var(--filterbar-h)); background: var(--paper); z-index: 10;
}
tbody td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody td.wrap { white-space: normal; }
/* data columns speak mono: ZIP, phone, industry $, completeness, tenure */
tbody td:nth-child(6), tbody td:nth-child(7),
tbody td:nth-child(9), tbody td:nth-child(10), tbody td:nth-child(11) {
  font-family: var(--mono); font-size: 12.5px;
}
tbody td:first-child { font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--card); box-shadow: inset 2.5px 0 0 var(--petrol); }
.muted { color: var(--ink-3); }
.empty { padding: 42px; text-align: center; color: var(--ink-2); }

/* address-confidence badge: weight ramp — hollow oxide, tinted petrol, solid petrol */
.badge {
  display: inline-block; min-width: 24px; text-align: center;
  padding: 1.5px 7px; border-radius: 5px;
  font-family: var(--mono); font-weight: 600; font-size: 12px;
}
.badge-red { background: var(--oxide-bg); color: var(--oxide); border: 1px solid transparent; }
.badge-yellow { background: var(--petrol-tint); color: var(--petrol-strong); border: 1px solid transparent; }
.badge-green { background: var(--petrol); color: #fdfcf9; border: 1px solid var(--petrol); }
sup.enum { color: var(--amber); font-weight: 700; }

.tablefoot {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 0; color: var(--ink-2);
}
.legend { font-size: 12px; color: var(--ink-3); }
#page-info { font-family: var(--mono); font-size: 12px; }

/* ---------- detail drawer (corroboration view) ---------- */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(51, 58, 69, .32); z-index: 30;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 92vw);
  background: var(--card); border-left: 1px solid var(--line-strong); z-index: 31;
  display: flex; flex-direction: column;
  box-shadow: -18px 0 40px rgba(51, 58, 69, .10);
}
.hidden { display: none; }
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.drawer-head h2 {
  margin: 0; font-family: var(--serif); font-size: 21px; font-weight: 560;
  letter-spacing: -0.01em;
}
.drawer-head .muted { font-family: var(--mono); font-size: 11.5px; }
.drawer-body { overflow-y: auto; padding: 14px 20px; }
.drawer h3 {
  margin: 22px 0 8px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--petrol-strong); font-weight: 700;
}
.drawer h3:first-child { margin-top: 4px; }

.fieldrow {
  display: grid; grid-template-columns: 175px 1fr auto; gap: 8px;
  padding: 5px 0; border-bottom: 1px solid var(--line); align-items: baseline;
}
.fieldrow .fname { color: var(--ink-2); font-size: 12px; }
.fieldrow .fval { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }

.pill {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  border-radius: 999px; padding: 1px 9px; white-space: nowrap;
}
.pill-red { background: var(--oxide-bg); color: var(--oxide); border: 1px solid transparent; }
.pill-yellow { background: var(--petrol-tint); color: var(--petrol-strong); border: 1px solid transparent; }
.pill-green { background: var(--petrol); color: #fdfcf9; border: 1px solid var(--petrol); }
.pill-none { background: var(--paper); color: var(--ink-3); border: 1px solid var(--line); }

details.sources { grid-column: 1 / -1; margin: 2px 0 4px; }
details.sources summary {
  cursor: pointer; color: var(--petrol); font-size: 11.5px; user-select: none;
}
details.sources summary:hover { color: var(--petrol-strong); text-decoration: underline; }
details.sources[open] summary { color: var(--ink-3); }
.obs-list { margin: 4px 0 4px 14px; padding: 0; list-style: none; }
.obs-list li {
  font-family: var(--mono); font-size: 11.5px; padding: 2px 0;
  display: flex; gap: 10px; align-items: baseline;
}
.obs-val { overflow-wrap: anywhere; }
.obs-src { color: var(--petrol); white-space: nowrap; }
.obs-date { color: var(--ink-3); white-space: nowrap; }
.loc-card {
  border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
  padding: 10px 12px; margin-bottom: 8px; font-family: var(--mono); font-size: 12.5px;
}
.loc-card .tag {
  color: var(--ink-2); font-family: var(--sans); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.08em;
}

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--paper); }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 36px 40px 32px; display: flex; flex-direction: column; gap: 14px; width: min(392px, 92vw);
  box-shadow: 0 14px 44px rgba(51, 58, 69, .08);
  text-align: left;
}
.login-mark { display: flex; justify-content: center; margin-bottom: 2px; color: var(--ink); }
.login-card h1 {
  margin: 0; font-family: var(--serif); font-size: 23px; font-weight: 560;
  letter-spacing: -0.012em; color: var(--ink); text-align: center; line-height: 1.2;
}
.login-sub {
  margin: -6px 0 8px; text-align: center; font-size: 11.5px; color: var(--ink-2);
}
.login-sub .wordmark { font-weight: 720; letter-spacing: -0.02em; color: var(--ink); }
.login-card label { display: flex; flex-direction: column; gap: 5px; color: var(--ink-2); font-size: 12.5px; }
.login-card input { padding: 8px 10px; }
.login-card button {
  background: var(--petrol); color: #fdfcf9; font-weight: 600;
  border: none; border-radius: 6px; padding: 10px; cursor: pointer; margin-top: 4px;
  transition: background .12s;
}
.login-card button:hover { background: var(--petrol-strong); }
.login-err { color: var(--err); min-height: 1em; margin: 0; font-size: 12.5px; text-align: center; }

/* one-time blade settle on the login mark — the brand's single motion moment */
@media (prefers-reduced-motion: no-preference) {
  .login-mark svg g { animation: blade-settle .22s ease-out both; transform-origin: 32px 32px; }
  @keyframes blade-settle { from { transform: rotate(-8deg); } to { transform: rotate(0deg); } }
}

/* ==================== responsive layer (≤1000px) ====================
   Desktop (>1000px) is untouched above this line. On small screens the page
   becomes an app shell: body is a 100dvh flex column (topbar → filters →
   results), the table scrolls inside .results on both axes, and the thead
   sticks at top:0 of that scroll container — no px-var offsets to drift.
   The filterbar collapses behind a native <details class="filters"> toggle
   (see index.html); it is display:none on desktop, so nothing changes there. */

details.filters { display: none; }

@media (max-width: 1000px) {
  html, body { height: 100%; }
  body {
    height: 100vh;   /* fallback */
    height: 100dvh;  /* tracks mobile browser chrome */
    display: flex; flex-direction: column;
  }

  /* --- topbar: brand + userbox on row 1, chips scroll on row 2 --- */
  .topbar {
    position: static;             /* always visible via the app shell instead */
    height: auto; flex: none;
    flex-wrap: wrap; gap: 10px; row-gap: 0;
    padding: 9px 14px 0;
  }
  .brand { min-width: 0; flex: 1 1 0; }  /* shrink+ellipsize so userbox keeps row 1 */
  .brand-text { min-width: 0; }
  .brand-title { overflow: hidden; text-overflow: ellipsis; }
  .userbox { flex: none; }
  #user-email {
    max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .chips {
    order: 3; flex: 1 1 100%;
    flex-wrap: nowrap; overflow-x: auto;
    padding: 8px 0 10px;
    scrollbar-width: none;        /* Firefox */
  }
  .chips::-webkit-scrollbar { display: none; }

  /* --- filters: collapsed behind a native details toggle --- */
  details.filters {
    display: block; flex: none;
    background: var(--paper); border-bottom: 1px solid var(--line);
  }
  details.filters summary {
    list-style: none;
    display: flex; align-items: center; gap: 9px;
    min-height: 46px; padding: 4px 14px;
    cursor: pointer; user-select: none;
    color: var(--petrol-strong); font-weight: 600; font-size: 13px;
  }
  details.filters summary::-webkit-details-marker { display: none; }
  details.filters summary::before {
    /* funnel glyph, petrol */
    content: ""; width: 15px; height: 15px; flex: none;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231e606f' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 5h18l-7 8.5V19l-4 2v-7.5L3 5z'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  details.filters summary::after {
    content: "\25BE"; margin-left: auto; color: var(--petrol); font-size: 12px;
  }
  details.filters[open] summary::after { content: "\25B4"; }
  details.filters[open] summary { border-bottom: 1px dashed var(--line); }

  .filterbar { display: none; }
  details.filters[open] + .filterbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    position: static; min-height: 0;
    padding: 10px 14px 14px;
    flex: none;                    /* never let the app-shell squash the panel */
    max-height: min(62dvh, 480px); /* short viewports: panel scrolls internally */
    overflow-y: auto;
    border-bottom: 1px solid var(--line);
  }
  .filterbar input:not([type="checkbox"]),
  .filterbar select,
  .filterbar .btn {
    width: 100%; min-height: 44px;
    font-size: 16px;              /* ≥16px stops iOS focus auto-zoom */
  }
  #f-q { width: 100%; grid-column: 1 / -1; }
  .filterbar .check { min-height: 44px; font-size: 15px; }
  .filterbar .check input { width: 18px; height: 18px; }
  .filterbar .spacer { display: none; }

  /* --- results: own scroll container, thead sticks within it --- */
  .results {
    flex: 1 1 auto; min-height: 0;
    overflow: auto;               /* the only horizontal-overflow guard */
    overscroll-behavior: contain;
    padding: 0 12px 24px;
  }
  thead th { top: 0; }

  /* --- pagination footer: big targets, clean wrap --- */
  .tablefoot { flex-wrap: wrap; gap: 8px 10px; padding: 14px 0 8px; }
  .tablefoot .spacer { display: none; }
  #page-info { order: 1; flex: 1 1 100%; text-align: center; }
  #btn-prev { order: 2; flex: 1 1 auto; min-height: 44px; }
  #btn-next { order: 3; flex: 1 1 auto; min-height: 44px; }
  .legend { order: 4; flex: 1 1 100%; text-align: center; }
}

/* ==================== phone (≤768px) ==================== */
@media (max-width: 768px) {
  /* columns: keep Name(1) / Specialty(3) / City(4) / Phone(7) / Addr conf(8);
     hide Cred(2), Address(5), ZIP(6), Industry $(9), Compl(10), Tenure(11) */
  thead th:nth-child(2), tbody td:nth-child(2),
  thead th:nth-child(5), tbody td:nth-child(5),
  thead th:nth-child(6), tbody td:nth-child(6),
  thead th:nth-child(9), tbody td:nth-child(9),
  thead th:nth-child(10), tbody td:nth-child(10),
  thead th:nth-child(11), tbody td:nth-child(11) { display: none; }

  tbody td { padding: 13px 10px; }   /* ≥44px row tap targets */

  /* drawer goes full-screen; head stays pinned (only .drawer-body scrolls) */
  .drawer { width: 100vw; border-left: none; }

  /* fieldrow: 3 columns → 2 rows (label + pill, then value) */
  .fieldrow { grid-template-columns: 1fr auto; row-gap: 2px; padding: 8px 0; }
  .fieldrow .fname { grid-row: 1; grid-column: 1; }
  .fieldrow > :nth-child(3) { grid-row: 1; grid-column: 2; justify-self: end; }
  .fieldrow .fval { grid-row: 2; grid-column: 1 / -1; }

  .login-card input { font-size: 16px; }
}

/* ==================== small phone (≤480px) ==================== */
@media (max-width: 480px) {
  thead th:nth-child(7), tbody td:nth-child(7) { display: none; }  /* Phone */
  .brand-title { font-size: 16px; }
  .topbar { gap: 8px; }
}

@media (max-width: 640px) {
  #user-email { display: none; }
}

@media (max-width: 380px) {
  .login-card { padding: 30px 24px 26px; }
}

/* ---------- CRM: notes, stars, fuzzy notice ---------- */
.star { font-size: 19px; line-height: 1; padding: 3px 9px; color: var(--ink-3); }
.star.star-on { color: var(--amber); }
.star:hover { color: var(--amber); border-color: var(--amber-line); }
.star-slot { margin-left: 8px; }
.note {
  border-bottom: 1px solid var(--line); padding: 7px 0;
}
.note-meta { font-size: 11px; color: var(--ink-2); margin-bottom: 2px; }
.note-meta .muted { margin-left: 8px; font-family: var(--mono); }
.note-body { font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-add { display: flex; gap: 8px; margin-top: 10px; align-items: flex-start; }
.note-add textarea {
  flex: 1; background: var(--card); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 7px 10px; font: inherit; color: var(--ink);
  resize: vertical; min-height: 40px;
}
.note-add textarea:focus { outline: none; border-color: var(--petrol); box-shadow: 0 0 0 3px var(--petrol-tint); }
.fuzzy-notice {
  margin: 10px 0 2px; padding: 7px 12px; border-radius: 6px;
  background: var(--amber-bg); border: 1px solid var(--amber-line);
  color: var(--amber); font-size: 12.5px;
}

/* pending-data affordance: filter exists, state data not yet acquired */
.check-pending { opacity: .55; cursor: help; }
