body:has(.navbar) { padding-top: 64px; }
body:has(.global-footer) { box-sizing: border-box; min-height: 100dvh; padding-bottom: 68px; }
body:is(.consulta-page, .geracao-page, .inutilizacao-page, .relatorios-page) { padding-bottom: 0; }

.navbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    padding: 0 clamp(16px, 2vw, 32px);
    border-bottom: 1px solid #34483a;
    background: #131b16;
    color: #f0f5ef;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.navbar .titulo {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 10px;
    text-decoration: none;
}
.navbar .titulo .logo {
    display: block;
    width: 46px;
    height: 46px;
    margin: 0;
    object-fit: contain;
}
.navbar .brand-name {
    color: #f0f5ef;
    font-size: 1.19rem;
    font-weight: 800;
    letter-spacing: -.035em;
    white-space: nowrap;
}
.navbar .brand-name span { color: #9de297; }
.nav-title {
    position: absolute;
    left: 50%;
    max-width: 33vw;
    overflow: hidden;
    color: #dce9dc;
    font-size: 1rem;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
    transform: translateX(-50%);
    pointer-events: none;
}
.nav-links { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav-item { position: relative; margin: 0; }
.navbar .nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto;
    min-height: 40px;
    margin: 0;
    padding: 0 13px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: #e6efe5;
    font-size: .9rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
.navbar .nav-link:hover,
.navbar .dropdown-toggle[aria-expanded="true"] {
    border-color: #3b5741;
    background: #263b2c;
    transform: none;
}
.navbar .nav-link:focus-visible,
.navbar .titulo:focus-visible,
.navbar .nav-menu-toggle:focus-visible,
.navbar .dropdown a:focus-visible {
    outline: 3px solid #9de297;
    outline-offset: 2px;
}
.dropdown-icon {
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    transition: transform .18s ease;
}
.dropdown-toggle[aria-expanded="true"] .dropdown-icon { transform: translateY(1px) rotate(225deg); }
.navbar .dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 1201;
    width: max-content;
    min-width: 220px;
    max-width: min(320px, calc(100vw - 32px));
    margin: 0;
    padding: 7px;
    border: 1px solid #405745;
    border-radius: 12px;
    background: #202c23;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .35);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
    transition: opacity .16s ease, transform .16s ease, visibility .16s;
    list-style: none;
    pointer-events: none;
}
.navbar .dropdown-right .dropdown { right: 0; left: auto; }
.navbar .dropdown-toggle[aria-expanded="true"] + .dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}
.navbar .dropdown li { list-style: none; }
.navbar .dropdown a {
    display: block;
    padding: 11px 12px;
    border-radius: 7px;
    color: #e8f1e8;
    font-size: .88rem;
    text-decoration: none;
}
.navbar .dropdown a:hover { background: #304534; }
.navbar .logout-item {
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid #405745;
}
.navbar .logout-item a { color: #f0ada5; }
.nav-menu-toggle { display: none; }

.global-footer {
    position: fixed;
    inset: auto 0 0;
    z-index: 900;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    min-height: 46px;
    padding: 7px clamp(16px, 2vw, 32px);
    border-top: 1px solid #34483a;
    background: #111a14;
    color: #dbe8da;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .15);
    font-size: .78rem;
}
.footer-left, .footer-center, .footer-right {
    display: flex;
    align-items: center;
    min-width: 0;
}
.footer-left { gap: 9px; }
.footer-presence {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #83cf78;
    box-shadow: 0 0 0 3px rgba(131, 207, 120, .12);
}
.company-info {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.footer-center { justify-content: center; text-align: center; }
.footer-message {
    overflow: hidden;
    color: #adc0af;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.footer-right { justify-content: flex-end; gap: 7px; white-space: nowrap; }
.date-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    background: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M7 2v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-2V2h-2v2H9V2H7ZM5 10h14v10H5V10Z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.modal-gen {
    box-sizing: border-box;
    width: min(560px, calc(100% - 32px));
    max-height: calc(100dvh - 32px);
    margin: auto;
    padding: 26px;
    border: 1px solid #4c6552;
    border-radius: 16px;
    background: #253128;
    color: #f0f5ef;
    box-shadow: 0 28px 85px rgba(0, 0, 0, .55);
    overflow-y: auto;
}
.modal-gen:not([open]) { display: none; }
.modal-gen::backdrop { background: rgba(4, 12, 7, .76); }
.modal-gen-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.modal-gen-kicker {
    color: #9ce096;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}
.modal-gen h2 {
    margin: 6px 0 0;
    color: #f0f5ef;
    font-size: 1.55rem;
    line-height: 1.2;
}
.modal-gen h2:focus { outline: none; }
.modal-gen .modal-gen-close {
    flex: 0 0 auto;
    width: 36px;
    min-height: 36px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: #344538;
    color: #f0f5ef;
    font-size: 1.45rem;
    line-height: 1;
}
.modal-gen .modal-gen-close:hover { background: #49634f; transform: none; }
.modal-gen-subtitulo {
    margin: 16px 0 0;
    color: #a9c6aa;
    font-size: .83rem;
}
.modal-gen-subtitulo[hidden] { display: none; }
.modal-gen-text {
    margin: 20px 0 0;
    padding: 18px;
    border: 1px solid #405345;
    border-radius: 10px;
    background: #1b271e;
    color: #e0eae0;
    line-height: 1.6;
    white-space: pre-line;
    overflow-wrap: anywhere;
}
.modal-gen-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}
.modal-gen-actions button {
    width: auto;
    min-width: 94px;
    min-height: 42px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: #2e7843;
    color: #fff;
    font-weight: 650;
}
.modal-gen-actions button:hover { background: #379150; }
.modal-gen button:focus-visible { outline: 3px solid #9de297; outline-offset: 2px; }

body .modal:not(dialog) {
    z-index: 2000;
    padding: 16px;
    background: rgba(4, 12, 7, .76);
}
body .modal:not(dialog) .modal-content {
    box-sizing: border-box;
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(560px, calc(100% - 32px));
    min-width: 0;
    height: auto;
    min-height: 0;
    max-height: calc(100dvh - 32px);
    margin: 0;
    padding: 26px;
    border: 1px solid #4c6552;
    border-radius: 16px;
    background: #253128;
    color: #f0f5ef;
    box-shadow: 0 28px 85px rgba(0, 0, 0, .55);
    text-align: left;
    overflow-y: auto;
    transform: translate(-50%, -50%);
}
body .modal:not(dialog) .modal-content h2,
body .modal:not(dialog) .modal-content h3 {
    margin: 0 40px 16px 0;
    color: #f0f5ef;
    font-size: 1.4rem;
}
body .modal:not(dialog) .modal-content p {
    color: #d6e2d6;
    line-height: 1.6;
    overflow-wrap: anywhere;
}
body .modal:not(dialog) .modal-content .close {
    position: absolute;
    top: 14px;
    right: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: #344538;
    color: #f0f5ef;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}
body .modal:not(dialog) .modal-content .close:hover { background: #49634f; }
body .modal:not(dialog) .modal-content button:not(.close) {
    width: auto;
    height: auto;
    min-height: 42px;
    margin: 8px 8px 0 0;
    padding: 8px 16px;
    border: 0;
    border-radius: 8px;
    background: #3a493d;
    color: #f0f5ef;
    font-size: .9rem;
    font-weight: 650;
}
body .modal:not(dialog) .modal-content button.confirm,
body .modal:not(dialog) .modal-content button.confirm-button {
    background: #2e7843;
}
body .modal:not(dialog) .modal-content button.confirm-descartar { background: #9b3b3b; }
body .modal:not(dialog) .modal-content .modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}
body .modal:not(dialog) .modal-content .modal-actions button:not(.close) { margin: 0; }
body .modal:not(dialog) .modal-content button:hover { filter: brightness(1.15); }
body .modal:not(dialog) .modal-content button:focus-visible,
body .modal:not(dialog) .modal-content .close:focus-visible {
    outline: 3px solid #9de297;
    outline-offset: 2px;
}
body .modal:not(dialog) .modal-content input,
body .modal:not(dialog) .modal-content select {
    max-width: 100%;
    min-height: 42px;
    border: 1px solid #526b57;
    border-radius: 8px;
    background: #18241b;
    color: #f0f5ef;
    color-scheme: dark;
}

@media (max-width: 1200px) {
    .nav-title { display: none; }
}
@media (max-width: 900px) {
    body:has(.global-footer) { padding-bottom: 78px; }
    body:is(.consulta-page, .geracao-page, .inutilizacao-page, .relatorios-page) { padding-bottom: 0; }
    body:is(.consulta-page, .geracao-page, .inutilizacao-page, .relatorios-page) > main { padding-bottom: 78px; }
    .navbar .nav-menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 9px;
        width: auto;
        min-height: 40px;
        padding: 0 12px;
        border: 1px solid #3b5741;
        border-radius: 9px;
        background: #263b2c;
        color: #f0f5ef;
        font-size: .85rem;
        font-weight: 650;
    }
    .nav-menu-toggle__icon {
        width: 16px;
        height: 12px;
        border-top: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        position: relative;
    }
    .nav-menu-toggle__icon::after {
        content: '';
        position: absolute;
        top: 4px;
        left: 0;
        width: 16px;
        border-top: 2px solid currentColor;
    }
    .navbar .nav-links {
        position: fixed;
        top: 64px;
        right: 0;
        left: 0;
        display: none;
        align-items: stretch;
        flex-direction: column;
        gap: 4px;
        max-height: calc(100dvh - 64px);
        margin: 0;
        padding: 14px 16px 22px;
        border-bottom: 1px solid #405745;
        background: #17221a;
        box-shadow: 0 18px 34px rgba(0, 0, 0, .35);
        overflow-y: auto;
    }
    .navbar .nav-menu-toggle[aria-expanded="true"] + .nav-links { display: flex; }
    .navbar .nav-item { width: 100%; }
    .navbar .nav-link { justify-content: space-between; width: 100%; min-height: 46px; padding: 0 12px; }
    .navbar .dropdown {
        position: static;
        display: none;
        width: 100%;
        max-width: none;
        margin: 4px 0 10px;
        padding: 4px 6px;
        border: 0;
        border-left: 2px solid #557c5a;
        border-radius: 0;
        background: #1f3023;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        pointer-events: auto;
    }
    .navbar .dropdown-toggle[aria-expanded="true"] + .dropdown { display: block; transform: none; }
    .global-footer {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 3px 12px;
        min-height: 62px;
        padding: 8px 16px;
    }
    .footer-center { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; text-align: left; }
    .footer-right { grid-column: 2; grid-row: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .navbar *, .modal-gen *, .global-footer * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
