/* ==============================================================
   CRISIS SHELL — App shell layout, topbar, rail, drawer, common
   Extracted from base.html inline styles for cacheability.
   ============================================================== */

:root {
    --primary-color:   #1e293b;
    --secondary-color: #3498db;
    --accent-color:    #e74c3c;
    --success-color:   #27ae60;
    --warning-color:   #f39c12;
    /* Module colors */
    --module-news:     #e74c3c;
    --module-squawk:   #1da1f2;
    --module-mail:     #f39c12;
    --module-company:  #27ae60;
    --module-pilotage: #9b59b6;
    --module-exercise: #8b5cf6;
    --module-eval:     #06b6d4;
    --module-inject:   #f97316;
    /* Shell */
    --topbar-h: 56px;
    --rail-w:   64px;
    --drawer-w: 220px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f0f2f5; overflow: hidden; }

/* ── TOPBAR ─────────────────────────────────────────────────────── */
.topbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: #fff; border-bottom: 1px solid #e2e8f0;
    display: flex; align-items: center; gap: 0.5rem; padding: 0 1rem;
    z-index: 200; box-shadow: 0 1px 4px rgba(0,0,0,.07);
}
.topbar-brand { font-weight: 700; font-size: 1.05rem; color: var(--primary-color); text-decoration: none; display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.topbar-brand:hover { color: var(--secondary-color); }
.topbar-brand i { color: var(--accent-color); }
.topbar-divider { width: 1px; height: 24px; background: #e2e8f0; flex-shrink: 0; }
.scenario-pill { display: inline-flex; align-items: center; gap: .35rem; background: linear-gradient(135deg,#667eea,#764ba2); color: #fff !important; padding: .28rem .75rem; border-radius: 2rem; font-size: .78rem; font-weight: 600; border: none; cursor: pointer; transition: filter .15s; text-decoration: none; }
.scenario-pill:hover { filter: brightness(1.1); }
.scenario-pill.no-scenario { background: #e2e8f0; color: #6b7280 !important; }
.topbar-spacer { flex: 1; }
.topbar-icon-btn { width: 34px; height: 34px; border: none; background: transparent; border-radius: 8px; color: #64748b; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background .15s; text-decoration: none; }
.topbar-icon-btn:hover { background: #f1f5f9; color: var(--primary-color); }

/* ── ACTIVE SCENARIO BANNER ──────────────────────────────────────── */
.scenario-active-banner {
    position: fixed;
    top: var(--topbar-h);
    left: 0; right: 0;
    height: 28px;
    background: linear-gradient(90deg, #16a34a 0%, #15803d 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    font-size: .78rem;
    font-weight: 600;
    z-index: 190;
    letter-spacing: .02em;
}
.scenario-active-banner__dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #fff;
    animation: pulse-banner 1.4s ease-in-out infinite;
}
@keyframes pulse-banner {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .5; transform: scale(.7); }
}
.scenario-active-banner__sep { opacity: .55; }

/* Shift shell down when banner is visible (adds margin to .app-shell) */
body:has(.scenario-active-banner) .app-shell { margin-top: calc(var(--topbar-h) + 28px) !important; }

/* ── GLOBAL SEARCH ──────────────────────────────────────────────── */
.topbar-search {
    position: relative;
    max-width: 260px;
    flex: 1;
}
.topbar-search input {
    width: 100%;
    height: 32px;
    padding: 0 .75rem 0 2rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: .82rem;
    background: #f8fafc;
    color: #374151;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
.topbar-search input:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52,152,219,.15);
    background: #fff;
}
.topbar-search input::placeholder { color: #94a3b8; }
.topbar-search .search-icon {
    position: absolute;
    left: .6rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: .78rem;
    color: #94a3b8;
    pointer-events: none;
}
.topbar-search kbd {
    position: absolute;
    right: .5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: .6rem;
    padding: 1px 5px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    background: #f1f5f9;
    color: #94a3b8;
    font-family: inherit;
    line-height: 1.4;
    pointer-events: none;
}
.topbar-search-results {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,.15);
    max-height: 380px;
    overflow-y: auto;
    z-index: 300;
}
.topbar-search-results.active { display: block; }
.topbar-search-results .search-result-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .85rem;
    font-size: .83rem;
    color: #374151;
    text-decoration: none;
    border-bottom: 1px solid #f3f4f6;
    transition: background .1s;
}
.topbar-search-results .search-result-item:last-child { border-bottom: none; }
.topbar-search-results .search-result-item:hover { background: #f8fafc; }
.topbar-search-results .search-result-item i { width: 16px; color: #94a3b8; flex-shrink: 0; }
.topbar-search-results .search-result-empty {
    text-align: center;
    padding: 1rem;
    color: #94a3b8;
    font-size: .83rem;
}

/* ── SHELL ──────────────────────────────────────────────────────── */
.app-shell { display: flex; position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0; overflow: hidden; }

/* ── RAIL ───────────────────────────────────────────────────────── */
.rail { width: var(--rail-w); flex-shrink: 0; background: var(--primary-color); display: flex; flex-direction: column; align-items: center; padding: .75rem 0; gap: .15rem; overflow-y: auto; overflow-x: hidden; }
.rail-item { position: relative; width: 48px; height: 48px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: rgba(255,255,255,.55); text-decoration: none; font-size: 1rem; gap: .1rem; transition: all .15s; border: none; background: transparent; cursor: pointer; }
.rail-item .rail-label { font-size: .65rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; line-height: 1; }
.rail-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.rail-item.active { color: #fff; background: rgba(255,255,255,.15); }
.rail-item.mod-pilotage.active { background: rgba(155,89,182,.35); }
.rail-item.mod-news.active     { background: rgba(231,76,60,.35); }
.rail-item.mod-squawk.active   { background: rgba(29,161,242,.35); }
.rail-item.mod-mail.active     { background: rgba(243,156,18,.35); }
.rail-item.mod-company.active  { background: rgba(39,174,96,.35); }
.rail-item.mod-exercise.active { background: rgba(139,92,246,.35); }
.rail-item.mod-eval.active     { background: rgba(6,182,212,.35); }
.rail-item.mod-inject.active   { background: rgba(249,115,22,.35); }
.rail-badge { position: absolute; top: 5px; right: 5px; background: var(--accent-color); color: #fff; border-radius: 999px; min-width: 15px; height: 15px; padding: 0 3px; font-size: .55rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.rail-sep { width: 32px; height: 1px; background: rgba(255,255,255,.12); margin: .2rem 0; }

/* ── DRAWER ─────────────────────────────────────────────────────── */
.drawer { width: var(--drawer-w); flex-shrink: 0; background: #273449; display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; transition: width .22s ease; }
.app-shell.drawer-hidden .drawer { width: 0; }
.drawer-section { padding: .6rem 0; }
.drawer-sep { border: none; border-top: 1px solid rgba(255,255,255,.07); margin: 0; }
.drawer-heading { font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: rgba(255,255,255,.3); padding: .25rem .9rem .4rem; white-space: nowrap; }
.drawer-heading.mod-pilotage { color: rgba(155,89,182,.85); }
.drawer-heading.mod-news     { color: rgba(231,76,60,.85); }
.drawer-heading.mod-squawk   { color: rgba(29,161,242,.85); }
.drawer-heading.mod-mail     { color: rgba(243,156,18,.85); }
.drawer-heading.mod-company  { color: rgba(39,174,96,.85); }
.drawer-heading.mod-exercise { color: rgba(139,92,246,.85); }
.drawer-heading.mod-eval     { color: rgba(6,182,212,.85); }
.drawer-heading.mod-inject   { color: rgba(249,115,22,.85); }
.drawer-link { display: flex; align-items: center; gap: .55rem; padding: .42rem .9rem; color: rgba(255,255,255,.6); text-decoration: none; font-size: .83rem; white-space: nowrap; transition: all .12s; }
.drawer-link i { width: 14px; text-align: center; flex-shrink: 0; }
.drawer-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.drawer-link.active { color: #fff; background: rgba(255,255,255,.1); border-left: 2px solid; padding-left: calc(.9rem - 2px); }
.drawer-link.active.mod-pilotage { border-color: var(--module-pilotage); }
.drawer-link.active.mod-news     { border-color: var(--module-news); }
.drawer-link.active.mod-squawk   { border-color: var(--module-squawk); }
.drawer-link.active.mod-mail     { border-color: var(--module-mail); }
.drawer-link.active.mod-company  { border-color: var(--module-company); }
.drawer-link.active.mod-exercise { border-color: var(--module-exercise); }
.drawer-link.active.mod-eval     { border-color: var(--module-eval); }
.drawer-link.active.mod-inject   { border-color: var(--module-inject); }

/* ── PAGE CONTENT ───────────────────────────────────────────────── */
.page-content { flex: 1; overflow-y: auto; padding: 1.5rem 2rem; background: #f0f2f5; }

/* ── BREADCRUMB ─────────────────────────────────────────────────── */
.breadcrumb-bar { margin-bottom: 1.25rem; }
.breadcrumb { margin: 0; font-size: .8rem; background: transparent; padding: 0; }
.breadcrumb-item a { color: #64748b; text-decoration: none; }
.breadcrumb-item a:hover { color: var(--secondary-color); text-decoration: underline; }
.breadcrumb-item.active { color: #374151; font-weight: 500; }
.breadcrumb-item + .breadcrumb-item::before { color: #94a3b8; }

/* ── CARDS / COMMON ─────────────────────────────────────────────── */
.card { border: none; border-radius: .75rem; box-shadow: 0 1px 3px rgba(0,0,0,.07); transition: box-shadow .2s; }
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.btn-primary { background-color: var(--secondary-color); border-color: var(--secondary-color); }
.btn-primary:hover { background-color: #2980b9; border-color: #2980b9; }
.alert { border-radius: .75rem; border: none; }
.scenario-badge { background: linear-gradient(45deg,var(--secondary-color),var(--primary-color)); color: white; padding: .3rem .75rem; border-radius: 2rem; font-size: .8rem; font-weight: 500; }
.notification-badge { position: absolute; top: -5px; right: -5px; background: var(--accent-color); color: white; border-radius: 50%; width: 18px; height: 18px; font-size: .65rem; display: flex; align-items: center; justify-content: center; }

/* ── MODULE CLASSES ─────────────────────────────────────────────── */
.module-news     { --module-color: var(--module-news); }
.module-squawk   { --module-color: var(--module-squawk); }
.module-mail     { --module-color: var(--module-mail); }
.module-company  { --module-color: var(--module-company); }
.module-pilotage { --module-color: var(--module-pilotage); }
.module-exercise { --module-color: var(--module-exercise); }
.module-eval     { --module-color: var(--module-eval); }
.module-inject   { --module-color: var(--module-inject); }
.module-page-header { border-left: 4px solid var(--module-color, var(--secondary-color)); padding-left: .75rem; margin-bottom: 1.5rem; }

/* ── VERTICAL TIMELINE ──────────────────────────────────────────── */
.vtimeline { position: relative; padding-left: 2rem; }
.vtimeline::before { content: ''; position: absolute; left: 7px; top: 0; bottom: 0; width: 2px; background: rgba(0,0,0,.07); }
.vtimeline-item { position: relative; margin-bottom: .85rem; }
.vtimeline-dot { position: absolute; left: -1.75rem; top: .3rem; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px rgba(0,0,0,.12); }
.vtimeline-dot.ch-news    { background: var(--module-news); }
.vtimeline-dot.ch-squawk  { background: var(--module-squawk); }
.vtimeline-dot.ch-mail    { background: var(--module-mail); }

/* ── LEGACY compat ──────────────────────────────────────────────── */
.feature-icon { width: 56px; height: 56px; background: linear-gradient(135deg,var(--secondary-color),var(--primary-color)); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-size: 1.4rem; margin: 0 auto 1rem; }
.squawk-card { border-left: 4px solid #1da1f2; }
.news-card   { border-left: 4px solid var(--accent-color); }
.company-card{ border-left: 4px solid var(--success-color); }
.mail-card   { border-left: 4px solid var(--warning-color); }

.fade-in { animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }

/* ── MOBILE: Bottom nav + slide-in drawer ───────────────────────── */
.mobile-nav-bottom { display: none; }
.mobile-drawer-backdrop { display: none; }

@media (max-width: 767px) {
    .rail { display: none; }
    .drawer {
        position: fixed;
        left: -280px;
        top: var(--topbar-h);
        bottom: 56px;
        width: 280px !important;
        z-index: 300;
        transition: left .25s ease;
    }
    .drawer.mobile-open { left: 0; }
    .app-shell.drawer-hidden .drawer { width: 280px !important; }
    .page-content { padding: 1rem 1rem 72px 1rem; }
    .topbar-search { display: none; }

    /* Bottom navigation bar */
    .mobile-nav-bottom {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 56px;
        background: var(--primary-color);
        justify-content: space-around;
        align-items: center;
        z-index: 200;
        box-shadow: 0 -1px 4px rgba(0,0,0,.15);
        padding: 0 .25rem;
    }
    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        color: rgba(255,255,255,.5);
        text-decoration: none;
        font-size: 1rem;
        padding: .35rem .5rem;
        border-radius: 8px;
        transition: color .15s;
        border: none;
        background: transparent;
        cursor: pointer;
        min-width: 48px;
    }
    .mobile-nav-item span {
        font-size: .55rem;
        text-transform: uppercase;
        letter-spacing: .03em;
        font-weight: 600;
        line-height: 1;
    }
    .mobile-nav-item:hover,
    .mobile-nav-item.active { color: #fff; }

    /* Backdrop when drawer is open on mobile */
    .mobile-drawer-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.4);
        z-index: 299;
    }
    .mobile-drawer-backdrop.visible { display: block; }
}

/* ── TABLET (768px – 1024px): collapsed drawer, rail visible ───── */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Drawer collapsed by default on tablet */
    .app-shell { --drawer-w: 0px; }
    .drawer {
        width: 0 !important;
        overflow: hidden;
        transition: width .25s ease;
    }
    /* When drawer-open class added via JS, expand it */
    .app-shell:not(.drawer-hidden) .drawer {
        width: 220px !important;
    }
    /* Rail still visible but slightly smaller */
    .rail { width: 56px; }
    .rail-item { padding: .6rem 0; }
    /* Page content fills extra space from collapsed drawer */
    .page-content { padding: 1.25rem; }
    /* Scrollable body on tablet */
    html, body { overflow: auto; }
    /* Topbar search narrower */
    .topbar-search { max-width: 180px; }
}

/* ── DARK MODE ──────────────────────────────────────────────────── */
[data-theme="dark"] { --dm-bg: #1a1a2e; --dm-surface: #16213e; --dm-text: #e2e8f0; --dm-border: #2d3748; }
[data-theme="dark"] body, [data-theme="dark"] html { background: var(--dm-bg) !important; color: var(--dm-text); }
[data-theme="dark"] .topbar { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; }
[data-theme="dark"] .topbar-brand, [data-theme="dark"] .topbar-icon-btn { color: var(--dm-text); }
[data-theme="dark"] .topbar-icon-btn:hover { background: #2d3748; }
[data-theme="dark"] .topbar-divider { background: var(--dm-border); }
[data-theme="dark"] .topbar-search input { background: #0f172a; border-color: var(--dm-border); color: var(--dm-text); }
[data-theme="dark"] .topbar-search input:focus { border-color: var(--secondary-color); }
[data-theme="dark"] .topbar-search-results { background: var(--dm-surface); border-color: var(--dm-border); }
[data-theme="dark"] .topbar-search-results .search-result-item { color: var(--dm-text); border-color: var(--dm-border); }
[data-theme="dark"] .topbar-search-results .search-result-item:hover { background: #2d3748; }
[data-theme="dark"] .rail { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; }
[data-theme="dark"] .rail-item { color: #94a3b8; }
[data-theme="dark"] .drawer { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; color: var(--dm-text); }
[data-theme="dark"] .drawer a { color: var(--dm-text) !important; }
[data-theme="dark"] .page-content { background: var(--dm-bg) !important; color: var(--dm-text); }
[data-theme="dark"] .card { background: var(--dm-surface) !important; border-color: var(--dm-border) !important; color: var(--dm-text); }
[data-theme="dark"] .card-header { background: rgba(255,255,255,.05) !important; border-color: var(--dm-border) !important; color: var(--dm-text); }
[data-theme="dark"] .table { color: var(--dm-text); --bs-table-bg: transparent; }
[data-theme="dark"] .table-light { --bs-table-bg: rgba(255,255,255,.05); color: var(--dm-text); }
[data-theme="dark"] .form-control, [data-theme="dark"] .form-select { background: #0f172a; border-color: var(--dm-border); color: var(--dm-text); }
[data-theme="dark"] .btn-light { background: var(--dm-surface); border-color: var(--dm-border); color: var(--dm-text); }
[data-theme="dark"] .dropdown-menu { background: var(--dm-surface); border-color: var(--dm-border); }
[data-theme="dark"] .dropdown-item { color: var(--dm-text); }
[data-theme="dark"] .dropdown-item:hover { background: #2d3748; }
[data-theme="dark"] .alert { border-color: var(--dm-border); }
[data-theme="dark"] .text-muted { color: #94a3b8 !important; }
[data-theme="dark"] #darkModeToggle i::before { content: "\f185"; }
[data-theme="dark"] .mobile-nav-bottom { background: var(--dm-surface); }
