/* ==========================================================================
   Fauna shell — sidebar, topbar, section nav, mobile tabbar, flash messages.
   ========================================================================== */

/* ===== Layout =========================================================== */
.fauna-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: row;
    background: var(--bg-page);
    font-family: var(--font-sans);
    color: var(--fg-default);
}

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

.fauna-page {
    flex: 1;
    padding: 0;
}

.fauna-page-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-6) var(--space-12);
    box-sizing: border-box;
    width: 100%;
}

/* ===== Desktop sidebar ================================================== */
.fauna-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    padding-top: 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    box-sizing: border-box;
    transition: width var(--dur-fast) var(--ease-out);
    overflow: hidden;
}

.fauna-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px 14px;
    border-bottom: 1px solid var(--sidebar-border);
    margin-bottom: 8px;
    color: var(--sidebar-fg-strong);
    text-decoration: none;
}

.fauna-sidebar-mark {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.fauna-sidebar-wordmark {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.015em;
    color: var(--sidebar-fg-strong);
}

.fauna-sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-fg-muted);
    padding: 10px 16px 6px;
}

.fauna-sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--sidebar-fg);
    text-decoration: none;
    font-weight: 500;
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out);
}

.fauna-sidebar-item:hover {
    background: var(--sidebar-bg-hover);
    color: var(--sidebar-fg-strong);
}

.fauna-sidebar-item.is-active {
    background: var(--sidebar-bg-active);
    color: var(--sidebar-fg-strong);
    font-weight: 600;
}

.fauna-sidebar-item.is-module-active {
    border-left-color: var(--module-accent, var(--accent));
}

.fauna-sidebar-item.is-module-active i {
    color: var(--module-accent, var(--accent));
}

.fauna-sidebar-item i {
    flex-shrink: 0;
    font-size: 16px;
    line-height: 1;
}

.fauna-sidebar-spacer {
    flex: 1;
    min-height: 16px;
}

.fauna-sidebar-version {
    display: block;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--sidebar-fg-muted);
    text-decoration: none;
    padding: 10px 0 14px;
    border-top: 1px solid var(--sidebar-border);
}

.fauna-sidebar-version:hover {
    color: var(--sidebar-fg);
}

/* Sidebar — rail collapse (768–1023px) */
@media (max-width: 1023px) and (min-width: 768px) {
    .fauna-sidebar {
        width: var(--sidebar-width-rail);
        min-width: var(--sidebar-width-rail);
    }
    .fauna-sidebar-brand {
        padding: 0 0 12px;
        justify-content: center;
        gap: 0;
    }
    .fauna-sidebar-wordmark,
    .fauna-sidebar-label,
    .fauna-sidebar-section-label {
        display: none;
    }
    .fauna-sidebar-item {
        padding: 10px 0;
        justify-content: center;
    }
    .fauna-sidebar-version {
        font-size: 9px;
        padding: 8px 0;
    }
}

/* Sidebar — hidden on mobile */
@media (max-width: 767px) {
    .fauna-sidebar { display: none; }
}

/* ===== Desktop topbar =================================================== */
.fauna-topbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: 8px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    font-size: 13px;
}

.fauna-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--fg-muted);
    flex-wrap: wrap;
    min-width: 0;
}

.fauna-breadcrumb a {
    color: var(--fg-muted);
    text-decoration: none;
}

.fauna-breadcrumb a:hover { color: var(--fg-default); }

.fauna-breadcrumb .is-current {
    color: var(--fg-default);
    font-weight: 600;
}

.fauna-breadcrumb-sep { color: var(--neutral-300); }

.fauna-topbar-controls {
    display: flex;
    gap: 14px;
    align-items: center;
    color: var(--neutral-600);
    flex-shrink: 0;
}

.fauna-topbar-sep { color: var(--neutral-300); }

.fauna-search {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-pill);
    background: var(--bg-page);
    height: 28px;
}

.fauna-search i {
    color: var(--fg-muted);
    font-size: 14px;
}

.fauna-search input {
    border: 0;
    background: transparent;
    outline: none;
    font: inherit;
    color: var(--fg-default);
    width: 140px;
}

.fauna-username { color: var(--fg-default); }

.fauna-role-badge {
    padding: 2px 7px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.4;
}

.fauna-role-admin       { background: var(--danger-50); color: var(--danger-500); }
.fauna-role-technician  { background: var(--info-50);   color: var(--info-600); }
.fauna-role-viewer      { background: var(--neutral-100); color: var(--neutral-600); }
.fauna-role-member      { background: var(--neutral-100); color: var(--neutral-600); }

.fauna-lang-switcher {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
}

.fauna-lang-switcher a {
    color: var(--fg-muted);
    text-decoration: none;
    padding: 2px 4px;
}

.fauna-lang-switcher a.is-active {
    color: var(--fg-default);
    font-weight: 600;
}

.fauna-lang-sep { color: var(--neutral-300); }

.fauna-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 0;
    color: var(--fg-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 18px;
    line-height: 1;
}

.fauna-icon-btn:hover {
    color: var(--fg-default);
    background: var(--bg-hover);
}

.fauna-topbar-link {
    color: var(--fg-default);
    text-decoration: none;
    font-weight: 500;
}

/* Theme toggle icon swap (desktop) */
.fauna-theme-toggle .icon-sun,
.fauna-theme-toggle .icon-moon { line-height: 1; }
.fauna-theme-toggle .icon-sun  { display: none; }
.fauna-theme-toggle .icon-moon { display: inline-block; }
[data-theme="dark"] .fauna-theme-toggle .icon-sun  { display: inline-block; }
[data-theme="dark"] .fauna-theme-toggle .icon-moon { display: none; }

@media (max-width: 767px) {
    .fauna-topbar { display: none; }
}

/* ===== Section nav (module hero with sub-tabs) ========================== */
.fauna-section-nav {
    background: var(--accent);
    color: #fff;
}

.fauna-section-nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}

.fauna-section-nav-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.fauna-section-nav-title i {
    font-size: 20px;
    line-height: 1;
}

.fauna-section-nav-title h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: #fff;
    font-family: var(--font-sans);
}

.fauna-section-nav-sub {
    font-size: 12px;
    opacity: 0.8;
    font-family: var(--font-mono);
}

.fauna-section-nav-tabs {
    display: flex;
    gap: 2px;
    font-size: 13px;
    flex-shrink: 0;
}

.fauna-section-nav-tabs a {
    color: #fff;
    text-decoration: none;
    padding: 6px 12px;
    opacity: 0.8;
    border-bottom: 2px solid transparent;
    font-weight: 500;
}

.fauna-section-nav-tabs a:hover { opacity: 1; }

.fauna-section-nav-tabs a.is-active {
    opacity: 1;
    font-weight: 600;
    border-bottom-color: #fff;
}

@media (max-width: 767px) {
    .fauna-section-nav { display: none; }
}

/* ===== Mobile topbar ==================================================== */
.fauna-mobile-topbar { display: none; }

@media (max-width: 767px) {
    .fauna-mobile-topbar {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 12px 14px;
        background: var(--accent);
        color: #fff;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    .fauna-mobile-topbar.is-dashboard {
        background: var(--neutral-800);
    }
    .fauna-mobile-mark { width: 20px; height: 20px; }
    .fauna-mobile-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: 0;
        padding: 4px;
        color: #fff;
        text-decoration: none;
        opacity: 0.9;
        cursor: pointer;
        font-size: 20px;
    }
    .fauna-mobile-title {
        margin: 0;
        font-size: 16px;
        font-weight: 700;
        letter-spacing: -0.015em;
        color: #fff;
        font-family: var(--font-sans);
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .fauna-mobile-topbar .fauna-icon-btn { color: #fff; opacity: 0.9; }
    .fauna-mobile-topbar .fauna-icon-btn:hover { background: rgba(255,255,255,0.1); }
}

/* ===== Mobile tab bar =================================================== */
.fauna-mobile-tabbar { display: none; }

@media (max-width: 767px) {
    .fauna-mobile-tabbar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--mobile-tabbar-h);
        background: var(--bg-surface);
        border-top: 1px solid var(--border-subtle);
        padding-bottom: env(safe-area-inset-bottom);
        z-index: 20;
    }
    .fauna-mobile-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        background: transparent;
        border: 0;
        padding: 8px 0 10px;
        font-family: inherit;
        font-size: 11px;
        color: var(--fg-muted);
        font-weight: 500;
        cursor: pointer;
        text-decoration: none;
    }
    .fauna-mobile-tab i { font-size: 22px; line-height: 1; }
    .fauna-mobile-tab.is-active {
        color: var(--module-accent, var(--accent));
        font-weight: 600;
    }
    .fauna-page-inner {
        padding: var(--space-5) var(--space-4) calc(var(--mobile-tabbar-h) + var(--space-5));
    }
}

/* ===== More sheet ======================================================= */
.fauna-more-sheet[hidden] { display: none; }

.fauna-more-sheet {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: flex-end;
}

.fauna-more-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 15, 14, 0.4);
}

.fauna-more-panel {
    position: relative;
    background: var(--bg-surface);
    width: 100%;
    border-radius: 14px 14px 0 0;
    padding: 10px 0 calc(16px + env(safe-area-inset-bottom));
    max-height: 80vh;
    overflow-y: auto;
}

.fauna-more-handle {
    width: 36px;
    height: 4px;
    background: var(--border-default);
    border-radius: 2px;
    margin: 6px auto 14px;
}

.fauna-more-section-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--fg-muted);
    padding: 16px 18px 8px;
}

.fauna-more-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 12px 18px;
    border: 0;
    border-top: 1px solid var(--bg-subtle);
    background: transparent;
    color: var(--fg-default);
    font-size: 14px;
    font-family: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.fauna-more-row.is-danger { color: var(--danger-700); }

.fauna-more-row-meta {
    color: var(--fg-muted);
    font-family: var(--font-mono);
    font-size: 13px;
}

.fauna-more-row .fauna-role-badge { margin: 0; }

#theme-toggle-mobile .icon-sun,
#theme-toggle-mobile .icon-moon { line-height: 1; }
#theme-toggle-mobile .icon-sun  { display: none; }
#theme-toggle-mobile .icon-moon { display: inline-block; }
[data-theme="dark"] #theme-toggle-mobile .icon-sun  { display: inline-block; }
[data-theme="dark"] #theme-toggle-mobile .icon-moon { display: none; }

@media (min-width: 768px) {
    .fauna-more-sheet { display: none !important; }
}

/* ===== Flash messages =================================================== */
.fauna-flash-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.fauna-alert {
    padding: 12px 16px 12px 40px;
    border-radius: var(--radius-md);
    border: 1px solid;
    background: var(--bg-surface);
    font-size: var(--text-base);
    line-height: var(--leading-snug);
    position: relative;
}

.fauna-alert::before {
    position: absolute;
    left: 14px;
    top: 12px;
    font-weight: 700;
    line-height: 1.4;
}

.fauna-alert-success {
    color: var(--success-500);
    background: var(--success-50);
    border-color: var(--success-500);
}
.fauna-alert-success::before { content: "\2713"; color: var(--success-600); }

.fauna-alert-error,
.fauna-alert-danger {
    color: var(--danger-500);
    background: var(--danger-50);
    border-color: var(--danger-500);
}
.fauna-alert-error::before,
.fauna-alert-danger::before { content: "\2717"; color: var(--danger-600); }

.fauna-alert-warning {
    color: var(--warning-700);
    background: var(--warning-50);
    border-color: var(--warning-500);
}
.fauna-alert-warning::before { content: "\26A0"; color: var(--warning-600); }

.fauna-alert-info,
.fauna-alert-message {
    color: var(--info-600);
    background: var(--info-50);
    border-color: var(--info-500);
}
.fauna-alert-info::before,
.fauna-alert-message::before { content: "\2139"; color: var(--info-600); }

/* ===== Focus ring (a11y, keyboard users) ================================ */
.fauna-shell a:focus-visible,
.fauna-shell button:focus-visible,
.fauna-shell input:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-sm);
}
