/*
 * Responsive layer - loaded LAST on every page (app, admin, auth, landing). Mobile-first; breakpoints 480 / 640 / 768 / 1024 / 1280.
 * Reuses the existing colour variables (light + dark), so nothing here sets a hard-coded theme colour.
 */

/* ============================== 1. foundations ============================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, video { max-width: 100%; height: auto; }
svg { max-width: 100%; }
body { overflow-x: hidden; }
/* Long words, URLs and names wrap instead of pushing the page wider. */
.bubble, .chat-msg, .reply-quote, .chat-title, .member-name, .community-card h3, .community-card .desc, .modal-box h2, .confirm-box,
.report-card, .joined-item, .chat-sidebar-name, .chat-sidebar-preview { overflow-wrap: anywhere; word-break: normal; }
.admin-table td { overflow-wrap: break-word; }   /* break-word (not anywhere) keeps short words like "Davao" whole while a long alias still wraps */
pre, code { max-width: 100%; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-panel .bubble { max-width: 85%; }
.chat-panel .bubble img, .chat-panel .bubble video { max-width: 100%; height: auto; }

/* Fluid type + 16px page gutters on every container. */
h1 { font-size: clamp(1.5rem, 1.1rem + 2vw, 2.25rem); }
.dash-wrap, .admin-main { padding-inline: clamp(16px, 4vw, 32px); }
.dash-wrap { max-width: 1280px; margin-inline: auto; }

/* ============================== 4. community grid: 1 / 2 / 3 columns ============================== */
.community-grid { grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) { .community-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .community-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.community-card { min-width: 0; }
.community-card h3 { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.community-card .desc { display: -webkit-box; -webkit-line-clamp: 4; line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.badge-row { flex-wrap: wrap; }
.badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Topic chips scroll sideways on phones instead of piling up. */
@media (max-width: 639px) {
  .filter-chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; padding-bottom: 6px; margin-inline: -16px; padding-inline: 16px; scroll-snap-type: x proximity; scroll-padding-inline: 16px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); }
  .filter-chips .chip { flex: 0 0 auto; scroll-snap-align: start; }
  .filter-chips::after { content: ""; flex: 0 0 24px; }   /* lets the last chip scroll clear of the fade */
  #pickerQ, #pickerAudience, #pickerCity { width: 100%; max-width: 100%; }
  .community-card .btn, .community-card button, .community-card form { width: 100%; }
}
/* Leave room under the page so the floating "Messages" button never covers the last card. */
.messages-floating-btn { bottom: max(16px, env(safe-area-inset-bottom)); right: max(16px, env(safe-area-inset-right)); }
body:has(.messages-floating-btn) .dash-wrap { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
/* Inside a chat the button would cover the composer: hide it there. */
body:has(.chat-panel.open) .messages-floating-btn { display: none; }

/* ============================== 5. chat ============================== */
.chat-panel { height: 100vh; height: 100dvh; max-width: min(380px, 100%); }
@media (max-width: 768px) {
  .chat-panel { width: 100%; max-width: 100%; }
  .chat-sidebar { max-width: 86vw; }
}
.chat-composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); flex-shrink: 0; }
.chat-composer textarea { font-size: 16px; }   /* 16px stops iOS zooming into the box */
/* No hover-only actions: on touch screens the message menu next to a grouped bubble is always visible. */
@media (hover: none) {
  .chat-msg.grouped .meta { opacity: 1; }
  .chat-msg .msg-actions, .chat-msg .msg-reactions { opacity: 1; visibility: visible; }
  .media-tile-meta { opacity: 1; }
}
/* Lightbox: edge-to-edge on phones (swipe handled in lightbox.js). */
@media (max-width: 640px) {
  .lightbox-body { padding: 0; }
  .lightbox-nav { display: none; }
  .lightbox-media { max-height: calc(100dvh - 130px); border-radius: 0; }
}

/* ============================== 6. modals ============================== */
.modal-box, .warn-modal, .confirm-box { max-width: calc(100vw - 32px); max-height: 90vh; max-height: 90dvh; overflow-y: auto; }
@media (max-width: 480px) {
  .confirm-actions { flex-direction: column-reverse; }
  .confirm-actions .btn, .modal-box .btn { width: 100%; }
}

/* ============================== 3 + 8. touch targets and form fields ============================== */
@media (max-width: 767px), (pointer: coarse) {
  .btn, button.btn, a.btn, .chip, .back-link, .back-to-list, .admin-nav-link, .admin-sidebar-foot button, .modal-close, .chat-sidebar-open, .chat-sidebar-close,
  .attach-btn, .theme-toggle, .report-picker summary, .report-tabs a, .confirm-stay, a.brand, .chat-menu-card button.danger {
    min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center;
  }
  a.brand, .back-link, .back-to-list { justify-content: flex-start; }
  .btn.block, .btn.full { display: flex; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not(.attach-input), select, textarea { min-height: 44px; font-size: 16px; }
  input[type="checkbox"]:not(.nav-check):not(.drawer-check):not(.sr-only), input[type="radio"] { width: 20px; height: 20px; }
  /* Plain text links sitting under forms / in footers: padded so a thumb can hit them. */
  .auth-links a, .form-foot a, .modal-box p a, footer a { display: inline-block; padding-block: 12px; }
  /* Small in-message links keep their look but get a 44px hit area. */
  .msg-actions a, .msg-actions summary, .msg-actions button, .msg-menu summary, .chat-menu summary { position: relative; }
  .msg-actions a::after, .msg-actions summary::after, .msg-actions button::after { content: ""; position: absolute; inset: -12px -8px; }
}
form .field, .form-row { min-width: 0; }
@media (max-width: 639px) {
  .form-grid, .form-row, .two-col { grid-template-columns: 1fr; flex-direction: column; }
  label { display: block; }
  .field-error, .error, .form-error { overflow-wrap: anywhere; }
}

/* ============================== 7. admin ============================== */
@media (max-width: 720px) {
  /* php-compat.css forces the nav to block; restore the tappable strip. */
  .admin-sidebar nav { display: flex; }
  .admin-sidebar-foot button { width: auto; }
  .admin-main { padding-inline: 16px; }
  .report-card-body, .detail-grid, .admin-grid { grid-template-columns: 1fr; }
  .admin-filters, .report-filters, .admin-search { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .admin-filters > *, .report-filters > *, .admin-search > * { width: 100%; }
  .row-actions { flex-direction: column; align-items: stretch; }
  .row-actions .btn, .row-actions form, .row-actions button { width: 100%; }
}
/* Tables become stacked cards on phones; labels come from the column headings (script in layouts/admin). */
.admin-table-wrap { max-width: 100%; -webkit-overflow-scrolling: touch; }
@media (max-width: 767px) {
  .admin-table, .admin-table tbody, .admin-table tr, .admin-table td { display: block; width: 100%; min-width: 0; }
  .admin-table td > * { min-width: 0; overflow-wrap: anywhere; }
  .admin-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .admin-table tr { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; margin-bottom: 12px; }
  .admin-table td { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border: 0; border-bottom: 1px solid var(--line); text-align: right; }
  .admin-table td:last-child { border-bottom: 0; }
  .admin-table td::before { content: attr(data-label); flex: 0 0 38%; text-align: left; font-weight: 600; color: var(--ink-soft); }
  .admin-table td:not([data-label])::before, .admin-table td[data-label=""]::before { content: none; }
}.report-body, .report-message, .scroll-box { max-height: min(60vh, 480px); overflow-y: auto; }
.admin-body { min-height: 100vh; min-height: 100dvh; }
.admin-sidebar { height: 100vh; height: 100dvh; }
@media (max-width: 720px) { .admin-sidebar { height: auto; } }

/* ============================== 9. landing ============================== */
.hero h1, .hero-title { font-size: clamp(2rem, 1.2rem + 4vw, 3.5rem); }
@media (max-width: 639px) {
  .hero-actions, .cta-row, .hero .btn-row { flex-direction: column; align-items: stretch; }
  .hero-actions .btn, .cta-row .btn { width: 100%; }
}

/* ============================== large screens ============================== */
@media (min-width: 1280px) { .dash-wrap { padding-inline: 40px; } }

/* ============================== logo ============================== */
.logo { display: inline-flex; align-items: center; line-height: 0; }
.logo img { display: block; height: auto; max-width: 100%; filter: none !important; }
.logo .logo-lockup-dark, .logo .logo-icon { display: none; }
[data-theme="dark"] .logo .logo-lockup-light { display: none; }
[data-theme="dark"] .logo .logo-lockup-dark { display: block; }
.logo.logo-on-dark .logo-lockup-light { display: none; }
.logo.logo-on-dark .logo-lockup-dark { display: block; }
@media (max-width: 479px) {
  .logo .logo-lockup { display: none !important; }
  .logo .logo-icon { display: block; width: 36px; height: 36px; }
}
.brand, .brand-mini { line-height: 0; }
.banned-brand { justify-content: center; margin-bottom: 16px; }
.logo .logo-lockup { width: 176px; height: 44px; }
.auth-panel .logo .logo-lockup { width: 220px; height: 55px; }

/* ============================== community picture ============================== */
.community-avatar { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.card-icon-glow { overflow: hidden; flex-shrink: 0; }
.chat-head-avatar { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; background: var(--paper); box-shadow: 0 0 0 1px var(--line) inset; color: var(--plum); }
.chat-head-info { min-width: 0; flex: 1; }
.avatar-settings { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.avatar-preview { width: 96px; height: 96px; border-radius: 50%; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; background: var(--paper); box-shadow: 0 0 0 1px var(--line) inset; color: var(--plum); flex: 0 0 auto; }
.avatar-actions { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1 1 200px; }
.avatar-actions form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.avatar-actions input[type="file"] { max-width: 100%; font-size: 16px; }

/* ============================== profile modal: sticky title bar, internal scroll, stacked buttons ============================== */
.modal-box > .modal-head { position: sticky; top: -28px; z-index: 3; margin: -28px -28px 12px; padding: 20px 28px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
@media (max-width: 479px) {
  .modal-box > .modal-head { top: -20px; margin: -20px -20px 12px; padding: 16px 20px 10px; }
  .modal-box { padding: 20px; }
  .modal-box form .btn, .modal-box form button[type="submit"] { width: 100%; }
}


/* ============================== dashboard on phones / in-app browsers (Messenger, Facebook) ============================== */
body { min-height: 100vh; min-height: 100dvh; }
/* Header: logo | toggle + avatar on ONE row, vertically centred, nothing wraps. */
header { gap: 12px; flex-wrap: nowrap; min-height: 64px; }
header .brand { flex: 0 1 auto; min-width: 0; overflow: hidden; align-items: center; }
header .header-right { flex: 0 0 auto; align-items: center; gap: 8px; }
header .profile-chip { padding: 2px; }
@media (max-width: 479px) {
  header { padding: 10px 16px; }
  /* Full lockup (icon + "Lantern Communities") scaled to fit; never the stacked two-line text. */
  header .brand .logo { min-width: 0; max-width: 100%; }
  header .brand .logo .logo-icon { display: none; }
  header .brand .logo .logo-lockup-dark { display: block !important; width: auto; max-width: 100%; height: 40px; }
  header .profile-chip .alias { display: none; }
}
/* Under 360px: icon + "Lantern" only. */
@media (max-width: 359px) {
  header .brand .logo .logo-lockup { display: none !important; }
  header .brand .logo .logo-icon { display: block; width: 32px; height: 32px; flex: 0 0 auto; }
  header .brand .logo::after { content: "Lantern"; margin-left: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-family: var(--font-serif); font-weight: 600; font-size: 19px; line-height: 1.2; color: #E7DAD8; }
}

/* Search + filters: one column on phones, identical 48px controls; two columns from 480px. */
.picker-search { display: grid; grid-template-columns: 1fr; gap: 12px; }
.picker-search input[type="search"], .picker-search select, .picker-search .btn {
  width: 100%; min-width: 0; max-width: 100%; height: 48px; min-height: 48px; font-size: 16px; border-radius: 12px; margin: 0;
  display: flex; align-items: center; justify-content: center; -webkit-appearance: none; appearance: none;
}
.picker-search input[type="search"], .picker-search select { display: block; padding: 0 14px; }
.picker-search select { padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
@media (min-width: 480px) {
  .picker-search { grid-template-columns: 1fr 1fr; }
  .picker-search input[type="search"], .picker-search .btn { grid-column: 1 / -1; }
}
@media (min-width: 768px) {
  .picker-search { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto auto; }
  .picker-search input[type="search"] { grid-column: auto; }
  .picker-search .btn { grid-column: auto; width: auto; padding-inline: 22px; }
}

/* Topic chips: the first chip ("All") starts exactly at the 16px gutter; the fade only covers the right edge. */
@media (max-width: 639px) {
  .chip-section { overflow: hidden; }
  .filter-chips { scroll-padding-inline: 16px; }
}

/* Webview hardening: solid fallbacks where blur isn't supported, prefixed blur, room under the floating Messages button. */
.modal-backdrop { -webkit-backdrop-filter: blur(4px); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .modal-backdrop { background: var(--bg-2a2028-55); }
}
@media (max-width: 767px) {
  .dash-wrap { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }   /* also where :has() is unsupported */
}
/* ============================== admin: drawer nav, forms, logs, chart (shared by every admin page) ============================== */
.admin-topbar, .admin-scrim { display: none; }
.admin-nav-check { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.admin-main { min-width: 0; flex: 1 1 0; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.analytics-grid { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.admin-section-title { font-size: 18px; margin: 24px 0 12px; }
.muted { color: var(--ink-soft); font-weight: 400; }
@media (max-width: 720px) {
  .admin-topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30; padding: 8px 16px; min-height: 60px; color: #fff;
    background: linear-gradient(90deg, var(--bg-573258), var(--bg-a33b50)); }
  .admin-topbar .brand-mini { margin: 0; }
  .admin-burger { display: inline-flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; width: 44px; height: 44px; border-radius: 10px; cursor: pointer;
    border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .1); }
  .admin-burger span { display: block; width: 20px; height: 2px; border-radius: 2px; background: #fff; }
  .admin-nav-check:focus-visible ~ .admin-topbar .admin-burger { outline: 3px solid #fff; outline-offset: 2px; }
  .admin-sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; width: min(280px, 86%); height: 100vh; height: 100dvh; padding: 22px 18px; overflow-y: auto;
    transform: translateX(-105%); transition: transform .25s ease; flex-direction: column; box-shadow: 12px 0 40px rgba(0, 0, 0, .35); }
  .admin-sidebar nav { display: block; overflow: visible; }
  .admin-nav-link { display: block; white-space: normal; margin-bottom: 4px; }
  .admin-sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .2); flex-direction: column; align-items: stretch; }
  .admin-sidebar-foot form, .admin-sidebar-foot button { width: 100%; }
  .admin-nav-check:checked ~ .admin-sidebar { transform: none; }
  .admin-nav-check:checked ~ .admin-scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .5); }
}
@media (prefers-reduced-motion: reduce) { .admin-sidebar { transition: none; } }

/* forms: one column on phones, two from 720px; inputs full width and 44px tall */
.admin-form { display: flex; flex-direction: column; gap: 16px; }
.admin-form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 720px) { .chart-card .admin-form-grid { grid-template-columns: 1fr 1fr; } }
.admin-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.admin-field label { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.admin-field input { width: 100%; min-height: 44px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1.5px solid var(--line); border-radius: 11px; }
.admin-field input:focus { outline: none; border-color: var(--plum); box-shadow: 0 0 0 3px var(--rg-573258-15); }
.admin-field input[aria-invalid="true"] { border-color: var(--rose); }
.admin-field small { color: var(--ink-soft); font-size: 12px; }
.field-error { color: var(--rose); font-size: 12.5px; font-weight: 600; margin: 0; }
.admin-form .btn { align-self: flex-start; min-height: 44px; }
@media (max-width: 479px) { .admin-form .btn { align-self: stretch; } }

/* shared filter bar: stacks on phones */
.report-search select, .report-search input { min-height: 44px; }
@media (max-width: 639px) { .report-search { flex-direction: column; align-items: stretch; } .report-search > *, .report-search label { width: 100%; flex: 0 0 auto !important; } .report-search label input { flex: 1; } .report-tabs { flex-wrap: wrap; } }
.report-tabs a { min-height: 44px; display: inline-flex; align-items: center; }

/* chart */
.chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.chart-head h2 { margin: 0; }
.chart-range { display: flex; gap: 6px; }
.chart-range .btn.active { background: var(--plum-solid); border-color: var(--plum); color: #fff; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; font-size: 12.5px; color: var(--ink-soft); }
.chart-legend .lg::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: currentColor; }
.lg-members::before { color: var(--plum); } .lg-messages::before { color: var(--marigold); } .lg-reports::before { color: var(--rose); }
.chart-stage { width: 100%; min-width: 0; overflow: hidden; }
.chart-stage svg { display: block; max-width: 100%; }
.chart-state { padding: 36px 12px; text-align: center; }
/* ============================== profile picture, bio, account info; topic chips ============================== */
.avatar, .msg-avatar, .member-avatar, .profile-card-avatar, .avatar-preview { overflow: hidden; }
.user-avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.profile-card-bio { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; white-space: pre-line; }
.account-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px 14px; margin: 0 0 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.account-info dt { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }
.account-info dd { margin: 2px 0 0; font-size: 13.5px; overflow-wrap: anywhere; }
.account-info small { color: var(--ink-soft); }
.field textarea { width: 100%; padding: 10px 12px; font: inherit; font-size: 16px; resize: vertical; border: 1.5px solid var(--line); border-radius: 11px; background: var(--card); color: var(--ink); }
/* Topic chips: one tidy scrolling row on every screen, with a fade where more chips are hidden. */
.filter-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; padding-bottom: 6px;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
.filter-chips::-webkit-scrollbar { display: none; }
.filter-chips .chip { flex: 0 0 auto; scroll-snap-align: start; white-space: nowrap; }
@media (min-width: 640px) { .filter-chips { margin-inline: 0; padding-inline: 0; } }
/* ============================== chat: outgoing message bubble (sending / "Not sent" like Messenger) ============================== */
.chat-msg.outbox { display: flex; flex-direction: column; align-items: flex-end; }
.outbox .bubble { opacity: .85; max-width: 85%; }
.outbox.failed .bubble { opacity: 1; box-shadow: 0 0 0 2px var(--rose); }
.outbox-thumb { display: block; max-width: min(240px, 100%); max-height: 200px; border-radius: 10px; margin-bottom: 6px; object-fit: cover; }
.outbox-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.outbox-progress { width: min(240px, 85%); height: 4px; margin-top: 6px; border-radius: 4px; background: var(--line); overflow: hidden; }
.outbox-progress i { display: block; height: 100%; width: 0; background: var(--marigold); transition: width .15s linear; }
.outbox-status { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 4px 10px; margin-top: 4px; font-size: 12.5px; color: var(--ink-soft); }
.outbox.failed .outbox-status { color: var(--rose); font-weight: 600; }
.outbox-icon { width: 16px; height: 16px; border-radius: 50%; background: var(--rose); color: #fff; font-size: 11px; font-weight: 800; line-height: 16px; text-align: center; }
.outbox-btn { font: inherit; font-weight: 700; color: var(--rose); background: transparent; border: 0; padding: 12px 6px; margin: -12px 0; min-height: 44px; cursor: pointer; text-decoration: underline; }
.outbox-btn[hidden], .outbox-icon[hidden], .outbox-progress[hidden] { display: none; }
@media (hover: none) { .outbox-btn { padding-inline: 10px; } }
/* ============================== Discord-style profile card ============================== */
.profile-card { position: relative; }
.profile-card-banner { height: 72px; margin: -4px -4px 0; border-radius: 14px 14px 0 0; background: linear-gradient(110deg, var(--bg-573258), var(--bg-a33b50) 60%, var(--bg-d9694e)); }
.profile-card-head { align-items: flex-end; margin-top: -34px; padding-inline: 6px; position: relative; }
.profile-card-avatar { width: 68px; height: 68px; flex: 0 0 auto; border: 4px solid var(--card); box-shadow: 0 2px 8px rgba(0, 0, 0, .18); font-size: 28px; }
.profile-card-head h2 { margin: 0 0 4px; overflow-wrap: anywhere; }
.profile-card-bio { padding-inline: 6px; }
/* Discover: lighter first paint for long lists */
.community-card { content-visibility: auto; contain-intrinsic-size: auto 260px; }
/* ============================== admin members: compact table + manage drawer ============================== */
.members-table { min-width: 860px; }
.members-table th { white-space: nowrap; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; background: var(--paper); padding: .75rem 1rem; }
.members-table td { padding: .75rem 1rem; vertical-align: middle; font-size: 13.5px; }
.members-table .nowrap, .members-table td.hide-sm { white-space: nowrap; }
.m-member { display: flex; align-items: center; gap: 10px; min-width: 0; }
.m-names { display: flex; flex-direction: column; min-width: 0; }
.m-names strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-email { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); font-size: 12px; }
.mini-avatar { width: 32px; height: 32px; flex: 0 0 auto; border-radius: 50%; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; background: var(--plum-solid); color: #fff; font-size: 13px; font-weight: 700; }
.members-table .member-community-list { display: flex; flex-wrap: nowrap; gap: 6px; max-width: 280px; overflow: hidden; }
.members-table .member-community-badge { flex: 0 1 auto; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.members-table .member-community-badge.more { flex: 0 0 auto; }
#memberTable.is-loading { opacity: .5; pointer-events: none; }
@media (max-width: 767px) {
  .members-table { min-width: 0; }
  .members-table .hide-sm { display: none; }
  .members-table .member-community-list { flex-wrap: wrap; max-width: none; }
  .members-table td { text-align: left; }
  .m-email { max-width: 100%; }
}
body.drawer-open { overflow: hidden; }
.member-drawer { position: fixed; inset: 0; z-index: 200; }
.member-drawer[hidden] { display: none; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(440px, 100%); display: flex; flex-direction: column; background: var(--card); color: var(--ink); box-shadow: -12px 0 40px rgba(0, 0, 0, .3); outline: 0; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.drawer-close { width: 44px; height: 44px; font-size: 26px; line-height: 1; border: 0; background: transparent; color: var(--ink-soft); cursor: pointer; }
.drawer-body { flex: 1; overflow-y: auto; padding: 6px 18px 24px; }
.drawer-sec { padding: 14px 0; border-bottom: 1px solid var(--line); }
.drawer-sec:last-child { border-bottom: 0; }
.drawer-sec h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.drawer-sec .ban-form input, .drawer-sec .ban-form select { min-height: 44px; font-size: 16px; }
.drawer-sec .btn { min-height: 44px; }
@media (prefers-reduced-motion: no-preference) { .drawer-panel { animation: lcDrawerIn .2s ease-out; } }
@keyframes lcDrawerIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
/* ============================== admin analytics (Chart.js) ============================== */
.an-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 12px; margin: 14px 0; }
.an-kpi { padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-soft); min-width: 0; }
.an-kpi-num { font-family: var(--font-serif); font-size: 1.75rem; line-height: 1.1; color: var(--plum); }
.an-kpi-label { margin-top: 4px; font-size: 12.5px; font-weight: 700; color: var(--ink); }
.an-kpi-note { margin-top: 2px; font-size: 12px; color: var(--ink-soft); }
.an-kpi-note.up { color: var(--sage); } .an-kpi-note.down { color: var(--rose); }
.an-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 16px; }
.an-grid .chart-card { margin: 0; min-width: 0; }
.an-grid h2 { font-size: 15px; margin: 0 0 10px; }
.an-canvas { position: relative; height: 260px; }
.an-table-wrap { max-height: 300px; overflow: auto; }
.an-table-wrap .admin-table { min-width: 0; }
@media (max-width: 479px) { .an-canvas { height: 220px; } }
/* ============================== admin: member drawer (brand surfaces) ============================== */
.drawer-panel { width: min(420px, 100vw); background: var(--paper); color: var(--ink); border-left: 1px solid var(--line); }
.drawer-head { position: sticky; top: 0; z-index: 2; background: var(--card); border-bottom: 1px solid var(--line); gap: 10px; }
.drawer-title { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.drawer-title h2 { color: var(--plum); }
.drawer-title .status-pill { font-size: 11px; }
.drawer-back { display: none; min-height: 44px; padding: 0 6px; font: inherit; font-weight: 700; color: var(--plum); background: transparent; border: 0; cursor: pointer; }
.drawer-body { padding: 4px 16px 28px; background: var(--paper); }
.drawer-sec { margin: 12px 0; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.drawer-sec h3 { color: var(--plum); }
.drawer-sec.danger-zone { border-color: var(--rose); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.chip-btn { min-height: 40px; padding: 0 14px; font: inherit; font-size: 13px; font-weight: 700; color: var(--ink); background: transparent; border: 1.5px solid var(--line); border-radius: 999px; cursor: pointer; }
.chip-btn.small { min-height: 32px; padding: 0 10px; font-size: 12px; color: var(--ink-soft); }
.chip-btn:hover { border-color: var(--plum-soft); }
.chip-btn.active { background: var(--plum-solid); border-color: var(--marigold); color: #fff; }
.ban-form2 { display: flex; flex-direction: column; gap: 8px; }
.ban-form2 .ban-custom { display: flex; gap: 8px; }
.ban-form2 .ban-custom[hidden] { display: none; }
.ban-form2 .ban-custom input { width: 90px; }
.ban-form2 textarea, .ban-form2 input, .ban-form2 select { font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; box-sizing: border-box; }
.ban-form2 .ban-custom select { flex: 1; }
.ban-reason-label { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.ban-submit { width: 100%; min-height: 46px; color: #fff; background: var(--bg-a33b50, #a33b50); border: 0; border-radius: 11px; font-weight: 700; cursor: pointer; }
.ban-submit:hover { filter: brightness(1.1); }
.ban-count { margin: 10px 0 4px; font-size: 13px; color: var(--ink-soft); }
.mini-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.mini-dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 10px; font-size: 13.5px; }
.mini-dl dt { color: var(--ink-soft); font-weight: 600; } .mini-dl dd { margin: 0; }
.drawer-sec .btn.block { width: 100%; justify-content: center; }
@media (max-width: 767px) {
  .drawer-panel { width: 100%; border-left: 0; }
  .drawer-back { display: inline-flex; align-items: center; }
  .drawer-close { display: none; }
}

/* ============================== admin dark mode: brand tokens only ============================== */
[data-theme="dark"] .stat-card:nth-child(n) { background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--marigold); }
[data-theme="dark"] .stat-card:nth-child(3n+2) { border-top-color: var(--plum-soft); }
[data-theme="dark"] .stat-card:nth-child(3n+3) { border-top-color: var(--rose); }
[data-theme="dark"] .stat-num { color: var(--plum); }
[data-theme="dark"] .stat-label { color: var(--ink-soft); }
[data-theme="dark"] .admin-table-wrap { background: var(--card); border-color: var(--line); }
[data-theme="dark"] .admin-table th, [data-theme="dark"] .members-table th { background: var(--lavender-soft); color: var(--ink-soft); border-bottom-color: var(--line); }
[data-theme="dark"] .admin-table td { border-bottom-color: var(--line); color: var(--ink); }
[data-theme="dark"] .admin-table td strong { color: var(--plum); }
[data-theme="dark"] .admin-table tbody tr:hover { background: color-mix(in srgb, var(--plum-solid) 22%, transparent); }
[data-theme="dark"] .type-pill { background: var(--lavender-soft); color: var(--plum); border: 1px solid var(--line); }
[data-theme="dark"] .status-pill.active { background: color-mix(in srgb, var(--sage) 18%, transparent); color: var(--sage); }
[data-theme="dark"] .status-pill.paused, [data-theme="dark"] .status-pill.banned { background: color-mix(in srgb, var(--rose) 18%, transparent); color: var(--rose); }

/* ============================== admin account: two cards, 1 column under 900px ============================== */
.account-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 900px) { .account-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.account-grid > * { min-width: 0; }
.account-grid .admin-form-grid { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1500px) { .account-grid .admin-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.account-grid input { max-width: 100%; }
.drawer-body .member-community-list { flex-wrap: wrap; max-width: none; overflow: visible; }
.drawer-body .member-community-badge { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.drawer-body { overflow-x: hidden; }

/* ============================== analytics layout (12 columns), KPI chips, chart cards ============================== */
.an .chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 12px; margin: 0 0 16px; }
.an-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0 0 24px; }
@media (min-width: 640px) { .an-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .an-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.an-kpi { padding: 12px 14px; min-height: 88px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.an-kpi-num { font-size: 1.6rem; }
.an-kpi-label { margin: 0; }
.an-chip { display: inline-flex; align-items: center; gap: 4px; align-self: flex-start; margin-top: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; line-height: 1.5; white-space: nowrap; max-width: 100%; }
.an-chip.good { color: var(--sage); background: color-mix(in srgb, var(--sage) 16%, transparent); }
.an-chip.bad { color: var(--rose); background: color-mix(in srgb, var(--rose) 16%, transparent); }
.an-chip.flat { color: var(--ink-soft); background: color-mix(in srgb, var(--ink-soft) 12%, transparent); }
.an-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 24px; }
.an-grid .chart-card { grid-column: 1 / -1; display: flex; flex-direction: column; margin: 0; min-width: 0; padding: 18px 20px; }
@media (min-width: 900px) { .an-grid .an-c8 { grid-column: span 8; } .an-grid .an-c4 { grid-column: span 4; } .an-grid .an-c6 { grid-column: span 6; } }
.an-canvas { position: relative; height: 280px; width: 100%; }
.an-canvas.is-empty canvas { visibility: hidden; }
.an-empty { height: 280px; margin: 0; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--ink-soft); font-size: 14px; border: 1px dashed var(--line); border-radius: 12px; }
.an-canvas.is-empty { display: none; }
@media (max-width: 639px) { .an-canvas, .an-empty { height: 220px; } .an-grid { gap: 16px; } .an-grid .chart-card { padding: 14px; } }
.an-table-wrap { max-height: 320px; overflow: auto; }
.an-empty[hidden] { display: none; }

.an-kpi { padding: 9px 14px; min-height: 0; gap: 0; }
.an-kpi-num { font-size: 1.45rem; line-height: 1.1; }
.an-kpi-label { font-size: 12px; line-height: 1.3; }
.an-chip { margin-top: 3px; }

.an-grid { margin-bottom: 24px; }

/* ============================== z-index scale (one place) ============================== */
/* Anchor offset must equal nav height exactly. Do not add extra pixels or the previous section shows under the nav.
   --nav-h is the ONLY place the offset is defined: the fallback here, then measured from the real sticky bar (landing.js / layouts/app). */
:root { --nav-h: 65px; --z-float: 50; --z-nav: 100; --z-drawer: 200; --z-modal: 300; --z-toast: 400; }
header, .site-header, .admin-topbar { z-index: var(--z-nav); }
.messages-floating-btn { z-index: var(--z-float); }
.theme-toggle { z-index: 60; }
.chat-backdrop { z-index: calc(var(--z-drawer) - 10); }
.chat-panel, .joined-drawer, .member-drawer { z-index: var(--z-drawer); }
.admin-sidebar { z-index: var(--z-drawer); }
.modal-backdrop, .warn-modal-backdrop, .confirm-backdrop, .a-modal-backdrop { z-index: var(--z-modal); }
.confirm-backdrop, .lightbox { z-index: calc(var(--z-modal) + 10); }
.toast, .lc-toast { z-index: var(--z-toast); }
@media (max-width: 720px) { .admin-nav-check:checked ~ .admin-scrim { z-index: calc(var(--z-drawer) - 10); } .admin-topbar { z-index: var(--z-nav); } }
/* sticky bars are fully opaque: nothing shows through or peeks out below them */
header, .site-header, .admin-topbar { backdrop-filter: none; -webkit-backdrop-filter: none; }
html { scroll-padding-top: var(--nav-h); scroll-behavior: smooth; }   /* scroll-margin-top stays 0: margin and padding ADD UP, so setting both would double the offset */

/* ============================== auth pages: one screen on laptops, normal scrolling elsewhere ============================== */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; justify-items: center; align-items: start; box-sizing: border-box; padding: clamp(16px, 3vh, 32px) 20px; }
.auth-shell, .help-shell { margin-block: auto; }
.auth-wrap > .back-link { position: absolute; }
.auth-form-side .form-switch.mod-link { margin-top: 4px; font-size: 12px; color: var(--ink-soft); text-align: center; }
.auth-form-side .form-switch { margin-top: 10px; text-align: center; }
@media (min-width: 900px) and (min-height: 700px) {
  .auth-wrap:has(.compact-form) { padding-block: 16px; }
  .auth-shell:has(.compact-form) { max-width: 960px; }
  .auth-shell:has(.compact-form) .auth-panel { padding: 28px 28px; gap: 12px; justify-content: center; }
  .auth-shell:has(.compact-form) .auth-panel h1 { font-size: clamp(22px, 2.4vw, 26px); }
  .auth-shell:has(.compact-form) .auth-panel-sub { font-size: 13px; }
  .auth-form-side:has(.compact-form) { padding: clamp(16px, 2.4vh, 24px) 28px; }
  .auth-form-side:has(.compact-form) h1 { font-size: 22px; margin: 0 0 2px; }
  .auth-form-side:has(.compact-form) .auth-sub { margin-bottom: 8px; }
  .compact-form .field { margin-bottom: 12px; }
  .compact-form .field label { margin-bottom: 3px; }
  .compact-form .field input:not([type="checkbox"]):not([type="radio"]), .compact-form .combobox input { height: 44px; min-height: 44px; padding-block: 0; }
  .compact-form .field-row { gap: 12px; }
  .compact-form .btn.block { min-height: 44px; margin-top: 4px; }
}
/* The floating dark-mode toggle on auth / content pages scrolls away with the page (absolute, takes no layout space) so it never covers form fields. */
.theme-toggle-float { position: absolute; }

/* ============================== "Your data" page ============================== */
.your-data h2 { margin: 22px 0 6px; font-size: 17px; }
.owned-community { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.owned-community strong { flex: 1 1 100%; overflow-wrap: anywhere; }
.owned-community form { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.owned-community select { min-height: 44px; padding: 0 10px; font-size: 16px; color: var(--ink); background: var(--card); border: 1.5px solid var(--line); border-radius: 10px; max-width: 100%; }
.btn.danger-delete { color: #fff; background: var(--bg-a33b50, #a33b50); border: 0; }
.auth-wrap:has(.your-data) { padding-top: 72px; }   /* clears the back link and theme button */
.your-data .btn.secondary { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.your-data a { color: var(--plum); font-weight: 700; }
.owned-community > a { flex: 1 1 100%; }

/* Chat message actions: Reply and React sit on one line, same height and alignment (touch screens get 44px rows). */
.msg-actions { display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 14px; }
.msg-actions > a, .msg-actions .react-picker > summary { display: inline-flex; align-items: center; gap: 4px; min-height: 28px; margin: 0; padding: 0 2px; line-height: 1; white-space: nowrap; list-style: none; }
.msg-actions > .react-picker { margin: 0; display: block; }
.msg-actions .react-picker > summary .icon { vertical-align: 0; }
@media (max-width: 767px), (pointer: coarse) {
  .msg-actions > a, .msg-actions .react-picker > summary { min-height: 44px; min-width: 44px; justify-content: center; }
  .msg-actions > a::after, .msg-actions .react-picker > summary::after { content: none; }   /* the row itself is now the hit area */
}

/* ============================== phone + landscape polish ============================== */
/* Chat header on phones: give the name the room; details stay on one line. */
.chat-head-info .hint { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 479px) {
  .chat-head { gap: 4px; padding: 8px 8px 8px 4px; }
  .chat-head-avatar { width: 32px; height: 32px; }
  .chat-head h2.chat-title { font-size: 16px; }
  .chat-head .hint { font-size: 12px; }
}
/* Short screens (landscape phones): slim header and composer so the messages keep most of the height. */
@media (max-height: 500px) {
  .chat-head { padding-block: 4px; }
  .chat-head-info .hint { display: none; }
  .chat-head-avatar { width: 30px; height: 30px; }
  .chat-composer { padding-block: 6px calc(6px + env(safe-area-inset-bottom)); }
  .chat-composer textarea { max-height: 80px; }
  header { min-height: 52px; padding-block: 4px; }
  .messages-floating-btn .emoji-stack { display: none; }
}
/* File pickers: styled like the other controls and never wider than their box. */
input[type="file"]:not(.attach-input) { width: 100%; max-width: 100%; min-width: 0; font: inherit; font-size: 13px; color: var(--ink-soft); }
input[type="file"]:not(.attach-input)::file-selector-button { min-height: 40px; margin-right: 10px; padding: 0 14px; font: inherit; font-weight: 700; color: var(--plum); background: var(--card); border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer; }
/* The floating Messages button covers less of the cards on phones. */
@media (max-width: 479px) {
  .messages-floating-btn { padding: 8px 14px; gap: 8px; }
  .messages-floating-btn .emoji-stack { display: none; }
}
/* Very narrow screens: content pages start below the back link and theme button. */
@media (max-width: 479px) { .auth-wrap:has(.help-shell) { padding-top: 72px; } }

/* Confirm-your-email page */
.verify-card strong { overflow-wrap: anywhere; }
.verify-change { margin-top: 16px; }
.verify-change summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 700; color: var(--plum); }
.verify-out { margin-top: 8px; text-align: center; }
.verify-out .link-button { min-height: 44px; }
.verify-card .btn.secondary { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
