/* ═══════════════════════════════════════════════════════════
   BOWTIE — Sidebar Navigation Layout
   Adapted from ESTAS-AQUABC design pattern
   ═══════════════════════════════════════════════════════════ */

/* ─── Sidebar Variables (compatible with both themes) ─────── */
:root {
    --sidebar-width: 230px;
    --sidebar-collapsed-width: 54px;
    --sidebar-bg: linear-gradient(180deg, #0c1520 0%, #162231 100%);
    --sidebar-border: rgba(14, 165, 233, 0.15);
    --sidebar-accent: var(--bioluminescent, #00d4aa);
    --sidebar-accent-glow: var(--bioluminescent-glow, rgba(0, 212, 170, 0.3));
    --sidebar-accent-dim: rgba(0, 212, 170, 0.08);
    --sidebar-text: #94a3b8;
    --sidebar-text-bright: #f1f5f9;
    --sidebar-font: var(--font-body, 'DM Sans', system-ui, sans-serif);
    --sidebar-header-height: 38px;
}

/* ─── Kill bslib's injected white backgrounds ─────────────── */
/* bslib page_fillable wraps everything in .bslib-page-fill which has
   a white background — override it to be transparent so the deep ocean
   body background shows through */
.bslib-page-fill,
[data-bslib-page-fill],
.html-fill-container,
.html-fill-item {
    background: transparent !important;
}
/* Also override the Bootstrap default card/container backgrounds inside
   the layout wrapper so only explicit cards keep their own bg */
.bowtie-layout {
    background: transparent;
}

/* Ensure html/body fill viewport so body bg gradient covers everything */
html, body {
    height: 100%;
    overflow: hidden; /* page-level scroll disabled; each region scrolls */
}

/* ─── Reset bslib page wrapper ────────────────────────────── */
.bslib-page-fill,
.container-fluid {
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
}
.shiny-html-output { margin: 0; padding: 0; }

/* ─── App Header ──────────────────────────────────────────── */
.bowtie-app-header {
    background: linear-gradient(135deg, #0a1628 0%, #0f2137 50%, #0a1628 100%);
    color: #f1f5f9;
    padding: 0 1rem;
    height: var(--sidebar-header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 212, 170, 0.2);
    position: relative;
    z-index: 200;
    flex-shrink: 0;
}
.bowtie-app-header::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--sidebar-accent) 30%, #4a7c9b 70%, transparent 100%);
    opacity: 0.6;
}
.bowtie-app-header-title {
    display: flex;
    align-items: center;
    font-family: var(--font-display, 'Crimson Pro', Georgia, serif);
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: #f1f5f9;
}
.bowtie-app-header-title i {
    color: var(--sidebar-accent);
    margin-right: 0.4rem;
    font-size: 0.95rem;
}
.bowtie-version-badge {
    font-family: var(--font-mono, monospace);
    font-size: 0.65rem;
    background: rgba(0, 212, 170, 0.1);
    color: var(--sidebar-accent);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    margin-left: 0.75rem;
    border: 1px solid rgba(0, 212, 170, 0.25);
}

/* ─── Header (top bar) nav: Help / Feedback / About, left side ─ */
.bowtie-app-header-left {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    min-width: 0;          /* let the title shrink before the nav wraps */
}
.bowtie-header-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.bowtie-header-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-family: var(--sidebar-font);
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1;
    color: var(--sidebar-text);
    text-decoration: none;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.bowtie-header-nav-link i { font-size: 0.95rem; }
.bowtie-header-nav-link:hover,
.bowtie-header-nav-link:focus-visible {
    color: var(--sidebar-text-bright);
    background: var(--sidebar-accent-dim);
    border-color: rgba(0, 212, 170, 0.25);
}
.bowtie-header-nav-link.active {
    color: var(--sidebar-accent);
    background: rgba(0, 212, 170, 0.1);
    border-color: rgba(0, 212, 170, 0.35);
}
/* On narrow viewports, drop the labels and keep the icons. */
@media (max-width: 720px) {
    .bowtie-header-nav-link span { display: none; }
    .bowtie-header-nav-link { padding: 0.25rem 0.45rem; }
}

/* ─── Main Layout ─────────────────────────────────────────── */
.bowtie-layout {
    display: flex;
    height: calc(100vh - var(--sidebar-header-height));
    margin: 0;
    padding: 0;
    overflow: hidden; /* sidebar + content each scroll independently */
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.bowtie-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100%;
    background: var(--sidebar-bg);
    padding: 0;
    transition: width 0.3s ease, min-width 0.3s ease;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--sidebar-border);
    z-index: 100;
}
.bowtie-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    min-width: var(--sidebar-collapsed-width);
}
.bowtie-sidebar.collapsed .bowtie-nav-link span,
.bowtie-sidebar.collapsed .bowtie-sidebar-title,
.bowtie-sidebar.collapsed .bowtie-nav-group-label,
.bowtie-sidebar.collapsed .bowtie-sidebar-settings-label { display: none; }
.bowtie-sidebar.collapsed .bowtie-nav-link { justify-content: center; padding: 0.75rem 0; }
.bowtie-sidebar.collapsed .bowtie-nav-link i { margin-right: 0; }
.bowtie-sidebar.collapsed .bowtie-sidebar-header { justify-content: center; padding: 0.75rem 0.5rem; }
.bowtie-sidebar.collapsed .bowtie-sidebar-settings { padding: 0.5rem 0; }
.bowtie-sidebar.collapsed .bowtie-sidebar-settings > * { display: none; }
.bowtie-sidebar.collapsed .bowtie-sidebar-settings-icon { display: flex !important; justify-content: center; }

/* ─── Sidebar Header ──────────────────────────────────────── */
.bowtie-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.bowtie-sidebar-title {
    color: var(--sidebar-accent);
    font-family: var(--sidebar-font);
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}
.bowtie-sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 1.3rem;
    padding: 0.25rem;
    line-height: 1;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}
.bowtie-sidebar-toggle:hover {
    color: var(--sidebar-accent);
    background: var(--sidebar-accent-dim);
}

/* ─── Nav Groups & Links ──────────────────────────────────── */
.bowtie-nav-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.bowtie-nav-group-label {
    color: var(--sidebar-text);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.75rem 1rem 0.2rem;
    opacity: 0.6;
    white-space: nowrap;
}
.bowtie-nav-link {
    color: var(--sidebar-text);
    padding: 0.55rem 1rem;
    border-radius: 0;
    border-left: 3px solid transparent;
    margin: 1px 0;
    white-space: nowrap;
    display: flex;
    align-items: center;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 500;
    transition: all 0.2s ease;
    background: transparent;
}
.bowtie-nav-link i {
    margin-right: 0.7rem;
    font-size: 1rem;
    width: 1.2rem;
    text-align: center;
    transition: color 0.2s;
    flex-shrink: 0;
}
.bowtie-nav-link:hover {
    background: var(--sidebar-accent-dim);
    border-left-color: var(--sidebar-accent);
    color: var(--sidebar-text-bright);
    text-decoration: none;
}
.bowtie-nav-link:hover i { color: var(--sidebar-accent); }
.bowtie-nav-link.active {
    background: rgba(0, 212, 170, 0.1);
    border-left-color: var(--sidebar-accent);
    color: var(--sidebar-text-bright);
    font-weight: 600;
    box-shadow: inset 3px 0 12px var(--sidebar-accent-glow);
}
.bowtie-nav-link.active i { color: var(--sidebar-accent); }

/* ─── Sidebar Bottom Settings ─────────────────────────────── */
.bowtie-sidebar-settings {
    border-top: 1px solid var(--sidebar-border);
    padding: 0.75rem;
    flex-shrink: 0;
    overflow-y: auto;
    max-height: 22vh; /* slimmed — accordion moved to header offcanvas */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.bowtie-sidebar-settings label { font-size: 0.78rem; color: var(--sidebar-text); }
.bowtie-sidebar-settings .form-select,
.bowtie-sidebar-settings .form-control { font-size: 0.78rem; }
.bowtie-sidebar-settings .btn { font-size: 0.78rem; }
.bowtie-sidebar-settings-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text);
    opacity: 0.6;
    margin-bottom: 0.5rem;
    display: block;
}

/* ─── Main Content Area ───────────────────────────────────── *//* ─── Light-marine-theme sidebar overrides ────────────────── */
html[data-theme="light-marine"] .bowtie-sidebar {
    background: linear-gradient(180deg, #dde6f0 0%, #eef3f8 100%);
    border-right-color: rgba(14, 100, 160, 0.18);
}
html[data-theme="light-marine"] .bowtie-app-header {
    background: linear-gradient(135deg, #c8dae8 0%, #dde6f0 100%);
    color: #1a3a5c;
}
html[data-theme="light-marine"] .bowtie-sidebar-title { color: #1a6490; }
html[data-theme="light-marine"] .bowtie-nav-link { color: #4a6a8a; }
html[data-theme="light-marine"] .bowtie-nav-link.active {
    color: #1a3a5c;
    background: rgba(14, 100, 160, 0.08);
}
html[data-theme="light-marine"] .bowtie-sidebar-header { background: rgba(0, 0, 0, 0.05); }
html[data-theme="light-marine"] .bowtie-version-badge {
    background: rgba(0, 157, 128, 0.12);
    color: #009d80;
    border-color: rgba(0, 157, 128, 0.25);
}

/* ─── Compact dash counter tiles ──────────────────────────────────────────── */
.dash-counters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}
.dash-counter {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex: 1 1 120px;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
    border-left: 3px solid currentColor;
    background: rgba(255,255,255,0.07);
    min-height: 0;
}
.dash-counter__icon {
    font-size: 1.1rem;
    opacity: 0.75;
    flex-shrink: 0;
}
.dash-counter__body {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}
.dash-counter__body span:first-child,
.dash-counter__body strong {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.1;
}
.dash-counter__body span:last-child {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.7;
}
/* colour variants */
.dash-counter--primary  { color: #0d6efd; }
.dash-counter--info     { color: #0dcaf0; }
.dash-counter--success  { color: #198754; }
.dash-counter--warning  { color: #fd7e14; }
.dash-counter--secondary{ color: #6c757d; }

/* ─── Compact main content padding (merged with base rule above) ────────── */
/* Note: padding override only — other properties inherited from base rule */
.bowtie-main-content {
    flex: 1;
    padding: 0.75rem 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    background: transparent;
}

/* ─── Bowtie Diagram — full-height direct DOM (pyvis 4.2, no iframe) ── */
/* pyvis 4.2 renders vis.Network directly into a div, no iframe */
#bowtie_diagram_container {
    overflow: hidden;
}

/* The pyvis output div fills the container */
#bowtie_network,
div[id="bowtie_network"] {
    width: 100% !important;
    height: 100% !important;
}

/* vis.js canvas wrapper fills too */
#bowtie_network .vis-network {
    width: 100% !important;
    height: 100% !important;
}

/* ─── Bowtie fullscreen state ───────────────────────────────── */
#bowtie_diagram_container:fullscreen {
    height: 100vh !important;
    background: #0f1923;
}
/* pyvis 4.2 uses direct DOM (no iframe) — fullscreen fills the vis div */
#bowtie_diagram_container:fullscreen .vis-network {
    height: 100% !important;
}
#bowtie_fullscreen_btn:hover {
    background: rgba(255,255,255,1) !important;
}

