/* app.css - Global styles for Lyberon PWA */

/* ============================================
   Global Utilities
   ============================================ */

/* Conditional visibility class used by data-binding.js */
.visibility-hidden {
    display: none !important;
}

/* Generic floating utility for overlay-style components */
.ui-floating {
    position: absolute;
    z-index: var(--floating-z, 100);
    background: var(--floating-bg, var(--bg-surface, rgba(22, 27, 34, 0.95)));
    border: var(--floating-border-width, 1px) solid var(--floating-border, var(--color-border, rgba(0, 229, 255, 0.25)));
    border-radius: var(--floating-radius, 12px);
    padding: var(--floating-padding, 1rem);
    box-shadow: var(--floating-shadow, 0 8px 32px rgba(0, 0, 0, 0.5));
    color: var(--floating-text, var(--text-primary, #fff));
    backdrop-filter: var(--floating-backdrop-filter, blur(12px));
    -webkit-backdrop-filter: var(--floating-backdrop-filter, blur(12px));
}

.ui-floating--top-left { top: 1rem; left: 1rem; }
.ui-floating--top-right { top: 1rem; right: 1rem; }
.ui-floating--bottom-left { bottom: 1rem; left: 1rem; }
.ui-floating--bottom-right { bottom: 1rem; right: 1rem; }

/* ============================================
   Base Styles
   ============================================ */

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary, #f5f5f5);
    color: var(--text-primary, #111);
    overflow: hidden; /* No body scroll - app-frame handles viewport */
    height: 100vh;
}

#app {
    height: 100vh;
    overflow: hidden;
}

/* App frame - flex column structure */
.app-frame {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden; /* Frame doesn't scroll - ContentRoot does */
    background: var(--bg-primary);
    color: var(--text-primary);
}

.app-header {
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    background: var(--bg-header);
    color: var(--text-header);
    display: flex;
    justify-content: flex-start; /* Changed from space-between */
    align-items: center;
    gap: 0.5rem;
    max-width: 100%;
    overflow: hidden; /* Prevent any overflow */
    box-sizing: border-box;
}

/* Content root - the scrollable main content area */
.content-root {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    min-height: 0; /* Critical for flex child scrolling */
    background: var(--bg-content);
    color: var(--text-primary);
}

.app-footer {
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    background: var(--bg-footer);
    color: var(--text-footer);
    text-align: center;
    font-size: 0.875rem;
}

/* Footer is mobile-only control bar */
.app-footer.mobile-only {
    display: none;
}

@media (max-width: 767.98px) {
    .app-footer.mobile-only {
        display: block;
    }
}

/* Themed content areas */
.landing-page,
.showcase-page {
    background: var(--bg-content);
    color: var(--text-primary);
    padding: 0 !important;
    min-height: min-content;
}

/* Compact Bootstrap form components */
.form-control,
.form-select {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 0.75rem;
    height: calc(1.5em + 0.75rem + 2px);
}

.form-control-sm,
.form-select-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    height: calc(1.5em + 0.5rem + 2px);
}

input[type="text"],
input[type="number"],
input[type="search"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-bottom: 0.75rem;
}

button,
.btn {
    margin-bottom: 0.75rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* Bootstrap grid for components */
.component-wrapper,
[data-component-type],
[data-component-code] {
    margin-bottom: 0.75rem;
    clear: both;
    overflow: visible;
    position: relative;
}

/* Prevent float collapse */
[data-component-type]::after,
[data-component-code]::after {
    content: "";
    display: table;
    clear: both;
}

/* Use Bootstrap grid utilities */
.showcase-page,
.landing-page {
    max-width: 100%;
    box-sizing: border-box;
}

/* Showcase page uses full width with Bootstrap row behavior */
.showcase-page {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0 1rem;
}

/* Components inherit Bootstrap col-* classes from ComponentRenderer */

/* Optional: Enable grid for non-showcase pages */
@media (min-width: 768px) {
    .landing-page:not(.showcase-page) {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 1rem;
        align-items: start;
    }
    
    /* Full width for headings and images */
    .landing-page h1, 
    .landing-page h2, 
    .landing-page h3, 
    .landing-page h4, 
    .landing-page h5, 
    .landing-page h6,
    .landing-page [data-component-type="heading"],
    .landing-page [data-component-type="image"] {
        grid-column: 1 / -1;
    }
}

h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    margin-bottom: 0.75rem;
    line-height: 1.3;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p {
    margin-top: 0;
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Chart components */
.chart-container {
    min-height: 300px;
    max-height: 400px;
    min-width: 300px;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: var(--bg-content);
    border-radius: 0.25rem;
}

.chart-container canvas {
    max-height: 300px !important;
    min-width: 250px !important;
}

/* ============================================
   Table Styles (Theme-Aware)
   Override Bootstrap defaults with theme colors
   ============================================ */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-background, #fff) !important;
    color: var(--color-text-primary, #111) !important;
}

table thead {
    background: var(--color-surface, #f8f9fa) !important;
    color: var(--color-text-primary, #111) !important;
    border-bottom: 2px solid var(--color-border, #dee2e6) !important;
}

table thead th {
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-text-primary, #111) !important;
    background-color: transparent !important;
}

table tbody tr {
    border-bottom: 1px solid var(--color-border, #dee2e6) !important;
    transition: background-color 0.15s ease;
}

table tbody td {
    padding: 0.75rem;
    font-size: 0.875rem;
    color: var(--color-text-primary, #111) !important;
}

table tbody td * {
    color: inherit !important;
}

/* Striped table rows using theme colors - override Bootstrap */
table.table-striped tbody tr:nth-child(odd),
table.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: var(--color-background, #fff) !important;
    --bs-table-bg-type: var(--color-background, #fff) !important;
}

table.table-striped tbody tr:nth-child(even),
table.table-striped > tbody > tr:nth-of-type(even) > * {
    background-color: var(--color-surface, #f8f9fa) !important;
    --bs-table-bg-type: var(--color-surface, #f8f9fa) !important;
}

/* Hover effect for interactive tables */
table tbody tr:hover,
table tbody tr:hover > * {
    background-color: var(--color-surface-hover, #f1f3f5) !important;
}

/* Compact tables */
table.table-sm thead th,
table.table-sm tbody td {
    padding: 0.5rem;
    font-size: 0.8125rem;
}

/* Textarea sizing */
textarea.form-control {
    min-height: 150px;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .content-root {
        padding: 0.5rem;
    }
    
    .app-frame {
        font-size: 0.9rem;
    }
    
    .showcase-page,
    .landing-page {
        padding: 0.5rem !important;
        display: block !important; /* Disable grid on mobile */
    }
    
    /* Reduce input heights on mobile */
    .form-control,
    .form-select,
    input, select, textarea {
        font-size: 0.875rem;
        padding: 0.25rem 0.5rem;
    }
    
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
}

@media (max-width: 480px) {
    body {
        font-size: 14px;
    }
    
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.3rem; }
    h3 { font-size: 1.1rem; }
}

.app-header {
    color: #ffffff;
    min-height: auto;
}

.app-sidebar {
    color: #ffffff;
}

.app-footer {
    color: #ffffff;
}

.landing-page,
.showcase-page,
.content-root,
.page-root {
    color: #111;
}

/* ============================================
   Header Navigation Components
   ============================================ */

/* Generic icon button base */
.icon-btn {
    background: transparent;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md, 0.25rem);
    transition: background-color 0.15s ease;
    color: inherit; /* Inherit from parent (header) */
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    /* SVG uses stroke="currentColor" so it inherits the text color */
}

/* Hamburger Button - Desktop/Tablet only */
.hamburger-btn {
    background: transparent;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md, 0.25rem);
    transition: background-color 0.15s ease;
    color: inherit; /* Inherit text color from header */
}

.hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.hamburger-btn svg {
    width: 24px;
    height: 24px;
    /* Uses stroke="currentColor" - inherits from button's color */
}

/* Page Title - Clickable on mobile */
.page-title {
    margin: 0 !important;
    padding: 0;
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
    border: none !important;
    padding-bottom: 0 !important;
}

/* Mobile: Page title becomes nav trigger */
@media (max-width: 767.98px) {
    .page-title {
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 0.25rem;
    }

    .page-title::after {
        content: '▾';
        font-size: 0.75rem;
        opacity: 0.7;
        transition: transform 0.2s ease;
    }

    .page-title:hover::after,
    .page-title:focus::after {
        opacity: 1;
    }

    .page-title[aria-expanded="true"]::after {
        transform: rotate(180deg);
    }
}

/* Header Spacer */
.header-spacer {
    flex: 1;
    min-width: 1rem;
}

/* Tenant Selector */
.tenant-selector {
    max-width: 180px;
    margin: 0;
}

/* Hide tenant selector when only one option or no data */
.tenant-selector.single-tenant,
.tenant-selector:empty,
.tenant-selector.visibility-hidden {
    display: none !important;
}

.tenant-selector select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: inherit;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    border-radius: var(--radius-md, 0.25rem);
    cursor: pointer;
}

.tenant-selector select:focus {
    outline: none;
    border-color: var(--color-accent, #F8B603);
    box-shadow: 0 0 0 2px rgba(248, 182, 3, 0.25);
}

@media (max-width: 575.98px) {
    .tenant-selector {
        max-width: 100px;
    }
    
    .tenant-selector select {
        font-size: 0.75rem;
        padding: 0.2rem 0.35rem;
    }
}

/* Profile Button */
.profile-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    color: inherit; /* Inherit text color from header */
}

.profile-btn:hover,
.profile-btn:focus {
    border-color: var(--color-accent, #F8B603);
    box-shadow: 0 0 0 2px rgba(248, 182, 3, 0.25);
    outline: none;
}

.profile-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-btn svg {
    width: 20px;
    height: 20px;
    /* Uses stroke="currentColor" - inherits from button's color */
    opacity: 0.8;
}

@media (max-width: 575.98px) {
    .profile-btn {
        width: 32px;
        height: 32px;
    }
    
    .profile-btn svg {
        width: 16px;
        height: 16px;
    }
}

/* ============================================
   Navigation Overlay (Unified for all viewports)
   Glass-like semi-transparent background
   ============================================ */

.nav-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    display: none;
}

.nav-backdrop.active {
    display: block !important;
    opacity: 1;
    pointer-events: auto;
}

.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    z-index: 1000;
    background: var(--bg-sidebar, rgba(52, 73, 94, 0.95));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-sidebar, #fff);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.3);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: none;
    flex-direction: column;
}

.nav-overlay.active {
    display: flex !important;
    transform: translateX(0);
}

.nav-overlay-header {
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.1);
    width: 100%;
    box-sizing: border-box;
}

.nav-overlay-title {
    margin: 0 !important;
    border: none !important;
    padding-bottom: 0 !important;
    color: inherit;
}

.nav-overlay-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    color: inherit;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--radius-md, 0.25rem);
    transition: background-color 0.15s ease;
    z-index: 10;
}

.nav-overlay-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.nav-overlay-close svg {
    width: 24px;
    height: 24px;
}

.nav-overlay-menu {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ============================================
   Menu Items
   ============================================ */

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    color: inherit;
    text-decoration: none;
    border-radius: var(--radius-md, 0.25rem);
    margin: 0.25rem 0;
    transition: background-color 0.15s ease;
    cursor: pointer;
    font-size: 0.95rem;
}

.menu-item:hover,
.menu-item:focus {
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

.menu-item.active {
    background: rgba(255, 255, 255, 0.15);
    font-weight: 600;
}

.menu-item-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.8;
}

.menu-item-icon svg {
    width: 100%;
    height: 100%;
}

.menu-item-label {
    flex: 1;
}

/* Menu Group (collapsible section) */
.menu-group {
    margin: 0.5rem 0;
}

.menu-group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.7;
    cursor: pointer;
}

.menu-group-header:hover {
    opacity: 1;
}

.menu-group-chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
}

.menu-group.collapsed .menu-group-chevron {
    transform: rotate(-90deg);
}

.menu-group-content {
    overflow: hidden;
    transition: max-height 0.2s ease;
}

.menu-group.collapsed .menu-group-content {
    max-height: 0;
}

/* Page-contributed menu items section */
.menu-group-page {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

/* ============================================
   Mobile: Nav overlay becomes full screen
   ============================================ */

@media (max-width: 767.98px) {
    .nav-overlay {
        width: 100vw !important;
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
        background: var(--bg-primary, rgba(255, 255, 255, 0.98));
        color: var(--text-primary, #111);
    }
    
    .nav-overlay-header {
        background: var(--bg-header);
        color: var(--text-header);
    }
    
    /* Larger touch targets on mobile */
    .menu-item {
        padding: 1rem 1.25rem;
        font-size: 1.1rem;
        margin: 0;
        border-radius: 0;
        border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.1));
    }
    
    .menu-item-icon {
        width: 24px;
        height: 24px;
    }
    
    .menu-group-header {
        padding: 0.75rem 1.25rem;
        font-size: 0.8rem;
    }
    
    /* Hide backdrop on mobile since overlay is full screen */
    .nav-backdrop {
        display: none !important;
    }
}

/* ============================================
   Legacy class support (will remove later)
   ============================================ */

/* Development/Debug styles */
.page-renderer-stub,
.component-renderer-stub {
    margin: 1rem;
}

/* ============================================
   Header Auth: user pill, connection dot, user menu
   ============================================ */
.header-auth-area {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

/* .connection-dot removed — replaced by .header-online-indicator */

/* ============================================
   Header Online Indicator (failure-driven, not polling)
   ============================================ */
.header-online-indicator {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    opacity: 0.85;
    user-select: none;
}
.header-online-indicator .indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.4s ease, box-shadow 0.4s ease;
}
.header-online-indicator .indicator-label {
    transition: color 0.4s ease;
}
.header-online-indicator[data-online="true"] .indicator-dot {
    background: var(--color-success, #00FF99);
    box-shadow: 0 0 5px var(--color-success, #00FF99);
}
.header-online-indicator[data-online="true"] .indicator-label {
    color: var(--color-success, #00FF99);
}
.header-online-indicator[data-online="false"] .indicator-dot {
    background: var(--color-danger, #FF3366);
    box-shadow: 0 0 5px var(--color-danger, #FF3366);
}
.header-online-indicator[data-online="false"] .indicator-label {
    color: var(--color-danger, #FF3366);
}

/* ============================================
   Header Online Indicator (connectivity state)
   Driven by State.isOnline via script component.
   data-online="true"  → green dot + "Online"
   data-online="false" → red dot  + "Offline"
   ============================================ */
.header-online-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted, #888);
    user-select: none;
    white-space: nowrap;
}

.header-online-indicator .indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.4s ease, box-shadow 0.4s ease;
    background: var(--color-text-muted, #888);
}

.header-online-indicator[data-online="true"] .indicator-dot {
    background: var(--color-success, #00FF99);
    box-shadow: 0 0 5px var(--color-success, #00FF99);
}

.header-online-indicator[data-online="false"] .indicator-dot {
    background: var(--color-danger, #FF3366);
    box-shadow: 0 0 5px var(--color-danger, #FF3366);
}

.header-online-indicator[data-online="true"] .indicator-label {
    color: var(--color-success, #00FF99);
}

.header-online-indicator[data-online="false"] .indicator-label {
    color: var(--color-danger, #FF3366);
}

/* Hide text label on small screens, keep dot */
@media (max-width: 480px) {
    .header-online-indicator .indicator-label {
        display: none;
    }
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    border: 1px solid var(--color-border, rgba(255,255,255,0.2));
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 0.8rem;
    transition: border-color 0.2s, background 0.2s;
    white-space: nowrap;
}
.user-pill:hover {
    border-color: var(--color-primary, #00E5FF);
    background: rgba(255,255,255,0.05);
}
.user-pill-icon { display: flex; align-items: center; }
.user-pill-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.user-pill-chevron { font-size: 0.65rem; opacity: 0.6; }

.user-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 240px;
    border-radius: 0.5rem;
    border: 1px solid var(--color-border, rgba(255,255,255,0.15));
    background: var(--bg-primary, #161B22);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 2000;
    overflow: hidden;
}

.user-menu-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}
.user-menu-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--color-primary, #00E5FF);
    color: var(--color-background, #0D1117);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}
.user-menu-info { min-width: 0; }
.user-menu-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary, #fff);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-menu-email {
    font-size: 0.75rem;
    color: var(--text-secondary, #888);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu-divider {
    height: 1px;
    background: var(--color-border, rgba(255,255,255,0.1));
    margin: 0.25rem 0;
}

.user-menu-section-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #888);
    padding: 0.5rem 1rem 0.25rem;
    font-weight: 600;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-primary, #fff);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
    text-align: left;
}
.user-menu-item:hover {
    background: rgba(255,255,255,0.05);
}
.user-menu-item.active {
    color: var(--color-primary, #00E5FF);
}
.user-menu-check {
    margin-left: auto;
    font-size: 0.7rem;
}
.user-menu-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

/* ============================================
   Auth SSO icon row (login page)
   ============================================ */
.auth-sso-row {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.auth-sso-icon {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--color-border, rgba(255,255,255,0.2));
    background: var(--bg-surface, rgba(255,255,255,0.05));
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.auth-sso-icon:hover {
    border-color: var(--color-primary, #00E5FF);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.auth-sso-icon.last-used {
    border-color: var(--color-primary, #00E5FF);
    box-shadow: 0 0 0 2px var(--color-primary-light, rgba(0,229,255,0.2));
}
.auth-sso-logo { display: flex; align-items: center; }

.auth-sso-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.35rem 0.6rem;
    border-radius: 0.25rem;
    background: var(--bg-primary, #161B22);
    color: var(--text-primary, #fff);
    font-size: 0.7rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    border: 1px solid var(--color-border, rgba(255,255,255,0.15));
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.auth-sso-icon:hover .auth-sso-tooltip {
    opacity: 1;
}

/* Auth form feedback */
.auth-error {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
    border: 1px solid rgba(220, 53, 69, 0.3);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}
.auth-success {
    background: rgba(40, 167, 69, 0.1);
    color: #28a745;
    border: 1px solid rgba(40, 167, 69, 0.3);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}
.auth-info, .auth-ad-autologin-status .auth-info {
    background: rgba(0, 123, 255, 0.1);
    color: #007bff;
    border: 1px solid rgba(0, 123, 255, 0.2);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    text-align: center;
    animation: pulse-subtle 1.5s ease-in-out infinite;
}
@keyframes pulse-subtle {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}
.auth-mode-toggle {
    text-align: center;
    font-size: 0.85rem;
    margin-top: 0.75rem;
}
.auth-mode-toggle a {
    color: var(--accent-primary, #007bff);
    text-decoration: none;
}
.auth-mode-toggle a:hover {
    text-decoration: underline;
}

/* ============================================
   Auth credential tabs (unified basic/AD form)
   ============================================ */
.auth-cred-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.auth-cred-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border: 1px solid var(--color-border, #dee2e6);
    border-radius: 0.5rem;
    background: var(--bg-surface, rgba(255,255,255,0.05));
    color: var(--text-secondary, #717888);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.auth-cred-tab:hover {
    background: var(--bg-surface-hover, rgba(255,255,255,0.08));
    border-color: var(--color-primary, #007bff);
}

.auth-cred-tab.active {
    background: var(--color-primary-light, rgba(0,123,255,0.1));
    border-color: var(--color-primary, #007bff);
    color: var(--color-primary, #007bff);
}

.auth-cred-tab-icon {
    display: flex;
    align-items: center;
}

/* Auth divider ("or sign in with credentials") */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
    color: var(--text-tertiary, #93908f);
    font-size: 0.85rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border, rgba(255,255,255,0.15));
}

/* Utility: hide elements when switching credential tabs */
.hidden {
    display: none !important;
}

/* ============================================
   BIM Viewer Page — Full-bleed 3D with floating panels
   Uses theme CSS variables for all colors.
   Layout: viewport-filling canvas + absolute-positioned overlays
   ============================================ */

/*
 * When the BIM viewer page is active, collapse the shell chrome (header/footer)
 * and remove content-root padding so the 3D canvas can own the entire viewport.
 * :has() is supported in all modern browsers (Chrome 105+, Safari 15.4+, Firefox 121+).
 */
.app-frame:has(.bim-viewer-page) .app-header,
.app-frame:has(.bim-viewer-page) .app-footer {
    display: none !important;
}

.app-frame:has(.bim-viewer-page) .content-root {
    padding: 0 !important;
    overflow: hidden !important;
}

/* Page container: full-height flex child, becomes positioning anchor */
.bim-viewer-page {
    position: relative !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    min-height: 0;
}

/* 3D canvas fills the entire page */
.bim-viewer-page > .bim-viewer-component {
    position: absolute !important;
    inset: 0;
    z-index: 0;
}

.bim-viewer-component .bim-viewer-container {
    width: 100% !important;
    height: 100% !important;
}

/* Floating panel base — navy glass, matching demo */
.ui-floating,
.bim-floating-panel {
    position: absolute;
    z-index: 100;
    background: var(--floating-bg, rgba(26, 32, 90, 0.92));
    backdrop-filter: var(--floating-backdrop-filter, blur(16px));
    -webkit-backdrop-filter: var(--floating-backdrop-filter, blur(16px));
    border: var(--floating-border-width, 2px) solid var(--floating-border, #F8B603);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--floating-shadow, 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(248, 182, 3, 0.15));
    color: var(--floating-text, var(--text-primary, #fff));
    font-size: 0.875rem;
}

/* Ensure all content inside BIM panels stays light — overrides .page-root { color: #111 } */
.bim-floating-panel * {
    color: inherit;
}
.btn-bim-primary,
.btn-bim-primary * {
    color: #1a1a2e !important;
}

/* --- Controls panel (top-left) --- */
.bim-controls {
    top: 1rem;
    left: 1rem;
    width: 280px;
}

.bim-controls-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #F8B603;
    border-bottom: 2px solid #F8B603;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
    text-shadow: 0 0 12px rgba(248, 182, 3, 0.4);
}

/* Buttons inside controls */
.bim-controls .btn {
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 8px;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
    text-align: left;
    border: none;
    cursor: pointer;
}

.bim-controls .btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.bim-controls .btn:active {
    transform: translateY(0);
}

.bim-controls .btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Primary CTA — gold, matching demo (#F8B603) */
.btn-bim-primary {
    background: linear-gradient(135deg, #F8B603 0%, #e09c00 100%);
    color: #1a1a2e;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(248, 182, 3, 0.35);
}
.btn-bim-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #ffc820 0%, #F8B603 100%);
    box-shadow: 0 4px 16px rgba(248, 182, 3, 0.5) !important;
}

/* Secondary — navy/glass */
.btn-bim-secondary {
    background: rgba(43, 52, 146, 0.55);
    color: #e0e8ff;
    border: 1px solid rgba(80, 100, 220, 0.5) !important;
}
.btn-bim-secondary:hover:not(:disabled) {
    background: rgba(43, 52, 146, 0.85);
    border-color: rgba(120, 140, 255, 0.7) !important;
}

/* Accent — teal for smart-select */
.btn-bim-accent {
    background: linear-gradient(135deg, #00b8d9 0%, #0088aa 100%);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 184, 217, 0.35);
}
.btn-bim-accent:hover:not(:disabled) {
    background: linear-gradient(135deg, #1dd0f0 0%, #00b8d9 100%);
    box-shadow: 0 4px 16px rgba(0, 184, 217, 0.5) !important;
}

/* Info section at bottom of controls */
.bim-info {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-surface-hover, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--color-border, rgba(255, 255, 255, 0.1));
    border-radius: 8px;
    font-size: 0.75rem;
    line-height: 1.7;
}

.bim-info .info-label {
    color: var(--color-accent, var(--text-primary));
    font-weight: 600;
}

/* --- Properties panel (top-right) --- */
.bim-properties {
    top: 1rem;
    right: 1rem;
    width: 380px;
    max-height: calc(100% - 2rem);
    overflow-y: auto;
    display: none; /* hidden by default, shown when element selected */
}

.bim-properties.visible,
.bim-properties[data-visible="true"] {
    display: block;
    animation: bimSlideInRight 0.3s ease-out;
}

@keyframes bimSlideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.bim-properties-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #F8B603;
    border-bottom: 2px solid #F8B603;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
    text-shadow: 0 0 12px rgba(248, 182, 3, 0.4);
}

/* No-selection placeholder */
.bim-no-selection {
    text-align: center;
    padding: 1.5rem 0.5rem;
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.825rem;
    line-height: 1.7;
}
.bim-no-selection .bim-no-sel-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.6;
}
/* Hide placeholder when element is selected */
.bim-properties.has-selection .bim-no-selection {
    display: none;
}
/* Hide property rows when nothing is selected */
.bim-properties:not(.has-selection) .bim-property-row,
.bim-properties:not(.has-selection) .bim-property-section-title {
    display: none;
}

.bim-property-section {
    margin-bottom: 1rem;
}

.bim-property-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-accent, var(--text-primary));
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.bim-property-row {
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--color-border, rgba(255, 255, 255, 0.06));
    font-size: 0.8rem;
    line-height: 1.7;
}

.bim-property-row .prop-key {
    color: var(--text-secondary, rgba(255, 255, 255, 0.6));
    font-weight: 600;
    display: inline-block;
    min-width: 120px;
    font-size: 0.75rem;
}

.bim-property-row .prop-value {
    color: var(--text-primary, #fff);
    font-weight: 500;
    word-break: break-word;
}

/* Close button in properties panel */
.bim-panel-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-primary, #fff);
    font-size: 1.25rem;
    cursor: pointer;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    padding: 0;
    margin: 0;
    line-height: 1;
}

.bim-panel-close:hover {
    background: var(--bg-surface-hover, rgba(255, 255, 255, 0.1));
    color: var(--color-danger, #ff4444);
}

/* --- Status bar (bottom-left) --- */
.bim-status {
    bottom: 1rem;
    left: 1rem;
    padding: 0.6rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 8px;
    max-width: calc(100% - 2rem);
}

.bim-status .status-loading {
    color: var(--color-accent, var(--color-warning, #F8B603));
}

.bim-status .status-success {
    color: var(--color-success, #10B981);
}

.bim-status .status-error {
    color: var(--color-danger, #EF4444);
}

/* Loading overlay */
.bim-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary, rgba(13, 17, 23, 0.9));
    color: var(--text-primary, #fff);
}

.bim-loading-overlay .bim-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-border, rgba(255, 255, 255, 0.2));
    border-top-color: var(--color-accent, var(--text-primary, #00E5FF));
    border-radius: 50%;
    animation: bimSpin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes bimSpin {
    to { transform: rotate(360deg); }
}

.bim-loading-overlay .bim-loading-text {
    font-size: 1rem;
    font-weight: 600;
}

/* ---- Mobile responsive (iPhone PWA) ---- */
@media (max-width: 767.98px) {
    /* Controls → bottom toolbar */
    .bim-controls {
        position: absolute;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: none;
        border-radius: 0;
        padding: 0.5rem;
        display: flex;
        flex-wrap: nowrap;
        gap: 0.25rem;
        justify-content: space-around;
        align-items: center;
        border-top: 1px solid var(--color-border, rgba(255, 255, 255, 0.15));
    }

    /* Hide title and info on mobile */
    .bim-controls .bim-controls-title,
    .bim-controls .bim-info {
        display: none;
    }

    /* Buttons become icon-only circles */
    .bim-controls .btn {
        flex: 0 0 auto;
        width: auto;
        margin: 0;
        padding: 0.65rem;
        font-size: 0;       /* hide text */
        min-height: auto;
        border-radius: 8px;
        text-align: center;
    }

    /* Show only the emoji icon via data-icon attribute */
    .bim-controls .btn[data-icon]::before {
            content: attr(data-icon);
        font-size: 1.25rem;
    }

        /* Token-based icon mapping to avoid encoding issues from DB text payloads */
        .bim-controls .btn[data-icon="load-ifc"]::before { content: "\1F4C2"; }
        .bim-controls .btn[data-icon="load-sample"]::before { content: "\1F3EB"; }
        .bim-controls .btn[data-icon="smart-select"]::before { content: "\1F3AF"; }
        .bim-controls .btn[data-icon="unload"]::before { content: "\1F9F9"; }
        .bim-controls .btn[data-icon="wireframe"]::before { content: "\25A2"; }
        .bim-controls .btn[data-icon="properties"]::before { content: "\1F4CB"; }

    /* Properties → top slide-down */
    .bim-properties {
        top: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 70vh;
        border-radius: 0 0 12px 12px;
        animation-name: bimSlideDownMobile;
    }

    @keyframes bimSlideDownMobile {
        from { transform: translateY(-100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    /* Status → above bottom toolbar */
    .bim-status {
        bottom: 3.5rem;
        left: 0.5rem;
        right: 0.5rem;
        text-align: center;
    }
}

/* Small phones (iPhone SE etc.) */
@media (max-width: 375px) {
    .bim-controls .btn {
        padding: 0.5rem;
    }
    .bim-controls .btn[data-icon]::before {
        font-size: 1.1rem;
    }
    .bim-properties {
        max-height: 60vh;
    }
}

@media (max-width: 575.98px) {
    .user-pill-name { display: none; }
    .user-pill-chevron { display: none; }
    .user-pill { padding: 0.25rem 0.4rem; }
    .user-menu { right: -0.5rem; min-width: 200px; }
}
