/* ============================================
   TOPBAR PREMIUM - Sistema Disciplinar Pantanal
   Design: Corporate Refined + Glass Morphism
   ============================================ */

/* ============================================
   Base Topbar Container
   ============================================ */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: linear-gradient(135deg, #1D357F 0%, #152a66 50%, #0d1f4d 100%);
    box-shadow:
        0 4px 20px rgba(29, 53, 127, 0.25),
        0 1px 3px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

/* Subtle animated gradient overlay */
.top-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(0, 137, 123, 0.08) 25%,
        rgba(0, 137, 123, 0.12) 50%,
        rgba(0, 137, 123, 0.08) 75%,
        transparent 100%
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.top-bar:hover::before {
    opacity: 1;
}

/* ============================================
   Left Section - Logo & Brand
   ============================================ */
.top-bar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Hamburger Menu Button */
.hamburger-menu {
    display: none;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.hamburger-menu:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

.hamburger-menu span {
    display: block;
    width: 18px;
    height: 2px;
    background: white;
    border-radius: 2px;
    position: relative;
    transition: all 0.3s ease;
}

.hamburger-menu span::before,
.hamburger-menu span::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 2px;
    background: white;
    border-radius: 2px;
    left: 0;
    transition: all 0.3s ease;
}

.hamburger-menu span::before { top: -6px; }
.hamburger-menu span::after { top: 6px; }

/* App Launcher Grid */
.app-launcher {
    width: 32px;
    height: 32px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 7px;
    cursor: pointer;
    background: transparent;
    border: none;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.app-launcher:hover {
    background: rgba(255, 255, 255, 0.1);
}

.app-launcher span {
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.app-launcher:hover span {
    background: white;
}

/* Sidebar Toggle Button na Topbar */
.sidebar-toggle-topbar {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: white;
    flex-shrink: 0;
}

.sidebar-toggle-topbar:hover {
    background: rgba(0, 137, 123, 0.3);
    border-color: rgba(0, 137, 123, 0.5);
    transform: scale(1.05);
}

.sidebar-toggle-topbar:active {
    transform: scale(0.95);
}

.sidebar-toggle-topbar svg {
    width: 22px;
    height: 22px;
    stroke: white;
    transition: all 0.3s ease;
}

.sidebar-toggle-topbar:hover svg {
    stroke: #4db6ac;
}

/* Quando sidebar está aberta, mudar ícone */
body:not(.sidebar-collapsed) .sidebar-toggle-topbar {
    background: rgba(0, 137, 123, 0.25);
    border-color: rgba(0, 137, 123, 0.4);
}

/* Brand Name */
.app-name {
    font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: white;
    letter-spacing: -0.3px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

/* School Name Badge */
.school-name {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    background: rgba(0, 137, 123, 0.25);
    border: 1px solid rgba(0, 137, 123, 0.4);
    border-radius: 20px;
    font-family: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #6ee7b7;
    letter-spacing: 0.3px;
    backdrop-filter: blur(4px);
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: visible;
    flex-shrink: 0;
}

.school-name:hover {
    background: rgba(0, 137, 123, 0.35);
    transform: translateY(-1px);
}

/* ============================================
   Right Section - Controls & User
   ============================================ */
.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Unit Selector - Glass Card */
.unidade-selector-container {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.unidade-selector-container:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

.unidade-selector-container .unidade-icon {
    font-size: 14px;
    filter: grayscale(0);
}

.unidade-selector-container .unidade-icon svg {
    width: 14px;
    height: 14px;
}

.unidade-selector-container select {
    background: rgba(255, 255, 255, 0.95);
    border: none;
    padding: 4px 22px 4px 8px;
    border-radius: 6px;
    font-family: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: #1D357F;
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%231D357F' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    transition: all 0.2s ease;
    min-width: 70px;
}

.unidade-selector-container select:hover {
    background-color: white;
}

.unidade-selector-container select:focus {
    box-shadow: 0 0 0 2px rgba(0, 137, 123, 0.4);
}

/* Theme Toggle Container */
#theme-toggle-container {
    display: flex;
    align-items: center;
}

/* User Profile Link - Glass Card */
.user-profile-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px 6px 6px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 28px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.user-profile-link:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* User Avatar */
.user-profile {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00897B 0%, #00695C 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 15px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 137, 123, 0.3);
    overflow: hidden;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.user-profile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-profile-link:hover .user-profile {
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

/* User Name */
.user-name {
    font-family: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: white;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Logout Button */
.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.9) 0%, rgba(185, 28, 28, 0.9) 100%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    font-family: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.btn-logout:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(220, 38, 38, 0.35);
}

.btn-logout:active {
    transform: translateY(0);
}

.btn-logout::before {
    content: '';
    display: none;
}

.btn-logout-icon {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
}

/* ============================================
   Dark Mode Adjustments
   ============================================ */
[data-theme="dark"] .top-bar {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    border-bottom-color: rgba(255, 255, 255, 0.06);
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .unidade-selector-container,
[data-theme="dark"] .user-profile-link {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .unidade-selector-container:hover,
[data-theme="dark"] .user-profile-link:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .school-name {
    background: rgba(0, 137, 123, 0.2);
    border-color: rgba(0, 137, 123, 0.3);
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1024px) {
    .school-name {
        display: none;
    }
}

@media (max-width: 768px) {
    .top-bar {
        height: 56px;
        padding: 0 16px;
    }

    /* Botão toggle da sidebar - garantir visibilidade no mobile */
    .sidebar-toggle-topbar {
        width: 38px;
        height: 38px;
        display: flex !important;
    }

    .app-name {
        font-size: 15px;
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .top-bar-right {
        gap: 8px;
    }

    .unidade-selector-container {
        padding: 6px 10px;
    }

    .unidade-selector-container .unidade-icon {
        display: none;
    }

    .unidade-selector-container select {
        font-size: 12px;
        padding: 5px 24px 5px 8px;
        min-width: 80px;
    }

    .user-profile-link {
        padding: 4px;
        border-radius: 50%;
    }

    .user-profile-link .user-name {
        display: none;
    }

    .user-profile {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    .btn-logout {
        padding: 8px 12px;
        font-size: 12px;
    }

    .btn-logout span {
        display: none;
    }

    /* Toggle de tema menor no mobile */
    .theme-toggle-btn {
        width: 36px;
        height: 36px;
    }
}

@media (max-width: 480px) {
    .top-bar {
        padding: 0 10px;
        gap: 8px;
    }

    .top-bar-left {
        gap: 8px;
    }

    .sidebar-toggle-topbar {
        width: 36px;
        height: 36px;
    }

    .app-name {
        font-size: 13px;
        max-width: 90px;
    }

    .unidade-selector-container {
        display: none;
    }

    .btn-logout {
        padding: 8px;
        min-width: auto;
    }

    .btn-logout .btn-logout-icon {
        width: 18px;
        height: 18px;
    }

    .theme-toggle-btn {
        width: 34px;
        height: 34px;
    }

    .user-profile {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }
}

/* ============================================
   Animation - Entrance
   ============================================ */
@keyframes topbarSlideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.top-bar {
    animation: topbarSlideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Stagger children */
.top-bar-left > * {
    animation: topbarSlideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    opacity: 0;
}

.top-bar-left > *:nth-child(1) { animation-delay: 0.1s; }
.top-bar-left > *:nth-child(2) { animation-delay: 0.15s; }
.top-bar-left > *:nth-child(3) { animation-delay: 0.2s; }
.top-bar-left > *:nth-child(4) { animation-delay: 0.25s; }

.top-bar-right > * {
    animation: topbarSlideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    opacity: 0;
}

.top-bar-right > *:nth-child(1) { animation-delay: 0.2s; }
.top-bar-right > *:nth-child(2) { animation-delay: 0.25s; }
.top-bar-right > *:nth-child(3) { animation-delay: 0.3s; }
.top-bar-right > *:nth-child(4) { animation-delay: 0.35s; }

/* ============================================
   Accessibility - Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .top-bar,
    .top-bar-left > *,
    .top-bar-right > * {
        animation: none;
        opacity: 1;
    }

    .hamburger-menu:hover,
    .app-launcher:hover,
    .user-profile-link:hover,
    .btn-logout:hover {
        transform: none;
    }
}

/* ============================================
   Fix main content spacing
   ============================================ */
.main-layout {
    margin-top: 64px !important;
}

@media (max-width: 768px) {
    .main-layout {
        margin-top: 56px !important;
    }
}
