/* =============================================================
   Bibits – brand colours
     --bibits-red:       #E50B46
     --bibits-yellow:    #F5A800
     --bibits-blue:      #67B1E2
     --bibits-navy:      #202549
     --bibits-darkest:   #131022
     --bibits-gray:      #8784A3
   ============================================================= */

@import url('components/dropdown-select.css');

/* =============================================================
   Accessibility — skip link (WCAG 2.4.1)
   ============================================================= */
.skip-link {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9999;
    padding: 0.5rem 1rem;
    background: #202549;
    color: #ffffff;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 0 0 6px 0;
    text-decoration: none;
    /* Off-screen until focused */
    transform: translateY(-100%);
    transition: transform 0.15s ease;
}

.skip-link:focus-visible {
    transform: translateY(0);
    outline: 2px solid #67B1E2;
    outline-offset: 2px;
}

/* Bootstrap primary override → Bibits red */
:root {
    --bs-primary:              #E50B46;
    --bs-primary-rgb:          229, 11, 70;
    --bs-link-color:           #67B1E2;
    --bs-link-color-rgb:       103, 177, 226;
    --bs-link-hover-color:     #E50B46;
    --bs-link-hover-color-rgb: 229, 11, 70;
}

.btn-primary {
    --bs-btn-bg:           #E50B46;
    --bs-btn-border-color: #E50B46;
    --bs-btn-hover-bg:           #c2093c;
    --bs-btn-hover-border-color: #c2093c;
    --bs-btn-active-bg:          #a8082f;
    --bs-btn-active-border-color:#a8082f;
    --bs-btn-color:        #fff;
}

/* =============================================================
   Theme colour palette
   Adjust these values to restyle the entire shell in one place.

    --color-header-bg-light:  #202549;    header bar              
    --color-sidebar-bg-light: #202549;   side navigation         
    --color-content-bg-light: #f0f0f6;    main content area      

    --color-header-bg-dark:   #131022;    header bar              
    --color-sidebar-bg-dark:  #131022;    side navigation         
    --color-content-bg-dark:  #1a1628;    main content area      
   ============================================================= */
:root {
        
    /* ── Light mode backgrounds ───────────────────────────────── */
    --color-header-bg-light:     rgb(196,196,196);              /* header bar              */
    --color-sidebar-bg-light:    rgb(196,196,196);              /* side navigation         */
    --color-content-bg-light:    #ffffff;              /* main content area       */

    /* ── Dark mode backgrounds ────────────────────────────────── */
    --color-header-bg-dark:      #181818;              /* header bar              */
    --color-sidebar-bg-dark:     #181818;              /* side navigation         */
    --color-content-bg-dark:     #212121;              /* main content area       */

    /* ── Light mode borders ───────────────────────────────────── */
    --color-header-border-light:  #E2E8F0; /* bottom border of header */
    --color-sidebar-border-light: #E2E8F0; /* right border of sidebar */

    /* ── Dark mode borders ────────────────────────────────────── */
    --color-header-border-dark:   #1e1e1e; /* bottom border of header */
    --color-sidebar-border-dark:  #1e1e1e; /* right border of sidebar */

    /* ── Light mode text ──────────────────────────────────────── */
    --color-header-text-light:   #222222;             /* header icons & labels   */
    --color-sidebar-text-light:  #222222;             /* sidebar nav labels      */
    --color-content-text-light:  #222222;             /* main content text       */

    /* ── Dark mode text ───────────────────────────────────────── */
    --color-header-text-dark:    #c4c4c4;             /* header icons & labels   */
    --color-sidebar-text-dark:   #c4c4c4;             /* sidebar nav labels      */
    --color-content-text-dark:   #e8e8e8;             /* main content text       */
}

/* =============================================================
   CSS Design Tokens
   ============================================================= */
:root {
    /* Layout */
    --header-height: 56px;
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 52px;
    --sidebar-speed: 0.22s;

    /* Header + Sidebar shell — light mode */
    --header-bg:         var(--color-header-bg-light);
    --header-color:      var(--color-header-text-light);
    --header-btn-hover:  rgba(255, 255, 255, 0.09);
    --header-border:     var(--color-header-border-light);

    /* Sidebar — light mode */
    --sidebar-bg:           var(--color-sidebar-bg-light);
    --sidebar-color:        var(--color-sidebar-text-light);
    --sidebar-hover-bg:     rgba(255, 255, 255, 0.07);
    --sidebar-active-bg:    rgba(103, 177, 226, 0.1);
    --sidebar-active-color: #ffffff;
    --sidebar-border:       var(--color-sidebar-border-light);
    --sidebar-icon-color:   #67B1E2;
    --sidebar-icon-active:  #67B1E2;
    --sidebar-active-accent:#67B1E2;

    /* Content — light mode */
    --content-bg:    var(--color-content-bg-light);
    --content-color: var(--color-content-text-light);
}

[data-bs-theme="dark"] {
    /* Header + Sidebar shell — dark mode */
    --header-bg:         var(--color-header-bg-dark);
    --header-color:      var(--color-header-text-dark);
    --header-border:     var(--color-header-border-dark);

    /* Sidebar — dark mode */
    --sidebar-bg:           var(--color-sidebar-bg-dark);
    --sidebar-color:        var(--color-sidebar-text-dark);
    --sidebar-hover-bg:     rgba(255, 255, 255, 0.05);
    --sidebar-active-bg:    rgba(103, 177, 226, 0.1);
    --sidebar-active-color: #ffffff;
    --sidebar-border:       var(--color-sidebar-border-dark);
    --sidebar-icon-color:   #67B1E2;
    --sidebar-icon-active:  #67B1E2;
    --sidebar-active-accent:#67B1E2;

    /* Content — dark mode */
    --content-bg:    var(--color-content-bg-dark);
    --content-color: var(--color-content-text-dark);
}

/* =============================================================
   Base reset
   ============================================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    height: 100%;
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
}

@media (min-width: 768px) {
    html { font-size: 15px; }
}

body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background-color: var(--content-bg);
    color: var(--content-color);
}

/* =============================================================
   Layout wrapper — full viewport, no scroll
   ============================================================= */
#layout-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* =============================================================
   Header
   ============================================================= */
#app-header {
    flex-shrink: 0;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.625rem;
    gap: 0.5rem;
    background-color: var(--header-bg);
    color: var(--header-color);
    border-bottom: 1px solid var(--header-border);
    z-index: 1030;
}

.header-start {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    min-width: 0;
    flex-shrink: 1;
}

.header-end {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

/* =============================================================
   Tenant / environment dropdown in header-start
   ============================================================= */
#tenant-dropdown .btn {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    max-width: 260px;
}

#tenant-dropdown .bi-building {
    font-size: 0.9rem;
    line-height: 1;
    display: flex;
}

.tenant-chevron {
    font-size: 0.6rem;
    opacity: 0.7;
    line-height: 1;
    display: flex;
}

.tenant-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

.tenant-logo {
    width: 20px;
    height: 20px;
    object-fit: contain;
    border-radius: 3px;
}

/* Show img, hide icon when logo is loaded; default: icon visible */
.tenant-logo-wrap { display: flex; align-items: center; }
.tenant-logo-wrap .tenant-logo.d-none ~ i { display: inline-block !important; }
.tenant-logo-wrap .tenant-logo:not(.d-none) ~ i { display: none !important; }

/* =============================================================
   Account / settings dropdown
   ============================================================= */
.account-menu {
    min-width: 240px;
}

.account-menu .dropdown-item {
    display: flex;
    align-items: center;
}

/* Community (tenant) dropdown — Bootstrap dropdown-item needs flex for icon alignment */
#tenant-list .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Header buttons */
.header-btn {
    color: var(--header-color) !important;
    background: transparent !important;
    border-color: transparent !important;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    transition: background-color 0.15s ease;
}

.header-btn:hover,
.header-btn.show,
.header-btn[aria-expanded="true"] {
    background-color: var(--header-btn-hover) !important;
    color: var(--header-color) !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

/* Keyboard focus ring — separate from hover so mouse clicks don't show it (WCAG 2.4.7) */
.header-btn:focus-visible {
    background-color: var(--header-btn-hover) !important;
    color: var(--header-color) !important;
    border-color: transparent !important;
    outline: 2px solid #67B1E2;
    outline-offset: 1px;
    box-shadow: none !important;
}

/* Notification bell badge */
.notification-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.6rem;
    padding: 0.18em 0.38em;
    min-width: 1.1em;
    pointer-events: none;
}

/* Notification panel dropdown */
.notification-panel {
    width: 320px;
    max-height: 420px;
    padding: 0;
    overflow: hidden;
    /* display is controlled by Bootstrap (.show adds display:block);
       we override it to flex only when visible */
}

.notification-panel.show {
    display: flex !important;
    flex-direction: column;
}

.notification-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    flex-shrink: 0;
    font-size: 0.875rem;
}

.notification-panel-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.notification-panel-footer {
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--bs-border-color);
    text-align: center;
    flex-shrink: 0;
    font-size: 0.8rem;
}

.notification-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--bs-secondary-color);
    font-size: 0.8rem;
}

/* Auth buttons — on dark header */
.btn-header-login {
    background-color: #67B1E2;
    border-color: #67B1E2;
    color: #131022 !important;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn-header-login:hover,
.btn-header-login:focus {
    background-color: #90c8f0;
    border-color: #90c8f0;
    color: #131022 !important;
    box-shadow: 0 0 0 3px rgba(103, 177, 226, 0.3);
}

.btn-header-register {
    background-color: transparent;
    border-color: rgba(103, 177, 226, 0.4);
    color: #67B1E2 !important;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-header-register:hover,
.btn-header-register:focus {
    background-color: rgba(103, 177, 226, 0.1);
    border-color: #67B1E2;
    color: #90c8f0 !important;
}

/* Blue action button for content pages (save, confirm, etc.) */
.btn-action {
    background-color: #67B1E2;
    border-color: #67B1E2;
    color: #131022 !important;
    font-weight: 600;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn-action:hover,
.btn-action:focus {
    background-color: #90c8f0;
    border-color: #90c8f0;
    color: #131022 !important;
    box-shadow: 0 0 0 3px rgba(103, 177, 226, 0.3);
}

/* =============================================================
   App body — sidebar + main side by side
   ============================================================= */
#app-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* =============================================================
   Sidebar
   ============================================================= */
#app-sidebar {
    flex-shrink: 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    transition: width var(--sidebar-speed) ease;
    z-index: 1020;
}

#app-sidebar.sidebar-collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Scrollable menu area */
.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.375rem 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

.sidebar-menu::-webkit-scrollbar { width: 3px; }
.sidebar-menu::-webkit-scrollbar-track { background: transparent; }
.sidebar-menu::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-item {
    margin: 1px 0;
}

/* Individual sidebar link */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem 0.55rem 0.85rem;
    color: var(--sidebar-color) !important;
    text-decoration: none !important;
    border-radius: 0;
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sidebar-link:hover {
    background-color: var(--sidebar-hover-bg);
    color: #e8eaf6 !important;
}

.sidebar-link:hover .sidebar-icon {
    color: #90c8f0;
}

.sidebar-link.active {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-color) !important;
    border-left-color: var(--sidebar-active-accent);
}

.sidebar-link.active .sidebar-icon {
    color: var(--sidebar-icon-active);
    filter: drop-shadow(0 0 5px rgba(103, 177, 226, 0.55));
}

.sidebar-icon {
    font-size: 1.15rem;
    flex-shrink: 0;
    width: 1.3rem;
    text-align: center;
    color: var(--sidebar-icon-color);
    transition: color 0.15s ease, filter 0.15s ease;
}

.sidebar-text {
    font-size: 0.875rem;
    font-weight: 450;
    letter-spacing: 0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--sidebar-speed) ease, max-width var(--sidebar-speed) ease;
    max-width: 180px;
}

/* Submenu chevron */
.submenu-chevron {
    font-size: 0.68rem;
    margin-left: auto !important;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.sidebar-link[aria-expanded="true"] .submenu-chevron {
    transform: rotate(180deg);
}

/* Submenu */
.sidebar-submenu {
    list-style: none;
    padding: 2px 0 4px 0;
    margin: 0;
}

.submenu-link {
    padding-left: 2.4rem !important;
    font-size: 0.82rem !important;
}

/* Collapsed state */
#app-sidebar.sidebar-collapsed .sidebar-text,
#app-sidebar.sidebar-collapsed .submenu-chevron {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    pointer-events: none;
}

#app-sidebar.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding: 0.55rem;
    gap: 0;
    border-left-color: transparent !important;
}

#app-sidebar.sidebar-collapsed .sidebar-item-has-children > .sidebar-link {
    pointer-events: none;
}

#app-sidebar.sidebar-collapsed .collapse {
    display: none !important;
}

/* Sidebar footer */
.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--sidebar-border);
    padding: 0.5rem 0.6rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

/* Brand link: icon + wordmark side by side */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none !important;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-brand:hover { opacity: 0.8; }

.sidebar-brand-icon {
    flex-shrink: 0;
    height: 22px;
    width: auto;
}

/* Wordmark: light/dark theme-aware */
.sidebar-brand-wordmark {
    height: 16px;
    width: auto;
    flex-shrink: 0;
    transition: opacity var(--sidebar-speed) ease, max-width var(--sidebar-speed) ease;
    max-width: 120px;
    overflow: hidden;
}

.sidebar-brand-wordmark-dark  { display: none; }
.sidebar-brand-wordmark-light { display: block; }

[data-bs-theme="dark"] .sidebar-brand-wordmark-light { display: none; }
[data-bs-theme="dark"] .sidebar-brand-wordmark-dark  { display: block; }

/* Meta: version + session */
.sidebar-footer-meta {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity var(--sidebar-speed) ease, max-height var(--sidebar-speed) ease;
    max-height: 2rem;
}

.sidebar-version {
    font-size: 0.63rem;
    color: var(--sidebar-color);
    opacity: 0.65;
    white-space: nowrap;
}

.sidebar-session {
    font-size: 0.62rem;
    color: var(--sidebar-color);
    opacity: 0.55;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: default;
}

/* Collapsed state: hide wordmark and meta */
#app-sidebar.sidebar-collapsed .sidebar-brand-wordmark {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    pointer-events: none;
}

#app-sidebar.sidebar-collapsed .sidebar-footer-meta {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    pointer-events: none;
}

#app-sidebar.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    gap: 0;
}

/* =============================================================
   Main area
   ============================================================= */
#app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Server-side notification alerts (below header) */
#notification-area {
    flex-shrink: 0;
}

.portal-alert {
    display: flex;
    align-items: center;
    padding: 0.55rem 1rem;
    margin: 0;
    border: none;
    border-radius: 0;
    font-size: 0.855rem;
    border-bottom: 1px solid transparent;
}

.portal-alert-success {
    background-color: #dcfce7;
    color: #166534;
    border-bottom-color: #bbf7d0;
}

.portal-alert-error {
    background-color: #fee2e2;
    color: #991b1b;
    border-bottom-color: #fecaca;
}

.portal-alert-info {
    background-color: #dbeafe;
    color: #1e40af;
    border-bottom-color: #bfdbfe;
}

[data-bs-theme="dark"] .portal-alert-success {
    background-color: #052e16;
    color: #86efac;
    border-bottom-color: #14532d;
}

[data-bs-theme="dark"] .portal-alert-error {
    background-color: #2d0b0b;
    color: #fca5a5;
    border-bottom-color: #7f1d1d;
}

[data-bs-theme="dark"] .portal-alert-info {
    background-color: #0c1a4e;
    color: #93c5fd;
    border-bottom-color: #1e3a8a;
}

/* Content area — THE ONLY element that scrolls */
#app-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    scrollbar-width: thin;
    scrollbar-gutter: stable;
    background-color: var(--content-bg);
    color: var(--content-color);
}

#app-content::-webkit-scrollbar { width: 8px; }
#app-content::-webkit-scrollbar-track { background: transparent; }
#app-content::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.14);
    border-radius: 4px;
}

[data-bs-theme="dark"] #app-content::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.12);
}

/* =============================================================
   Mobile — sidebar as overlay
   ============================================================= */
@media (max-width: 767.98px) {
    #app-sidebar {
        position: absolute;
        left: 0;
        top: var(--header-height);
        height: calc(100dvh - var(--header-height));
        transform: translateX(-100%);
        transition: transform var(--sidebar-speed) ease;
        z-index: 1025;
        width: var(--sidebar-width) !important;
    }

    #app-sidebar.sidebar-open-mobile {
        transform: translateX(0);
    }
}

/* Mobile overlay */
#sidebar-mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0, 0, 0, 0.45);
    z-index: 1024;
}

#sidebar-mobile-overlay.active {
    display: block;
}

@media (min-width: 768px) {
    #sidebar-mobile-overlay { display: none !important; }
}

/* =============================================================
   Utility
   ============================================================= */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Dropdown menus spawned from header sit flush */
#app-header .dropdown-menu {
    margin-top: 0.3rem;
}

/* =============================================================
   Registration modal — password strength
   ============================================================= */
.pwd-strength-track {
    height: 4px;
    border-radius: 2px;
    background-color: var(--bs-border-color);
}

.pwd-strength-track .progress-bar {
    border-radius: 2px;
    transition: width 0.3s ease, background-color 0.3s ease;
}

/* =============================================================
   Language loading state
   While the API auto-translates a new language (DeepL call),
   html.lang-loading is set. Entire page gets a wait cursor and
   the flag in the language button is replaced by a small spinner.
   ============================================================= */
html.lang-loading,
html.lang-loading * {
    cursor: wait !important;
}

html.lang-loading #lang-current-flag {
    display: inline-block;
    width:  1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: lang-spin 0.65s linear infinite;
    vertical-align: middle;
    font-size: 0 !important;   /* hide emoji text while spinning */
}

@keyframes lang-spin {
    to { transform: rotate(360deg); }
}

/* =============================================================
   Offline overlay
   Shown by network.js when the connection is lost.
   body.app-offline also disables pointer interaction on content.
   ============================================================= */

/* Dim and block the entire content area when offline */
body.app-offline #app-content {
    pointer-events: none;
    user-select:    none;
    opacity:        0.45;
    transition:     opacity 0.3s;
}

/* The overlay banner — sits above the header */
#offline-overlay {
    position: fixed;
    top:      0;
    left:     0;
    right:    0;
    z-index:  9999;
    background: #131022;
    border-bottom: 1px solid rgba(229, 11, 70, 0.4);
    padding: 0.55rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    /* iOS safe area */
    padding-top: max(0.55rem, env(safe-area-inset-top));
    padding-left:  max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
}

#offline-overlay[hidden] {
    display: none;
}

.offline-overlay-inner {
    display:     flex;
    align-items: center;
    gap:         0.6rem;
    font-size:   0.82rem;
    color:       #F0F0F0;
}

.offline-icon {
    width:  16px;
    height: 16px;
    flex-shrink: 0;
    fill: #E50B46;
}

.offline-message {
    font-weight: 600;
    color: #F0F0F0;
}

.offline-polling {
    color:     #8784A3;
    font-style: italic;
    /* pulsing opacity to signal active polling */
    animation: offline-pulse 2.2s ease-in-out infinite;
}

@keyframes offline-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}

/* Shift the entire layout down to make room for the offline banner */
body.app-offline #layout-wrapper {
    padding-top: 2.15rem;
    transition: padding-top 0.2s;
}
