/* ==========================================================================
   Samnvay Platform - Dashboard & Studio Stylesheet
   Modern, responsive, glassmorphic dark B2B SaaS theme
   ========================================================================== */

/* Main Application Shell */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100vw;
    overflow: hidden;
    background-color: var(--color-bg);
}

/* Sidebar Styles */
.sidebar {
    width: 270px;
    min-width: 270px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    z-index: 40;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: 1.25rem 1.25rem 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--color-text-main);
    margin-bottom: 1rem;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
    color: white;
}

.brand-text h1 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.brand-badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(99, 102, 241, 0.15);
    color: var(--color-primary-light);
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-full);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

/* Tenant Context Switcher */
.tenant-selector-box {
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.tenant-selector-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--color-text-muted);
    font-weight: 600;
    letter-spacing: 0.05em;
}

.tenant-select {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--color-text-main);
    font-size: 0.85rem;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}

.tenant-select option {
    background: var(--color-surface);
    color: var(--color-text-main);
}

/* Nav Menu */
.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Superadmin-only elements are strictly hidden by default to eliminate flicker/FOUC */
.superadmin-only {
    display: none !important;
}

html.is-superadmin .superadmin-only.nav-item {
    display: flex !important;
}

html.is-superadmin span.superadmin-only.nav-section-title {
    display: block !important;
}

html.is-superadmin #studio-direct-glb-container.superadmin-only {
    display: flex !important;
}

html.is-superadmin #studio-knowledge-step.superadmin-only {
    display: block !important;
}

html.is-superadmin #studio-voice-step.superadmin-only {
    display: block !important;
}

html.is-superadmin #studio-save-action-container.superadmin-only {
    display: block !important;
}

html.is-superadmin #studio-crawl-bar.superadmin-only {
    display: flex !important;
}

html.is-superadmin div.superadmin-only.superadmin-only-block,
html.is-superadmin .superadmin-only-block {
    display: block !important;
}

.nav-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.75rem 0.75rem 0.35rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition-fast);
    cursor: pointer;
    border: 1px solid transparent;
}

.nav-item:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-main);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.12);
    color: var(--color-primary-light);
    font-weight: 600;
    border-color: rgba(99, 102, 241, 0.25);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Sidebar Footer & Usage Quota */
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: rgba(15, 23, 42, 0.5);
}

.quota-widget {
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
}

.quota-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    margin-bottom: 0.4rem;
}

.quota-title {
    color: var(--color-text-muted);
    font-weight: 600;
}

.quota-value {
    color: var(--color-primary-light);
    font-weight: 700;
}

.quota-bar {
    width: 100%;
    height: 6px;
    background: var(--color-surface-active);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.quota-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    border-radius: var(--radius-full);
    transition: width 0.4s ease;
}

.user-profile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    overflow: hidden;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    color: white;
    flex-shrink: 0;
}

.user-meta {
    overflow: hidden;
}

.user-email {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

.user-role-badge {
    font-size: 0.65rem;
    color: var(--color-primary-light);
    font-weight: 700;
    text-transform: uppercase;
}

.btn-logout {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0.35rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-logout:hover {
    color: var(--color-danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Main Content Area */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.04) 0%, transparent 60%),
                radial-gradient(circle at 85% 85%, rgba(139, 92, 246, 0.04) 0%, transparent 60%),
                var(--color-bg);
}

/* App Header */
.app-header {
    height: 64px;
    border-bottom: 1px solid var(--color-border);
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 30;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.page-title {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--color-text-main);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.system-status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: var(--color-success);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.system-status-indicator:hover {
    background: rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.system-status-indicator:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.15);
}

.status-dot {
    width: 7px;
    height: 7px;
    background-color: var(--color-success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--color-success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.8; }
    50% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.8; }
}

/* Main Tab Viewports */
.tab-pane {
    display: none;
    padding: 1.75rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Metrics & KPI Cards */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

.metric-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.metric-card:hover {
    transform: translateY(-2px);
    border-color: rgba(99, 102, 241, 0.35);
}

.metric-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
    opacity: 0.4;
}

.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--color-text-muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.metric-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--color-surface-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary-light);
}

.metric-value {
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--color-text-main);
    letter-spacing: -0.03em;
    margin: 0.75rem 0 0.25rem;
}

.metric-sub {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.metric-sub.positive {
    color: var(--color-success);
}

/* Agents Fleet Grid */
.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.agent-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all var(--transition-fast);
}

.agent-card:hover {
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.agent-card-preview {
    height: 210px;
    background: radial-gradient(circle at center, #1e1b4b, #0f172a);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.agent-card-preview model-viewer {
    width: 100%;
    height: 100%;
}

.agent-card-avatar-placeholder {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    color: white;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.agent-card-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--color-text-main);
}

.agent-card-body {
    padding: 1.25rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.agent-card-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text-main);
}

.agent-card-description {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.agent-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.agent-tag {
    font-size: 0.7rem;
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-sm);
    background: var(--color-surface-hover);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}

.agent-card-actions {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: rgba(15, 23, 42, 0.3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* Studio Layout (Split View: Pinned 3D Viewport on Left + Scrollable Configuration Steps on Right) */
.studio-layout {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 1.5rem;
    height: calc(100vh - 180px);
    max-height: calc(100vh - 180px);
    min-height: 480px;
    overflow: hidden;
    align-items: stretch;
}

@media (max-width: 1024px) {
    .studio-layout {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
        overflow: visible;
        padding-bottom: 3rem;
    }
}

.studio-preview-pane {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    padding: 0.75rem;
    gap: 0.75rem;
}

.studio-preview-viewport {
    flex: 1;
    min-height: 0;
    border-radius: var(--radius-md);
    background: radial-gradient(circle at center, #1e1b4b, #090d16);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.studio-preview-controls {
    padding: 0.85rem 1rem;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.studio-form-pane {
    background: transparent;
    border: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.75rem;
    padding-bottom: 2.5rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.4) rgba(15, 23, 42, 0.4);
}

.studio-form-pane::-webkit-scrollbar {
    width: 6px;
}

.studio-form-pane::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.4);
    border-radius: 999px;
}

.studio-form-pane::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.4);
    border-radius: 999px;
}

.studio-form-pane::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.7);
}

.studio-form-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    background: rgba(15, 23, 42, 0.4);
    padding: 0 1rem;
    overflow-x: auto;
}

.studio-tab-btn {
    padding: 0.85rem 1rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.studio-tab-btn.active {
    color: var(--color-primary-light);
    border-bottom-color: var(--color-primary);
}

.studio-tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1.5rem;
}

.modal-backdrop.active {
    display: flex;
}

.modal-box {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-box.large {
    max-width: 900px;
    height: 80vh;
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.5rem;
}

.modal-close:hover {
    color: var(--color-text-main);
    background: var(--color-surface-hover);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    background: rgba(15, 23, 42, 0.3);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ==========================================================================
   Tables & Data Grids (Enterprise SaaS)
   ========================================================================== */
.table-container {
    width: 100%;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.table-scroll {
    max-height: 520px;
    overflow-y: auto;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    color: var(--color-text-main);
    text-align: left;
}

.table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #0d1526 !important;
    box-shadow: 0 1px 0 var(--color-border);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.table tbody tr {
    transition: background-color var(--transition-fast);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.table tbody tr:last-child {
    border-bottom: none;
}

.table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.table tbody td {
    padding: 1rem 1.25rem;
    vertical-align: middle;
}

/* Multi-tenant directory — compact, scannable rows */
.tenants-table .tn-name {
    font-weight: 700;
    color: #f8fafc;
    font-size: 0.92rem;
}
.tenants-table .tn-meta {
    margin-top: 3px;
    font-size: 0.72rem;
    color: var(--color-text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.tenants-table .tn-stat {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.tenants-table .tn-stat strong {
    color: #f1f5f9;
    font-weight: 700;
}
.tenants-table .tn-stat span {
    color: var(--color-text-muted);
    font-weight: 500;
}
.tenants-table .tn-quota {
    min-width: 140px;
    max-width: 180px;
}
.tenants-table .tn-quota-line {
    font-variant-numeric: tabular-nums;
    font-size: 0.84rem;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
}
.tenants-table .tn-quota-bar {
    margin-top: 6px;
    height: 5px;
    border-radius: 99px;
    background: rgba(148, 163, 184, 0.2);
    overflow: hidden;
}
.tenants-table .tn-quota-bar > i {
    display: block;
    height: 100%;
    border-radius: 99px;
}
.tenants-table .tn-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    flex-wrap: nowrap;
}
.tenants-table .tn-actions .btn {
    padding: 4px 10px;
    font-size: 0.75rem;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1;
    white-space: nowrap;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-primary {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border: 1px solid rgba(99, 102, 241, 0.35);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.35);
}

.mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #94a3b8;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem !important;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Studio Header Bar */
.studio-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.studio-selector-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.studio-avatar-ring {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   Loaders, Spinners & Progress Indicators
   ========================================================================== */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.04); }
}

.spinner-border {
    display: inline-block;
    width: 1.15rem;
    height: 1.15rem;
    vertical-align: -0.15em;
    border: 0.16em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.spinner-border-sm {
    width: 0.85rem;
    height: 0.85rem;
    border-width: 0.14em;
    margin-right: 0.4rem;
}

/* 3D Viewport Glassmorphic Loader Overlay */
.viewport-loader-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    background: rgba(9, 13, 22, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.viewport-loader-spinner {
    width: 48px;
    height: 48px;
    border: 3.5px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--color-primary, #6366f1);
    border-right-color: var(--color-primary-light, #818cf8);
    border-radius: 50%;
    animation: spin 0.85s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    margin-bottom: 1rem;
    box-shadow: 0 0 25px rgba(99, 102, 241, 0.35);
}

.viewport-loader-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #f8fafc;
    margin-bottom: 0.65rem;
    letter-spacing: -0.01em;
}

.viewport-loader-progress-wrap {
    width: 220px;
    max-width: 80%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
    margin-bottom: 0.45rem;
}

.viewport-loader-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #6366f1, #a855f7, #38bdf8);
    border-radius: 999px;
    transition: width 0.2s ease-out;
}

.viewport-loader-percent {
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: #cbd5e1;
}

/* Avatar Mode Selector Cards */
.avatar-mode-card {
    border-radius: var(--radius-md);
    padding: 0.85rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    position: relative;
}

.avatar-mode-card:hover {
    border-color: rgba(99, 102, 241, 0.6) !important;
    transform: translateY(-1px);
}

.avatar-mode-card.active {
    background: rgba(99, 102, 241, 0.12) !important;
    border-color: var(--color-primary, #6366f1) !important;
    box-shadow: 0 0 0 1px var(--color-primary, #6366f1), 0 4px 14px rgba(99, 102, 241, 0.2);
}

/* In-progress API Banner */
.api-process-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin-top: 0.75rem;
    animation: pulseGlow 3s ease-in-out infinite;
}

/* ==========================================================================
   Audit Ledger — tenant + platform console
   ========================================================================== */
.audit-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 1.15rem;
    flex-wrap: wrap;
}
.audit-hero h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: #f8fafc;
}
.audit-hero p {
    margin: 6px 0 0;
    max-width: 560px;
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--color-text-muted);
}
.audit-hero-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.audit-scope-pill {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #c4b5fd;
    background: rgba(124, 58, 237, 0.16);
    border: 1px solid rgba(167, 139, 250, 0.35);
}
.audit-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
    gap: 12px;
    margin-bottom: 1rem;
}
.audit-stat {
    padding: 14px 14px 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.55), rgba(15, 23, 42, 0.7));
}
.audit-stat-label {
    color: #94a3b8;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.audit-stat-value {
    color: #f8fafc;
    font-size: 1.35rem;
    font-weight: 750;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}
.audit-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.audit-filter {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(15, 23, 42, 0.65);
    color: #cbd5e1;
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 12.5px;
    font-weight: 650;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.audit-filter:hover {
    border-color: rgba(167, 139, 250, 0.4);
    color: #f8fafc;
}
.audit-filter.active {
    background: rgba(124, 58, 237, 0.22);
    border-color: rgba(167, 139, 250, 0.55);
    color: #ede9fe;
}
.audit-table-wrap {
    overflow: hidden;
}
.audit-table {
    min-width: 960px;
    width: 100%;
}
.audit-table tbody td {
    vertical-align: middle;
    padding: 0.85rem 1rem;
    color: #e2e8f0;
}
.audit-cell-when {
    white-space: nowrap;
    width: 135px;
}
.audit-time {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.audit-time strong {
    color: #f1f5f9;
    font-size: 0.82rem;
    font-weight: 650;
}
.audit-time span {
    color: #64748b;
    font-size: 0.72rem;
}
.audit-cell-tenant {
    max-width: 170px;
    white-space: nowrap;
}
.audit-tenant-cell {
    display: flex;
    align-items: center;
}
.audit-tenant-name {
    font-weight: 600;
    color: #f1f5f9;
    font-size: 0.84rem;
}
.audit-tenant-global {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.18rem 0.5rem;
    border-radius: 6px;
    background: rgba(148, 163, 184, 0.12);
    color: #94a3b8;
    font-size: 0.74rem;
    font-weight: 500;
    border: 1px dashed rgba(148, 163, 184, 0.25);
    white-space: nowrap;
}
.audit-cell-stream,
.audit-cell-cat,
.audit-cell-level {
    white-space: nowrap;
}
.audit-cell-action {
    white-space: normal;
    min-width: 140px;
    max-width: 200px;
}
.audit-action-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.audit-action-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: #f8fafc;
    font-size: 0.84rem;
    line-height: 1.3;
}
.audit-action-icon {
    font-size: 0.92rem;
    line-height: 1;
}
.audit-action-sub {
    font-size: 0.68rem;
    color: #64748b;
    font-family: ui-monospace, 'JetBrains Mono', monospace;
}
.audit-cell-msg {
    white-space: normal !important;
    min-width: 250px;
    max-width: 440px;
    line-height: 1.45;
    word-break: break-word;
}
.audit-msg-wrap {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}
.audit-msg-text {
    color: #cbd5e1;
    font-size: 0.82rem;
}
.audit-msg-text strong {
    color: #f8fafc;
    font-weight: 600;
}
.audit-code-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: ui-monospace, 'JetBrains Mono', monospace;
    white-space: nowrap;
    line-height: 1.2;
}
.audit-code-pill.status-ok {
    background: rgba(16, 185, 129, 0.16);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.35);
}
.audit-code-pill.status-warn {
    background: rgba(245, 158, 11, 0.16);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.35);
}
.audit-code-pill.status-danger {
    background: rgba(239, 68, 68, 0.16);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.35);
}
.audit-plan-transition {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.28);
    border-radius: 6px;
    padding: 0.18rem 0.55rem;
    font-size: 0.78rem;
    color: #e2e8f0;
}
.audit-plan-transition .from {
    color: #94a3b8;
}
.audit-plan-transition .arrow {
    color: #818cf8;
    font-weight: bold;
}
.audit-plan-transition .to {
    color: #38bdf8;
    font-weight: 600;
}
.audit-cell-actor {
    white-space: nowrap;
    max-width: 170px;
}
.audit-actor-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.audit-actor-chip.user {
    color: #cbd5e1;
}
.audit-actor-chip.embed {
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
}
.audit-actor-chip.system {
    color: #94a3b8;
    font-style: italic;
}
.audit-pill {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.71rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.2;
    white-space: nowrap;
    border: 1px solid transparent;
}
.audit-pill-event {
    background: rgba(99, 102, 241, 0.14);
    color: #a5b4fc;
    border-color: rgba(99, 102, 241, 0.3);
}
.audit-pill-ok {
    background: rgba(16, 185, 129, 0.14);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.3);
}
.audit-pill-warn {
    background: rgba(245, 158, 11, 0.14);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.3);
}
.audit-pill-danger {
    background: rgba(239, 68, 68, 0.14);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}
.audit-pill-muted {
    background: rgba(148, 163, 184, 0.12);
    color: #94a3b8;
    border-color: rgba(148, 163, 184, 0.25);
}
.audit-pill-cat-billing { background: rgba(16, 185, 129, 0.14); color: #34d399; border-color: rgba(16, 185, 129, 0.3); }
.audit-pill-cat-wallet { background: rgba(20, 184, 166, 0.14); color: #2dd4bf; border-color: rgba(20, 184, 166, 0.3); }
.audit-pill-cat-agent { background: rgba(99, 102, 241, 0.14); color: #a5b4fc; border-color: rgba(99, 102, 241, 0.3); }
.audit-pill-cat-avatar { background: rgba(168, 85, 247, 0.14); color: #c084fc; border-color: rgba(168, 85, 247, 0.3); }
.audit-pill-cat-authentication { background: rgba(59, 130, 246, 0.14); color: #60a5fa; border-color: rgba(59, 130, 246, 0.3); }
.audit-pill-cat-security { background: rgba(245, 158, 11, 0.14); color: #fbbf24; border-color: rgba(245, 158, 11, 0.3); }
.audit-pill-cat-crawler { background: rgba(6, 182, 212, 0.14); color: #22d3ee; border-color: rgba(6, 182, 212, 0.3); }
.audit-pill-cat-voice { background: rgba(132, 204, 22, 0.14); color: #a3e635; border-color: rgba(132, 204, 22, 0.3); }
.audit-pill-cat-error { background: rgba(239, 68, 68, 0.14); color: #f87171; border-color: rgba(239, 68, 68, 0.3); }
.audit-pill-cat-ops { background: rgba(148, 163, 184, 0.14); color: #cbd5e1; border-color: rgba(148, 163, 184, 0.3); }
.audit-muted {
    color: #94a3b8;
}
.audit-strong {
    color: #f8fafc;
    font-weight: 600;
}
.audit-change {
    font-family: ui-monospace, 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: #cbd5e1;
}
.audit-sessions-delta {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}
.audit-sessions-delta.pos { color: #34d399; }
.audit-sessions-delta.neg { color: #f87171; }
.audit-sessions-delta.zero { color: #94a3b8; }

.analytics-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin: 0 0 1rem;
}
.audit-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin: 0.75rem 0 1rem;
}
.audit-search {
    flex: 1 1 220px;
    min-width: 180px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: #e2e8f0;
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
}
.audit-select {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: #e2e8f0;
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    font-size: 0.8rem;
}
.audit-tenant-select {
    flex: 1 1 200px;
    min-width: 180px;
    max-width: 320px;
    font-weight: 600;
}
.audit-focus-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    margin: 0.35rem 0 0.75rem;
}
/* CSS display:flex otherwise overrides the HTML hidden attribute */
.audit-focus-row[hidden],
.audit-select[hidden],
.audit-toggle[hidden],
.audit-demo-guide[hidden] {
    display: none !important;
}
.audit-demo-guide {
    margin: 0 0 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.55);
    color: #cbd5e1;
    font-size: 0.82rem;
    line-height: 1.45;
}
.audit-demo-guide strong {
    display: block;
    color: #f8fafc;
    margin-bottom: 0.45rem;
    font-size: 0.9rem;
}
.audit-demo-guide ol {
    margin: 0;
    padding-left: 1.2rem;
}
.audit-demo-guide li {
    margin: 0.25rem 0;
}
.audit-demo-guide b {
    color: #e2e8f0;
}
.audit-focus-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
    margin-right: 0.25rem;
}
.audit-chip {
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(15, 23, 42, 0.55);
    color: #cbd5e1;
    border-radius: 999px;
    padding: 0.28rem 0.7rem;
    font-size: 0.75rem;
    cursor: pointer;
}
.audit-chip:hover { border-color: rgba(167, 139, 250, 0.5); color: #f8fafc; }
.audit-chip.active {
    background: rgba(124, 58, 237, 0.28);
    border-color: rgba(167, 139, 250, 0.65);
    color: #f5f3ff;
    font-weight: 600;
}
.audit-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: #cbd5e1;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
.audit-toggle input { accent-color: #8b5cf6; }
.audit-expand-cell {
    width: 72px;
    text-align: right;
}
.audit-row-detail td {
    background: rgba(2, 6, 23, 0.55);
    border-top: none !important;
    padding: 0.75rem 1rem 1rem !important;
}
.audit-detail-json {
    margin: 0;
    max-height: 240px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
    line-height: 1.45;
    color: #cbd5e1;
    white-space: pre-wrap;
    word-break: break-word;
}
.audit-detail-container {
    padding: 0.35rem 0;
}
.audit-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.6rem;
    margin-bottom: 0.6rem;
    background: rgba(15, 23, 42, 0.7);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.15);
}
.audit-detail-item {
    font-size: 0.8rem;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.audit-detail-item strong {
    color: #94a3b8;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.audit-detail-item code {
    background: rgba(0, 0, 0, 0.4);
    padding: 0.12rem 0.4rem;
    border-radius: 4px;
    color: #38bdf8;
    font-family: ui-monospace, 'JetBrains Mono', monospace;
    font-size: 0.75rem;
}

/* Production table pager */
.admin-pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(8, 12, 22, 0.55);
}
.admin-pager.is-loading,
.admin-pager-loading {
    opacity: 0.72;
    pointer-events: none;
}
.admin-pager-loading {
    justify-content: center;
    color: #94a3b8;
    font-size: 12.5px;
}
.admin-pager-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #94a3b8;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}
.admin-pager-size select {
    height: 30px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: #0f172a;
    color: #e2e8f0;
    padding: 0 8px;
    font-size: 12px;
}
.admin-pager-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}
.admin-pager-page {
    color: #cbd5e1;
    font-size: 12.5px;
    font-weight: 600;
    min-width: 88px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.admin-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.admin-toolbar input[type="search"],
.admin-toolbar select {
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(15, 23, 42, 0.85);
    color: #e2e8f0;
    padding: 0 12px;
    font-size: 13px;
    min-width: 180px;
}


