/* SHARED_NETWORKING — themeable stylesheet (W0 contract §10).
 * Constraints (DEV_GUIDE): rem-only sizing; light/dark
 * paired selectors, theme deferred to the shared header (NO page-level toggle);
 * #4 modals max-height 85vh + 85dvh (fixed head/foot, scrollable body); #6 touch targets
 * >= 2.75rem; mobile-first from a 22.5rem base. EVERY accent surface uses
 * var(--net-accent); tints use color-mix so ONE variable cascades.
 *
 * BRAND INHERITANCE (OPT-IN): when the consuming site sets
 * NetworkingConfig.inherit_site_theme=True, render_page() links SHARED_AUTH's
 * generated per-site stylesheet (/auth/api/branding/theme.css) LAST, and the
 * accent variables below read the site's brand from its --site-* custom
 * properties. Every var() keeps the previous hardcoded literal as its
 * fallback, so a page WITHOUT that stylesheet — every unopted site, plus any
 * opted site the hub serves the neutral stub to — computes exactly as before
 * this change. Unopted sites additionally keep the O11 inline accent block
 * (<style>:root { --net-accent: ... }</style>, substituted server-side from
 * config.accent_color), which loads after this sheet and therefore still wins
 * the cascade at equal specificity, exactly as it always has. */

:root {
  /* --site-accent-fill is the luminance-clamped fill that --site-on-accent is
   * guaranteed to clear WCAG AA against; --site-accent (raw brand) is NOT safe
   * under text. --site-accent-ink is the brand as TEXT on a plain surface
   * (proven against the reference surfaces only — NOT against tints, which is
   * why .net-avatar/.net-role-tag switch to the fill+on-accent pair when the
   * site tokens are present). */
  --net-accent: var(--site-accent-fill, #8b5cf6);
  --net-accent-ink: var(--site-accent-ink, var(--net-accent));
  --net-bg: #f7f8fa;
  --net-surface: #ffffff;
  --net-surface-2: #f1f3f7;
  --net-border: #e3e7ee;
  --net-text: #1b2330;
  --net-text-muted: #5a6679;
  --net-danger: #dc2626;
  --net-on-accent: var(--site-on-accent, #ffffff);
  --net-radius: 0.75rem;
  --net-radius-sm: 0.5rem;
  --net-gap: 1rem;
  --net-header-gap: 3.75rem;             /* shared header height (standalone) */
  --net-touch: 2.75rem;                  /* min touch target */
}

/* Dark theme — paired selectors (documentElement carries .dark AND [data-theme]). */
html.dark, html[data-theme="dark"] {
  --net-bg: #0f141c;
  --net-surface: #161d28;
  --net-surface-2: #1d2632;
  --net-border: #2a3543;
  --net-text: #e8edf5;
  --net-text-muted: #9aa7ba;
  --net-danger: #f87171;
  --net-on-accent: var(--site-on-accent, #ffffff);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding-top: var(--net-header-gap);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--net-text);
  background: var(--net-bg);
  -webkit-text-size-adjust: 100%;
}

/* Embedded in the workspace iframe: the parent supplies header chrome; drop our
 * top gap so content is not double-offset. Keys on the embedded marker classes
 * the parent (content-loader.js) AND our pre-paint script set on documentElement. */
html.hh-embedded body,
html.dashboard-embedded body { padding-top: 0; }

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

/* Visually-hidden (labels for inputs — DEV_GUIDE #17). */
.net-vh {
  position: absolute; width: 0.0625rem; height: 0.0625rem;
  padding: 0; margin: -0.0625rem; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.net-app {
  max-width: 64rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
}

.net-head { margin-bottom: 1rem; }
.net-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 0.25rem; }
.net-sub { margin: 0; color: var(--net-text-muted); font-size: 0.9375rem; }

/* -------- stats bar -------- */
.net-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.625rem;
  margin-bottom: 1.25rem;
}
.net-stat {
  background: var(--net-surface);
  border: 0.0625rem solid var(--net-border);
  border-radius: var(--net-radius);
  padding: 0.875rem 1rem;
  display: flex; flex-direction: column; gap: 0.125rem;
}
.net-stat-num { font-size: 1.375rem; font-weight: 700; color: var(--net-accent-ink); }
.net-stat-label { font-size: 0.8125rem; color: var(--net-text-muted); }
.net-stat-health { grid-column: 1 / -1; }
.net-stat-health .net-stat-num { color: var(--net-text); }

/* -------- tabs -------- */
.net-tabs {
  display: flex; gap: 0.25rem; border-bottom: 0.0625rem solid var(--net-border);
  margin-bottom: 1.25rem; overflow-x: auto;
}
.net-tab {
  appearance: none; background: transparent; border: 0;
  border-bottom: 0.1875rem solid transparent;
  padding: 0.75rem 1rem; min-height: var(--net-touch);
  font-size: 0.9375rem; font-weight: 600; color: var(--net-text-muted);
  cursor: pointer; position: relative; flex: 0 0 auto;
}
/* Selected-tab underline is a NON-TEXT indicator: opted sites use
 * --site-accent-strong (>= 3.0 guaranteed against the theme bg); the fallback
 * keeps the exact pre-theming accent for unopted pages. Same rule for focus
 * rings and the selected-thread border below. */
.net-tab[aria-selected="true"] { color: var(--net-accent-ink); border-bottom-color: var(--site-accent-strong, var(--net-accent)); }
.net-tab:hover { color: var(--net-text); }
.net-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.125rem; height: 1.125rem; padding: 0 0.3125rem; margin-left: 0.375rem;
  font-size: 0.6875rem; font-weight: 700; line-height: 1;
  color: var(--net-on-accent); background: var(--net-accent); border-radius: 999rem;
}

.net-panel { animation: net-fade 0.18s ease; }
@keyframes net-fade { from { opacity: 0; } to { opacity: 1; } }

/* -------- toolbar / search / filter -------- */
.net-toolbar { display: flex; gap: 0.625rem; margin-bottom: 1rem; flex-wrap: wrap; }
.net-search, .net-filter { flex: 1 1 13.75rem; }
.net-search input, .net-filter select {
  width: 100%; min-height: var(--net-touch);
  padding: 0.5rem 0.875rem; font-size: 0.9375rem;
  color: var(--net-text); background: var(--net-surface);
  border: 0.0625rem solid var(--net-border); border-radius: var(--net-radius-sm);
}
.net-search input:focus, .net-filter select:focus {
  outline: 0.125rem solid var(--site-accent-strong, var(--net-accent)); outline-offset: 0.0625rem; border-color: var(--site-accent-strong, var(--net-accent));
}

/* -------- discover grid + cards -------- */
.net-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
.net-card {
  background: var(--net-surface);
  border: 0.0625rem solid var(--net-border);
  border-radius: var(--net-radius);
  padding: 1rem;
  display: flex; gap: 0.875rem; align-items: flex-start;
}
.net-avatar {
  flex: 0 0 auto; width: 3rem; height: 3rem; border-radius: 999rem;
  /* Ink-on-TINT is NOT a proven pair: measured across all 25 fleet brands,
   * --site-accent-ink on a 14% fill wash bottoms out at 3.75:1. Opted sites
   * therefore render the avatar as a solid FILL chip with its guaranteed
   * >= 4.5:1 --site-on-accent ink; unopted pages (no --site-* defined) keep
   * the original 14% tint + accent initials via the fallbacks, unchanged. */
  background: var(--site-accent-fill, color-mix(in srgb, var(--net-accent) 14%, transparent));
  color: var(--site-on-accent, var(--net-accent)); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.125rem; overflow: hidden;
}
.net-avatar img { width: 100%; height: 100%; object-fit: cover; }
.net-card-body { flex: 1 1 auto; min-width: 0; }
.net-card-name {
  font-weight: 600; font-size: 1rem; display: flex; align-items: center;
  gap: 0.375rem; flex-wrap: wrap; overflow-wrap: anywhere;
}
.net-card-meta { font-size: 0.8125rem; color: var(--net-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.net-role-tag {
  font-size: 0.6875rem; font-weight: 600; padding: 0.0625rem 0.4375rem; border-radius: 999rem;
  /* Same ink-on-tint rule as .net-avatar: opted sites get a solid fill chip
   * (proven on-accent pair); unopted keep the 12% tint + accent text. */
  color: var(--site-on-accent, var(--net-accent));
  background: var(--site-accent-fill, color-mix(in srgb, var(--net-accent) 12%, transparent));
  max-width: 100%; overflow-wrap: anywhere;
}
.net-signal { font-size: 0.75rem; color: var(--net-text-muted); margin-top: 0.125rem; }
.net-card-action { flex: 0 0 auto; display: flex; flex-direction: column; gap: 0.5rem; }

/* -------- connection / thread list rows -------- */
.net-subtabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; flex-wrap: wrap; }
.net-subtab {
  appearance: none; cursor: pointer; min-height: var(--net-touch);
  padding: 0.5rem 0.875rem; font-size: 0.875rem; font-weight: 600;
  color: var(--net-text-muted); background: var(--net-surface-2);
  border: 0.0625rem solid var(--net-border); border-radius: 999rem;
}
.net-subtab[aria-selected="true"],
.net-subtab[aria-pressed="true"] { color: var(--net-on-accent); background: var(--net-accent); border-color: var(--net-accent); }

.net-list { display: flex; flex-direction: column; gap: 0.5rem; }
.net-row {
  display: flex; gap: 0.875rem; align-items: center;
  background: var(--net-surface); border: 0.0625rem solid var(--net-border);
  border-radius: var(--net-radius); padding: 0.75rem 1rem;
}
.net-row .net-card-body { display: flex; flex-direction: column; }
.net-row-actions { display: flex; gap: 0.5rem; flex: 0 0 auto; }

/* -------- buttons -------- */
.net-btn {
  appearance: none; cursor: pointer; min-height: var(--net-touch);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 600;
  border-radius: var(--net-radius-sm); border: 0.0625rem solid transparent;
  transition: background 0.12s ease, opacity 0.12s ease;
  white-space: nowrap;
}
.net-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.net-btn-primary { color: var(--net-on-accent); background: var(--net-accent); }
.net-btn-primary:hover:not(:disabled) { background: var(--site-accent-hover, color-mix(in srgb, var(--net-accent) 88%, black)); }
.net-btn-ghost { color: var(--net-text); background: var(--net-surface-2); border-color: var(--net-border); }
.net-btn-ghost:hover:not(:disabled) { background: color-mix(in srgb, var(--net-accent) 10%, var(--net-surface-2)); }
.net-btn-danger { color: var(--net-on-accent); background: var(--net-danger); }
.net-btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--net-danger) 88%, black); }
.net-btn-icon { min-width: var(--net-touch); padding: 0.5rem; font-size: 1.25rem; }

/* -------- pager -------- */
.net-pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.25rem; flex-wrap: wrap; }
.net-pageinfo { font-size: 0.8125rem; color: var(--net-text-muted); }

.net-empty { padding: 2.5rem 1rem; text-align: center; color: var(--net-text-muted); font-size: 0.9375rem; }

/* -------- messages -------- */
.net-messages { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.net-threads { display: flex; flex-direction: column; gap: 0.5rem; max-height: 28rem; overflow-y: auto; }
.net-thread {
  display: flex; gap: 0.75rem; align-items: center; cursor: pointer;
  background: var(--net-surface); border: 0.0625rem solid var(--net-border);
  border-radius: var(--net-radius); padding: 0.75rem; min-height: var(--net-touch);
}
.net-thread[aria-current="true"] { border-color: var(--site-accent-strong, var(--net-accent)); background: color-mix(in srgb, var(--net-accent) 8%, var(--net-surface)); }
.net-thread-body { flex: 1 1 auto; min-width: 0; }
.net-thread-name { font-weight: 600; font-size: 0.9375rem; }
.net-thread-preview { font-size: 0.8125rem; color: var(--net-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.net-thread-unread {
  flex: 0 0 auto; min-width: 1.25rem; height: 1.25rem; padding: 0 0.375rem;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.6875rem; font-weight: 700; color: var(--net-on-accent);
  background: var(--net-accent); border-radius: 999rem;
}
.net-thread-more { display: flex; justify-content: center; padding: 0.5rem 0; }
.net-conv {
  display: flex; flex-direction: column;
  background: var(--net-surface); border: 0.0625rem solid var(--net-border);
  border-radius: var(--net-radius); min-height: 24rem;
}
.net-conv-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; border-bottom: 0.0625rem solid var(--net-border); }
.net-conv-name { font-weight: 600; }
.net-conv-back { display: none; }
.net-conv-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; max-height: 24rem; }
.net-load-earlier { align-self: center; }
.net-msg { max-width: 80%; padding: 0.5rem 0.75rem; border-radius: var(--net-radius); font-size: 0.9375rem; word-wrap: break-word; }
.net-msg-in { align-self: flex-start; background: var(--net-surface-2); color: var(--net-text); }
.net-msg-out { align-self: flex-end; background: var(--net-accent); color: var(--net-on-accent); }
.net-msg-time { display: block; font-size: 0.6875rem; opacity: 0.7; margin-top: 0.125rem; }
.net-compose { display: flex; gap: 0.5rem; padding: 0.75rem; border-top: 0.0625rem solid var(--net-border); align-items: flex-end; }
.net-compose textarea {
  flex: 1 1 auto; resize: none; min-height: var(--net-touch); max-height: 9rem;
  padding: 0.5rem 0.75rem; font: inherit; font-size: 0.9375rem;
  color: var(--net-text); background: var(--net-bg);
  border: 0.0625rem solid var(--net-border); border-radius: var(--net-radius-sm);
}
.net-compose textarea:focus { outline: 0.125rem solid var(--site-accent-strong, var(--net-accent)); outline-offset: 0.0625rem; }

.net-help { margin-top: 2rem; text-align: center; font-size: 0.875rem; }

/* -------- modal (delete confirmations — DEV_GUIDE #4/#18) -------- */
.net-modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.net-modal {
  width: 100%; max-width: 26rem; max-height: 85vh; max-height: 85dvh;
  display: flex; flex-direction: column;
  background: var(--net-surface); border-radius: var(--net-radius);
  border: 0.0625rem solid var(--net-border); overflow: hidden;
}
.net-modal-head { flex: 0 0 auto; padding: 1rem 1.25rem; border-bottom: 0.0625rem solid var(--net-border); }
.net-modal-title { margin: 0; font-size: 1.125rem; font-weight: 700; }
.net-modal-body { flex: 1 1 auto; overflow-y: auto; padding: 1.25rem; color: var(--net-text-muted); white-space: pre-line; }
.net-modal-foot { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 0.625rem; padding: 1rem 1.25rem; border-top: 0.0625rem solid var(--net-border); flex-wrap: wrap; }

/* -------- toast -------- */
.net-toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 60;
  width: calc(100% - 2rem); max-width: 22rem; padding: 0.75rem 1.125rem;
  background: var(--net-text); color: var(--net-bg);
  border-radius: var(--net-radius-sm); font-size: 0.875rem; box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.25);
}

/* -------- responsive: tablet/desktop -------- */
@media (min-width: 40rem) {
  .net-stats { grid-template-columns: repeat(5, 1fr); }
  .net-stat-health { grid-column: auto; }
  .net-grid { grid-template-columns: repeat(2, 1fr); }
  .net-messages { grid-template-columns: 20rem 1fr; align-items: start; }
  .net-threads { max-height: 32rem; }
}
@media (min-width: 60rem) {
  .net-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Mobile messaging: on a narrow viewport opening a conversation hides the thread
 * list, so the conversation MUST expose a back control (else the user is trapped
 * with no way back to the thread list). */
@media (max-width: 39.99rem) {
  .net-conv-back { display: inline-flex; }
  .net-messages.is-conversation-open .net-threads { display: none; }
  .net-row { flex-wrap: wrap; }
  .net-row-actions { flex: 1 1 100%; flex-wrap: wrap; }
  .net-row-actions .net-btn { flex: 1 1 auto; }
  .net-card { flex-wrap: wrap; }
  .net-card-action { width: 100%; }
  .net-card-action .net-btn { width: 100%; }
}

html.hh-embedded .net-messages,
html.dashboard-embedded .net-messages {
  min-height: min(38rem, calc(100vh - 10rem));
}
html.hh-embedded .net-conv,
html.dashboard-embedded .net-conv {
  min-height: min(34rem, calc(100vh - 12rem));
}
html.hh-embedded .net-conv-body,
html.dashboard-embedded .net-conv-body {
  max-height: none;
}

/* Reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .net-panel { animation: none; }
  .net-btn { transition: none; }
}
