/* =============================================
   BASE
   ============================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:       #1e40af;
    --primary-light: #3b82f6;
    --primary-dark:  #1e3a8a;
    --accent:        #f59e0b;
    --bg:            #f1f5f9;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --border:        #e2e8f0;
    --text:          #1e293b;
    --text-2:        #64748b;
    --text-inv:      #ffffff;
    --sidebar-w:     260px;
    --header-h:      64px;
    --radius:        12px;
    --shadow-sm:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:     0 4px 12px rgba(0,0,0,.10);
    --shadow-lg:     0 10px 30px rgba(0,0,0,.15);
    --transition:    0.2s ease;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* =============================================
   VISIBILIDADE (usadas pelo JS)
   ============================================= */
.display-flex  { display: flex  !important; }
.display-none  { display: none  !important; }
.display-block { display: block !important; }

/* =============================================
   HEADER
   ============================================= */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 30;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 20px;
    position: relative;
}

/* Logo + título */
.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1;
}

.menu-toggle-btn {
    font-size: 24px !important;
    color: var(--text-2);
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: background var(--transition), color var(--transition);
}
.menu-toggle-btn:hover { background: var(--bg); color: var(--primary); }

.header-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform var(--transition);
}
.header-logo:hover { transform: scale(1.08); }

.header-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: -.3px;
    white-space: nowrap;
}

/* Temis — centro absoluto */
.header-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border: 1px solid #bfdbfe;
    border-radius: 50px;
    padding: 6px 16px;
    transition: box-shadow var(--transition);
}
.header-center:hover { box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

.temis-icon { width: 28px; height: 28px; }

.temis-link {
    font-size: .82rem;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
    transition: color var(--transition);
}
.temis-link:hover { color: var(--primary-dark); }

/* Login */
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1;
}

.user-email {
    font-size: .85rem;
    font-weight: 500;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 4px 14px;
}

/* =============================================
   LAYOUT
   ============================================= */
.layout {
    display: flex;
    padding-top: var(--header-h);
    min-height: 100vh;
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
    width: var(--sidebar-w);
    height: calc(100vh - var(--header-h));
    position: fixed;
    top: var(--header-h);
    left: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    z-index: 20;
}

.sidebar-close {
    display: none;
    position: absolute;
    top: 10px; right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-2);
    padding: 4px;
    border-radius: 6px;
    transition: background var(--transition);
}
.sidebar-close:hover { background: var(--bg); }
.sidebar-close .material-icons { font-size: 20px; }

.sidebar-nav {
    padding: 12px 10px;
    flex: 1;
}

/* Item de navegação */
.sidebar-item { margin-bottom: 2px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 10px;
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    color: var(--text);
    transition: background var(--transition), color var(--transition), transform var(--transition);
    position: relative;
}
.nav-link:hover {
    background: #eff6ff;
    color: var(--primary);
    transform: translateX(3px);
}

.nav-icon { font-size: 20px !important; color: var(--text-2); transition: color var(--transition); }
.nav-link:hover .nav-icon { color: var(--primary); }

.nav-icon-img { width: 22px; height: 22px; object-fit: contain; }

/* Seta dos submenus */
.submenu-arrow {
    margin-left: auto;
    font-size: 18px !important;
    color: var(--text-2);
    transition: transform .3s cubic-bezier(.4,0,.2,1), color var(--transition);
}
.nav-link:hover .submenu-arrow { color: var(--primary); }
.submenu-arrow-rotated  { transform: rotate(180deg); }
.submenu-arrow-normal   { transform: rotate(0deg); }

/* =============================================
   SUBMENU
   ============================================= */
.submenu {
    background: linear-gradient(160deg, #1e293b, #0f172a);
    border-radius: 10px;
    padding: 6px;
    margin: 4px 0;
    max-height: 400px;
    overflow: hidden;
    overflow-y: auto;
    opacity: 1;
    transform: scaleY(1);
    transform-origin: top;
    transition: max-height .35s cubic-bezier(.4,0,.2,1),
                opacity .25s ease,
                transform .25s ease,
                padding .25s ease,
                margin .25s ease;
}

.submenu.hidden {
    max-height: 0 !important;
    opacity: 0 !important;
    transform: scaleY(.95) !important;
    padding: 0 6px !important;
    margin: 0 !important;
}

/* Scrollbar */
.submenu::-webkit-scrollbar { width: 4px; }
.submenu::-webkit-scrollbar-track { background: transparent; }
.submenu::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }

.submenu li { list-style: none; margin-bottom: 2px; }
.submenu li:last-child { margin-bottom: 0; }

.submenu li a {
    display: block;
    padding: 8px 12px;
    border-radius: 7px;
    font-size: .83rem;
    font-weight: 500;
    color: rgba(255,255,255,.8);
    text-decoration: none;
    transition: background var(--transition), color var(--transition), transform var(--transition);
}
.submenu li a:hover {
    background: rgba(59,130,246,.25);
    color: #fff;
    transform: translateX(4px);
}

/* =============================================
   SIDEBAR FOOTER
   ============================================= */
.sidebar-footer {
    padding: 16px 12px;
    text-align: center;
    border-top: 1px solid var(--border);
}

.sidebar-footer-text {
    font-size: .78rem;
    color: var(--text-2);
    line-height: 1.6;
}

.sidebar-app-img {
    width: 120px;
    height: 160px;
    object-fit: contain;
    margin: 6px auto 0;
    display: block;
    cursor: pointer;
    transition: transform var(--transition);
}
.sidebar-app-img:hover { transform: scale(1.04); }

.sidebar-footer-copy {
    font-size: .75rem;
    color: var(--text-2);
    margin-top: 8px;
}

/* =============================================
   MAIN CONTENT
   ============================================= */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 28px 24px;
    min-height: calc(100vh - var(--header-h));
}

/* Label de seção */
.news-section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary-light);
}
.news-section-label .material-icons { color: var(--primary-light); font-size: 22px; }

/* Grid de notícias */
.news-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.news-col { display: flex; flex-direction: column; gap: 16px; }

/* =============================================
   CARDS DE NOTÍCIAS (gerados pelo JS)
   ============================================= */
.news-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow var(--transition), transform var(--transition);
}
.news-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.news-card img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
}

.news-card-body { padding: 14px 16px; }

.news-card-tag {
    display: inline-block;
    font-size: .72rem;
    font-weight: 600;
    color: var(--primary-light);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 6px;
}

.news-card-title {
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.45;
    margin-bottom: 12px;
}
.news-card-title a { color: inherit; text-decoration: none; }
.news-card-title a:hover { color: var(--primary); }

.news-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .8rem;
}

.news-card-date { color: var(--text-2); }

.news-card-link {
    color: var(--primary-light);
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 2px;
    transition: color var(--transition);
}
.news-card-link:hover { color: var(--primary-dark); }

/* =============================================
   MODAL
   ============================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    backdrop-filter: blur(4px);
    padding: 16px;
}

.modal-box {
    background: var(--surface);
    border-radius: 16px;
    width: 520px;
    max-width: 100%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalIn .2s ease;
    overflow: hidden;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(.96) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Cabeçalho fixo */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.modal-close {
    background: var(--bg);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 6px;
    color: var(--text-2);
    transition: background var(--transition), color var(--transition);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.modal-close:hover { background: #fee2e2; color: #ef4444; }
.modal-close .material-icons { font-size: 20px; }

/* Lista de cards */
.modal-grid {
    overflow-y: auto;
    padding: 10px 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.modal-grid::-webkit-scrollbar { width: 4px; }
.modal-grid::-webkit-scrollbar-track { background: transparent; }
.modal-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Card individual */
.modal-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 12px;
    border-radius: 10px;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.modal-card:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
    transform: translateX(3px);
}

.modal-card-img {
    width: 46px;
    height: 46px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.modal-card-title {
    flex: 1;
    font-size: .9rem;
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
}
.modal-card:hover .modal-card-title { color: var(--primary); }

.modal-card-arrow {
    font-size: 18px !important;
    color: var(--border);
    flex-shrink: 0;
    transition: color var(--transition);
}
.modal-card:hover .modal-card-arrow { color: var(--primary-light); }

/* Mobile */
@media (max-width: 480px) {
    .modal-box {
        max-height: 92vh;
        border-radius: 14px;
    }
    .modal-card-img { width: 40px; height: 40px; }
    .modal-card-title { font-size: .85rem; }
}

/* =============================================
   POPUP
   ============================================= */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
}

.popup-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px 32px;
    text-align: center;
    max-width: 360px;
    width: 90vw;
    box-shadow: var(--shadow-lg);
    animation: modalIn .2s ease;
}

.popup-icon {
    font-size: 36px !important;
    color: var(--primary-light);
    margin-bottom: 12px;
    display: block;
}

.popup-text {
    font-size: .95rem;
    color: var(--text);
    margin-bottom: 20px;
    line-height: 1.5;
}

.popup-close-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 24px;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}
.popup-close-btn:hover { background: var(--primary-dark); }

/* =============================================
   QR CODE
   ============================================= */
#qrCodeOverlay { transition: opacity .3s ease; opacity: 0; }
#qrCodeOverlay.flex { opacity: 1; }
#qrCodeOverlay.hidden { opacity: 0; pointer-events: none; }

.qr-wrapper {
    background: #fff;
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.qr-wrapper img { width: 200px; display: block; }

/* =============================================
   SPINNER
   ============================================= */
.spinner-overlay { background: rgba(0,0,0,.45); }

.spiral-loader {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255,255,255,.2);
    border-top: 4px solid var(--primary-light);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =============================================
   RESPONSIVO
   ============================================= */
@media (max-width: 1024px) {
    .news-grid { grid-template-columns: 1fr; }
}

/* Tablet — sidebar sempre visível */
@media (max-width: 768px) {
    .temis-link { display: none; }
    .header-center { background: none; border: none; padding: 0; }
    .news-grid { grid-template-columns: 1fr; }
}

/* Mobile — sidebar recolhida, acionada pelo menu */
@media (max-width: 540px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 25;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: flex; }

    .main-content {
        margin-left: 0;
        padding: 16px 12px;
    }
}

@media (max-width: 480px) {
    .header-title { display: none; }
    .user-email { display: none !important; }
}
