/* MexDrone expert database — research interface.
 *
 * overflow-x lives on html, NEVER on body: on body it makes the body its own
 * scroll container and silently kills position:sticky, so the header stops
 * pinning and nothing reports an error.
 */
html { overflow-x: hidden; box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }

:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1b1c1e;
  --muted: #63666b;
  --line: #dcdcd8;
  --accent: #1f5f8b;
  --accent-soft: #e8f0f6;
  --warn: #b00020;
  --ok: #2f6f43;
  --radius: 6px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

a { color: var(--accent); }

.skip {
  position: absolute; left: -9999px;
  background: var(--panel); padding: .5rem .75rem; z-index: 100;
}
.skip:focus { left: .5rem; top: .5rem; }

/* --- header ------------------------------------------------------------ */
.site-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none; color: inherit;
}
.brand-mark { font-size: 1.4rem; color: var(--accent); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1rem; letter-spacing: .01em; }
.brand-text small { color: var(--muted); font-size: .75rem; }
.header-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.result-count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Anchor targets must clear the pinned header, or it covers the heading you
 * just jumped to. */
:target, #results { scroll-margin-top: 4.5rem; }

/* --- layout ------------------------------------------------------------ */
.layout {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr) 13rem;
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}
.facets, .side-panels > section, .results { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.facets, .side-panels > section { padding: .85rem; position: sticky; top: 4.2rem; max-height: calc(100vh - 5rem); overflow-y: auto; }
.facets h2, .side-panels h2 { margin: 0 0 .6rem; font-size: .95rem; }

.field { display: block; margin-bottom: .7rem; }
.field > span { display: block; font-weight: 600; margin-bottom: .2rem; font-size: .8rem; }
.field input, .field select { width: 100%; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 4px; font: inherit; }

.facet-group { border-top: 1px solid var(--line); padding-top: .6rem; margin-top: .6rem; }
.facet-group h3 { margin: 0 0 .35rem; font-size: .8rem; }
.facet-option { display: flex; align-items: center; gap: .4rem; padding: .1rem 0; font-size: .82rem; }
.facet-option .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.range-row { display: flex; gap: .4rem; align-items: center; }
.range-row input { width: 100%; padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 4px; font: inherit; }
.range-note { color: var(--muted); font-size: .75rem; min-height: 1em; }

/* --- results ----------------------------------------------------------- */
.results { padding: .5rem; min-width: 0; }
.results-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; min-height: 2rem; padding: .25rem; }
.selection-count { font-weight: 600; }
.table-scroll { overflow-x: auto; }
/* Long free-text cells wrap rather than forcing the table wider — but at
 * word boundaries. `anywhere` breaks mid-word and renders "Acade mia". */
td { overflow-wrap: break-word; word-break: normal; hyphens: none; }
td:nth-child(2) { min-width: 8rem; }   /* name */
td:nth-child(4), td:nth-child(5) { min-width: 6rem; }  /* sector, role */
th:first-child, td:first-child { width: 1.6rem; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel); z-index: 1; white-space: nowrap; }
th button { background: none; border: 0; font: inherit; font-weight: 700; cursor: pointer; padding: 0; color: inherit; }
tbody tr:hover { background: var(--accent-soft); }
tbody tr.selected { background: #eef6ee; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-open { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; text-align: left; }
.empty { color: var(--muted); padding: 1rem; }

.pill { display: inline-block; padding: .05rem .4rem; border-radius: 999px; background: var(--accent-soft); font-size: .75rem; }

/* --- detail panel ------------------------------------------------------ */
.detail {
  position: fixed; inset: 0 0 0 auto; width: min(34rem, 100%);
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 1rem; overflow-y: auto; z-index: 30;
  box-shadow: -4px 0 18px rgb(0 0 0 / .08);
}
.detail h2 { margin-top: 0; }
.detail-close { float: right; }
.detail dl { display: grid; grid-template-columns: 9rem 1fr; gap: .2rem .6rem; margin: .4rem 0 1rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail section { border-top: 1px solid var(--line); padding-top: .7rem; margin-top: .7rem; }

/* --- notes ------------------------------------------------------------- */
.note { border: 1px solid var(--line); border-radius: 4px; padding: .45rem .55rem; margin-bottom: .45rem; }
.note-meta { color: var(--muted); font-size: .75rem; }
.note textarea, .note-new textarea { width: 100%; min-height: 4.5rem; font: inherit; padding: .4rem; border: 1px solid var(--line); border-radius: 4px; }
.error { color: var(--warn); }

button { font: inherit; padding: .35rem .7rem; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 4px; cursor: pointer; }
button.ghost { background: none; color: var(--accent); }
button.danger { background: var(--warn); border-color: var(--warn); }
button.wide { width: 100%; }
button[disabled] { opacity: .55; cursor: default; }

/* --- narrow screens ---------------------------------------------------- */
@media (max-width: 60rem) {
  .layout { grid-template-columns: 1fr; }
  .facets, .side-panels > section { position: static; max-height: none; }
  .detail { width: 100%; }
}
