:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #dde1e6;
  --text: #1c2430;
  --muted: #5b6572;
  --accent: #2a5d8f;
  --accent-hover: #1f4a73;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --success: #1e7d32;
  --success-bg: #eaf6ec;
  --warn-bg: #fff6e5;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

header.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
}

header.topnav .brand { font-weight: 700; font-size: 1.1rem; color: var(--accent); }

header.topnav nav a {
  margin-right: 1.25rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
header.topnav nav a.active,
header.topnav nav a:hover { color: var(--accent); }

header.topnav .session { color: var(--muted); font-size: 0.85rem; display: flex; align-items: center; gap: 0.75rem; }

main { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.5rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

/* "Secondary screen" modals (e.g. public/turfs.html's Generate Turfs
   dialog) — native <dialog>, styled to match .card rather than the
   browser default, opened via .showModal()/.close() in JS. */
dialog {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
dialog::backdrop { background: rgba(20, 24, 30, 0.45); }

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.85rem; }

input[type=text], input[type=email], input[type=password], select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}
button:hover { background: var(--accent-hover); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius, 8px);
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 0.75rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone p { margin: 0 0 0.5rem; color: var(--muted); }
.dropzone p:last-child { margin: 0.5rem 0 0; }
.dropzone.dragover { border-color: var(--accent); background: rgba(42, 93, 143, 0.06); }
button.secondary { background: #fff; color: var(--accent); border: 1px solid var(--accent); }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
tr:hover td { background: #fafbfc; }

/* Turf list <-> overview map hover sync (public/turfs.html) — applied via
   JS on both row mouseenter/mouseleave and the matching map circle's
   mouseover/mouseout, not just native :hover, since either side can
   trigger the highlight. Tinted with --accent so it reads clearly next
   to the plainer default tr:hover above. */
tr.turf-row.row-highlighted td { background: rgba(42, 93, 143, 0.1); }

/* Selected-batch row on the Postcards page (public/postcards.html) --
   same convention/tint as turf-row above, marking which row's detail is
   showing on the right instead of a per-row "View" button. */
tr.batch-row.row-highlighted td { background: rgba(42, 93, 143, 0.1); }

/* Same row-highlight convention for the SMS page's campaign list
   (public/sms.html) and (once built) its Ongoing Messages conversation
   list. */
tr.campaign-row.row-highlighted td { background: rgba(42, 93, 143, 0.1); }

/* Small color key next to each status-filter checkbox on the turf overview
   map (public/turfs.html) — background color set inline per-checkbox to
   match STATUS_COLORS there. */
.color-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

/* "More actions" kebab (⋮) dropdown — generic enough for any infrequent
   per-item action, not just the turf detail panel's Delete (Brian: Delete
   should be "much more hidden" than a standalone button, with room for
   more items here later). Toggled via JS (menu-open class on .menu-wrap);
   closes on an outside click or after picking an item. */
.menu-wrap { position: relative; }
.menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 140px;
  z-index: 20;
  overflow: hidden;
}
.menu-dropdown .menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 0;
  padding: 0.55rem 0.8rem;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}
.menu-dropdown .menu-item:hover { background: var(--bg); }

.pill { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.pill.ok { background: var(--success-bg); color: var(--success); }
.pill.warn { background: var(--warn-bg); color: #8a6100; }
.pill.err { background: var(--danger-bg); color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

.muted { color: var(--muted); }
.error-banner { background: var(--danger-bg); color: var(--danger); padding: 0.6rem 0.8rem; border-radius: 6px; margin-bottom: 0.75rem; font-size: 0.85rem; }
.stat { text-align: center; padding: 0.75rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 0.8rem; }

.progress-wrap { margin: 0.75rem 0; }
.progress-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
.progress-track { background: var(--border); border-radius: 999px; height: 10px; overflow: hidden; }
.progress-fill { background: var(--accent); height: 100%; border-radius: 999px; width: 0%; transition: width 0.25s ease; }
.progress-fill.indeterminate {
  width: 40% !important;
  animation: progress-slide 1.1s ease-in-out infinite;
}
@keyframes progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

.mapping-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.mapping-row .field-name { font-weight: 600; }
.required-badge { color: var(--danger); font-size: 0.75rem; margin-left: 0.35rem; }

.map-layout { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; align-items: start; }
#map { height: 600px; border-radius: var(--radius); border: 1px solid var(--border); }
.legend { display: flex; gap: 1rem; align-items: center; margin: 0.5rem 0 1rem; font-size: 0.8rem; color: var(--muted); }
.legend .dot { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; margin-right: 0.3rem; }
.review-list { max-height: 500px; overflow-y: auto; }
.review-list .item { padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.review-list .item:last-child { border-bottom: none; }
.review-list button { font-size: 0.8rem; padding: 0.3rem 0.6rem; margin-top: 0.3rem; }
.placing-banner { background: var(--warn-bg); color: #8a6100; padding: 0.6rem 0.8rem; border-radius: 6px; margin-bottom: 0.75rem; font-size: 0.85rem; }

/* Voter detail's interaction timeline (public/voters.html) -- one row per
   door/postcard/SMS touchpoint, newest-first by default. */
.timeline-item { border-bottom: 1px solid var(--border); padding: 0.6rem 0; }
.timeline-item:last-child { border-bottom: none; }
.timeline-summary { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; font-size: 0.88rem; }
.timeline-summary .timeline-text { flex: 1; }
.timeline-details { margin-top: 0.5rem; font-size: 0.82rem; color: var(--muted); display: none; }
.timeline-details.open { display: block; }
.timeline-details dl { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 0.6rem; margin: 0; }
.timeline-details dt { font-weight: 600; color: var(--text); }
.timeline-details dd { margin: 0; }
.household-member-link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }
.household-member-link:hover { color: var(--accent-hover); }

/* Sortable table-header columns, used across every sortable table in the
   app (voters.html's Name/Interactions, ...) -- an idle low-opacity "⇕" on
   any sortable-but-not-currently-sorted column, a solid "▲"/"▼" on
   whichever one IS the active sort. Mirrors the DATASCI241 project's own
   report-view th.sortable/::after convention exactly (Brian: "reference
   the report view of the DATASCI 241 project"), just tinted with this
   app's own --accent instead of that page's hardcoded blue. See
   applySortIndicators()/wireSortableTable() in api.js -- the JS side only
   ever toggles the sort-asc/sort-desc classes below, never rewrites
   header text by hand. */
th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 1.1rem; }
th.sortable:hover { color: var(--accent); }
th.sortable::after { content: '⇕'; position: absolute; right: 0.3rem; top: 50%; transform: translateY(-50%); opacity: 0.5; font-size: 0.68rem; }
th.sortable.sort-asc::after { content: '▲'; opacity: 1; font-size: 0.6rem; }
th.sortable.sort-desc::after { content: '▼'; opacity: 1; font-size: 0.6rem; }

/* Click-to-enlarge inline preview images (voter timeline, postcards,
   door hangers) -- a thumbnail that opens a fixed-position lightbox with
   the same image shown larger, no page navigation/download involved
   (Brian: "I don't want to download or view pdf... see the image
   in-line... clickable to full size"). */
.preview-thumb { max-width: 140px; max-height: 100px; border: 1px solid var(--border); border-radius: 6px; cursor: zoom-in; display: block; }
.lightbox-overlay { position: fixed; inset: 0; background: rgba(20, 24, 30, 0.75); display: flex; align-items: center; justify-content: center; z-index: 100; cursor: zoom-out; padding: 2rem; }
.lightbox-overlay img { max-width: 90vw; max-height: 90vh; border-radius: 8px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4); }

/* SMS Ongoing Messages (public/sms.html) -- unread indicator + chat-bubble
   thread. Unread dot styled like the existing .legend .dot (same size/
   shape convention), just tinted blue specifically (Brian: "highlighting
   with a blue dot any conversations that have an unread message" --
   a literal ask, not just "some indicator"), independent of --accent so a
   future theme change to --accent doesn't accidentally make "unread"
   ambiguous with anything else that also uses --accent. */
.unread-dot { display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: #2563eb; margin-right: 0.4rem; flex-shrink: 0; }
.conversation-list .item { display: flex; align-items: center; cursor: pointer; }
.conversation-list .item:hover { background: var(--bg); }
.conversation-list .item.row-highlighted { background: rgba(42, 93, 143, 0.1); }
.conversation-list .item.archived-item { opacity: 0.6; }

.msg-thread { display: flex; flex-direction: column; gap: 0.5rem; max-height: 420px; overflow-y: auto; padding: 0.5rem 0; }
.msg-bubble { max-width: 75%; padding: 0.5rem 0.75rem; border-radius: 12px; font-size: 0.88rem; position: relative; }
.msg-bubble.outbound { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg-bubble.inbound { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg-bubble .msg-meta { font-size: 0.7rem; opacity: 0.75; margin-top: 0.25rem; }
.msg-bubble .link-clicked-badge { display: inline-block; margin-top: 0.3rem; font-size: 0.72rem; font-weight: 600; background: var(--success-bg); color: var(--success); padding: 0.1rem 0.4rem; border-radius: 999px; }
.msg-bubble.outbound .link-clicked-badge { background: rgba(255,255,255,0.25); color: #fff; }
