/* =========================================================
   Friending Admin — styles
   Brand accent: cyan from cat.svg (#8CFDFD)
   ========================================================= */

:root {
    /* Lets the browser style native widgets (scrollbars, date picker
       popup, autofill) appropriately. Flipped by the theme override. */
    color-scheme: dark;

    --bg:        #0a0d12;
    --surface:   #12161e;
    --card:      #171c25;
    --card-2:    #1d2330;
    --border:    #252c3a;
    --border-2:  #2f3849;

    --text:      #eef2f8;
    --muted:     #8b94a7;
    --muted-2:   #5b6377;

    --accent:    #8CFDFD;
    --accent-dim: rgba(140, 253, 253, 0.14);
    --accent-glow: rgba(140, 253, 253, 0.32);
    --accent-ink: #06343a;

    --ok:        #46d39a;
    --warn:      #ffb455;
    --danger:    #ff6b6b;

    --radius:    14px;
    --radius-sm: 10px;
    --shadow:    0 18px 48px -16px rgba(0, 0, 0, 0.6);

    --sidebar-w: 248px;

    /* Body background radial-glow tint. Cyan in dark, neutral in light. */
    --body-glow: rgba(140, 253, 253, 0.05);
    /* Sidebar uses a darker gradient than the body bg in dark mode. */
    --sidebar-bg: linear-gradient(180deg, #11151c 0%, #0c1018 100%);
    /* Map tile filter — darken OSM tiles to fit dark theme. Light mode clears it. */
    --map-tile-filter: brightness(0.85) saturate(0.9);
    --map-empty-bg: #0d1116;
    --avatar-placeholder: linear-gradient(135deg, #1f2532 0%, #161b25 100%);
    --leaflet-attrib-bg: rgba(15, 18, 24, 0.7);

    /* Brand/category text colors that need adjusting on light bg. */
    --purple:        #b894ff;
    --purple-text:   #c9b3ff;
    --gold:          #ffd060;
    --gold-ink:      #2a1d00;
}

/* =========================================================
   Light theme — opt-in via <html data-theme="light">
   Keeps the cyan brand identity but swaps surfaces, text and
   accent contrast so cyan text on white is readable.
   ========================================================= */
[data-theme="light"] {
    color-scheme: light;

    --bg:        #f4f6fb;
    --surface:   #ffffff;
    --card:      #ffffff;
    --card-2:    #f6f8fc;
    --border:    #e2e6ee;
    --border-2:  #ccd2dd;

    --text:      #182030;
    --muted:     #5e677a;
    --muted-2:   #8a93a6;

    /* Cyan is too light against white; use a darker tone for
       text, links and chrome. The brand cyan stays alive in
       glows and decorative tints. */
    --accent:    #0a8a93;
    --accent-dim: rgba(10, 138, 147, 0.10);
    --accent-glow: rgba(10, 138, 147, 0.26);
    --accent-ink: #ffffff;

    --ok:        #168a5d;
    --warn:      #c47700;
    --danger:    #c23a32;

    --shadow:    0 18px 48px -16px rgba(20, 30, 50, 0.16);

    --body-glow: rgba(10, 138, 147, 0.05);
    --sidebar-bg: linear-gradient(180deg, #ffffff 0%, #f1f4fa 100%);
    --map-tile-filter: none;
    --map-empty-bg: #eef1f6;
    --avatar-placeholder: linear-gradient(135deg, #eef1f6 0%, #dde3ee 100%);
    --leaflet-attrib-bg: rgba(255, 255, 255, 0.8);

    --purple:        #6a3edb;
    --purple-text:   #4f23b8;
    --gold:          #c47700;
    --gold-ink:      #ffffff;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: radial-gradient(1200px 600px at -10% -10%, var(--body-glow), transparent 60%) , var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--text); }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

button {
    font-family: inherit;
}

/* =========================================================
   Sign-in
   ========================================================= */

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-wrap {
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}
.login-logo {
    width: 56px;
    height: 56px;
    filter: drop-shadow(0 0 24px var(--accent-glow));
}
.login-brand-text {
    line-height: 1.1;
}
.login-brand-text strong {
    display: block;
    font-size: 22px;
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.01em;
}
.login-brand-text span {
    display: block;
    font-size: 13px;
    color: var(--accent);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin-top: 2px;
}

.login-card {
    width: 100%;
    background: linear-gradient(180deg, var(--card) 0%, var(--surface) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 26px 22px;
    box-shadow: var(--shadow);
}
.login-card h1 {
    margin: 0 0 4px;
    font-size: 20px;
}
.login-card .muted {
    font-size: 13px;
    margin: 0 0 18px;
}
.login-card label {
    display: block;
    margin-top: 14px;
}
.login-card label > span {
    display: block;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 6px;
}
.login-card input {
    width: 100%;
    padding: 11px 13px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}
.login-card .btn-primary {
    margin-top: 20px;
}
.login-card button.ghost {
    margin-top: 10px;
    width: 100%;
    padding: 11px;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
}
.login-card button.ghost:hover {
    background: var(--card-2);
    color: var(--text);
}

.code-input {
    text-align: center;
    font-size: 26px !important;
    letter-spacing: 0.55em !important;
    font-weight: 700 !important;
    padding: 16px 12px !important;
    font-variant-numeric: tabular-nums;
}

/* =========================================================
   App layout (sidebar + main)
   ========================================================= */

body.app {
    display: block;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 22px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    z-index: 30;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px 16px;
    border-bottom: 1px solid var(--border);
}
.brand-logo {
    width: 36px;
    height: 36px;
    filter: drop-shadow(0 0 18px var(--accent-glow));
    flex-shrink: 0;
}
.brand-text {
    line-height: 1.1;
    display: flex;
    flex-direction: column;
}
.brand-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}
.brand-sub {
    font-size: 10px;
    color: var(--accent);
    letter-spacing: 0.22em;
    text-transform: uppercase;
    margin-top: 3px;
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
    position: relative;
}
.menu-item:hover {
    background: var(--card);
    color: var(--text);
}
.menu-item.active {
    background: var(--accent-dim);
    color: var(--accent);
}
.menu-item.active::before {
    content: "";
    position: absolute;
    left: -16px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.menu-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: currentColor;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 18px 18px;
    /* Default — users icon */
}
.menu-icon[data-icon="users"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238b94a7' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2'/><circle cx='9' cy='7' r='4'/><path d='M23 21v-2a4 4 0 0 0-3-3.87'/><path d='M16 3.13a4 4 0 0 1 0 7.75'/></svg>");
}
.menu-item.active .menu-icon[data-icon="users"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238CFDFD' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2'/><circle cx='9' cy='7' r='4'/><path d='M23 21v-2a4 4 0 0 0-3-3.87'/><path d='M16 3.13a4 4 0 0 1 0 7.75'/></svg>");
}
.menu-icon[data-icon="shield"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238b94a7' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/></svg>");
}
.menu-icon[data-icon="density"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238b94a7' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><circle cx='6' cy='6' r='2'/><circle cx='6' cy='18' r='2'/><circle cx='18' cy='6' r='2'/><circle cx='18' cy='18' r='2'/><circle cx='12' cy='12' r='3'/></svg>");
}
.menu-item.active .menu-icon[data-icon="density"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238CFDFD' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><circle cx='6' cy='6' r='2'/><circle cx='6' cy='18' r='2'/><circle cx='18' cy='6' r='2'/><circle cx='18' cy='18' r='2'/><circle cx='12' cy='12' r='3'/></svg>");
}
.menu-item.active .menu-icon[data-icon="shield"],
.menu-group.active .menu-parent .menu-icon[data-icon="shield"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238CFDFD' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/></svg>");
}
.menu-icon[data-icon="msg"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238b94a7' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/></svg>");
}
.menu-group.active .menu-parent .menu-icon[data-icon="msg"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238CFDFD' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/></svg>");
}
.menu-icon[data-icon="stats"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238b94a7' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><polyline points='3 17 9 11 13 15 21 7'/><polyline points='14 7 21 7 21 14'/></svg>");
}
.menu-item.active .menu-icon[data-icon="stats"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238CFDFD' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><polyline points='3 17 9 11 13 15 21 7'/><polyline points='14 7 21 7 21 14'/></svg>");
}

.menu-group {
    display: flex;
    flex-direction: column;
}
.menu-parent {
    cursor: pointer;
    user-select: none;
    color: var(--muted);
}
.menu-parent:hover { background: var(--card); color: var(--text); }
.menu-group.active .menu-parent { color: var(--accent); }
.menu-group.active .menu-parent::before {
    content: "";
    position: absolute;
    left: -16px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}
.menu-caret {
    margin-left: auto;
    width: 10px;
    height: 10px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%238b94a7' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><polyline points='9 18 15 12 9 6'/></svg>") no-repeat center;
    transition: transform 0.16s ease;
}
.menu-group.open .menu-caret { transform: rotate(90deg); }

.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease;
    display: flex;
    flex-direction: column;
}
.menu-group.open .submenu { max-height: 240px; }

.submenu-item {
    padding: 7px 12px 7px 42px;
    margin: 1px 0;
    color: var(--muted);
    font-size: 13px;
    border-radius: 8px;
    transition: background 0.1s, color 0.1s;
}
.submenu-item:hover {
    color: var(--text);
    background: var(--card);
}
.submenu-item.active {
    color: var(--accent);
    background: var(--accent-dim);
}
.menu-item { color: var(--muted); }
.menu-item.active .menu-icon { color: var(--accent); }
/* Some browsers don't honor currentColor inside background-image data
   URLs — duplicate it as an opacity dial so the icon still reads. */
.menu-icon { opacity: 0.85; }
.menu-item.active .menu-icon { opacity: 1; }

.sidebar-foot {
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.signed-as {
    color: var(--muted);
    font-size: 12px;
    padding: 0 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sign-out {
    padding: 8px 12px;
    color: var(--muted);
    font-size: 13px;
    border-radius: 8px;
}
.sign-out:hover {
    background: var(--card);
    color: var(--text);
}

/* Day / night theme toggle — sits in the sidebar foot. The label
   updates in JS (`Day mode` vs `Night mode`) so a brand-new admin
   can tell at a glance what clicking the button will do. */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.theme-toggle:hover {
    background: var(--card);
    color: var(--text);
    border-color: var(--border-2);
}
.theme-toggle-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    /* Moon icon in dark mode; the [data-theme="light"] override below
       swaps to a sun glyph. Mask + currentColor lets the icon track
       the button's text color on hover. */
    background: currentColor;
    -webkit-mask: var(--theme-toggle-glyph) no-repeat center / contain;
            mask: var(--theme-toggle-glyph) no-repeat center / contain;
    --theme-toggle-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z' fill='black'/%3E%3C/svg%3E");
}
[data-theme="light"] .theme-toggle-icon {
    --theme-toggle-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='4' fill='black'/%3E%3Cg stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cline x1='12' y1='2' x2='12' y2='5'/%3E%3Cline x1='12' y1='19' x2='12' y2='22'/%3E%3Cline x1='2' y1='12' x2='5' y2='12'/%3E%3Cline x1='19' y1='12' x2='22' y2='12'/%3E%3Cline x1='4.5' y1='4.5' x2='6.6' y2='6.6'/%3E%3Cline x1='17.4' y1='17.4' x2='19.5' y2='19.5'/%3E%3Cline x1='4.5' y1='19.5' x2='6.6' y2='17.4'/%3E%3Cline x1='17.4' y1='6.6' x2='19.5' y2='4.5'/%3E%3C/g%3E%3C/svg%3E");
}

/* Mobile hamburger sits over the top — hidden on desktop */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    width: 40px;
    height: 40px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    z-index: 40;
    padding: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.mobile-menu-btn span {
    display: block;
    width: 16px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
}

.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 25;
}

/* Main column shifts right of the sidebar on desktop */
.main {
    margin-left: var(--sidebar-w);
    padding: 24px 28px 48px;
    max-width: 1400px;
}

/* Standalone user-detail page: opens in its own browser tab, so the
   sidebar is intentionally absent. Center the content and reclaim the
   left gutter that would otherwise sit reserved for the missing nav. */
body.app-detail-standalone .main {
    margin-left: 0;
    margin-right: auto;
    margin-inline: auto;
    max-width: 980px;
}
.topbar-detail {
    /* Without the "← Back to list" sibling, the title needs a bit of
       breathing room on the left so it doesn't hug the viewport edge. */
    padding-top: 8px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    gap: 16px;
}
.page-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.015em;
}
.topbar-meta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
}
.topbar-meta .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.content {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* =========================================================
   Filter card
   ========================================================= */

.filter-card,
.results-card {
    background: linear-gradient(180deg, var(--card) 0%, var(--surface) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.filter-card-head {
    padding: 16px 20px 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}
.filter-card-head h2 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
}

.filter-grid {
    display: grid;
    grid-template-columns: minmax(260px, 1.4fr) minmax(180px, 1fr) auto;
    gap: 18px;
    padding: 16px 20px 20px;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.group-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
}

/* Segmented control (date mode) */
.seg {
    display: inline-flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
    width: fit-content;
}
.seg-btn {
    padding: 6px 12px;
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
    background: var(--card-2);
    color: var(--text);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}
/* Light mode: --bg (page) and --card-2 differ by only ~2 luminance
   steps, so the active pill barely registers. Bump to plain white
   + an accent-tinted bottom edge so the selection reads clearly. */
[data-theme="light"] .seg-btn.active {
    background: #ffffff;
    box-shadow: 0 0 0 1px var(--accent-dim) inset, 0 1px 2px rgba(20, 30, 50, 0.08);
    color: var(--accent);
}

.mode {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quick-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.chip {
    padding: 6px 12px;
    background: var(--bg);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.chip:hover {
    color: var(--text);
    border-color: var(--border-2);
}
.chip.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

.num-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.num-label > span {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.num-wrap {
    display: flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.num-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}
.num-wrap input {
    flex: 1;
    background: transparent;
    border: 0;
    padding: 9px 12px;
    color: var(--text);
    font-size: 14px;
    width: 0;
    min-width: 0;
}
.num-wrap input:focus { outline: none; }
.num-suffix {
    padding: 0 12px;
    color: var(--muted);
    font-size: 12px;
}

.range-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.range-grid label > span {
    display: block;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 4px;
}
.range-grid input[type="date"] {
    width: 100%;
    padding: 9px 11px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    /* color-scheme is inherited from :root / [data-theme] so the
       native picker popup follows the active theme automatically. */
}
.range-grid input[type="date"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}

/* Toggle (custom checkbox) */
.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    padding: 4px 0;
}
.toggle input { display: none; }
.toggle .track {
    width: 36px;
    height: 20px;
    background: var(--card-2);
    border: 1px solid var(--border-2);
    border-radius: 999px;
    position: relative;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
}
.toggle .track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: var(--muted);
    border-radius: 50%;
    transition: transform 0.18s ease, background 0.15s;
}
.toggle input:checked + .track {
    background: var(--accent-dim);
    border-color: var(--accent);
}
.toggle input:checked + .track::after {
    transform: translateX(16px);
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}
.toggle-label {
    font-size: 13px;
    color: var(--text);
}

.filter-actions {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
}

.btn-primary {
    padding: 10px 18px;
    background: var(--accent);
    color: var(--accent-ink);
    border: 0;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 0 0 1px rgba(140, 253, 253, 0.3), 0 0 24px -8px var(--accent-glow);
    transition: transform 0.08s, box-shadow 0.15s;
    width: 100%;
}
.btn-primary:hover {
    box-shadow: 0 0 0 1px rgba(140, 253, 253, 0.5), 0 0 28px -6px var(--accent-glow);
}
.btn-primary:active { transform: translateY(1px); }

/* =========================================================
   Results card
   ========================================================= */

.results-card {
    padding: 4px 4px 8px;
}
.results-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 12px;
    gap: 12px;
}
.results-head h2 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
}
.results-head .small {
    display: block;
    margin-top: 2px;
}

.pager {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 4px;
}
.pager button {
    width: 28px;
    height: 28px;
    background: transparent;
    color: var(--muted);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.12s, color 0.12s;
}
.pager button:hover:not([disabled]) { background: var(--card-2); color: var(--text); }
.pager button[disabled] { opacity: 0.3; cursor: default; }
#page_label {
    padding: 0 8px;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

/* Rows */
.rows {
    display: flex;
    flex-direction: column;
    padding: 0 8px 8px;
}
.row {
    display: grid;
    grid-template-columns: 48px 1fr auto;
    grid-template-rows: auto auto;
    grid-template-areas:
        "avatar primary meta"
        "avatar secondary meta";
    column-gap: 14px;
    row-gap: 2px;
    padding: 12px 12px;
    border-radius: 10px;
    transition: background 0.1s;
    align-items: center;
}
.row:hover {
    background: var(--card-2);
}

.row .avatar {
    grid-area: avatar;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--card-2);
    border: 1px solid var(--border);
    object-fit: cover;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
}
.row .avatar.no-image {
    background: var(--avatar-placeholder);
}

.row .primary {
    grid-area: primary;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}
.row .display {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.row .code {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.row .code.code-muted {
    color: var(--muted-2);
    font-style: italic;
}
.user-row-clickable {
    cursor: pointer;
    transition: background 0.08s;
}
.user-row-clickable:hover {
    background: var(--accent-dim);
}
.user-row-clickable .user-actions,
.user-row-clickable .user-actions * {
    cursor: default;
}
.user-row-clickable .user-btn { cursor: pointer; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--accent-dim);
    color: var(--accent);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.badge::before {
    content: "";
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent-glow);
}
.badge.badge-fake {
    background: rgba(255, 180, 85, 0.18);
    color: var(--warn);
}
.badge.badge-fake::before {
    background: var(--warn);
    box-shadow: 0 0 6px rgba(255, 180, 85, 0.45);
}

.row .secondary {
    grid-area: secondary;
    color: var(--muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.row .secondary .pin {
    color: var(--muted-2);
}

.row .meta {
    grid-area: meta;
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    line-height: 1.4;
}
.row .meta .label {
    color: var(--muted-2);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.row .meta .reg {
    color: var(--text);
    font-weight: 500;
}

/* State views */
.state {
    padding: 40px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}
.state-error {
    color: var(--danger);
}
.state-loading {
    display: inline-flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--border-2);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.3);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    margin: 10px 0;
}

/* =========================================================
   Admins page
   ========================================================= */

.add-admin {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 14px 20px 18px;
    align-items: stretch;
}
.add-wrap {
    overflow: hidden;
}
.add-wrap input {
    flex: 1;
    background: transparent;
    border: 0;
    padding: 10px 14px;
    color: var(--text);
    font-size: 14px;
    width: 100%;
}
.add-wrap input:focus { outline: none; }
.add-admin .btn-primary {
    width: auto;
    padding: 10px 22px;
}

.admin-row {
    grid-template-columns: 48px 1fr auto;
    grid-template-rows: auto auto;
    grid-template-areas:
        "avatar primary actions"
        "avatar secondary actions";
}

.admin-actions {
    grid-area: actions;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.mini-btn {
    padding: 5px 11px;
    background: var(--bg);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.mini-btn:hover {
    color: var(--text);
    border-color: var(--border-2);
    background: var(--card-2);
}
.mini-btn.danger {
    color: var(--danger);
    border-color: rgba(255, 107, 107, 0.3);
}
.mini-btn.danger:hover {
    background: rgba(255, 107, 107, 0.1);
    color: var(--danger);
    border-color: rgba(255, 107, 107, 0.55);
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.pill::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}
.pill-ok {
    background: rgba(70, 211, 154, 0.13);
    color: var(--ok);
}
.pill-muted {
    background: rgba(139, 148, 167, 0.12);
    color: var(--muted);
}
.pill-danger {
    background: rgba(255, 107, 107, 0.13);
    color: var(--danger);
}

/* =========================================================
   Filter search row + summary bar
   ========================================================= */

.filter-grid-search {
    grid-template-columns: 1fr 1fr;
    padding-bottom: 0;
    align-items: end;
}
.filter-grid-search input[type="search"],
.filter-grid-search input[type="text"] {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.filter-grid-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}

.summary-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 20px;
    background: linear-gradient(180deg, var(--card) 0%, var(--surface) 100%);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.summary-stat {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}
.summary-num {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}
.summary-label {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}
.summary-sep { color: var(--muted-2); }
.summary-pagesize {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.summary-pagesize label {
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 11px;
}

/* =========================================================
   Density page — mode switch, autocomplete, slider, map, groups
   ========================================================= */

/* Mode switch (City / Density toggle cards) */
.mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
/* Wrap is positioning context for the absolutely-placed `?` help
   button — keeps the help out of the button tag (HTML doesn't allow
   nested <button>) while visually still living on the card. */
.mode-btn-wrap {
    position: relative;
}
.mode-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    width: 100%;
    background: linear-gradient(180deg, var(--card) 0%, var(--surface) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.mode-help-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 2;
}
.mode-btn:hover { border-color: var(--border-2); }
.mode-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 0 28px -10px var(--accent-glow);
    background: linear-gradient(180deg, rgba(140, 253, 253, 0.06) 0%, var(--surface) 100%);
}
.mode-btn > div { display: flex; flex-direction: column; gap: 2px; line-height: 1.2; }
.mode-btn strong { font-size: 14px; }
.mode-btn .muted { font-size: 12px; }
.mode-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--card-2) center / 20px 20px no-repeat;
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.mode-btn.active .mode-icon {
    background-color: var(--accent-dim);
    border-color: var(--accent);
}
.mode-icon[data-icon="pin"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238b94a7' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/><circle cx='12' cy='10' r='3'/></svg>");
}
.mode-btn.active .mode-icon[data-icon="pin"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238CFDFD' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/><circle cx='12' cy='10' r='3'/></svg>");
}
.mode-icon[data-icon="grid"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238b94a7' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><circle cx='6' cy='6' r='2'/><circle cx='6' cy='18' r='2'/><circle cx='18' cy='6' r='2'/><circle cx='18' cy='18' r='2'/><circle cx='12' cy='12' r='3'/></svg>");
}
.mode-btn.active .mode-icon[data-icon="grid"] {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238CFDFD' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><circle cx='6' cy='6' r='2'/><circle cx='6' cy='18' r='2'/><circle cx='18' cy='6' r='2'/><circle cx='18' cy='18' r='2'/><circle cx='12' cy='12' r='3'/></svg>");
}

/* Density filter grid — uses the same .filter-grid pattern */
.filter-grid-density {
    grid-template-columns: minmax(220px, 1.4fr) minmax(220px, 1fr) auto;
    align-items: end;
}
.filter-grid-density .city-field { grid-column: 1 / -1; }

/* Autocomplete */
.autocomplete { position: relative; }
.autocomplete input[type="search"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.autocomplete input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}
.autocomplete-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 20;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
}
.autocomplete-row {
    padding: 8px 12px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 14px;
}
.autocomplete-row:hover {
    background: var(--accent-dim);
    color: var(--accent);
}

/* Slider */
.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 4px;
    outline: none;
    margin: 6px 0 4px;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg);
    box-shadow: 0 0 0 1px var(--accent), 0 0 12px var(--accent-glow);
}
.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    border: 2px solid var(--bg);
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--accent), 0 0 12px var(--accent-glow);
}
.slider-ticks {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--muted-2);
    letter-spacing: 0.05em;
}
.group-label .muted {
    margin-left: 8px;
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    font-size: 12px;
}

/* Map */
.map-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.map-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.map {
    height: 320px;
    width: 100%;
    background: var(--map-empty-bg);
}
/* Leaflet tile tweaks — darken in dark mode, leave alone in light. */
.leaflet-tile-pane { filter: var(--map-tile-filter); }
.leaflet-control-attribution {
    background: var(--leaflet-attrib-bg) !important;
    color: var(--muted) !important;
    font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

/* Group cards (density mode) */
#groups { display: flex; flex-direction: column; gap: 14px; }
.group-card .group-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}
.group-card .group-title + .muted { display: block; margin-top: 1px; font-size: 12px; }
.group-card .results-head { gap: 10px; flex-wrap: wrap; }

/* =========================================================
   Users — row + actions + bulk toolbar
   ========================================================= */

.user-row {
    grid-template-columns: 48px minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    grid-template-areas:
        "avatar primary actions"
        "avatar secondary actions";
    column-gap: 14px;
    row-gap: 4px;
    align-items: center;
}

.user-secondary {
    color: var(--muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}
.user-secondary .loc { color: var(--text); opacity: 0.85; }
.user-secondary .user-when { color: var(--muted); }
.user-secondary .sep-dot { color: var(--muted-2); }
.user-secondary .last-msg { color: var(--accent); }

.user-actions {
    grid-area: actions;
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 12px;
    border-left: 1px solid transparent; /* hover bump only */
}

.user-btn-row {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.user-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 9px;
    background: var(--bg);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    font-family: inherit;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s, background 0.12s, transform 0.08s;
}
.user-btn:hover { color: var(--text); border-color: var(--border-2); background: var(--card-2); }
.user-btn:active { transform: translateY(1px); }
.user-btn.disabled,
.user-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.user-btn-sms:hover     { color: var(--warn); border-color: rgba(255,180,85,0.4); }
.user-btn-push:hover    { color: var(--accent); border-color: rgba(140,253,253,0.45); }
.user-btn-email:hover   { color: var(--purple); border-color: rgba(184,148,255,0.45); }
.user-btn-history:hover { color: var(--text); }

/* WR exception + Fake persona toggle buttons. Off-state matches the
   other action buttons; on-state stamps a tinted background so the
   "active flag" is readable at a glance from across the row. */
.user-btn-wr:hover       { color: var(--ok); border-color: rgba(70,211,154,0.45); }
.user-btn-wr-on {
    color: #06343a;
    background: #46d39a;
    border-color: #46d39a;
}
[data-theme="light"] .user-btn-wr-on { color: #ffffff; background: var(--ok); border-color: var(--ok); }
.user-btn-wr-on:hover {
    color: #06343a;
    background: #3dbf8a;
    border-color: #3dbf8a;
}
[data-theme="light"] .user-btn-wr-on:hover { color: #ffffff; background: #0e6b46; border-color: #0e6b46; }
.user-btn-fake:hover     { color: var(--gold); border-color: rgba(255,208,96,0.5); }
.user-btn-fake-on {
    color: var(--gold-ink);
    background: var(--gold);
    border-color: var(--gold);
}
.user-btn-fake-on:hover {
    color: var(--gold-ink);
    background: #f5c54a;
    border-color: #f5c54a;
}
[data-theme="light"] .user-btn-fake-on:hover { background: #a05a00; border-color: #a05a00; }

.user-btn-label {
    display: inline-block;
}

/* Custom checkbox (replaces native look) */
.check-wrap {
    position: relative;
    display: inline-flex;
    width: 18px;
    height: 18px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.check-wrap input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    margin: 0;
}
.check-wrap .checkmark {
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--border-2);
    border-radius: 5px;
    background: var(--bg);
    transition: background 0.12s, border-color 0.12s;
    position: relative;
}
.check-wrap input:checked + .checkmark {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}
.check-wrap input:checked + .checkmark::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid var(--accent-ink);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.check-wrap input:indeterminate + .checkmark {
    background: var(--accent-dim);
    border-color: var(--accent);
}
.check-wrap input:indeterminate + .checkmark::after {
    content: "";
    position: absolute;
    left: 3px;
    right: 3px;
    top: 7px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}

/* Bulk toolbar */
.results-head-bulk {
    flex-wrap: wrap;
    gap: 12px;
}
.bulk-left { display: flex; align-items: center; gap: 14px; }
.bulk-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.bulk-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px 4px 10px;
    background: var(--accent-dim);
    border: 1px solid rgba(140, 253, 253, 0.3);
    border-radius: 999px;
}
.bulk-actions .small { color: var(--accent); font-weight: 600; }

.select-min {
    padding: 6px 12px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}
.select-min:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim); }

/* =========================================================
   Send modal extras
   ========================================================= */

.recipients-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.canned-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    background: linear-gradient(180deg, rgba(140, 253, 253, 0.06) 0%, transparent 100%);
    border: 1px solid rgba(140, 253, 253, 0.2);
    border-radius: 10px;
}
.canned-picker-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.canned-select {
    width: 100%;
    padding: 10px 36px 10px 12px;
    background: var(--bg) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238CFDFD' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") no-repeat right 12px center;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}
.canned-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}
.recipient-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--card-2);
    color: var(--text);
    font-size: 12px;
    border: 1px solid var(--border);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.recipient-more {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

.warn-banner {
    margin-top: 4px;
    padding: 10px 12px;
    background: rgba(255, 180, 85, 0.12);
    border: 1px solid rgba(255, 180, 85, 0.35);
    color: var(--warn);
    border-radius: 10px;
    font-size: 13px;
}
.warn-banner .warn-head {
    font-weight: 600;
    margin-bottom: 6px;
}
.warn-banner .failed-list {
    margin: 6px 0 0;
    padding-left: 18px;
    max-height: 180px;
    overflow-y: auto;
    font-size: 12.5px;
    line-height: 1.5;
}
.warn-banner .failed-list li {
    margin: 2px 0;
}
.warn-banner .failed-list strong {
    color: var(--text);
    font-weight: 600;
}
.warn-banner .failed-more {
    margin-top: 6px;
    color: var(--muted);
}

/* =========================================================
   History timeline
   ========================================================= */

.timeline {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 0;
}
.tl-entry {
    display: grid;
    grid-template-columns: 36px 1fr;
    column-gap: 12px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    position: relative;
}
.tl-entry.tl-failed {
    border-color: rgba(255, 107, 107, 0.35);
    background: rgba(255, 107, 107, 0.04);
}
.tl-marker {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--card-2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--accent);
}
.tl-entry.tl-sms   .tl-marker { color: var(--warn); }
.tl-entry.tl-email .tl-marker { color: var(--purple); }
.tl-entry.tl-push  .tl-marker { color: var(--accent); }

.tl-content { min-width: 0; }
.tl-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.tl-subject {
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
    margin: 2px 0 4px;
}
.tl-body {
    margin: 4px 0;
    cursor: pointer;
}
.tl-body summary {
    list-style: none;
    color: var(--muted);
    font-size: 13px;
    padding: 0;
}
.tl-body summary::marker,
.tl-body summary::-webkit-details-marker { display: none; }
.tl-body summary:hover { color: var(--text); }
.tl-body[open] summary { color: var(--muted-2); margin-bottom: 8px; }
.tl-body-full {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.55;
    max-height: 360px;
    overflow-y: auto;
    color: var(--text);
    white-space: pre-wrap;
}
.tl-body-full p { margin: 6px 0; }
.tl-body-full a { color: var(--accent); }

/* Sandboxed iframe rendering for stored email HTML — keeps untrusted
   admin-authored markup from running scripts against the webadmin
   session. The parent .tl-body-full keeps its frame; the iframe sits
   flush inside it. */
.tl-body-full.tl-body-full-email {
    padding: 0;
    overflow: hidden;
    white-space: normal;
}
.tl-body-iframe {
    display: block;
    width: 100%;
    min-height: 320px;
    max-height: 480px;
    border: 0;
    background: #fff;
    border-radius: 8px;
}

/* =========================================================
   Canned templates page
   ========================================================= */

.canned-row {
    cursor: pointer;
    grid-template-columns: 48px 1.4fr 1.6fr auto;
    grid-template-areas: "avatar primary secondary meta";
    grid-template-rows: auto;
    column-gap: 14px;
}
.canned-row:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.btn-small { padding: 7px 14px !important; font-size: 12px; width: auto !important; }

/* =========================================================
   Modal
   ========================================================= */

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
}
.modal-sheet {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--card) 0%, var(--surface) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: sheet-pop 0.16s ease-out;
}
.modal-sheet-wide { max-width: 720px; }
@keyframes sheet-pop {
    from { transform: translateY(8px) scale(0.98); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; font-weight: 600; }
.modal-close {
    width: 32px;
    height: 32px;
    background: transparent;
    color: var(--muted);
    border: 0;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    border-radius: 8px;
}
.modal-close:hover { background: var(--card-2); color: var(--text); }

.modal-body {
    padding: 18px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.18);
}
.modal-foot .spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label,
.field-label-row .field-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
}
.field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.field input[type="text"],
.field input[type="email"],
.field input[type="number"],
.field textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    resize: vertical;
}
.field input:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-dim);
}
.muted.small.warn { color: var(--warn); }

/* RTE */
.seg-small { padding: 2px; }
.seg-small .seg-btn { padding: 4px 9px; font-size: 11px; }

.rte-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 10px 10px 0 0;
    padding: 6px 8px;
    flex-wrap: wrap;
}
.rte-toolbar button {
    width: 28px;
    height: 28px;
    background: transparent;
    color: var(--muted);
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.rte-toolbar button:hover { background: var(--card-2); color: var(--text); }
.rte-toolbar .sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
}
.rte-stage {
    border: 1px solid var(--border);
    border-radius: 0 0 10px 10px;
    background: var(--bg);
    overflow: hidden;
}
.rte {
    min-height: 200px;
    max-height: 360px;
    padding: 14px 16px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    outline: none;
}
.rte:focus { box-shadow: inset 0 0 0 2px var(--accent-dim); }
.rte h1 { font-size: 20px; margin: 8px 0; }
.rte h2 { font-size: 17px; margin: 8px 0; }
.rte p { margin: 6px 0; }
.rte ul, .rte ol { padding-left: 24px; margin: 6px 0; }
.rte a { color: var(--accent); }
.rte-stage textarea {
    border: 0;
    border-radius: 0;
    background: transparent;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px;
    line-height: 1.5;
    padding: 14px 16px;
    width: 100%;
    min-height: 240px;
}
.rte-stage textarea:focus { box-shadow: none; }

/* =========================================================
   Mobile
   ========================================================= */

@media (max-width: 860px) {
    :root {
        --sidebar-w: 240px;
    }

    .mobile-menu-btn { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.22s ease;
    }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .nav-backdrop { display: block; }

    .main {
        margin-left: 0;
        padding: 64px 16px 32px;
    }
    .topbar {
        margin-bottom: 16px;
    }
    .page-title {
        font-size: 18px;
    }

    .filter-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 14px 16px 18px;
    }
    .filter-card-head { padding: 14px 16px 0; }
    .filter-actions { justify-content: stretch; }
    .btn-primary { width: 100%; }

    .results-head {
        padding: 12px 14px;
        flex-wrap: wrap;
    }

    .row {
        grid-template-columns: 40px 1fr;
        grid-template-rows: auto auto auto;
        grid-template-areas:
            "avatar primary"
            "avatar secondary"
            "avatar meta";
        padding: 10px 10px;
    }
    .row:hover { background: transparent; }
    .row + .row { border-top: 1px solid var(--border); border-radius: 0; }
    .row .avatar { width: 40px; height: 40px; }
    .row .meta {
        text-align: left;
        flex-direction: row;
        gap: 8px;
        white-space: normal;
    }
    .row .meta .label { display: none; }
    .row .meta > div { display: inline-flex; gap: 4px; align-items: baseline; }

    /* Users page row */
    .user-row {
        grid-template-columns: 40px 1fr auto;
        grid-template-rows: auto auto auto;
        grid-template-areas:
            "avatar primary check"
            "avatar secondary secondary"
            "actions actions actions";
        column-gap: 12px;
        row-gap: 6px;
    }
    .user-actions {
        grid-area: actions;
        border-left: 0;
        padding-left: 0;
        padding-top: 4px;
        justify-content: space-between;
    }
    /* Put the per-row checkbox in the top-right slot on mobile */
    .user-row > .user-actions > .check-wrap {
        position: absolute;
        right: 12px;
        top: 14px;
    }
    .user-row { position: relative; }
    .user-btn-row { flex: 1; gap: 6px; flex-wrap: wrap; }
    .user-btn { flex: 1; justify-content: center; min-width: 60px; }
    .user-btn-label { font-size: 11px; }

    /* Bulk toolbar wraps */
    .results-head-bulk .bulk-right {
        width: 100%;
        justify-content: space-between;
    }

    /* Density page */
    .mode-switch { grid-template-columns: 1fr; }
    .filter-grid-density { grid-template-columns: 1fr; }
    .map { height: 240px; }

    /* Summary bar + filter search */
    .summary-bar {
        flex-direction: column;
        align-items: flex-start;
        padding: 14px 16px;
    }
    .summary-pagesize {
        width: 100%;
        justify-content: space-between;
    }
    .summary-num { font-size: 24px; }
    .filter-grid-search {
        grid-template-columns: 1fr;
        padding: 14px 16px 0;
    }

    /* Admins page */
    .add-admin {
        grid-template-columns: 1fr;
        padding: 12px 14px 16px;
    }
    .add-admin .btn-primary { width: 100%; }

    .admin-row {
        grid-template-columns: 40px 1fr;
        grid-template-rows: auto auto auto;
        grid-template-areas:
            "avatar primary"
            "avatar secondary"
            "actions actions";
    }
    .admin-actions {
        flex-wrap: wrap;
        padding-top: 6px;
    }
    .mini-btn { flex: 1; text-align: center; }
}

/* =========================================================
   Registration Stats — KPI tiles, chart cards, scope switch
   ========================================================= */

.filter-grid-stats {
    grid-template-columns: 1.4fr 1.4fr 1fr auto;
}
.filter-grid-stats .filter-actions { align-self: end; }
.select-tz {
    width: 100%;
    max-width: 280px;
}
.seg-scope { width: max-content; }
.window-summary {
    margin-top: 14px;
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}

.kpi-grid {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 18px;
}

/* Each row groups tiles that belong to the same conceptual flow
   (e.g. "All signups − Deletions = Active signups"). The row
   itself is a flex line so we can drop operator pills between
   tiles and the whole thing wraps gracefully on narrow screens. */
.kpi-row-section { display: flex; flex-direction: column; gap: 6px; }
.kpi-row-title {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 11px;
    color: var(--muted-2);
    padding-left: 2px;
}
.kpi-row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 10px;
}
.kpi-row .kpi-tile {
    flex: 1 1 200px;
    min-width: 200px;
    max-width: 320px;
}

/* Operator pill: tall enough to read against the tile rows, narrow
   enough to keep the equation legible. The pill stacks a small
   help `?` (optional) on top of the glyph so the inexact-equals
   caveat can be discovered exactly where it matters. Tone uses the
   muted text so it doesn't fight the colored tile accents. */
.kpi-op {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 36px;
    flex: 0 0 36px;
    font-size: 22px;
    font-weight: 600;
    color: var(--muted-2);
    user-select: none;
    gap: 2px;
}
.kpi-op-glyph { line-height: 1; }
.kpi-op-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.kpi-op-help:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}
.kpi-op-equals { color: var(--accent); }
.kpi-op-approx { color: var(--warn); }
.kpi-op-minus  { color: var(--danger); }
.kpi-op-arrow  { color: var(--muted-2); font-weight: 400; }

/* Narrow viewport: row wraps, operators collapse to a small inline
   chevron between stacked tiles so the math still reads top-down. */
@media (max-width: 720px) {
    .kpi-row .kpi-tile { max-width: none; }
    .kpi-op {
        width: 100%;
        flex-basis: 100%;
        flex-direction: row;
        height: auto;
        min-height: 20px;
        font-size: 16px;
        gap: 8px;
    }
}

/* ---- Stats results loading overlay -------------------------------- */
/* The wrapper houses the KPI grid + 3 chart cards. When we set
   `.is-loading` on it the children fade and a centered overlay
   covers them; pointer-events stop the user from clicking through
   the spinner. The filter card outside this wrapper stays live. */
.stats-results { position: relative; }
.stats-results > .kpi-grid,
.stats-results > .chart-card {
    transition: opacity 0.18s ease, filter 0.18s ease;
}
.stats-results.is-loading > .kpi-grid,
.stats-results.is-loading > .chart-card {
    opacity: 0.45;
    filter: blur(1px);
    pointer-events: none;
}
.stats-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(10, 13, 18, 0.18);
    border-radius: var(--radius);
    z-index: 5;
    backdrop-filter: blur(1px);
}
[data-theme="light"] .stats-overlay { background: rgba(245, 247, 251, 0.55); }
.stats-results.is-loading > .stats-overlay { display: flex; }
.stats-overlay .spinner {
    width: 22px;
    height: 22px;
    border-width: 3px;
}
.stats-overlay-label {
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}
.kpi-tile {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    overflow: hidden;
}
.kpi-tile::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--accent);
}
.kpi-tile.kpi-ok::before      { background: var(--ok); }
.kpi-tile.kpi-persona::before { background: var(--purple); }
.kpi-tile.kpi-danger::before  { background: var(--danger); }
.kpi-tile.kpi-warn::before    { background: var(--warn); }
.kpi-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
}
.kpi-numbers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: end;
}
.kpi-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.kpi-col-label {
    font-size: 11px;
    color: var(--muted-2);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.kpi-col-num {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.kpi-tile.kpi-accent  .kpi-col-num { color: var(--accent); }
.kpi-tile.kpi-ok      .kpi-col-num { color: var(--ok); }
.kpi-tile.kpi-persona .kpi-col-num { color: var(--purple-text); }
.kpi-tile.kpi-danger  .kpi-col-num { color: var(--danger); }
.kpi-tile.kpi-warn    .kpi-col-num { color: var(--warn); }
.kpi-desc { line-height: 1.45; }

/* ---- Single-column KPI layout (post-scope-switch rewrite) -----------
   When the scope toggle is the source of truth, we render only one big
   number per tile instead of a Global+USA pair. Same color tokens; the
   `?` help button sits opposite the label so it can't collide with the
   number. */
.kpi-head {
    display: flex;
    align-items: center;
    gap: 8px;
}
.kpi-head .kpi-label { flex: 1 1 auto; }
.kpi-help-btn {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.kpi-help-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}
.kpi-scope {
    font-size: 11px;
    color: var(--muted-2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.kpi-num-single {
    font-size: 34px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    margin-top: -2px;
}
.kpi-tile.kpi-accent  .kpi-num-single { color: var(--accent); }
.kpi-tile.kpi-ok      .kpi-num-single { color: var(--ok); }
.kpi-tile.kpi-persona .kpi-num-single { color: var(--purple-text); }

/* ---- Tile child sub-line --------------------------------------- */
/* The deletion tiles fold their 24h-quit subset in here as a small
   indented row so the breakdown reads as "of these N, M happened
   within 24h" — without burning a separate tile. */
.kpi-child {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    line-height: 1.4;
}
.kpi-child-bullet {
    color: var(--muted-2);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.kpi-child-text { color: var(--muted); }
.kpi-child-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 9px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.kpi-child-help:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}
.kpi-tile.kpi-danger  .kpi-num-single { color: var(--danger); }
.kpi-tile.kpi-warn    .kpi-num-single { color: var(--warn); }

/* ---- Page-level help pill in the topbar --------------------------- */
.page-help-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--muted);
    border-radius: 999px;
    padding: 4px 12px 4px 6px;
    font-size: 12px;
    cursor: pointer;
    margin-left: auto;
    transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.page-help-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}
.page-help-icon {
    display: inline-flex;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg);
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
}

/* ---- Help modal body styling -------------------------------------- */
.stats-help-sheet { max-width: 720px; }
.stats-help-body {
    max-height: 70vh;
    overflow-y: auto;
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
}
.stats-help-body p   { margin: 0 0 12px; }
.stats-help-body h4  { margin: 18px 0 6px; font-size: 13px; color: var(--accent); letter-spacing: 0.04em; text-transform: uppercase; }
.stats-help-body ul  { margin: 6px 0 12px; padding-left: 20px; }
.stats-help-body li  { margin: 4px 0; }
.stats-help-body b   { color: var(--text); }
.stats-help-body code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 12.5px;
}

.chart-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 18px;
}
.chart-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.chart-card-head h2 {
    margin: 0 0 2px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}
.chart-legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: center;
    font-size: 12px;
    color: var(--muted);
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 8px currentColor;
}
.chart-wrap {
    position: relative;
    height: 280px;
}

@media (max-width: 720px) {
    .filter-grid-stats { grid-template-columns: 1fr; }
    .kpi-numbers { grid-template-columns: 1fr; gap: 6px; }
    .kpi-col-num { font-size: 22px; }
    .chart-wrap { height: 220px; }
}

/* =========================================================
   User Detail page — hero carousel + sections + lightbox
   ========================================================= */

.topbar-detail {
    display: flex;
    align-items: center;
    gap: 18px;
}
.back-link {
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.back-link:hover { color: var(--text); border-color: var(--border-2); background: var(--card-2); }

#detail_body { max-width: 920px; }

.detail-hero {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 18px;
}
.detail-carousel-wrap {
    position: relative;
}
.detail-carousel {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 220px;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
    scrollbar-color: var(--border-2) transparent;
}
/* Right-edge fade hint there's more to scroll. Hidden by JS when the
   carousel is scrolled to the end. */
.detail-carousel-wrap::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 14px;
    width: 36px;
    pointer-events: none;
    background: linear-gradient(to left, var(--card), transparent);
    opacity: 0.95;
    transition: opacity 0.16s;
}
.detail-carousel-wrap.scrolled-end::after { opacity: 0; }
.detail-carousel-frame {
    width: 220px;
    height: 280px;
    border: 0;
    padding: 0;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg);
    cursor: zoom-in;
    transition: transform 0.12s;
}
.detail-carousel-frame:hover { transform: scale(1.01); }
.detail-carousel-frame img {
    width: 100%;
    height: 100%;
    /* `contain` preserves the source aspect (no cropped foreheads on
       portrait shots, no cropped sides on landscape) — letterboxing
       lives against the frame's `--bg` color. */
    object-fit: contain;
    display: block;
}
.detail-no-images {
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-style: italic;
    background: var(--bg);
    border-radius: 12px;
}

.detail-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
    padding: 0 4px;
}
.detail-name {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}
.badge.badge-wr {
    background: rgba(70, 211, 154, 0.16);
    color: var(--ok);
}
.badge.badge-wr::before {
    background: var(--ok);
    box-shadow: 0 0 6px rgba(70, 211, 154, 0.45);
}

.detail-meta-row {
    color: var(--muted);
    font-size: 13px;
    padding: 0 4px;
    margin-bottom: 18px;
    font-variant-numeric: tabular-nums;
}

.detail-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}
.detail-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    color: var(--text);
}
.detail-chip-icon {
    font-size: 14px;
    line-height: 1;
}

.detail-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 16px;
}
.detail-section-title {
    margin: 0 0 10px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}
.detail-bio {
    white-space: pre-wrap;
    line-height: 1.55;
    color: var(--text);
}
.detail-headline {
    margin-top: 8px;
    font-style: italic;
    font-size: 13px;
}

.detail-tag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.detail-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    color: var(--text);
}
.detail-tag-icon {
    font-size: 14px;
    line-height: 1;
}
.detail-tag-star {
    color: var(--gold);
    font-size: 12px;
}

.detail-kv-grid {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) 2fr;
    gap: 8px 16px;
    align-items: baseline;
}
.detail-kv-label {
    color: var(--muted);
    font-size: 13px;
}
.detail-kv-value {
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

/* Location section — two stacked rows (Last + Hometown), each with a
   compact map button on the right. Wider rhythm so the map pill has
   breathing room next to the text. */
.detail-loc-grid {
    row-gap: 12px;
}
.detail-loc-value {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.detail-loc-text {
    /* Let the flag + city wrap naturally on narrow screens without
       pushing the button to a second row alone. */
    flex: 1 1 auto;
    min-width: 0;
}
.detail-loc-note {
    font-size: 12px;
    flex: 0 0 auto;
}
.detail-map-btn {
    flex: 0 0 auto;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    line-height: 1.4;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.detail-map-btn:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
}
.detail-map-btn:active { transform: translateY(1px); }

/* Map modal — embeds a Google Maps iframe. 16:10 stage so the modal
   stays usable on shorter laptop screens. */
.loc-map-sheet { max-width: 880px; }
.loc-map-body {
    padding: 0;
    background: #000;
}
.loc-map-iframe {
    display: block;
    width: 100%;
    height: 520px;
    border: 0;
}
.loc-map-foot {
    display: flex;
    align-items: center;
    gap: 12px;
}
.loc-map-meta {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Custom popup section — admin-set one-shot message that fires on the
   target user's next app open. Same accent treatment as other write
   surfaces so admins can tell at a glance that this is a "writes to the
   live app" widget, not a passive readout. */
.detail-popup-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}
.popup-status {
    flex: 0 0 auto;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 11.5px;
}
.popup-status-active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}
.popup-form-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}
.popup-form-row {
    display: grid;
    grid-template-columns: minmax(120px, 160px) 1fr;
    align-items: start;
    gap: 12px;
}
.popup-form-toggles {
    display: flex;
    flex-direction: row;
    gap: 24px;
    margin-top: 4px;
}
.popup-form-label {
    color: var(--muted);
    font-size: 13px;
    padding-top: 8px;
}
.popup-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
.popup-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}
.popup-textarea {
    resize: vertical;
    min-height: 84px;
    line-height: 1.45;
}
select.popup-input,
.popup-form-row select#popup_btn_action {
    appearance: none;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    font: inherit;
}
.popup-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 13.5px;
    cursor: pointer;
    user-select: none;
}
.popup-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Reachability checkbox row on the users-list filter card. Uses the
   same `.popup-checkbox` pill style as the user detail popup form so
   the visual language stays consistent across admin write surfaces. */
.channel-checks {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 18px;
    margin: 4px 0 6px;
}
/* Indented sub-checkbox that appears under the SMS row when SMS is
   on. Slightly muted so it reads as "secondary modifier", not a
   first-class channel. */
.channel-sub {
    margin: 2px 0 4px 12px;
    font-size: 12.5px;
    color: var(--muted);
}

/* Inline ? help button used next to filter labels. Smaller and quieter
   than the KPI tile button on the stats page — it sits in a label
   that already carries strong typography. */
.filter-help-btn {
    margin-left: 6px;
    width: 16px;
    height: 16px;
    line-height: 1;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.filter-help-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}
/* Mode picker tile help button: pin to the top-right corner so it
   doesn't push the existing mode-card layout. The tiles use flex
   already; we absolutely-position the button instead. */
.mode-btn { position: relative; }
.mode-help-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    margin-left: 0;
}

/* Bottom pager — mirror of the top pager, lives in the results-card
   footer so admins can flip pages without scrolling back up. */
.results-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

/* ---- Density: group card map + show/hide users -------------------- */
.group-map {
    height: 220px;
    margin: 0 16px 12px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    /* Leaflet drops a grey background until tiles load; match the card
       so the gap isn't jarring. */
    background: var(--bg);
}
.group-toggle-row {
    display: flex;
    justify-content: center;
    padding: 0 16px 14px;
}
/* Stacked secondary line under the group title showing additional
   cities in the cluster. Below the main meta line, slightly indented. */
.group-cities {
    display: block;
    margin-top: 3px;
    font-style: italic;
}
/* Users block is shown only after "Show users" — keep the layout
   collapsed and avoid emitting a tall empty rows container. */
.group-users.hidden {
    display: none;
}
.form-row-disabled {
    opacity: 0.45;
    pointer-events: none;
}
.popup-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    align-items: center;
}
/* Save/clear feedback — green when OK, red when bad. We piggyback on
   .warn-banner so the existing layout/spacing rules apply, then tint
   the colors per state. */
.warn-banner-ok {
    background: rgba(120, 220, 160, 0.10);
    border-color: rgba(120, 220, 160, 0.35);
    color: var(--ok);
}
.warn-banner-err {
    background: rgba(255, 120, 120, 0.10);
    border-color: rgba(255, 120, 120, 0.35);
    color: var(--danger);
}

.detail-verify {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: 24px 0 16px;
}
.detail-verify-pic {
    width: 96px;
    height: 96px;
    border: 0;
    padding: 0;
    background: var(--bg);
    border-radius: 14px;
    overflow: hidden;
    cursor: zoom-in;
    position: relative;
}
.detail-verify-pic img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Admin-only view — render the verify pic at full clarity. The
       blur seen in-app is for other end users; admins need to confirm
       it's the same person. */
}
.detail-verify-label {
    color: var(--ok);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.03em;
}
.detail-verify-label::before {
    content: "✓ ";
    color: var(--accent);
}

.detail-meta-footer {
    margin-top: 24px;
    padding: 12px 14px;
    color: var(--muted-2);
    background: transparent;
    border: 1px dashed var(--border);
    text-align: center;
}

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lightbox img {
    max-width: 92vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}
.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: absolute;
    background: rgba(20, 24, 32, 0.6);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.12s, transform 0.08s;
}
.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
    background: rgba(40, 50, 65, 0.85);
}
.lightbox-close { top: 16px; right: 16px; }
.lightbox-prev  { left: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-next  { right: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-counter {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.75);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
    .detail-carousel { grid-auto-columns: 160px; }
    .detail-carousel-frame { width: 160px; height: 200px; }
    .detail-kv-grid { grid-template-columns: 1fr; }
    .detail-kv-label { font-size: 12px; }
}

/* 404 / load-error state for user_detail. */
.detail-error-hint {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 13px;
}

/* "Edit avatar" pencil overlay on the hero's first photo. */
.detail-carousel-frame { position: relative; }
.avatar-edit-tag {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(12, 17, 24, 0.85);
    color: var(--accent);
    border: 1px solid rgba(140, 253, 253, 0.45);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    cursor: pointer;
    backdrop-filter: blur(2px);
    transition: background 0.12s, color 0.12s;
}
.avatar-edit-tag:hover {
    background: var(--accent);
    color: var(--accent-ink);
}

/* Avatar editor modal — wider sheet (Cropper stage needs room),
   dark stage background, tool-row with monospaced buttons. */
.avatar-editor-sheet {
    max-width: 720px;
    width: 100%;
}
.avatar-editor-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.avatar-editor-stage {
    position: relative;
    width: 100%;
    height: 460px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.avatar-editor-stage img {
    /* Cropper.js detaches this element from layout once it mounts (it
       moves to a separate `cropper-container` and the original <img>
       gets `display: none` from Cropper itself). Keep it visible
       until then so a partial load is debuggable; Cropper will hide
       it the moment `new Cropper(img, …)` runs. */
    display: block;
    max-width: 100%;
}
.avatar-editor-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.tool-btn {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.tool-btn:hover {
    background: var(--card-2);
    border-color: var(--border-2);
    color: var(--accent);
}
.tool-btn:active { transform: translateY(1px); }

/* Cropper.js dark theme tweaks — keep the crop overlay readable on
   our dark surface. */
.cropper-view-box,
.cropper-face {
    outline-color: var(--accent) !important;
}
.cropper-line,
.cropper-point {
    background-color: var(--accent) !important;
}
.cropper-bg {
    background-color: var(--bg);
}
.avatar-editor-stage .cropper-container { border-radius: 10px; }

@media (max-width: 720px) {
    .avatar-editor-stage { height: 340px; }
}
