/* Shared app header ("topbar") used by every page except login.html.
   Structure/sizing is copied from control_center.html so every page has an
   identical header/nav — only the subtitle and nav buttons differ per page.
   Include via: <link rel="stylesheet" href="/static/topbar.css">
   Markup via: templates/partials/topbar.html (Jinja macro) */

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    backdrop-filter: blur(18px);
    background: rgba(255, 255, 255, 0.78);
    border-bottom: 1px solid rgba(226, 232, 240, 0.9);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.topbar::before {
    content: "";
    display: block;
    height: 6px;
    background: linear-gradient(90deg, #06b6d4 0%, #2563eb 50%, #7c3aed 100%);
}

.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    min-height: 60px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    flex-wrap: wrap;
}

.topbar-inner .brand {
    flex: 1 1 auto;
}

.topbar-inner .role-badge {
    font-size: 0.74rem;
    padding: 6px 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    flex: 0 0 auto; /* stay a pill — never stretch to full width */
    align-self: center;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

.theme-toggle-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(226, 232, 240, 0.9);
    background: rgba(255, 255, 255, 0.72);
    color: #475569;
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s ease;
    flex-shrink: 0;
}

.theme-toggle-btn:hover {
    transform: translateY(-1px);
    background: white;
    border-color: #cbd5e1;
}

.topbar .brand {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.topbar .brand-logo-img {
    height: 42px;
    width: auto;
    object-fit: contain;
}

.topbar .brand-logo-dark {
    display: none;
}

:root[data-theme="dark"] .topbar .brand-logo-light {
    display: none;
}

:root[data-theme="dark"] .topbar .brand-logo-dark {
    display: inline-block;
}

.topbar .role-badge {
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 8px;
    border-radius: 999px;
    border: 2px solid color-mix(in srgb, currentColor 35%, transparent);
}

.topbar .role-owner {
    background: linear-gradient(90deg, #f5f3ff, #ede9fe);
    color: #6d28d9;
}

.topbar .role-admin {
    background: #eef2ff;
    color: #1d4ed8;
}

.topbar .role-editor,
.topbar .role-creator {
    background: #ecfdf5;
    color: #059669;
}

/* Centered nav band along the bottom of the top bar */
.topbar-band {
    background: linear-gradient(90deg, #eef2ff 0%, #ede9fe 100%);
    border-top: 1px solid rgba(226, 232, 240, 0.9);
}

.topbar-band-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 9px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.topbar-band-inner .btn {
    height: 36px;
    border-radius: 10px;
    padding: 0 13px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    cursor: pointer;
    transition: 0.2s ease;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.82rem;
    font-family: inherit;
}

.topbar-band-inner .btn-ghost {
    background: rgba(255, 255, 255, 0.72);
    border-color: #e2e8f0;
    color: #475569;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.topbar-band-inner .btn-ghost:hover {
    transform: translateY(-1px);
    background: white;
    border-color: #cbd5e1;
    color: #0f172a;
}

.topbar-band-inner .btn-primary {
    background: linear-gradient(90deg, #2563eb 0%, #7c3aed 100%);
    color: white;
    border: none;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.26);
}

.topbar-band-inner .btn-primary:hover {
    transform: translateY(-1px);
    background: linear-gradient(90deg, #1d4ed8 0%, #6d28d9 100%);
}

.topbar-band-inner .btn-danger {
    background: white;
    color: #dc2626;
    border-color: #fecaca;
}

.topbar-band-inner .btn-danger:hover {
    background: #fef2f2;
}

/* Every page that includes the topbar must add class="has-topbar" to <body>
   so content clears the fixed header on desktop, collapsing to 0 once the
   header leaves fixed position below 1340px (see media query).
   --topbar-height is measured from the real header by theme.js (so wrapped
   nav rows or size tweaks can never open a gap or overlap); 124px is the
   single-row fallback before the script runs. --topbar-gap is breathing
   room above page content — pages whose first section should sit flush
   against the nav band (e.g. the landing hero) set it to 0px locally. */
body.has-topbar {
    padding-top: calc(var(--topbar-height, 124px) + var(--topbar-gap, 20px));
}

@media (max-width: 1340px) {
    /* Header leaves its fixed position and flows inline so it never eats
       vertical space on shorter screens (laptops, tablets, phones). */
    .topbar {
        position: static;
        margin-bottom: 16px;
    }

    body.has-topbar {
        padding-top: 0;
    }

    .topbar-inner {
        min-height: 0;
    }
}

@media (max-width: 820px) {
    .topbar-inner {
        padding: 14px 16px;
    }
}

@media (max-width: 560px) {
    /* Phones: shrink the wide wordmark so the brand row can't overflow, and let
       the nav buttons grow to fill each wrapped row instead of clustering. */
    .topbar .brand-logo-img {
        height: 34px;
    }

    .topbar-band-inner {
        padding: 9px 14px;
        gap: 8px;
        justify-content: stretch;
    }

    .topbar-band-inner .btn {
        flex: 1 1 auto;
    }
}

@media (max-width: 400px) {
    /* Very small phones: drop the subtitle so the brand never overflows. */
    .topbar .brand-logo-img {
        height: 28px;
    }

    .topbar .brand > a > span {
        display: none;
    }
}

/* ---------------------------------------------------------------------
   Dark mode. Toggled by adding data-theme="dark" to <html> (see theme.js
   and the anti-flash inline snippet in each page's <head>).
   --------------------------------------------------------------------- */
:root[data-theme="dark"] .topbar {
    background: rgba(15, 20, 32, 0.86);
    border-bottom-color: rgba(51, 65, 85, 0.7);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

:root[data-theme="dark"] .topbar .brand > a > span {
    color: #94a3b8;
    border-left-color: #334155;
}

:root[data-theme="dark"] .topbar .role-owner {
    background: linear-gradient(90deg, #2e1065, #3b0764);
    color: #c4b5fd;
}

:root[data-theme="dark"] .topbar .role-admin {
    background: rgba(37, 99, 235, 0.18);
    color: #93c5fd;
}

:root[data-theme="dark"] .topbar .role-editor,
:root[data-theme="dark"] .topbar .role-creator {
    background: rgba(5, 150, 105, 0.18);
    color: #6ee7b7;
}

:root[data-theme="dark"] .topbar-band {
    background: linear-gradient(90deg, #1a1a2e 0%, #201a35 100%);
    border-top-color: rgba(51, 65, 85, 0.7);
}

:root[data-theme="dark"] .topbar-band-inner .btn-ghost,
:root[data-theme="dark"] .theme-toggle-btn {
    background: rgba(30, 41, 59, 0.65);
    border-color: rgba(71, 85, 105, 0.8);
    color: #cbd5e1;
}

:root[data-theme="dark"] .topbar-band-inner .btn-ghost:hover,
:root[data-theme="dark"] .theme-toggle-btn:hover {
    background: #1e293b;
    border-color: #64748b;
    color: #f1f5f9;
}

:root[data-theme="dark"] .topbar-band-inner .btn-danger {
    background: rgba(220, 38, 38, 0.12);
    color: #fca5a5;
    border-color: rgba(127, 29, 29, 0.7);
}

:root[data-theme="dark"] .topbar-band-inner .btn-danger:hover {
    background: rgba(220, 38, 38, 0.22);
}
