/* Shared authenticated-app shell -- dark navy fixed sidebar + top bar, applied via
   shell.js's AppShell.mount(), which wraps a page's content into `.app-content`. Reconciled from
   two independently-drifted per-frontend copies (2026-09-10): BusinessService's was a strict
   subset missing the dialog styles AppShell.confirm/alert/prompt depend on, so its dialogs
   rendered unstyled. Dropped `.app-sidebar-help` (StaticFrontend-only, dead since the hardcoded
   Help Center link became a seeded nav item instead of shell markup). */

body.has-app-shell {
    display: block;
    align-items: initial;
    justify-content: initial;
    background: #f4f6f9;
    min-height: 100vh;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Shown by AppShell.mount() from the moment it starts until the shell is fully built -- covers
   whatever raw page background/content was there first (see mount()'s own comment). Fixed +
   viewport-covering + opaque so nothing under it can show through or shift layout once removed. */
.app-shell-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: #f4f6f9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-shell-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e0e4ec;
    border-top-color: var(--brand-primary, #667eea);
    border-radius: 50%;
    animation: app-shell-spin 0.8s linear infinite;
}

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

/* ---- Sidebar ---- */

.app-sidebar {
    /* Grows to fit the widest rendered item (e.g. a longer translated label on a deeply nested
       menu entry) instead of truncating it -- min-width is the floor, max-width a safety cap. */
    width: max-content;
    min-width: 240px;
    max-width: 380px;
    flex-shrink: 0;
    background: var(--nav-background, #182238);
    color: var(--nav-foreground, #b8c2d9);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

/* Slim (~1/3 default width) scrollbar; webkit pseudo-elements, since scrollbar-width can't set an exact size. */
.app-sidebar::-webkit-scrollbar {
    width: 5px;
}

.app-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.app-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
}

.app-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

@supports (-moz-appearance: none) {
    .app-sidebar {
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
    }
}

/* Desktop-only "collapse the sidebar" preference (see setNavCollapsed in shell.js) -- reclaims
   the full width for .app-main. Scoped to the desktop breakpoint since ≤860px uses .nav-open
   on the same toggle button for the (unrelated) off-canvas drawer instead. */
@media (min-width: 861px) {
    .app-shell.nav-collapsed .app-sidebar {
        display: none;
    }
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px;
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.app-sidebar-brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--brand-primary, #667eea) 0%, var(--brand-secondary, #764ba2) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    flex-shrink: 0;
    overflow: hidden;
}

/* A tenant-uploaded logo (Branding Console, `logo.url` token) replaces the "DN" text mark --
   see auth.js's applyTenantBranding(). Fills the same fixed square rather than the gradient. */
.app-sidebar-brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
}

.app-sidebar-nav {
    list-style: none;
    margin: 8px 0 0;
    padding: 0 12px;
    flex: 1;
    overflow-x: hidden;
}

.app-sidebar-nav li {
    margin-bottom: 2px;
}

.app-sidebar-nav a,
.app-sidebar-nav .app-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    padding-left: calc(12px + (var(--nav-depth, 0) * 16px));
    border: none;
    background: none;
    border-radius: 8px;
    color: var(--nav-foreground, #b8c2d9);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.app-sidebar-nav a:hover,
.app-sidebar-nav .app-nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.app-sidebar-nav a.active,
.app-sidebar-nav .app-nav-link.active {
    background: #ffffff;
    color: var(--nav-background, #182238);
    font-weight: 600;
    /* Always-present (transparent by default) so there's no layout shift when a real
       `color.accent` token gets configured -- see auth.js's applyTenantBranding(). */
    border-left: 3px solid var(--brand-accent, transparent);
    padding-left: calc(9px + (var(--nav-depth, 0) * 16px));
}

.app-sidebar-nav .app-nav-icon {
    font-size: 15px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.app-sidebar-nav .app-nav-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar-nav .app-nav-caret {
    flex-shrink: 0;
    font-size: 11px;
    opacity: 0.7;
    padding: 4px;
    margin: -4px;
}

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

.app-sidebar-nav .app-nav-group.expanded > .app-nav-children {
    display: block;
}

.app-sidebar-footer {
    padding: 14px 20px;
    font-size: 11px;
    color: #6b7794;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ---- Main column: top bar + content ---- */

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-broadcast-list {
    flex-shrink: 0;
}

.app-broadcast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.app-broadcast-info {
    background: #e8f1ff;
    color: #1a4a8a;
}

.app-broadcast-warning {
    background: #fff4d6;
    color: #7a5a00;
}

.app-broadcast-critical {
    background: #fde2e1;
    color: #8a1f1a;
}

.app-broadcast-message {
    flex: 1;
    min-width: 0;
}

.app-broadcast-dismiss {
    flex-shrink: 0;
    width: auto;
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    padding: 0 4px;
}

.app-broadcast-dismiss:hover {
    opacity: 1;
}

.app-topbar {
    height: 64px;
    flex-shrink: 0;
    background: #fff;
    border-bottom: 1px solid #e6e9f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    gap: 20px;
}

.app-topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.app-topbar-title {
    font-size: 17px;
    font-weight: 700;
    color: #1a2233;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Nav toggle: on desktop it collapses/expands the always-visible sidebar (see the
   .nav-collapsed rule near the bottom of this file); at the ≤860px breakpoint below it instead
   opens/closes the off-canvas drawer. Visible at every width -- same button, two behaviors. */
.app-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: none;
    background: none;
    border-radius: 8px;
    font-size: 20px;
    line-height: 1;
    color: #1a2233;
    cursor: pointer;
}

.app-nav-toggle:hover {
    background: #f0f2f7;
}

.app-sidebar-close {
    display: none;
    margin-left: auto;
    border: none;
    background: none;
    color: #b8c2d9;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.app-nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 26, 0.5);
    z-index: 199;
}

.app-topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.app-locale-switcher {
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-locale-label {
    font-size: 12px;
    color: #667;
    white-space: nowrap;
}

.app-locale-switcher select {
    padding: 6px 8px;
    border: 1px solid #e0e4ec;
    border-radius: 8px;
    background: #f4f6f9;
    font-size: 13px;
    color: #333;
}

.app-locale-switcher select:focus {
    outline: none;
    border-color: var(--brand-primary, #667eea);
    background: #fff;
}

.app-search {
    position: relative;
    margin: 0 16px 14px;
}

.app-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: #99a3b8;
    pointer-events: none;
}

.app-search input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px 8px 30px;
    border: 1px solid #e0e4ec;
    border-radius: 8px;
    background: #f4f6f9;
    font-size: 13px;
    color: #333;
}

.app-search input:focus {
    outline: none;
    border-color: var(--brand-primary, #667eea);
    background: #fff;
}

.app-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e6e9f0;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(20, 30, 60, 0.12);
    z-index: 40;
    overflow: hidden;
    display: none;
}

.app-search-results.open {
    display: block;
}

.app-search-results a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    color: #333;
    text-decoration: none;
    font-size: 13px;
}

.app-search-results a:hover,
.app-search-results a.active {
    background: #f4f6f9;
}

.app-user {
    position: relative;
}

.app-user-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 8px;
    font: inherit;
}

.app-user-trigger:hover {
    background: #f4f6f9;
}

.app-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-primary, #667eea) 0%, var(--brand-secondary, #764ba2) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.app-user-avatar { position: relative; }

.app-user-unread-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #dc2626;
    border: 2px solid #fff;
}

.app-user-unread-dot[hidden],
.app-user-menu button[hidden],
.app-user-msg-badge[hidden] {
    display: none;
}

.app-user-menu #appShellMessagesBtn {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-user-msg-badge {
    min-width: 18px;
    padding: 0 6px;
    border-radius: 9px;
    background: #dc2626;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}

.app-user-info {
    text-align: left;
    line-height: 1.25;
}

.app-user-name {
    font-size: 13px;
    font-weight: 600;
    color: #1a2233;
}

.app-user-role {
    font-size: 11px;
    color: #8891a5;
}

.app-user-caret {
    font-size: 9px;
    color: #99a3b8;
}

.app-user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 160px;
    background: #fff;
    border: 1px solid #e6e9f0;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(20, 30, 60, 0.12);
    z-index: 40;
    display: none;
    overflow: hidden;
}

.app-user-menu.open {
    display: block;
}

.app-user-menu button,
.app-user-menu a {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    padding: 10px 14px;
    background: none;
    border: none;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    text-decoration: none;
}

.app-user-menu button:hover,
.app-user-menu a:hover {
    background: #f4f6f9;
}

.app-user-submenu-trigger {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
}

.app-user-submenu-caret {
    font-size: 10px;
    color: #99a3b8;
    transition: transform 0.15s ease;
}

.app-user-submenu-trigger[aria-expanded="true"] .app-user-submenu-caret {
    transform: rotate(90deg);
}

.app-user-submenu-panel {
    display: none;
    background: #fafbfd;
}

.app-user-submenu-panel.open {
    display: block;
}

.app-user-submenu-panel a {
    padding-left: 28px;
    font-size: 12.5px;
}

.app-content {
    flex: 1;
    padding: 28px;
    /* Transparent by default (shows the page's own body background) until a real
       `color.background` token is configured -- see auth.js's applyTenantBranding(). */
    background: var(--brand-background, transparent);
}

.app-shell-footer {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 20px;
    justify-content: space-between;
    align-items: center;
    padding: 14px 28px;
    background: #fff;
    border-top: 1px solid #e6e9f0;
    font-size: 12px;
    color: #888;
}

.app-shell-footer-powered {
    font-weight: 600;
}

.app-shell-footer a {
    color: inherit;
}

/* ---- Shared content card (platform-wide, replaces each console's own duplicated *-card class) ---- */

.app-card {
    background: var(--card-background, white);
    color: var(--card-foreground, #333);
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
    padding: 18px 20px;
    margin-bottom: 18px;
}

/* Reader-facing portals (guardian/donor/student/beneficiary/counselor/teacher) use a slightly
   roomier card than staff consoles -- a deliberate distinction kept from before consolidation. */
.app-card--roomy {
    padding: 20px 24px;
    margin-bottom: 20px;
}

/* A card whose own content stacks via flex/gap instead of relying on child margins. */
.app-card--flex {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* A card that needs space ABOVE it (e.g. following a toolbar) instead of below. */
.app-card--spacing-top {
    margin-top: 18px;
    margin-bottom: 0;
}

/* ---- Dashboard nav-card grid (admin-portal.html's home view) ---- */

.app-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    max-width: 1000px;
}

.app-nav-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(20, 30, 60, 0.06);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.app-nav-card:hover {
    box-shadow: 0 6px 18px rgba(20, 30, 60, 0.12);
    transform: translateY(-2px);
}

.app-nav-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #eef1fb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.app-nav-card-title {
    font-size: 15px;
    font-weight: 700;
    color: #1a2233;
}

.app-nav-card-desc {
    font-size: 12.5px;
    color: #8891a5;
    line-height: 1.4;
}

/* ---- Busy overlay (AppShell.showBusy/hideBusy/withBusy) -- full-page feedback for an async
   action that has no button of its own left to show a loading state on, e.g. anything following
   AppShell.confirm(), whose dialog is already gone by the time the real work starts ---- */

.ui-busy-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 1100;
}

.ui-busy-overlay .app-shell-spinner {
    width: 44px;
    height: 44px;
    border-color: rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
}

.ui-busy-message {
    color: #fff;
    font-size: 14px;
    font-weight: 500;
}

/* ---- Dialogs (AppShell.confirm/alert/prompt) -- replaces native confirm/alert/prompt, which
   block the tab and can't be driven by browser automation ---- */

.ui-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200; /* above .ui-busy-overlay, so a dialog opened while busy stays usable */
}

.ui-dialog {
    background: #fff;
    border-radius: 10px;
    padding: 20px 22px;
    width: 420px;
    max-width: 92vw;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    animation: uiDialogIn 0.12s ease;
}

@keyframes uiDialogIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.ui-dialog-title {
    font-size: 15px;
    font-weight: 700;
    color: #1a2233;
    margin: 0 0 8px;
}

.ui-dialog-message {
    font-size: 13.5px;
    color: #444;
    line-height: 1.5;
    margin: 0 0 16px;
    white-space: pre-wrap;
}

.ui-dialog-input {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #dbe0ea;
    border-radius: 6px;
    font-size: 13.5px;
    font-family: inherit;
    margin-bottom: 16px;
    box-sizing: border-box;
}

.ui-dialog-input:focus {
    outline: none;
    border-color: var(--brand-primary, #667eea);
}

.ui-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.ui-dialog-btn {
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.ui-dialog-btn-secondary { background: #eef1f6; color: #444; }
.ui-dialog-btn-secondary:hover { background: #e3e7ee; }
.ui-dialog-btn-primary { background: var(--brand-primary, #667eea); color: #fff; }
.ui-dialog-btn-primary:hover { opacity: 0.9; }
.ui-dialog-btn-danger { background: #d64545; color: #fff; }
.ui-dialog-btn-danger:hover { opacity: 0.9; }

/* Page Builder "Help" snippet icon -- mirrors PublicSite's own inline `help_style`. */
.pb-help-wrap { display: inline; }
.pb-help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 4px;
    border-radius: 50%;
    border: 1px solid #999;
    background: #f5f5f5;
    color: #555;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
}
.pb-help-popover {
    display: block;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fffef8;
    font-size: 13px;
    max-width: 360px;
}

/* Mobile: the sidebar becomes a full-width-labeled off-canvas drawer (hamburger-toggled), not a
   bare icon rail -- an icon with no label is unreadable unless you already know what it means,
   and a drawer keeps the exact same nested-group/search markup desktop already uses. */
@media (max-width: 860px) {
    .app-sidebar-close {
        display: block;
    }
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: max-content;
        min-width: 240px;
        max-width: 84vw;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 2px 0 24px rgba(10, 14, 26, 0.3);
    }
    .app-shell.nav-open .app-sidebar {
        transform: translateX(0);
    }
    .app-shell.nav-open .app-nav-backdrop {
        display: block;
    }
    body.app-nav-locked {
        overflow: hidden;
    }
    .app-topbar {
        flex-wrap: wrap;
        height: auto;
        min-height: 64px;
        padding: 10px 16px;
        gap: 10px;
    }
    .app-topbar-right {
        flex-wrap: wrap;
        width: 100%;
        justify-content: flex-end;
    }
}

.app-toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    background: #1f2937;
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    transition: opacity 0.5s ease;
}
.app-toast-hide { opacity: 0; }
