/* =============================================================================
   Zuno Admin — stylesheet for /admin-portal
   Dark by default. One file, in this order:
     0. Tokens          1. Base            2. Boot, sign-in, access denied
     3. App shell       4. Controls        5. Data (stats, tables, chips)
     6. Components      7. Desktop only    8. Phone (one place, compact)
   Colours come from the tokens below. The portal's script writes a few inline
   colours too (same slate/teal values), so keep these in step with them.
   ============================================================================= */

/* ---------- 0. Tokens ---------- */
:root {
    color-scheme: dark;
    --bg: #0b1220;
    --bg-deep: #080f1c;
    --surface: #111a2e;
    --surface-2: #0f172a;
    --surface-3: #0b1220;
    --line: #1e293b;
    --line-soft: rgba(148, 163, 184, .14);
    --text: #e2e8f0;
    --text-strong: #f1f5f9;
    --muted: #94a3b8;
    --faint: #64748b;
    --accent: #14b8a6;
    --accent-soft: #5eead4;
    --accent-bg: rgba(20, 184, 166, .1);
    --danger: #ef4444;
    --danger-soft: #fca5a5;
    --warn: #fbbf24;
    --ok: #4ade80;
    --radius: .7rem;
    --radius-lg: .9rem;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

/* ---------- 1. Base ---------- */
* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.4rem; margin: 0; letter-spacing: -.02em; }
.helper { color: var(--faint); font-size: .78rem; line-height: 1.45; }
.time-ago { color: var(--faint); font-size: .75rem; display: block; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
#app-screen { display: none; }
.tabs { display: none; } /* the in-page tab strip is replaced by the sidebar / drawer */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- 2. Boot screen, sign-in, access denied ---------- */
#app-loading {
    position: fixed; inset: 0; width: 100vw; height: 100dvh; z-index: 100;
    display: flex; flex-direction: column; gap: 1rem; align-items: center; justify-content: center;
    padding: 1.5rem; background: var(--bg);
}
#app-loading p { margin: 0; color: #cbd5e1; font-size: .875rem; font-weight: 600; }
.loading-logo-wrap { position: relative; display: grid; place-items: center; width: min(19rem, 82vw); min-height: 10rem; }
.loading-logo-wrap::before, .loading-logo-wrap::after {
    content: ''; position: absolute; width: 7.5rem; height: 7.5rem;
    border: 2px solid rgba(16, 179, 160, .45); border-radius: 9999px;
    animation: loading-logo-pulse 1.8s ease-out infinite;
}
.loading-logo-wrap::after { animation-delay: .9s; }
.loading-logo-wrap img {
    position: relative; z-index: 2; display: block; width: min(5rem, 24vw); max-height: 5rem;
    height: auto; object-fit: contain; animation: loading-logo-breathe 1.8s ease-in-out infinite;
}
#app-loading .zuno-startup-meta { width: min(88vw, 31rem); display: flex; flex-direction: column; align-items: center; gap: .85rem; }
#app-loading .zuno-startup-pulse { width: min(78vw, 18rem); height: 3px; overflow: hidden; border-radius: 999px; background: rgba(148, 163, 184, .18); }
#app-loading .zuno-startup-pulse::after {
    content: ""; display: block; width: 42%; height: 100%; border-radius: inherit;
    background: linear-gradient(90deg, transparent, #10b3a0, #6ee7d8, transparent);
    animation: zuno-startup-runway 1.6s ease-in-out infinite;
}
#app-loading .zuno-startup-signals { display: flex; justify-content: center; flex-wrap: wrap; gap: .45rem; }
#app-loading .zuno-startup-signal {
    display: inline-flex; align-items: center; gap: .36rem; padding: .38rem .62rem;
    border: 1px solid rgba(94, 234, 212, .22); border-radius: 999px; background: rgba(15, 29, 40, .9);
    color: #cbd5e1; font-size: .72rem; font-weight: 600; animation: zuno-startup-chip-in .4s ease both;
}
#app-loading .zuno-startup-signal:nth-child(2) { animation-delay: 90ms; }
#app-loading .zuno-startup-signal:nth-child(3) { animation-delay: 180ms; }
#app-loading .zuno-startup-dot { width: .38rem; height: .38rem; border-radius: 50%; background: #2dd4bf; box-shadow: 0 0 0 3px rgba(45, 212, 191, .12); }
@keyframes zuno-startup-runway { 0% { transform: translateX(-120%); opacity: 0; } 18% { opacity: 1; } 78% { opacity: 1; } 100% { transform: translateX(340%); opacity: 0; } }
@keyframes zuno-startup-chip-in { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes loading-logo-pulse { 0% { opacity: 0; transform: scale(.55); } 35% { opacity: .7; } 100% { opacity: 0; transform: scale(1.55); } }
@keyframes loading-logo-breathe { 0%, 100% { transform: scale(.98); opacity: .88; } 50% { transform: scale(1.02); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
    .loading-logo-wrap::before, .loading-logo-wrap::after, .loading-logo-wrap img,
    #app-loading .zuno-startup-pulse::after, #app-loading .zuno-startup-signal { animation: none; }
}

#login-screen, #denied-screen { display: flex; align-items: center; justify-content: center; min-height: 70vh; padding: 1.5rem; }
#login-card, #denied-card {
    width: 100%; max-width: 380px; text-align: center; padding: 2.25rem 2rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: 1rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}
#login-card .platform-brand-logo { width: 4rem; height: 4rem; object-fit: contain; margin: 0 auto 1.25rem; display: block; }
#login-card .login-kicker {
    display: inline-block; font-size: .68rem; font-weight: 800; letter-spacing: .1em;
    text-transform: uppercase; color: var(--accent-soft); margin-bottom: .6rem;
}
#login-card h2 { font-size: 1.4rem; font-weight: 800; color: var(--text-strong); margin: 0 0 .5rem; letter-spacing: -.01em; }
#login-card p, #denied-screen p { color: var(--muted); margin: 0 0 1.5rem; font-size: .88rem; line-height: 1.5; }
#login-screen .btn-primary { width: 100%; display: flex; align-items: center; justify-content: center; gap: .6rem; padding: .75rem 1rem; font-weight: 700; font-size: .92rem; }
#login-screen .btn-primary svg { width: 1.05rem; height: 1.05rem; flex-shrink: 0; }
#denied-screen { color: #f87171; }
#denied-card h2 { color: #f87171; font-size: 1.3rem; font-weight: 800; margin: 0 0 .6rem; }
#denied-card .btn-primary { width: 100%; padding: .75rem 1rem; font-weight: 700; background: #dc2626; color: #fff; }
#login-logo { width: 64px; height: 64px; object-fit: contain; margin-bottom: 1rem; }

/* Platform logo tiles: the backdrop is chosen by the admin in Settings, so it ignores the page theme. */
.logo-tile { display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; }
.logo-tile.logo-bg-white, #sidebar-logo.logo-bg-white, #loading-logo.logo-bg-white, #login-logo.logo-bg-white { background: #fff; }
.logo-tile.logo-bg-dark, #sidebar-logo.logo-bg-dark, #loading-logo.logo-bg-dark, #login-logo.logo-bg-dark { background: var(--bg); }
.logo-tile.logo-bg-transparent, #sidebar-logo.logo-bg-transparent, #loading-logo.logo-bg-transparent, #login-logo.logo-bg-transparent { background: transparent; }
#sidebar-logo, #loading-logo, #login-logo { padding: 4px; }
.platform-brand-logo:not([data-branding-ready]) { visibility: visible; }

/* ---------- 3. App shell ---------- */
.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.content-shell { min-width: 0; }
.wrap { max-width: 1440px; margin: 0 auto; padding: 1.25rem 2rem 3rem; }

.sidebar {
    position: sticky; top: 0; height: 100vh; z-index: 10;
    padding: 1rem .85rem; display: flex; flex-direction: column;
    background: var(--bg-deep); border-right: 1px solid var(--line);
}
.sidebar-brand { display: flex; align-items: center; gap: .7rem; padding: .35rem .4rem; margin-bottom: 1.1rem; }
.sidebar-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 11px; flex: none; }
.sidebar-brand strong { display: block; font-size: .95rem; }
.sidebar-brand small { display: inline-block; margin-top: .15rem; padding: .05rem .4rem; border-radius: 4px; background: var(--accent-bg); color: var(--accent-soft); font-size: .6rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-nav { display: flex; flex-direction: column; gap: .2rem; }
.tab-btn { background: none; color: var(--faint); font-weight: 700; border-radius: var(--radius); }
.sidebar .tab-btn {
    width: 100%; display: flex; gap: .65rem; align-items: center; text-align: left;
    padding: .6rem .75rem; font-size: .85rem; border: 1px solid transparent;
}
.sidebar .tab-btn:hover { color: var(--text); background: rgba(148, 163, 184, .06); }
.sidebar .tab-btn.active { color: var(--accent-soft); background: var(--accent-bg); border-color: rgba(20, 184, 166, .2); }
.sidebar-footer { margin-top: auto; }
.signed-in-user { padding: .7rem .4rem; margin-bottom: .5rem; border-top: 1px solid var(--line); }
.signed-in-user strong, .signed-in-user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signed-in-user span { color: var(--faint); font-size: .72rem; margin-top: .15rem; }
.mobile-nav-toggle, .mobile-nav-backdrop { display: none; }
.back-link { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; padding: .55rem .75rem; border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); font-size: .82rem; font-weight: 700; text-decoration: none; }
.back-link:hover { color: var(--text); border-color: var(--faint); }
.card-link { display: block; margin-top: 1rem; color: var(--muted); font-size: .85rem; }

/* Page header: title, a plain "Zuno Admin" label, and the environment tag */
header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
header .kicker { display: block; margin-bottom: .3rem; color: var(--accent-soft); font-size: .64rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.env-pill { flex: none; padding: .25rem .7rem; border-radius: 999px; background: var(--line); color: var(--muted); font-size: .68rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
#error-banner { display: none; margin-bottom: 1rem; padding: .7rem 1rem; border-radius: var(--radius); background: #3f1d1d; border: 1px solid #7f1d1d; color: var(--danger-soft); font-size: .85rem; }
/* The totals and system-health blocks belong to the Businesses tab only */
body[data-tab]:not([data-tab="businesses"]) #stats-row,
body[data-tab]:not([data-tab="businesses"]) #cost-recommendations-panel { display: none !important; }
#empty-state, #loading-state { text-align: center; color: var(--faint); padding: 3rem 0; }

/* ---------- 4. Controls ---------- */
button { font: inherit; cursor: pointer; border: none; border-radius: var(--radius); padding: .7rem 1.1rem; font-weight: 700; }
.btn-primary { background: var(--accent); color: #04120f; }
.btn-secondary { background: var(--line); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: .4rem .75rem; font-size: .78rem; }
.btn-signout-muted { background: rgba(148, 163, 184, .08); color: var(--muted); border: 1px solid rgba(148, 163, 184, .18); transition: background .15s, color .15s; }
.btn-signout-muted:hover { background: rgba(239, 68, 68, .12); color: var(--danger-soft); }
input, select, textarea { font: inherit; }
select, #search-input, .field-input { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); }
select { padding: .6rem .8rem; }
#search-input { width: 100%; padding: .6rem .9rem; margin-bottom: 1rem; }
.field-label { display: block; margin: .7rem 0 .3rem; color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.field-input { width: 100%; padding: .6rem .75rem; background: var(--surface-3); }
textarea.field-input { resize: vertical; }
.toolbar { display: flex; gap: .6rem; margin-bottom: 1rem; }
.toolbar #search-input { flex: 1; margin-bottom: 0; }
.permission-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .55rem; margin: .8rem 0; }
.permission-option { display: flex; gap: .55rem; align-items: flex-start; padding: .65rem; background: var(--surface-3); border: 1px solid var(--line); border-radius: var(--radius); font-size: .8rem; }
.permission-option input { margin-top: .15rem; accent-color: var(--accent); }
.admin-access-row.inactive { opacity: .6; }

/* ---------- 5. Data: stats, tables, chips ---------- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat-card { min-height: 84px; padding: .85rem 1rem; display: flex; flex-direction: column; justify-content: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.stat-card .num { font-size: 1.55rem; font-weight: 800; line-height: 1.1; }
.stat-card .label { margin-top: .2rem; color: var(--muted); font-size: .68rem; letter-spacing: .04em; text-transform: uppercase; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: #0e1728; }
.table-wrap table { min-width: 880px; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 700; font-size: .72rem; letter-spacing: .03em; text-transform: uppercase; }
tr { cursor: pointer; }
tr:hover td { background: #0f1729; }
tr.keyboard-selected td { background: #0f1729; box-shadow: inset 2px 0 0 #10b3a0; }
.org-identity { display: flex; align-items: center; gap: .65rem; font-weight: 700; }
.org-avatar, .staff-avatar { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 9px; object-fit: cover; background: var(--line); color: var(--accent-soft); font-weight: 800; }
.plan-chip { display: inline-block; padding: .18rem .55rem; border-radius: 999px; color: #fff; font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.fees-table { margin-top: .4rem; }
.fees-table th { padding: .5rem .6rem; font-weight: 600; white-space: nowrap; text-transform: none; font-size: .85rem; }
.fees-table td { padding: .55rem .6rem; }
.fees-table tr { cursor: default; }

/* ---------- 6. Components ---------- */
/* Cards that share one look */
.panel-card, .ticket-card, .catalog-plan-card, .zai-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.panel-card { padding: 1.2rem; }

/* Support tickets */
.ticket-card { padding: 1rem; margin-bottom: .7rem; }
.ticket-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: .4rem; transition: opacity .12s; }
.ticket-card-top:hover, .ticket-msg--preview:hover { opacity: .8; }
.ticket-card .subject { font-weight: 700; }
.ticket-card .biz { color: var(--accent); font-size: .75rem; font-weight: 700; }
.ticket-card .meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; color: var(--faint); font-size: .72rem; }
.ticket-reply-count { padding: .1rem .45rem; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: #93c5fd; font-size: .65rem; font-weight: 700; }
.ticket-status-tag { flex: none; padding: .2rem .55rem; border-radius: 999px; font-size: .65rem; font-weight: 800; text-transform: uppercase; }
.ticket-status-tag--open { background: #422006; color: var(--warn); }
.ticket-status-tag--resolved { background: #0f2e1c; color: var(--ok); }
.ticket-msg { margin: .5rem 0; color: #cbd5e1; font-size: .85rem; }
.ticket-msg--preview { color: var(--faint); font-style: italic; }
.ticket-reply-item { margin-top: .4rem; padding: .5rem .7rem; border-radius: .5rem; background: var(--bg); font-size: .82rem; }
.ticket-reply-item.from-admin { border-left: 3px solid var(--accent); }
.ticket-reply-item .who { margin-bottom: .15rem; color: var(--faint); font-size: .68rem; font-weight: 700; }
.ticket-reply-box { display: flex; gap: .5rem; margin-top: .6rem; }
.ticket-reply-box textarea { flex: 1; min-height: 2.4rem; padding: .5rem .7rem; resize: vertical; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: .5rem; }
.ticket-actions { display: flex; gap: .5rem; margin-top: .6rem; }

/* Zuno AI */
.zai-card { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; padding: .7rem .9rem; margin-bottom: .5rem; }
.zai-card small { display: block; margin-top: .3rem; color: var(--faint); font-size: .72rem; }
.zai-text { margin: 0; color: var(--text); font-size: .9rem; line-height: 1.4; overflow-wrap: anywhere; }
.zai-pill { flex: none; padding: .15rem .6rem; border: 1px solid; border-radius: 999px; font-size: .68rem; font-weight: 700; white-space: nowrap; }

/* Plans */
.catalog-plan-card { display: flex; align-items: flex-start; gap: 1rem; padding: 1rem; margin-bottom: .75rem; }
.catalog-plan-card .swatch { width: .85rem; height: .85rem; margin-top: .3rem; flex: none; border-radius: 999px; }
.catalog-plan-card .name { font-weight: 800; font-size: 1.05rem; }
.catalog-plan-card .id-tag { margin-left: .4rem; color: var(--faint); font-family: monospace; font-size: .72rem; }
.catalog-plan-card .tagline { margin: .15rem 0 .5rem; color: var(--muted); font-size: .82rem; }
.catalog-plan-card .price { font-weight: 700; color: var(--accent); }
.catalog-plan-card .features { margin: .5rem 0 0; padding-left: 1.1rem; color: #cbd5e1; font-size: .78rem; }
.catalog-plan-card .features li { margin-bottom: .15rem; }
.catalog-plan-card .inactive-tag { margin-left: .5rem; color: #f87171; font-size: .65rem; font-weight: 800; text-transform: uppercase; }
.catalog-plan-card .card-actions { display: flex; gap: .4rem; margin-top: .7rem; }
.limits-grid { display: grid; grid-template-columns: 1fr; }
#promo-active-banner { margin-bottom: .6rem; padding: .7rem .85rem; border-radius: var(--radius); background: rgba(245, 158, 11, .12); border: 1px solid rgba(245, 158, 11, .35); font-size: .82rem; }
#promo-active-banner .title { font-weight: 700; color: var(--warn); }
#promo-active-banner .sub { margin-top: .15rem; color: var(--muted); font-size: .75rem; }
.promo-duration-btn.selected { border-color: var(--accent); color: var(--accent); }

/* Settings */
.settings-grid { display: grid; grid-template-columns: minmax(260px, 360px) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.brand-preview { min-height: 220px; display: grid; place-items: center; text-align: center; padding: 2rem; background: linear-gradient(135deg, var(--bg), #142238); border: 1px dashed #334155; border-radius: var(--radius-lg); }
.brand-preview img { max-width: 180px; max-height: 100px; object-fit: contain; }

/* Dialogs */
.modal-overlay { display: none; position: fixed; inset: 0; z-index: 50; align-items: center; justify-content: center; padding: 1rem; background: rgba(0, 0, 0, .6); }
.modal-overlay.open { display: flex; }
.modal-box { width: 100%; max-width: 380px; max-height: 90vh; overflow-y: auto; padding: 1.4rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 1rem; }
.modal-box h2 { margin: 0 0 .25rem; font-size: 1.15rem; }
.modal-box .sub { margin-bottom: 1rem; color: var(--faint); font-size: .8rem; }
.modal-actions { display: flex; gap: .6rem; margin-top: 1rem; }
.modal-actions button { flex: 1; }
.plan-option { display: flex; align-items: center; gap: .65rem; padding: .65rem .8rem; margin-bottom: .5rem; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.plan-option.selected { border-color: var(--accent); background: rgba(20, 184, 166, .08); }
.plan-option .name { flex: 1; font-weight: 700; }
.plan-option .price { color: var(--faint); font-size: .78rem; }

/* Business detail (full-screen panel) */
.fullscreen-overlay { padding: 0; }
.fullscreen-panel { width: 100%; height: 100%; max-width: none; display: flex; flex-direction: column; overflow: hidden; border-radius: 0; background: var(--bg); }
.fullscreen-panel-header { flex: none; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.5rem; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.fullscreen-panel-identity { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.fullscreen-panel-title { min-width: 0; }
.fullscreen-panel-header h2 { margin: 0 0 .2rem; }
.fullscreen-panel-header .sub { margin: 0; color: var(--faint); font-size: .8rem; overflow-wrap: anywhere; }
.fullscreen-panel-body { flex: 1; overflow-y: auto; padding: 1.5rem; }
.fullscreen-panel-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr); gap: 1.25rem; max-width: 1100px; margin: 0 auto; align-items: start; }
.detail-column { display: grid; gap: 1.25rem; min-width: 0; }
.detail-column-title { margin: 0; font-size: 1rem; }
.detail-column-description { margin: .25rem 0 1rem; color: var(--faint); font-size: .76rem; line-height: 1.45; }
.panel-card .detail-section-label:first-child { margin-top: 0; }
.detail-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; padding: .8rem; background: var(--bg); border-radius: var(--radius); }
.detail-meta-item .label { color: var(--faint); font-size: .65rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.detail-meta-item .value { margin-top: .1rem; font-size: .85rem; font-weight: 700; word-break: break-all; }
.detail-section-label { margin: 1rem 0 .5rem; color: var(--faint); font-size: .72rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.staff-row { padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .8rem; }
.staff-row:last-child { border-bottom: none; }
.staff-row-top { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.staff-row .name { font-weight: 700; }
.staff-row .email { color: var(--faint); font-size: .72rem; }
.staff-role-tag { padding: .15rem .5rem; border-radius: 999px; background: var(--line); color: var(--muted); font-size: .62rem; font-weight: 800; text-transform: uppercase; }
.staff-role-tag.owner-tag { background: #422006; color: var(--warn); }
.staff-row-detail { display: none; margin-top: .6rem; padding: .65rem .75rem; background: var(--bg); border: 1px solid var(--line); border-radius: .6rem; }
.staff-row.expanded .staff-row-detail { display: block; }
.staff-row-detail .permissions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .35rem; margin-top: .5rem; }
.staff-perm-chip { padding: .2rem .5rem; border-radius: .4rem; background: var(--surface); font-size: .68rem; }
.staff-perm-chip.granted { color: #67e5cb; }
.staff-perm-chip.denied { color: var(--faint); text-decoration: line-through; }

/* ---------- 7. Desktop only ---------- */
@media (min-width: 801px) {
    .social-share-grid { grid-template-columns: initial; }
}

/* ---------- 8. Phone (<= 800px): compact, one place ----------
   Goals: small cards, small type, few taps. Inputs stay 16px so iOS does not zoom. */
@media (max-width: 800px) {
    body { background: var(--bg); font-size: 14px; }
    .admin-shell { display: block !important; grid-template-columns: minmax(0, 1fr); min-height: 100dvh; } /* the script sets display:grid inline on sign-in */
    .wrap { max-width: none; padding: .6rem .6rem calc(1rem + var(--safe-bottom)); }
    button { touch-action: manipulation; padding: .55rem .9rem; font-size: .82rem; }

    /* App bar */
    .sidebar {
        position: sticky; top: 0; z-index: 70; height: auto; min-height: 52px;
        padding: calc(.4rem + var(--safe-top)) .6rem .4rem;
        display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: .45rem;
        border-right: 0; border-bottom: 1px solid var(--line-soft);
        background: rgba(8, 15, 28, .96); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    }
    .sidebar-brand { min-width: 0; margin: 0; padding: 0; gap: .5rem; }
    .sidebar-brand > div { min-width: 0; }
    .sidebar-logo { width: 32px; height: 32px; min-width: 32px; border-radius: 9px; }
    .sidebar-brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
    .sidebar-brand small { margin-top: .05rem; font-size: .55rem; }
    .sidebar-footer { display: flex; align-items: center; gap: .4rem; margin: 0; }
    .signed-in-user { display: none; }
    #sidebar-signout-btn { width: 34px !important; height: 34px; padding: 0; display: grid; place-items: center; font-size: 0; border-radius: .6rem; }
    #sidebar-signout-btn::before { content: '↪'; font-size: .95rem; line-height: 1; }

    .mobile-nav-toggle {
        width: 34px; height: 34px; padding: 0; display: grid; place-content: center; gap: 3px;
        border: 1px solid var(--line-soft); border-radius: .6rem; background: var(--surface); color: var(--text);
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-nav-toggle span { display: block; width: 15px; height: 2px; border-radius: 999px; background: currentColor; transition: transform .18s, opacity .18s; }
    body.mobile-nav-open .mobile-nav-toggle span:nth-child(1) { transform: translateY(5px) rotate(45deg); }
    body.mobile-nav-open .mobile-nav-toggle span:nth-child(2) { opacity: 0; }
    body.mobile-nav-open .mobile-nav-toggle span:nth-child(3) { transform: translateY(-5px) rotate(-45deg); }

    /* Menu drawer */
    .sidebar-nav {
        position: fixed; top: 0; left: 0; bottom: 0; z-index: 90; width: min(78vw, 290px); height: 100dvh;
        gap: .25rem; overflow-y: auto; padding: calc(4rem + var(--safe-top)) .6rem calc(1rem + var(--safe-bottom));
        background: var(--bg-deep); border-right: 1px solid var(--line-soft); box-shadow: 24px 0 60px rgba(0, 0, 0, .34);
        transform: translateX(-105%); transition: transform .2s ease; scrollbar-width: none;
    }
    .sidebar-nav::-webkit-scrollbar { display: none; }
    body.mobile-nav-open .sidebar-nav { transform: none; }
    .sidebar .tab-btn { min-height: 42px; padding: .55rem .75rem; font-size: .85rem; border-radius: .65rem; }
    .mobile-nav-backdrop { position: fixed; inset: 0; z-index: 65; display: block; background: rgba(2, 6, 23, .6); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .2s, visibility .2s; }
    body.mobile-nav-open .mobile-nav-backdrop { opacity: 1; visibility: visible; pointer-events: auto; }
    body.mobile-nav-open { overflow: hidden; }

    /* Page header */
    header { margin: 0 0 .6rem; padding: 0 0 .6rem; align-items: flex-start; gap: .5rem; }
    header > div { min-width: 0; flex: 1; }
    header h1 { font-size: 1.15rem; line-height: 1.2; }
    header .helper { display: none; }
    header .kicker { margin-bottom: .15rem; font-size: .58rem; }
    .env-pill { padding: .15rem .45rem; font-size: .58rem; }

    /* Controls */
    #search-input, select, .field-input, textarea.field-input { width: 100%; min-width: 0; min-height: 40px; font-size: 16px; }
    textarea.field-input { min-height: 90px; }
    .toolbar { display: grid; grid-template-columns: 1fr; gap: .4rem; margin-bottom: .6rem; }
    .toolbar > * { width: 100%; min-width: 0; }
    .toolbar button { min-height: 40px; }
    #search-input { margin-bottom: .6rem; }
    .toolbar #search-input { margin-bottom: 0; }

    /* Small stat tiles: number and label side by side */
    .stats-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .35rem; margin-bottom: .6rem; }
    .stat-card { min-width: 0; min-height: 0; padding: .45rem .55rem; border-radius: .6rem; }
    .stat-card .num { font-size: .95rem; }
    .stat-card .label { margin-top: .1rem; font-size: .54rem; line-height: 1.2; }

    /* Cards, tighter */
    .panel-card { padding: .7rem; border-radius: .7rem; }
    .ticket-card, .catalog-plan-card { padding: .65rem .7rem; margin-bottom: .45rem; border-radius: .7rem; }
    .catalog-plan-card { gap: .6rem; }
    .zai-card { padding: .55rem .65rem; margin-bottom: .4rem; }
    .zai-q { flex-direction: column; gap: .35rem; }
    .zai-text { font-size: .82rem; }
    .ticket-card-top { display: grid; grid-template-columns: 1fr; gap: .25rem; }
    .ticket-actions, .ticket-reply-box { display: grid; grid-template-columns: 1fr; gap: .4rem; }
    .ticket-actions button, .ticket-reply-box button { width: 100%; min-height: 38px; }
    .settings-grid, .fullscreen-panel-grid, .permission-grid, .detail-grid { grid-template-columns: 1fr !important; gap: .6rem !important; }
    .social-share-grid { grid-template-columns: 1fr !important; }
    .permission-option { padding: .5rem; }
    .brand-preview { min-height: 120px; padding: .8rem; }
    .brand-preview img { max-width: min(150px, 60vw); max-height: 70px; }
    .detail-column { gap: .6rem; }
    .detail-meta-grid { padding: .6rem; gap: .45rem; }

    /* Tables become compact cards: first cell is the title, the rest wrap as small label/value pairs */
    .table-wrap { overflow: visible; border: 0; background: transparent; }
    .table-wrap table { min-width: 0 !important; display: block; }
    #org-table, #revenue-payments-table, #revenue-upcoming-table, #login-activity-table, #admin-access-table { display: block; }
    #org-table thead, #revenue-payments-table thead, #revenue-upcoming-table thead, #login-activity-table thead, #admin-access-table thead { display: none; }
    #org-table tbody, #revenue-payments-table tbody, #revenue-upcoming-table tbody, #login-activity-table tbody, #admin-access-table tbody { display: block; }
    #org-table tr, #revenue-payments-table tr, #revenue-upcoming-table tr, #login-activity-table tr, #admin-access-table tr {
        display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .9rem;
        margin: 0 0 .4rem; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface);
    }
    #org-table td, #revenue-payments-table td, #revenue-upcoming-table td, #login-activity-table td, #admin-access-table td {
        display: inline-flex; align-items: baseline; gap: .3rem; min-width: 0; padding: 0; border: 0 !important;
        font-size: .76rem; text-align: left; overflow-wrap: anywhere;
    }
    #org-table td::before, #revenue-payments-table td::before, #revenue-upcoming-table td::before, #login-activity-table td::before, #admin-access-table td::before {
        content: attr(data-label); color: var(--faint); font-size: .6rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
    }
    /* title cells: full width, no label */
    #org-table td[data-label="Business"], #admin-access-table td[data-label="Administrator"], #login-activity-table td[data-label="Email"],
    #revenue-payments-table td[data-label="Business"], #revenue-upcoming-table td[data-label="Business"] { flex: 1 0 100%; font-size: .88rem; font-weight: 700; color: var(--text-strong); }
    #org-table td[data-label="Business"]::before, #admin-access-table td[data-label="Administrator"]::before, #login-activity-table td[data-label="Email"]::before,
    #revenue-payments-table td[data-label="Business"]::before, #revenue-upcoming-table td[data-label="Business"]::before { display: none; }
    #org-table td[data-label="Organization ID"] { flex: 1 0 100%; order: 2; font-family: monospace; font-size: .62rem; color: var(--faint); }
    #org-table td[data-label="Actions"], #admin-access-table td[data-label="Actions"] { flex: 1 0 100%; margin-top: .2rem; }
    .org-identity { min-width: 0; gap: .5rem; }
    .org-avatar, .staff-avatar { width: 28px; height: 28px; border-radius: 8px; font-size: .75rem; }
    .org-identity > span { min-width: 0; overflow-wrap: anywhere; }

    /* Business detail as a phone screen */
    .fullscreen-panel { height: 100dvh !important; border-radius: 0 !important; }
    .fullscreen-panel-header {
        position: sticky; top: 0; z-index: 4; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .45rem;
        padding: calc(.5rem + var(--safe-top)) .6rem .5rem; background: rgba(15, 23, 42, .97); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    }
    .fullscreen-panel-title h2 { font-size: .95rem; overflow-wrap: anywhere; }
    .fullscreen-panel-header .sub { font-size: .7rem; }
    .fullscreen-panel-header .btn-secondary { min-height: 34px; padding: .4rem .7rem; }
    .fullscreen-panel-body { padding: .6rem; padding-bottom: calc(1rem + var(--safe-bottom)); overflow-x: hidden; }

    /* Dialogs become bottom sheets */
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal-box { max-width: none; max-height: 88dvh; padding: .9rem .8rem calc(.8rem + var(--safe-bottom)); border-radius: 1rem 1rem 0 0; border-bottom: 0; box-shadow: 0 -20px 60px rgba(0, 0, 0, .35); }
    .modal-actions { display: grid; grid-template-columns: 1fr; gap: .4rem; }
    .modal-actions button { width: 100%; min-height: 40px; }

    /* Sign-in / denied */
    #login-screen, #denied-screen { padding: .5rem 0; }
    #login-card, #denied-card { max-width: none; padding: 1.4rem 1rem; border-radius: 1rem; }
    #login-card h2 { font-size: 1.2rem; }
    #login-logo { width: 64px; height: 64px; display: block; margin: 0 auto 1rem; }
    #login-card .btn-primary { min-height: 46px; }

    #fees-section { overflow-x: auto; }
}

/* Billing and subscription (business detail) */
.bb-head{display:flex;align-items:center;gap:.6rem;margin-bottom:.8rem}
.bb-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:.6rem}
.bb-tile{padding:.7rem .8rem;border:1px solid var(--line);border-radius:var(--radius);background:var(--bg)}
.bb-l{color:var(--faint);font-size:.68rem;font-weight:600}
.bb-v{margin-top:.15rem;font-size:1rem;font-weight:700}
.bb-s{color:var(--faint);font-size:.72rem;font-weight:500}
.bb-chip{display:inline-block;padding:.15rem .55rem;border-radius:999px;font-size:.72rem;font-weight:700;border:1px solid transparent}
.bb-ok{background:rgba(74,222,128,.14);color:var(--ok);border-color:rgba(74,222,128,.3)}
.bb-info{background:rgba(96,165,250,.14);color:#93c5fd;border-color:rgba(96,165,250,.3)}
.bb-warn{background:rgba(251,191,36,.14);color:var(--warn);border-color:rgba(251,191,36,.3)}
.bb-bad{background:rgba(239,68,68,.14);color:var(--danger-soft);border-color:rgba(239,68,68,.3)}
.bb-idle{background:rgba(148,163,184,.14);color:var(--faint);border-color:rgba(148,163,184,.3)}
:root[data-theme="light"] .bb-ok{color:#15803d}:root[data-theme="light"] .bb-info{color:#1d4ed8}:root[data-theme="light"] .bb-warn{color:#a16207}:root[data-theme="light"] .bb-bad{color:#b91c1c}
.bb-notes{margin:.8rem 0 0;padding-left:1.1rem;font-size:.82rem;line-height:1.6}
.bb-sub{margin:1rem 0 .4rem;font-size:.85rem}
.bb-table-wrap{overflow-x:auto}
.bb-table{width:100%;border-collapse:collapse;font-size:.8rem}
.bb-table th{text-align:left;color:var(--faint);font-size:.68rem;font-weight:600;padding:.35rem .5rem;border-bottom:1px solid var(--line)}
.bb-table td{padding:.5rem;border-bottom:1px solid var(--line);vertical-align:top}
@media(max-width:520px){.bb-grid{grid-template-columns:1fr 1fr}}

.bb-actions{margin-top:.8rem;display:flex;gap:.5rem;flex-wrap:wrap}
.bb-panel{margin-top:.8rem;padding:.8rem;border:1px solid var(--line);border-radius:var(--radius);background:var(--bg)}
.bb-opt{display:block;margin:.35rem 0;font-size:.82rem}
.bb-msg{min-height:1.2em;margin:.5rem 0 0;font-size:.8rem;color:var(--accent-soft)}
.bb-row-actions{white-space:nowrap}

/* period filter bar (Revenue and Online booking fees) and smaller summary cards */
.pf{display:flex;flex-wrap:wrap;gap:.4rem;align-items:center;margin:0 0 .8rem}
.pf button{min-height:36px;padding:0 .85rem;border-radius:999px;border:1px solid var(--line);background:var(--surface);color:var(--muted);font:inherit;font-size:.82rem;font-weight:600;cursor:pointer}
.pf button.on{background:var(--accent,#0f766e);border-color:var(--accent,#0f766e);color:#fff}
.pf .pf-range{display:flex;gap:.4rem;align-items:center;flex-wrap:wrap}
.pf input[type=date]{min-height:36px;font-size:.82rem}
.pf .pf-label{width:100%;color:var(--faint);font-size:.75rem}
.stats-row.compact{grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:.5rem;margin-bottom:.9rem}
.stats-row.compact .stat-card{min-height:0;padding:.5rem .7rem}
.stats-row.compact .stat-card .num{font-size:1.1rem}
.stats-row.compact .stat-card .label{font-size:.62rem;margin-top:.1rem;line-height:1.2}
.stats-row.compact .stat-card.sub{opacity:.85}
