/* ═══════════════ One look for every control ═══════════════
   Loaded last. Earlier files grew page by page and disagreed (square buttons next to round ones, three card
   radii, black chips here and green ones there). These rules are the single source of truth for:
   buttons · chips · inputs · cards · filter rows · tables · spacing.  Change a token here, it changes everywhere. */

:root {
  --ui-radius-ctl: 8px;      /* buttons, inputs, selects */
  --ui-radius-card: 12px;    /* cards, panels, dialogs */
  --ui-ctl-h: 38px;          /* height of a button / input / select */
  --ui-chip-h: 32px;
  --ui-gap: 12px;            /* gap between controls in a row */
  --ui-gap-lg: 20px;         /* gap between cards / sections */
  --ui-pad-card: 16px;
  --ui-tint: #e7f2ef;        /* selected / hover tint (same as the sub-nav) */
  --ui-tint-line: #c6dfd6;
  --ui-shadow: 0 1px 2px rgba(24, 43, 50, .05);
  --ui-shadow-hover: 0 3px 10px rgba(24, 43, 50, .09);
}

/* ── inputs ── */
body.app :where(input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea) {
  min-height: var(--ui-ctl-h);
  padding: 0 .7rem;
  border: 1px solid var(--line);
  border-radius: var(--ui-radius-ctl);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
}
body.app textarea { padding: .55rem .7rem; }
body.app :where(input, select, textarea):hover { border-color: #b4c2c9; }
body.app :where(input, select, textarea):focus { border-color: var(--accent); }
body.app :where(input[type=checkbox], input[type=radio]) { accent-color: var(--accent); width: 16px; height: 16px; }

/* ── buttons: primary / secondary / quiet ── */
body.app :where(button.action, .action) {
  min-height: var(--ui-ctl-h);
  padding: 0 1rem;
  border-radius: var(--ui-radius-ctl);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}
body.app :where(button.action):hover:not(:disabled) { filter: brightness(1.08); }
body.app :where(button.action.secondary) { background: #fff; color: var(--ink); border-color: var(--line); }
body.app :where(button.action.secondary):hover:not(:disabled) { border-color: var(--accent); background: var(--ui-tint); filter: none; }
body.app :where(button.action):disabled { opacity: .45; cursor: not-allowed; }
/* quiet button: for Cancel, Clear, Delete, Save-this-filter */
body.app :where(button.ghost) {
  min-height: var(--ui-ctl-h);
  padding: 0 .85rem;
  border-radius: var(--ui-radius-ctl);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
  cursor: pointer;
}
body.app :where(button.ghost):hover:not(:disabled) { border-color: var(--accent); background: var(--ui-tint); }
body.app :where(button.ghost):disabled { opacity: .45; cursor: not-allowed; }
body.app .linkish { color: var(--accent); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ── chips: one pill shape ── */
body.app :where(button.chip) {
  min-height: var(--ui-chip-h);
  padding: 0 .8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .84rem;
  cursor: pointer;
}
body.app :where(button.chip):hover { border-color: var(--accent); }
/* selected = solid dashboard green with white text, on every page (several pages had black, teal or tinted ones) */
body.app .chip.active, body.app button.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
body.app .find-modes .chip { border-radius: var(--ui-radius-ctl); }

/* ── segmented switches (Place | Caste | Surname, Booth areas | Booth dots …): one joined control ── */
body.app :where(.lens-switch, .bm-seg, .seg) { display: inline-flex; }
body.app :where(.lens-switch, .bm-seg, .seg) > button {
  min-height: 34px;
  padding: 0 .95rem;
  border: 1px solid var(--line);
  border-left-width: 0;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .86rem;
  cursor: pointer;
}
body.app :where(.lens-switch, .bm-seg, .seg) > button:first-child { border-left-width: 1px; border-radius: var(--ui-radius-ctl) 0 0 var(--ui-radius-ctl); }
body.app :where(.lens-switch, .bm-seg, .seg) > button:last-child { border-radius: 0 var(--ui-radius-ctl) var(--ui-radius-ctl) 0; }
body.app :where(.lens-switch, .bm-seg, .seg) > button:hover:not(.active):not(:disabled) { background: var(--ui-tint); }
body.app :where(.lens-switch, .bm-seg, .seg) > button.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
body.app :where(.lens-switch, .bm-seg, .seg) > button:disabled { opacity: .45; cursor: not-allowed; }

/* ── cards: every boxed thing looks the same ── */
body.app :where(.block, .overview-panel, .profile-card, .stat, .task-card, .ov-stat, .ov-ward, .fl-card, .col-ward, .ex-card, .bm-card) {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--ui-radius-card);
  box-shadow: var(--ui-shadow);
}
body.app :where(.block, .overview-panel) { padding: var(--ui-pad-card) calc(var(--ui-pad-card) + 4px); }
body.app :where(.task-card, .ov-ward, .col-ward, .fl-card, .ov-stat) { padding: 12px 14px; }
body.app :where(.task-card, .ov-ward):hover { border-color: var(--accent); box-shadow: var(--ui-shadow-hover); }
body.app .block + .block, body.app .block + .overview-panel { margin-top: var(--ui-gap-lg); }
body.app :where(.block h2, .overview-panel h2, .ov-h) { font-family: var(--mono); font-size: 1.05rem; font-weight: 600; margin: 0 0 .5rem; letter-spacing: -.01em; }
body.app :where(.block h3) { font-size: .92rem; font-weight: 600; margin: 1rem 0 .4rem; }
body.app .hint { font-size: .84rem; color: var(--muted); line-height: 1.45; margin: 0 0 .75rem; }

/* Cards that were styled one-by-one (search sheets, review card, booth history, rank block) join the same family */
body.app :where(.find-sheet, .reach-sheet, .qr-card, .booth-history, .rank-page .block, #tab-rank .block) {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--ui-radius-card);
  box-shadow: var(--ui-shadow);
}
body.app :where(.find-sheet, .reach-sheet) { padding: var(--ui-pad-card) calc(var(--ui-pad-card) + 4px); }
body.app :where(.booth-history) { padding: 12px 14px; }
/* one vertical rhythm: 20px between stacked cards on a page, whatever their class */
body.app .panel > :where(.block, .find-sheet, .reach-sheet, .overview-panel, .qr-card, .booth-history) + :where(.block, .find-sheet, .reach-sheet, .overview-panel, .qr-card, .booth-history) { margin-top: var(--ui-gap-lg); }
body.app #tab-rank .block { margin-top: var(--ui-gap-lg); }
/* wide screens: keep reading width sensible (the maps use the full width) */
body.app main > .panel:not(#tab-boothmap):not(#tab-map) { max-width: 1360px; margin-inline: auto; }

/* ── filter rows and form rows: same gap, controls line up ── */
body.app :where(.fl-form, .fb, .col-bulk, .col-upload, .sv, .find-actions, .fl-actions, .overview-toolbar, .ex-actions) {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-gap);
  align-items: flex-end;
}
body.app .fl-form, body.app .fb { flex-direction: column; align-items: stretch; gap: 14px; }
body.app :where(.fl-form, .fb, .ex-card, .find-sheet) label, body.app .field { display: grid; gap: 4px; font-size: .84rem; color: var(--muted); font-weight: 500; }
body.app :where(.fl-form, .fb, .ex-card) label input, body.app :where(.fl-form, .fb, .ex-card) label select { color: var(--ink); font-weight: 400; }
body.app :where(.fl-form, .fb) :where(select, input:not([type=checkbox])) { max-width: 460px; }
body.app :where(.fl-form, .fb, .ex-card, .pg-grid2) label { align-content: start; }
body.app :where(.fl-form, .fb, .ex-card, .pg-grid2) label > :where(input, select) { align-self: start; height: var(--ui-ctl-h); }
body.app .fl-lab { font-size: .84rem; color: var(--muted); font-weight: 500; margin-right: 4px; }
body.app .fl-wards { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
body.app :where(.fl-actions, .ex-actions) { align-items: center; }
body.app .ex-card { padding: 20px 22px; }

/* ═══ Where things sit — the same on every page ═══
   1. Page title and one-line hint at the top of the card.
   2. FILTERS directly under it, left to right: the main choice, then narrowing chips, then saved filters on the far right.
   3. The button that runs the form sits directly under the filters, LEFT-aligned, primary first.
   4. RESULT bar: what you are looking at (sentence) on the left, what you can do with it (download, etc.) on the right.
   5. Detail tables and cards below that. */
body.app .fl-form, body.app .fb { max-width: none; }
body.app .fb-top { display: flex; flex-wrap: wrap; gap: var(--ui-gap); align-items: flex-end; justify-content: space-between; }
body.app .fb-top .sv { margin-left: auto; flex: 1 1 auto; justify-content: flex-end; }
/* two fields side by side where there is room (booth numbers + your name, etc.) */
body.app .pg-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 700px) { body.app .pg-grid2 { grid-template-columns: 1fr; } }
body.app .pg-grid2 :where(input, select) { max-width: none; width: 100%; }
body.app .pg-result {
  display: flex; flex-wrap: wrap; gap: var(--ui-gap); align-items: center; justify-content: space-between;
  margin: var(--ui-gap-lg) 0 var(--ui-gap); padding: 12px 14px;
  background: #f6f8f9; border: 1px solid var(--line); border-radius: var(--ui-radius-ctl);
}
body.app .pg-result .fd-sentence { margin: 0; }
body.app .pg-result .fl-actions { margin: 0; }
/* the button that runs a search / builds a list: never full width, always right under its fields, same size */
body.app button.action[id$="Go"], body.app #exploreApplyCaste {
  width: auto !important; min-height: var(--ui-ctl-h) !important; margin: 14px 0 0 !important; display: inline-flex; align-items: center; justify-content: center;
}
body.app .find-actions { margin-top: 14px; }
body.app .find-actions .action { flex: none; }

/* ── result summary (smHtml): big count + noun, conditions as tokens, small facts underneath ── */
body.app .sm { display: grid; gap: 8px; }
body.app .sm-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; line-height: 1.5; }
body.app .sm-n { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; color: var(--ink); }
body.app .sm-noun { font-size: 1.15rem; font-weight: 600; color: var(--ink); }
body.app .sm-cond { font-size: .95rem; color: var(--muted); display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; }
body.app .sm-tok { display: inline-block; padding: 1px 9px; border-radius: 999px; background: var(--ui-tint); border: 1px solid var(--ui-tint-line); color: var(--accent); font-weight: 600; font-size: .88rem; white-space: nowrap; }
body.app .sm-and { color: var(--muted); font-size: .82rem; }
body.app .sm-stats { display: flex; flex-wrap: wrap; gap: 6px 22px; padding-top: 8px; border-top: 1px solid #e5ebee; }
body.app .sm-stat { font-size: .9rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
body.app .sm-stat b { color: var(--ink); font-size: 1rem; font-weight: 700; }
body.app .sm-pills { display: inline-flex; flex-wrap: wrap; gap: 4px; }
body.app .sm-pill { padding: 0 8px; border-radius: 6px; background: #eef2f4; border: 1px solid var(--line); color: var(--ink); font-size: .8rem; font-weight: 600; min-width: 24px; text-align: center; }
body.app .sm-note { font-size: .82rem; color: var(--muted); }
body.app .sm-warn { font-size: .86rem; color: var(--warn); }
body.app .pg-result .sm { flex: 1 1 320px; }

/* rows of chips and buttons wrap instead of running off a narrow screen */
body.app :where(.find-modes, .chip-row, .filter-chips, .fd-wchips, .bm-presets, .bm-levels, .ls-tabs, .cm-tabs, .fl-wards, .fd-strip) { flex-wrap: wrap; }
body.app .find-modes { display: flex; gap: 8px; }
body.app img, body.app svg { max-width: 100%; }
/* a dropdown never gets wider than its box just because one option is long */
body.app :where(select, input:not([type=checkbox]):not([type=radio]), textarea) { max-width: 100%; min-width: 0; }
body.app :where(label, .field, .fd-line, .fd-rule, .rank-toolbar) { min-width: 0; }
body.app :where(.fd-line, .fd-rule, .rank-toolbar) { flex-wrap: wrap; }
@media (max-width: 700px) { body.app select { width: 100%; } }

/* ── tables: same header, padding and row lines everywhere ── */
body.app table { border-collapse: collapse; width: 100%; font-size: .87rem; }
body.app :where(th) { font-size: .74rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: #f6f8f9; text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
body.app :where(td) { padding: .5rem .7rem; border-bottom: 1px solid #edf1f3; vertical-align: top; }
body.app :where(th.num, td.num) { text-align: right; }
body.app tbody tr:hover td { background: #f9fbfa; }
body.app .table-scroll > table { min-width: 100%; width: max-content; max-width: none; }
body.app .table-scroll > table.bc-table, body.app .table-scroll > table { width: 100%; min-width: max-content; }
body.app .table-scroll { border: 1px solid var(--line); border-radius: var(--ui-radius-ctl); background: #fff; }

/* ── my newer bars and meters use the dashboard green, not a second green ── */
body.app :where(.col-bar i, .ov-bar-track i) { background: var(--accent); }
body.app .ok-txt { color: var(--accent); }
body.app :where(.ov-ward:hover, .task-card:hover) { border-color: var(--accent); }
body.app .col-bar, body.app .ov-bar-track { background: #e4eaed; }
body.app .ph-chip, body.app .bm-pick-chip { background: var(--ui-tint); }

/* ── headings: one family (the serif one only appeared on a few panels) ── */
body.app h2, body.app h2[class] { font-family: var(--mono); font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; }
body.app h3 { font-family: var(--mono); font-weight: 600; }

/* ── text sizes: one scale ── */
body.app { font-size: 15px; }
body.app .muted { color: var(--muted); }
body.app .warn-txt { color: var(--warn); font-size: .86rem; }
body.app .empty { color: var(--muted); padding: 1rem 0; }

@media (max-width: 700px) {
  :root { --ui-ctl-h: 42px; --ui-pad-card: 14px; }  /* bigger tap targets on a phone */
  body.app .fl-form label, body.app .fb label { width: 100%; }
}

/* ── "?" help tips and the welcome card ── */
body.app .tip { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; margin-left: 5px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--muted); font-size: .68rem; font-weight: 700; cursor: help; position: relative; vertical-align: middle; }
body.app .tip:hover, body.app .tip:focus, body.app .tip.open { border-color: var(--accent); color: var(--accent); }
body.app .tip::after { content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); width: min(280px, 70vw); padding: 9px 11px; border-radius: 8px; background: var(--ink); color: #fff; font-size: .78rem; font-weight: 400; line-height: 1.4; text-transform: none; letter-spacing: 0; text-align: left; box-shadow: 0 6px 18px rgba(0,0,0,.25); opacity: 0; pointer-events: none; z-index: 60; transition: opacity .12s; }
body.app .tip:hover::after, body.app .tip:focus::after, body.app .tip.open::after { opacity: 1; }
body.app .tip-inline { display: inline-flex; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--line); align-items: center; justify-content: center; font-size: .65rem; font-weight: 700; }
body.app .welcome { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; padding: 14px 18px; background: var(--ui-tint); border: 1px solid var(--ui-tint-line); border-radius: var(--ui-radius-card); }
body.app .welcome ol { margin: 6px 0; padding-left: 20px; display: grid; gap: 3px; font-size: .9rem; }

/* ── loading placeholders, offline queue badge ── */
body.app .skel { display: grid; gap: 10px; padding: 8px 0; }
body.app .skel i { display: block; height: 16px; border-radius: 6px; background: linear-gradient(90deg, #e9eef0 25%, #f4f7f8 50%, #e9eef0 75%); background-size: 200% 100%; animation: skel-shimmer 1.2s infinite; }
@keyframes skel-shimmer { to { background-position: -200% 0; } }
body.app .ph-queue { position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); z-index: 900; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--warn); background: #fff7ee; color: var(--warn); font: inherit; font-size: .86rem; font-weight: 600; cursor: pointer; box-shadow: var(--ui-shadow-hover); }
body.app .ov-fresh { margin: 18px 0 0; font-size: .8rem; color: var(--muted); }
body.app .ov-fresh b { color: var(--ink); font-weight: 600; }
