/* ========================================
   TOPBAR / HEADER
   ======================================== */

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 24px;
    height: 56px;
    background: linear-gradient(135deg, var(--ui-primary) 0%, #0842b3 100%);
    color: #fff;
    box-shadow: 0 2px 12px rgba(11, 95, 255, 0.25);
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
    flex-shrink: 0;
}

/* Brand Section - Contains logo and timezone */
.topbar .brand-section {
    display: flex;
    align-items: center;
    gap: 16px;
    justify-self: start;
}

/* Brand - Logo and name */
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.3px;
}

.topbar .brand-icon {
    opacity: 0.9;
}

/* Main Navigation - Centered */
.topbar .main-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.topbar .nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: rgba(255, 255, 255, 0.85);
    padding: 8px 14px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    transition: all 0.2s ease;
}

.topbar .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.topbar .nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.topbar .nav-link svg {
    opacity: 0.8;
    flex-shrink: 0;
}

.topbar .nav-link:hover svg,
.topbar .nav-link.active svg {
    opacity: 1;
}

/* Header Actions - Right aligned in right column */
.topbar .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-self: end;
}

/* Timezone Display */

/* Hide timezone on mobile */

/* Icon Buttons */
.topbar .header-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.topbar .header-icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    transform: translateY(-1px);
}

.topbar .header-icon-btn img {
    filter: brightness(0) invert(1);
    opacity: 0.9;
}

.topbar .header-icon-btn:hover img {
    opacity: 1;
}

/* Notification Badge */
.topbar .notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    animation: badge-pulse 2s ease-in-out infinite;
}

/* Notification Dropdown */
.topbar .notification-dropdown {
    position: relative;
}

.topbar .notification-panel {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    max-height: 600px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.08);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.98);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar .notification-panel.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.topbar .notification-panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--ui-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.topbar .notification-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--ui-text);
}

.topbar .notification-list {
    flex: 1;
    overflow-y: auto;
    max-height: 500px;
    -webkit-overflow-scrolling: touch;
}

.topbar .notification-loading,
.topbar .notification-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--ui-text-secondary);
    font-size: 14px;
}

.topbar .notification-item {
    display: flex;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
    position: relative;
    background: #fff;
}

.topbar .notification-item:hover {
    background: #f8fafc;
}

.topbar .notification-item.read {
    opacity: 0.6;
    background: #fafbfc;
}

.topbar .notification-item.read:hover {
    background: #f1f5f9;
}

/* Unread notifications are bolder */
.topbar .notification-item:not(.read) {
    background: #fff;
    border-left: 3px solid var(--ui-primary);
    padding-left: 17px;
}

.topbar .notification-icon {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: #f1f5f9;
    border-radius: 8px;
}

/* Unread notifications have more prominent icon */
.topbar .notification-item:not(.read) .notification-icon {
    background: #e0e7ff;
    border: 2px solid var(--ui-primary);
}

/* Read notifications have grayer icon */
.topbar .notification-item.read .notification-icon {
    background: #e2e8f0;
    opacity: 0.7;
}

.topbar .notification-content {
    flex: 1;
    min-width: 0;
}

.topbar .notification-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ui-text);
    margin-bottom: 4px;
    line-height: 1.4;
}

/* Unread notifications have bolder title */
.topbar .notification-item:not(.read) .notification-title {
    font-weight: 700;
    color: var(--ui-text);
}

/* Read notifications have lighter title */
.topbar .notification-item.read .notification-title {
    font-weight: 500;
    color: var(--ui-text-secondary);
}

.topbar .notification-message {
    font-size: 13px;
    color: var(--ui-text-secondary);
    line-height: 1.4;
    margin-bottom: 6px;
}

/* Read notifications have even lighter message */
.topbar .notification-item.read .notification-message {
    color: #94a3b8;
}

.topbar .notification-time {
    font-size: 11px;
    color: var(--ui-text-secondary);
    opacity: 0.8;
}

.topbar .notification-item.read .notification-time {
    opacity: 0.6;
}

.topbar .notification-action {
    flex: 0 0 auto;
    padding: 6px 12px;
    background: var(--ui-primary);
    color: white;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.15s;
    align-self: flex-start;
    margin-top: 4px;
}

.topbar .notification-action:hover {
    background: #0842b3;
    color: white;
}

/* Day headings and grouped entries */
.topbar .notification-day {
    padding: 8px 20px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ui-text-secondary);
    background: #f8fafc;
    border-bottom: 1px solid #f1f5f9;
}

.topbar .notification-count {
    display: inline-block;
    min-width: 20px;
    padding: 0 6px;
    margin-left: 4px;
    border-radius: 10px;
    background: #e0e7ff;
    color: var(--ui-primary-hover);
    font-size: 11px;
    line-height: 18px;
    text-align: center;
}

.topbar .notification-item .notification-message + .notification-message {
    margin-top: -2px;
}

.topbar .notification-more,
.topbar .notification-mark-all {
    padding: 0;
    border: none;
    background: none;
    color: var(--ui-primary-hover);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.topbar .notification-more {
    margin-bottom: 6px;
}

.topbar .notification-more:hover,
.topbar .notification-mark-all:hover {
    text-decoration: underline;
}

.topbar .notification-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.topbar .notification-mark {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--ui-border);
    border-radius: 50%;
    background: #fff;
    color: var(--ui-text-secondary);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.topbar .notification-mark:hover {
    border-color: var(--ui-success);
    background: var(--ui-success-light);
    color: var(--ui-success-text);
}

/* Mobile notification panel */
@media (max-width: 768px) {
    .topbar .notification-panel {
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
        right: 12px;
        left: auto;
        transform: translateY(-8px) scale(0.98);
        max-height: calc(100vh - 80px);
    }

    .topbar .notification-panel.active {
        transform: translateY(0) scale(1);
    }

    .topbar .notification-panel-header {
        padding: 12px 16px;
    }

    .topbar .notification-panel-header h3 {
        font-size: 15px;
    }

    .topbar .notification-item {
        padding: 12px 16px;
    }

    .topbar .notification-action {
        padding: 5px 10px;
        font-size: 11px;
    }
}

@keyframes badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* User Dropdown */
.topbar .user-dropdown {
    position: relative;
    margin-left: 8px;
    padding-left: 16px;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
}

.topbar .user-dropdown-trigger {
    position: relative; /* for the unread-news dot */
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.95);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
    font-weight: 500;
}

.topbar .user-dropdown-trigger:hover {
    background: rgba(255, 255, 255, 0.18);
}

.topbar .user-dropdown.open .user-dropdown-trigger {
    background: rgba(255, 255, 255, 0.2);
}

.topbar .user-greeting {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar .dropdown-chevron {
    opacity: 0.7;
    transition: transform 0.2s ease;
}

.topbar .user-dropdown.open .dropdown-chevron {
    transform: rotate(180deg);
}

/* Dropdown Menu */
.topbar .user-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 200;
    overflow: hidden;
}

.topbar .user-dropdown.open .user-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Dropdown Header (Organization) */
.topbar .dropdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    color: var(--ui-text);
    font-weight: 600;
    font-size: 13px;
}

.topbar .dropdown-header svg {
    color: var(--ui-primary);
    opacity: 0.8;
}

/* Dropdown Divider */
.topbar .dropdown-divider {
    height: 1px;
    background: var(--ui-border);
    margin: 0;
}

/* Dropdown Items */
.topbar .dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: var(--ui-text);
    font-size: 13px;
    text-decoration: none;
    transition: background 0.15s ease;
    cursor: pointer;
    width: 100%;
    border: none;
    background: none;
    text-align: left;
}

.topbar .dropdown-item:hover {
    background: #f8fafc;
}

/* User Info in Dropdown */
.topbar .dropdown-user-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    cursor: default;
}

.topbar .dropdown-user-info:hover {
    background: transparent;
}

.topbar .dropdown-label {
    font-size: 11px;
    color: var(--ui-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.topbar .dropdown-value {
    font-weight: 600;
    color: var(--ui-text);
}

/* Company switcher */
.topbar .dropdown-section-label {
    display: block;
    padding: 8px 16px 2px;
}

.topbar .dropdown-company {
    padding-top: 8px;
    padding-bottom: 8px;
    font-weight: 600;
}

.topbar .dropdown-company-unread {
    margin-left: auto;
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--ui-danger, #ef4444);
    color: #fff;
    font-size: 11px;
    text-align: center;
}

/* Another company has unread news */
.topbar .user-dropdown-news {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ui-danger, #ef4444);
}

/* Logout in Dropdown */
.topbar .dropdown-logout {
    color: var(--ui-danger-text);
}

.topbar .dropdown-logout:hover {
    background: #fef2f2;
}

.topbar .dropdown-logout svg {
    opacity: 0.8;
}

.topbar .logout-form {
    margin: 0;
}

/* Responsive Header */
@media (max-width: 1100px) {
    .topbar .nav-link span {
        display: none;
    }

    .topbar .nav-link {
        padding: 8px 10px;
    }

    .topbar .nav-link svg {
        width: 18px;
        height: 18px;
    }
}

@media (max-width: 900px) {
    .topbar .user-greeting {
        display: none;
    }

    .topbar .user-dropdown-trigger {
        padding: 8px 10px;
    }
}

/* ========================================
   MOBILE HAMBURGER NAVIGATION
   ======================================== */

/* Mobile nav toggle - hidden on desktop */
.mobile-nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.mobile-nav-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.mobile-nav-toggle .close-icon {
    display: none;
}

.topbar.nav-open .mobile-nav-toggle .hamburger-icon {
    display: none;
}

.topbar.nav-open .mobile-nav-toggle .close-icon {
    display: block;
}

/* Mobile nav overlay */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: 56px;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.mobile-nav-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Mobile breakpoint */
@media (max-width: 768px) {
    /* Show hamburger, hide desktop nav layout */
    .mobile-nav-toggle {
        display: flex;
        order: 1;
    }

    .mobile-nav-overlay {
        display: block;
    }

    /* Adjust grid for mobile: brand, hamburger, actions */
    .topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 12px;
        height: 56px;
    }

    .topbar .brand {
        flex: 0 0 auto;
    }

    .topbar .brand .brand-text {
        display: none;
    }

    /* Navigation becomes a dropdown panel */
    .topbar .main-nav {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
        border-bottom: 1px solid rgba(148, 163, 184, 0.2);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        flex-direction: column;
        align-items: stretch;
        padding: 8px 0;
        gap: 0;
        transform: translateY(-100%);
        opacity: 0;
        visibility: hidden;
        transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s ease;
        z-index: 95;
    }

    .topbar.nav-open .main-nav {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }

    .topbar .nav-link {
        width: 100%;
        padding: 14px 20px;
        border-radius: 0;
        justify-content: flex-start;
        gap: 12px;
        font-size: 15px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    .topbar .nav-link:last-child {
        border-bottom: none;
    }

    .topbar .nav-link span {
        display: inline;
    }

    .topbar .nav-link svg {
        width: 20px;
        height: 20px;
    }

    .topbar .nav-link.active {
        background: rgba(255, 255, 255, 0.1);
    }

    .topbar .nav-link:hover {
        background: rgba(255, 255, 255, 0.08);
    }

    /* Header actions */
    .topbar .header-actions {
        gap: 6px;
    }

    .topbar .header-icon-btn {
        width: 40px;
        height: 40px;
    }

    .topbar .user-greeting {
        display: none;
    }

    .topbar .user-dropdown {
        padding-left: 8px;
        margin-left: 6px;
    }

    .topbar .user-dropdown-trigger {
        padding: 8px;
    }

    .topbar .dropdown-chevron {
        display: none;
    }
}

/* Small mobile adjustments */
@media (max-width: 400px) {
    .topbar .header-icon-btn {
        width: 36px;
        height: 36px;
    }

    .topbar .header-icon-btn img {
        width: 20px;
        height: 20px;
    }

    .mobile-nav-toggle {
        width: 36px;
        height: 36px;
    }

    .mobile-nav-toggle svg {
        width: 20px;
        height: 20px;
    }
}

/* Phones: the bell isn't at the right edge, so anchor the panel to the screen instead of the bell */
@media (max-width: 768px) {
    .topbar .notification-panel {
        position: fixed;
        top: 64px;
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 80px);
    }
}
