:root {
    --drawer-w: 264px;
    /* Legacy pages use --sidenav-width; keep aligned with the real sidebar */
    --sidenav-width: var(--drawer-w);
    --radius: 8px;
    --dur: 300ms;
    --ease: cubic-bezier(.22,1,.36,1);
    --bg: #f3f6fb;
    --fg: #2b3440;
    --muted: #6b7a90;
    --border: #e5e7eb;
    --hover: #e5e7eb;
    --active-bg: #0d6efd;
    --active-fg: #ffffff;
    --sidebar-bg: #0d2f4f;
    --sidebar-fg: #e5ebf3;
    --sidebar-hover: rgba(255,255,255,0.1);
    --sidebar-active-bg: #00aaff;
    --sidebar-active-fg: #ffffff;
    --topbar-bg: #ffffff;
    --topbar-fg: #2b3440;
    --warning: #f59e0b;
    --danger: #ef4444;
    --scrim: rgba(0,0,0,.35);
    --content-left: var(--drawer-w);
    --content-width: calc(100vw - var(--drawer-w));
    --content-center-x: calc(var(--content-left) + (var(--content-width) / 2));
}

@media (max-width: 991px) {
    :root {
        --content-left: 0px;
        --content-width: 100vw;
        --content-center-x: 50vw;
        --sidenav-width: 0px;
    }
}

/* Toast: center in content area (viewport minus sidebar) */
.toast {
    left: var(--content-center-x, 50vw);
    transform: translateX(-50%);
}

html[data-theme="dark"] {
    --bg: #0b1220;
    --fg: #e5ebf3;
    --muted: #aab6c4;
    --border: #334155;
    --hover: #273446;
    --active-bg: #3b82f6;
    --active-fg: #ffffff;
    --sidebar-bg: #1f2937;
    --sidebar-fg: #e5ebf3;
    --sidebar-hover: #273446;
    --sidebar-active-bg: #3b82f6;
    --sidebar-active-fg: #ffffff;
    --topbar-bg: #1f2937;
    --topbar-fg: #e5ebf3;
    --scrim: rgba(0,0,0,.5);
}

html {
    overflow-x: hidden;
}

body {
    background: var(--bg);
    color: var(--fg);
    padding-left: var(--drawer-w);
    transition: padding-left var(--dur) var(--ease);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--drawer-w);
    height: 100dvh;
    overflow-y: auto;
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    border-right: 1px solid var(--border);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform var(--dur) var(--ease), background .2s, color .2s;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 12px 14px;
    font-weight: 700;
    font-size: 18px;
    border-bottom: 1px solid var(--border);
}

.dev-badge {
    margin-left: auto;
    font-size: .75rem;
    padding: .2rem .45rem;
    border-radius: 999px;
    background: #fff7ed;
    color: #7c2d12;
    border: 1px solid #fed7aa;
}

html[data-theme="dark"] .dev-badge {
    background: #2a1f14;
    color: #f3e8d3;
    border-color: #3b2a1c;
}

.sidebar__profile {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: grid;
    gap: 4px;
}

.sidebar__profile .name {
    font-weight: 600;
}

.sidebar__profile .email {
    color: var(--muted);
    font-size: .9rem;
}

.sidebar__menu {
    list-style: none;
    margin: 8px 0;
    padding: 8px;
    display: grid;
    gap: 6px;
}

.sidebar__menu a {
    display: grid;
    grid-template-columns: 24px 1fr auto;
    align-items: center;
    gap: .7rem;
    padding: 10px 10px;
    border-radius: var(--radius);
    color: inherit;
    text-decoration: none;
}

.sidebar__menu a:hover {
    background: var(--sidebar-hover);
}

.sidebar__menu a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-fg);
}

.sidebar__menu .hint {
    font-size: .85rem;
    opacity: .85;
}

/* Unread messages count badge next to Messages */
.sidebar__menu-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    margin-left: 0.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    background: var(--danger, #ef4444);
    border-radius: 999px;
}
.sidebar__menu a:hover .sidebar__menu-badge,
.sidebar__menu a.active .sidebar__menu-badge {
    background: rgba(255, 255, 255, 0.35);
    color: inherit;
}

.sidebar__footer {
    margin-top: auto;
    padding: 8px;
    border-top: 1px solid var(--border);
    display: grid;
    gap: 6px;
    background: var(--sidebar-bg);
}

.sidebar__note {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: 6px 8px;
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
}

.sidebar__note:hover {
    background: var(--sidebar-hover);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
}

.topbar-content-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 45px;
}

.hamburger {
    display: none;
    border: 0;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--topbar-fg);
}

.topbar__right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.notification-indicator {
    position: relative;
}

.notification-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 28px;
    height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: #6b7280;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    cursor: pointer;
}

.notification-link:hover {
    filter: brightness(0.95);
}

.notification-link i {
    font-size: 12px;
}

.notification-link.infractions {
    background: var(--warning);
}

.notification-link.infractions.warning {
    background: var(--danger);
    animation: pulseGlow 2.2s infinite;
}

@keyframes pulseGlow {
    0% { box-shadow: 0 0 0 0 rgba(239,68,68,.6); }
    70% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
    100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

.header-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 14px 40px rgba(0,0,0,.15);
    z-index: 1010;
    font-size: 14px;
    min-width: 320px;
    overflow: hidden;
}

.header-dropdown::before {
    content: '';
    display: block;
    position: absolute;
    top: -15px;
    left: 0;
    width: 100%;
    height: 15px;
    background: transparent;
}

.notification-indicator.active .header-dropdown {
    display: block;
}

.header-dropdown .tooltip-header {
    font-weight: 700;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--hover);
}

.header-dropdown .month-section-header {
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--muted);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.header-dropdown ul {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 350px;
    overflow-y: auto;
}

.header-dropdown li a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--border);
}

.header-dropdown li:last-child a {
    border-bottom: none;
}

.header-dropdown li a:hover {
    background: var(--hover);
}

.name-vessel {
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    flex-direction: column;
}

.vessel-name {
    color: var(--muted);
    font-size: .85em;
}

.message-count-badge {
    background: var(--active-bg);
    color: #fff;
    border-radius: 999px;
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    padding: 0 6px;
}

.date {
    font-size: 0.85em;
    color: var(--muted);
}

.date.old {
    color: var(--danger);
    font-weight: bold;
}

.drawer-scrim {
    position: fixed;
    inset: 0;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease);
    z-index: 1100;
}

@media (max-width: 991px) {
    body {
        padding-left: 0;
    }

    .hamburger {
        display: inline-flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    html.drawer-open .sidebar {
        transform: translateX(0);
    }

    html.drawer-open .drawer-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    body > :not(.sidebar):not(.drawer-scrim) {
        transition: transform var(--dur) var(--ease);
    }

    /* Do not translate .modal: it breaks position:fixed centering and shifts overlays too far right */
    html.drawer-open body > :not(.sidebar):not(.drawer-scrim):not(.modal) {
        transform: translateX(var(--drawer-w));
    }
}

@media (max-width: 768px) {
    .header-dropdown {
        position: fixed;
        top: 55px;
        left: 10px;
        right: 10px;
        width: auto;
        min-width: 0;
        max-height: 80vh;
    }

    .header-dropdown::before {
        display: none;
    }
}

#notification-bubbles {
    display: flex;
    align-items: center;
    gap: 12px;
}

.vessel-filter-select {
    background-color: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    max-width: 150px;
    cursor: pointer;
    margin-right: 10px;
}

html[data-theme="dark"] .vessel-filter-select {
    background-color: #374151;
    border-color: #4b5563;
}