/* PAHO/PHE · application styles (consume tokens.css only). */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
/* Display face = a bulletin serif, used for headings, hero and figures only —
   the body stays humanist sans (see DESIGN_SYSTEM.md). */
h1, h2, h3 { font-family: var(--font-display); color: var(--text-primary); line-height: 1.2; margin: 0 0 var(--space-3); font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 30px; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* Eyebrow — the tracked, uppercase field label used above sections and figures. */
.eyebrow { font-family: var(--font-mono); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--text-muted); }

/* ---- App shell ---- */
.app { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: var(--space-4);
}
.sidebar .brand { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-5); }
.sidebar .brand img { height: 26px; width: auto; }
.sidebar .brand .tag { font-size: 12px; color: var(--text-muted); font-weight: 600; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px var(--space-3); border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 14px; font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--hover-bg); color: var(--brand-fg); text-decoration: none; }
.nav a.active { background: var(--brand-subtle-bg); color: var(--brand-subtle-fg); font-weight: 600; }
.sidebar .spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--space-6); border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}
.topbar .spacer { flex: 1; }
.topbar .chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  border: 1px solid var(--border); border-radius: var(--radius-full);
  padding: 5px 12px; font-size: 13px; color: var(--text-secondary); background: var(--bg-surface);
}
.topbar .chip .flag { width: 18px; height: 13px; border-radius: 2px; object-fit: cover; }
.content { padding: var(--space-6); max-width: 1120px; width: 100%; }

/* ---- Controls ---- */
select, input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
input[type="url"], input[type="number"], input[type="search"], input[type="date"] {
  font: inherit; padding: 8px 10px; border: 1px solid var(--neutral-300);
  border-radius: var(--radius-sm); background: var(--bg-surface); color: var(--text-primary);
  min-height: 38px; width: 100%; transition: border-color .12s ease, box-shadow .12s ease;
}
/* A brand focus ring for the pointer; keyboard focus still gets the outline. */
select:focus, input:focus, .modal textarea:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--hover-bg); outline: none;
}
label { font-size: 13px; font-weight: 600; color: var(--text-secondary); display: block; margin-bottom: 4px; }
.field { margin-bottom: var(--space-4); }
.btn {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--primary); color: var(--on-primary); display: inline-flex; align-items: center; gap: var(--space-2);
  transition: background .12s ease, border-color .12s ease, transform .04s ease;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--bg-surface); border-color: var(--border); color: var(--brand-fg); }
.btn.secondary:hover { background: var(--hover-bg); border-color: var(--primary); }
.btn.danger { background: var(--danger-600); color: #fff; }
.btn.danger:hover { background: var(--danger-700); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn.ghost:hover { background: var(--hover-bg); color: var(--brand-fg); }

/* ---- Cards / tables ---- */
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-5); box-shadow: var(--shadow-sm); }
.card + .card, .stack > * + * { margin-top: var(--space-4); }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-4); }
.stat { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-5); box-shadow: var(--shadow-sm); }
.stat .n { font-family: var(--font-display); font-size: 34px; font-weight: 600; letter-spacing: -.01em; color: var(--brand-fg); font-variant-numeric: tabular-nums; line-height: 1.05; }
.stat .l { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; margin-top: 6px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-surface); box-shadow: var(--shadow-sm); }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; min-width: 640px; }
table.data th, table.data td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; font-variant-numeric: tabular-nums; }
/* Bulletin header — the mono registry voice, so a data table reads like a report. */
table.data thead th { background: var(--thead-bg); font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
table.data tbody tr { transition: background .1s ease; }
table.data tbody tr:hover { background: var(--hover-bg); }
table.data tbody tr:last-child td { border-bottom: none; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: var(--radius-full); }
.badge.ok { background: var(--success-050); color: var(--success-700); }
.badge.off { background: var(--chip-bg); color: var(--text-muted); }
.badge.global { background: var(--brand-subtle-bg); color: var(--brand-subtle-fg); }
.badge.sec { background: var(--danger-050); color: var(--danger-700); }
.badge.act { background: var(--chip-bg); color: var(--text-secondary); }

/* ---- Flashes ---- */
.flashes { list-style: none; margin: 0 0 var(--space-4); padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.flash { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; border: 1px solid transparent; }
.flash.success { background: var(--success-050); color: var(--success-700); }
.flash.danger  { background: var(--danger-050);  color: var(--danger-700); }
.flash.warning { background: var(--warning-050); color: var(--warning-700); }
.flash.info    { background: var(--info-050);    color: var(--info-700); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--space-5); background: var(--bg-app); }
.login-card { width: 100%; max-width: 380px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-6); box-shadow: var(--shadow-md); }
.login-card .brand { text-align: center; margin-bottom: var(--space-5); }
.login-card .brand img { height: 34px; }
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-top: var(--space-2); }

/* ---- EI plan ---- */
.ei-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); flex-wrap: wrap; }
.ei-country-picker { display: flex; align-items: center; gap: var(--space-2); }
.ei-country-picker label { margin: 0; white-space: nowrap; }
.ei-country-picker select { width: auto; min-width: 200px; }

/* status + kind badges */
.badge.baseline { background: var(--success-050); color: var(--success-700); }
.badge.target   { background: var(--brand-subtle-bg); color: var(--brand-subtle-fg); }
.badge.na       { background: var(--chip-bg); color: var(--text-muted); }
.badge.offer-b  { background: var(--success-050); color: var(--success-700); }
.badge.request-b{ background: var(--warning-050); color: var(--warning-700); }

/* summary strip */
.ei-summary { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin: var(--space-5) 0 var(--space-4); }
.ei-country-name { font-weight: 700; font-size: 16px; margin-right: var(--space-2); }
.ei-chip { display: inline-flex; align-items: baseline; gap: 6px; border: 1px solid var(--border); border-radius: var(--radius-full); padding: 5px 14px; font-size: 13px; color: var(--text-secondary); background: var(--bg-surface); }
.ei-chip__n { font-weight: 700; font-size: 16px; color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* tabs */
.ei-tabs { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--space-4); flex-wrap: wrap; }
.ei-tab { font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; border: none; background: none; color: var(--text-secondary); padding: 10px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 6px; }
.ei-tab:hover { color: var(--brand-fg); }
.ei-tab.active { color: var(--brand-fg); border-bottom-color: var(--primary); }
.ei-tab--mine { margin-left: var(--space-2); }
.ei-tab__badge { font-size: 11px; font-weight: 700; background: var(--brand-subtle-bg); color: var(--brand-subtle-fg); border-radius: var(--radius-full); padding: 1px 7px; }
.ei-tabs__spacer { flex: 1; }
.ei-filter { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-secondary); cursor: pointer; margin: 0; }
.ei-filter input { width: auto; min-height: 0; }

/* panels */
.ei-panel { display: none; }
.ei-panel.active { display: block; }
.ei-line-name { color: var(--text-muted); font-size: 13px; margin: 0 0 var(--space-3); }
.ei-obj { margin-top: var(--space-4); }
.ei-obj h3 { font-size: 16px; }
.ei-obj .activity { color: var(--text-muted); font-size: 13px; margin: 2px 0 var(--space-3); }

/* indicator row */
.ei-ind { padding: var(--space-3) 0; border-top: 1px solid var(--border); }
.ei-ind:first-of-type { border-top: none; }
.ei-ind.regional { opacity: .72; }
.ei-ind__head { display: flex; gap: var(--space-3); align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.ei-ind__code { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); margin-right: 4px; }
.ei-ind__text { flex: 1; min-width: 260px; font-size: 14px; }
.ei-actions { display: flex; gap: var(--space-2); align-items: center; }
.ei-only-mine .ei-ind:not(.has-entries) { display: none; }

/* entries */
.ei-entries { margin-top: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.ei-entry { border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); }
.ei-entry.offer { border-left-color: var(--success-600); }
.ei-entry.request { border-left-color: var(--warning-600); }
.ei-entry__meta { display: flex; justify-content: space-between; gap: var(--space-3); align-items: center; margin-bottom: 4px; }
.lang-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.lang-tag { min-width: 26px; font-size: 11px; font-weight: 700; color: var(--text-muted); }
.lang-row input { flex: 1; min-width: 0; }
.ei-entry__tags { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ei-entry__kind { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.ei-entry__type { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); background: var(--chip-bg); border-radius: var(--radius-full); padding: 2px 9px; }
.ei-entry.offer .ei-entry__kind { color: var(--success-700); }
.ei-entry.request .ei-entry__kind { color: var(--warning-700); }
.ei-entry__desc { font-size: 14px; white-space: pre-wrap; }
.modal textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--neutral-300); border-radius: var(--radius-sm); background: var(--bg-surface); color: var(--text-primary); resize: vertical; }
.ei-charhint { font-size: 12px; margin: 4px 0 0; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,58,93,.45); display: none; place-items: center; padding: var(--space-5); z-index: 50; }
.modal.open { display: grid; }
/* A size scale, not one width for everything (Aperture; see DESIGN_SYSTEM.md):
   sm for confirms, md for short forms, lg for the rare wide one. */
.modal .box { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md); width: 100%; max-width: 480px; padding: var(--space-6); max-height: 90vh; overflow-y: auto; }
.modal .box.box--sm { max-width: 400px; }
.modal .box.box--md { max-width: 600px; }
.modal .box.box--lg { max-width: 820px; }
.modal .box h2 { margin-bottom: var(--space-4); }

/* Right-side drawer for longer, referenceable forms (the event editor). */
.drawer { position: fixed; inset: 0; z-index: 55; display: none; }
.drawer.open { display: block; }
.drawer__scrim { position: absolute; inset: 0; background: rgba(0,58,93,.45); }
.drawer__panel { position: absolute; top: 0; right: 0; height: 100%; width: 100%; max-width: 540px; background: var(--bg-surface); box-shadow: var(--shadow-md); overflow-y: auto; padding: var(--space-6); }
@media (prefers-reduced-motion: no-preference) { .drawer.open .drawer__panel { animation: drawer-in .18s cubic-bezier(.2,.7,.3,1); } }
@keyframes drawer-in { from { transform: translateX(24px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-4); }
.drawer__head h2 { margin: 0; }

/* On a phone, a dialog or drawer is a full-screen sheet, never a 480px island. */
@media (max-width: 560px) {
  .modal { padding: 0; place-items: stretch; }
  .modal .box, .modal .box.box--sm, .modal .box.box--md, .modal .box.box--lg {
    max-width: 100%; max-height: 100%; min-height: 100vh; border-radius: 0; border: none;
  }
  .drawer__panel { max-width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  .modal.open .box { animation: modal-in .16s cubic-bezier(.2,.7,.3,1); }
}
@keyframes modal-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.modal .actions { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-5); }
.checks { display: flex; flex-direction: column; gap: 6px; }
.checks label { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.checks input { width: auto; min-height: 0; }

/* Dashboard — EI readiness per-line bars */
.ei-legend { display: flex; gap: var(--space-4); font-size: 12.5px; color: var(--text-muted); flex-wrap: wrap; }
.ei-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: baseline; }
.dot.baseline, .seg.baseline { background: var(--success-600); }
.dot.target, .seg.target { background: var(--warning-600); }
.dot.noinfo, .seg.noinfo { background: var(--neutral-300); }
.ei-lines { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-4); }
.ei-linerow { display: grid; grid-template-columns: 64px 1fr 68px; align-items: center; gap: var(--space-3); }
.ei-linelabel { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.ei-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--neutral-100); }
.ei-bar .seg { height: 100%; }
.ei-linecounts { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.ei-linecounts .c-b { color: var(--success-700); font-weight: 700; }
.ei-linecounts .c-t { color: var(--warning-700); font-weight: 700; }

/* EI matchmaking board */
.mm-collab { margin-bottom: var(--space-4); }
.mm-collab__svg { overflow: auto; max-height: 620px; margin-top: var(--space-3); }
.mm-collab__svg svg { max-width: 100%; height: auto; }
.collab-node { fill: var(--brand-fg); }
.collab-label { fill: var(--text-secondary); font-family: var(--font-sans); font-size: 12px; }
.collab-head { fill: var(--text-muted); font-family: var(--font-sans); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.collab-ribbon { transition: fill-opacity .12s; }
.collab-ribbon:hover { fill-opacity: .85; }
.mm-legend { display: flex; gap: var(--space-4); margin-top: var(--space-3); font-size: 12.5px; color: var(--text-muted); }
.mm-legend span { display: inline-flex; align-items: center; gap: 7px; }
.mm-key { width: 22px; height: 14px; border-radius: 3px; border: 1px solid var(--border); display: inline-block; }
.mm-key--req { background: var(--bg-surface); }
.mm-key--off { background: var(--surface-2); border-left: 3px solid var(--neutral-300); }
.mm-more { margin-top: var(--space-2); }
.mm-more.open { color: var(--brand-fg); }
.mm-other { margin-top: var(--space-2); }
.mm-filters { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.mm-filters select { width: auto; min-width: 150px; }
.mm-filters #f-ind { min-width: 260px; max-width: 420px; }
.mm-filters #f-text { width: auto; flex: 1; min-width: 180px; }
.mm-request.is-unmet { border-left: 3px solid var(--warning-600); }
.mm-request.mm-hidden { display: none; }
body.mm-unmet-only .mm-request:not(.is-unmet) { display: none; }
.mm-request__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.mm-entry { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mm-entry .flag { width: 22px; height: 16px; border-radius: 2px; object-fit: cover; box-shadow: 0 0 0 1px rgba(0,58,93,.10); }
.mm-type { font-size: 12.5px; color: var(--text-muted); }
.mm-desc { margin: var(--space-3) 0 2px; }
.mm-section { margin-top: var(--space-4); }
.mm-section__label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: var(--space-2); }
.mm-offer { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); margin-bottom: var(--space-2); }
.mm-offer.linked { border-left: 3px solid var(--success-600); }
.mm-offer__top { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.mm-offer__desc { font-size: 13.5px; color: var(--text-secondary); margin-top: 4px; white-space: pre-wrap; }
.mm-badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-full); background: var(--chip-bg); color: var(--text-secondary); }
.mm-badge.good { background: var(--brand-subtle-bg); color: var(--brand-subtle-fg); }
.mm-note { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.mm-note input { flex: 1; min-width: 0; min-height: 32px; }

/* EI by-indicator drill-down */
.drill-counts { font-size: 13px; margin-top: 6px; }
.drill-counts .c-b { color: var(--success-700); font-weight: 700; }
.drill-counts .c-t { color: var(--warning-700); font-weight: 700; }
.flag-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: var(--space-2); }
.flag-row__label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-right: 6px; min-width: 62px; }
.flag-row__label.c-b { color: var(--success-700); }
.flag-row__label.c-t { color: var(--warning-700); }
.flag-row .flag { width: 20px; height: 15px; border-radius: 2px; object-fit: cover; box-shadow: 0 0 0 1px rgba(0,58,93,.10); }
.drill-entry-country { display: flex; align-items: center; gap: 6px; }
.drill-entry-country .flag { width: 18px; height: 13px; border-radius: 2px; object-fit: cover; }

/* flag_select — custom member-state dropdown with flags */
.flag-select { position: relative; width: 100%; }
.flag-select__btn {
  width: 100%; text-align: left; font: inherit; min-height: 38px;
  padding: 7px 12px; border: 1px solid var(--neutral-300); border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-primary); cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.flag-select__btn:hover { border-color: var(--primary); }
.flag-select__current { display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.flag-select__caret { color: var(--text-muted); font-size: 11px; flex: 0 0 auto; }
.flag-select__list {
  position: absolute; z-index: 60; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 300px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
}
.flag-select__opt { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; }
.flag-select__opt:hover { background: var(--hover-bg); }
.flag-select img.flag, .flag-select__current img.flag {
  width: 20px; height: 15px; border-radius: 2px; object-fit: cover; flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0,58,93,.10);
}

/* Radio scope chooser (New/Edit user) */
.scope-choice { display: flex; flex-direction: column; gap: var(--space-2); }
.scope-opt { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; }
.scope-opt:hover { border-color: var(--primary); }
.scope-opt input { width: auto; min-height: 0; margin-top: 3px; }
.scope-opt strong { font-weight: 650; font-size: 14px; }
.scope-opt .muted { font-size: 12.5px; }
.scope-opt:has(input:checked) { border-color: var(--primary); background: var(--hover-bg); }

.inline { display: inline; }
.muted { color: var(--text-muted); }
.row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.mono { font-family: var(--font-mono); font-size: 13px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar .spacer, .sidebar .brand { display: none; }
}

/* Workspace discussions */
.hidden { display: none; }
.md { line-height: 1.5; }
.md p:first-child { margin-top: 0; }
.md p:last-child { margin-bottom: 0; }
.md pre { background: var(--surface-2, #f5f5f5); padding: var(--space-2); border-radius: 6px; overflow-x: auto; }
.md code { font-family: ui-monospace, monospace; font-size: 0.9em; }
.md img { max-width: 100%; height: auto; }
.md ul, .md ol { padding-left: 1.4em; }

/* Accessibility (WCAG 2.1 AA) */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  color: inherit;
  border: 2px solid currentColor;
  border-radius: 0 0 6px 0;
}
.skip-link:focus { left: 0; }

/* A visible focus ring for keyboard users on every interactive element. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
#main-content:focus { outline: none; }

/* Screen-reader-only helper text. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ---- Signature: the epi-curve (see DESIGN_SYSTEM.md) ------------------- */
/* A static case-count silhouette in brand blue — legible on both grounds. */
:root { --epi-mark:url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2080%2016'%20fill='%230099D6'%3E%3Crect%20x='0'%20y='11'%20width='8'%20height='5'%20rx='1'/%3E%3Crect%20x='12'%20y='8'%20width='8'%20height='8'%20rx='1'/%3E%3Crect%20x='24'%20y='5'%20width='8'%20height='11'%20rx='1'/%3E%3Crect%20x='36'%20y='0'%20width='8'%20height='16'%20rx='1'/%3E%3Crect%20x='48'%20y='4'%20width='8'%20height='12'%20rx='1'/%3E%3Crect%20x='60'%20y='8'%20width='8'%20height='8'%20rx='1'/%3E%3Crect%20x='72'%20y='11'%20width='8'%20height='5'%20rx='1'/%3E%3C/svg%3E"); }

/* Spot 2 — a short epi-curve rule under the page title. One h1 per page (the
   a11y norm), so this marks the title wherever it sits in the content tree. */
.content h1::after {
  content: ""; display: block; width: 84px; height: 15px; margin-top: 12px;
  background: var(--epi-mark) left center / contain no-repeat;
}
/* Suppress it where a title sits inline beside actions and a rule would crowd. */
.content h1.no-rule::after { content: none; }

/* Spot 1 — the sidebar brand mark. */
.brand .epi-mark {
  width: 32px; height: 20px; flex: 0 0 auto;
  background: var(--epi-mark) left bottom / contain no-repeat;
}

/* Topbar dateline — the mono "as-of" stamp, bulletin style. */
.topbar .dateline {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .02em;
  color: var(--text-secondary); white-space: nowrap;
}
.topbar .dateline .dow { color: var(--text-muted); }
@media (max-width: 640px) { .topbar .dateline { display: none; } }

/* ---- Sign-in: the two-panel hero (Threshold; see DESIGN_SYSTEM.md) ----- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; }
.auth__hero {
  position: relative; overflow: hidden;
  padding: var(--space-8) var(--space-7);
  display: flex; flex-direction: column; justify-content: space-between; gap: var(--space-6);
  background: linear-gradient(160deg, var(--paho-blue-900), var(--paho-blue-700));
  color: #fff;
}
.auth__mark { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 14px; letter-spacing: .04em; }
.auth__mark .epi-mark { width: 30px; height: 18px; filter: brightness(0) invert(1); opacity: .92; }
.auth__title { color: #fff; font-size: 34px; line-height: 1.12; max-width: 15ch; text-wrap: balance; }
/* The InteligentE wordmark — the raised, accented E stands for Epidemic. */
.auth__wordmark { font-size: 52px; letter-spacing: -.02em; max-width: none; }
.auth__e { color: var(--paho-blue-300); }
.auth__thesis { font-size: 15px; opacity: .85; max-width: 42ch; margin-top: var(--space-3); }
.auth__curve { width: 100%; height: 88px; display: block; }
@media (prefers-reduced-motion: no-preference) {
  .auth__curve rect { animation: epi-rise .5s cubic-bezier(.2,.7,.3,1) backwards; transform-origin: bottom; }
  .auth__curve rect:nth-child(even) { animation-delay: .05s; }
}
@keyframes epi-rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.auth__curve rect { fill: rgba(255,255,255,.16); }
.auth__panel { display: grid; place-items: center; padding: var(--space-6); background: var(--bg-app); }
.auth__card { width: 100%; max-width: 360px; }
.login-card__brand { margin-bottom: var(--space-5); }
.login-card__brand img { height: 32px; }
.login-card__brand .subtitle { color: var(--text-muted); font-size: 13px; margin-top: var(--space-2); }
@media (max-width: 800px) {
  .auth { grid-template-columns: 1fr; }
  .auth__hero { display: none; }   /* keep the form front-and-centre on small screens */
}

/* ---- Error pages — a dignified, on-system dead end ---- */
.errpage { min-height: 100vh; display: grid; place-items: center; padding: var(--space-6); background: var(--bg-app); text-align: center; }
.errpage .box { max-width: 420px; }
.errpage .epi-mark { width: 56px; height: 30px; margin: 0 auto var(--space-4); display: block; }
.errpage .code { font-family: var(--font-display); font-size: 56px; font-weight: 600; color: var(--brand-fg); line-height: 1; letter-spacing: -.02em; }
.errpage .msg { color: var(--text-secondary); margin: var(--space-3) 0 var(--space-5); }

/* ---- Atlas: final sweep (see DESIGN_SYSTEM.md) ------------------------- */
/* Flash messages encode severity in form as well as colour — a left stripe. */
.flash { border-left: 3px solid transparent; }
.flash.success { border-left-color: var(--success-600); }
.flash.danger  { border-left-color: var(--danger-600); }
.flash.warning { border-left-color: var(--warning-600); }
.flash.info    { border-left-color: var(--info-600); }

/* Reduced-motion: honour the OS preference everywhere, not just per-effect. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}

/* Small-screen shell: the sidebar already collapses to a scrollable nav rail
   (brand hidden). Just tighten the content gutters so pages breathe on mobile. */
@media (max-width: 820px) {
  .content { padding: var(--space-5) var(--space-4); }
}

/* ---- Compass: persistent in-space navigation (see DESIGN_SYSTEM.md) ---- */
.space-back { display: inline-block; font-size: 13px; color: var(--text-muted); margin-bottom: var(--space-2); }
.space-name { margin-bottom: var(--space-3); }
.space-tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); margin: var(--space-2) 0 var(--space-5);
}
.space-tabs a {
  padding: 9px 14px; font-size: 14px; font-weight: 600; text-decoration: none;
  color: var(--text-secondary); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.space-tabs a:hover { color: var(--brand-fg); }
.space-tabs a.active { color: var(--brand-fg); border-bottom-color: var(--primary); }
.space-tabs .tab-badge { font-size: 11px; font-weight: 700; background: var(--brand-subtle-bg); color: var(--brand-subtle-fg); border-radius: var(--radius-full); padding: 1px 7px; }
/* Section toolbar — subtitle on the left, the section's primary action on the right. */
.section-toolbar { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.section-toolbar .muted { margin: 0; }

/* ---- Confluence: the activity feed (see DESIGN_SYSTEM.md) -------------- */
textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--neutral-300); border-radius: var(--radius-sm); background: var(--bg-surface); color: var(--text-primary); width: 100%; resize: vertical; }
.composer input, .composer textarea { width: 100%; }
.badge.warn { background: var(--warning-050); color: var(--warning-700); }

.feed-filter { display: flex; gap: var(--space-2); margin: var(--space-4) 0; flex-wrap: wrap; }
.feed-filter .chip { font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 5px 14px; border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--bg-surface); color: var(--text-secondary); }
.feed-filter .chip:hover { border-color: var(--primary); color: var(--brand-fg); }
.feed-filter .chip.active { background: var(--brand-subtle-bg); border-color: transparent; color: var(--brand-subtle-fg); }

.feed { display: flex; flex-direction: column; gap: var(--space-3); }
.feed-card { display: flex; gap: var(--space-3); background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); box-shadow: var(--shadow-sm); }
.feed-card__avatar { flex: 0 0 auto; width: 40px; height: 40px; border-radius: var(--radius-full); display: grid; place-items: center; font-family: var(--font-mono); font-size: 13px; font-weight: 700; background: var(--brand-subtle-bg); color: var(--brand-subtle-fg); }
.feed-card__avatar--doc { background: var(--success-050); color: var(--success-700); }
.feed-card__avatar--event { background: var(--warning-050); color: var(--warning-700); }
.feed-card__body { flex: 1; min-width: 0; }
.feed-card__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; }
.feed-card__time { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.feed-card__title { display: inline-block; font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 4px 0 2px; }
.feed-card__snippet { color: var(--text-secondary); font-size: 14px; margin: 4px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.feed-card__meta { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-top: var(--space-2); font-size: 13px; color: var(--text-muted); }
.feed-card__meta a { font-weight: 600; }

.empty { text-align: center; padding: var(--space-7) var(--space-4); color: var(--text-muted); border: 1px dashed var(--border); border-radius: var(--radius-md); }
.empty__mark { display: block; width: 84px; height: 15px; margin: 0 auto var(--space-3); background: var(--epi-mark) center / contain no-repeat; opacity: .55; }

/* Client-side type filtering of the feed. */
.feed.filter-thread .feed-card:not([data-kind="thread"]),
.feed.filter-document .feed-card:not([data-kind="document"]),
.feed.filter-event .feed-card:not([data-kind="event"]) { display: none; }

/* ---- Cartouche: per-row overflow menu (see DESIGN_SYSTEM.md) ----------- */
/* Collapse a wall of row actions into one "Manage" menu (native <details>). */
.table-wrap--menu { overflow: visible; }        /* let the menu escape the table */
.rowmenu { position: relative; display: inline-block; }
.rowmenu > summary { list-style: none; cursor: pointer; }
.rowmenu > summary::-webkit-details-marker { display: none; }
.rowmenu[open] > summary { background: var(--hover-bg); border-color: var(--primary); color: var(--brand-fg); }
.rowmenu__panel {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 190px;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); padding: 4px; display: flex; flex-direction: column;
}
.rowmenu__item {
  display: block; width: 100%; text-align: left; font: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 10px; border: none; background: none; color: var(--text-secondary);
  cursor: pointer; border-radius: var(--radius-sm);
}
.rowmenu__item:hover { background: var(--hover-bg); color: var(--brand-fg); }
.rowmenu__item--danger { color: var(--danger-700); }
.rowmenu__item--danger:hover { background: var(--danger-050); color: var(--danger-700); }

/* ---- Roles matrix (editable permission grid) -------------------------- */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 14px; margin-top: var(--space-3); }
.perm-item { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; padding: 5px 6px; border-radius: var(--radius-sm); cursor: pointer; }
.perm-item:hover { background: var(--hover-bg); }
.perm-item input { width: auto; min-height: 0; }
.perm-item .mono { color: var(--text-secondary); }

/* ---- Sidebar product wordmark (InteligentE) --------------------------- */
.sidebar .brand-name { font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: -.01em; color: var(--text-primary); margin: -6px 0 var(--space-4); padding: 0 var(--space-2); }
.sidebar .brand-name__e { color: var(--primary); }
@media (max-width: 820px) { .sidebar .brand-name { display: none; } }
