:root {
    --brasil-verde: #009b3a;
    --brasil-amarelo: #ffd900;
    --brasil-azul: #002776;
    --brasil-branco: #ffffff;
    --texto-principal: #f8fafc;
    --texto-secundario: #94a3b8;
    --fundo-claro: #0f172a;
    --borda: rgba(255, 255, 255, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--texto-principal);
    background: var(--fundo-claro);
    min-height: 100vh;
    overflow-x: hidden;

    /* Previne seleção de texto no body como proteção básica */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Permite selecionar texto nos campos Editáveis/Inputs */
input,
textarea,
select {
    -webkit-user-select: auto;
    -moz-user-select: auto;
    -ms-user-select: auto;
    user-select: auto;
}

/* Animated Background Shapes */
.bg-shape {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    z-index: 0;
    animation: float 20s infinite ease-in-out alternate;
    pointer-events: none;
}

.shape1 {
    width: 400px;
    height: 400px;
    background: rgba(0, 155, 58, 0.25);
    top: -100px;
    left: -100px;
    animation-delay: 0s;
}

.shape2 {
    width: 500px;
    height: 500px;
    background: rgba(0, 39, 118, 0.4);
    bottom: -150px;
    right: -100px;
    animation-delay: -5s;
}

.shape3 {
    width: 300px;
    height: 300px;
    background: rgba(255, 217, 0, 0.15);
    top: 50%;
    left: 20%;
    transform: translate(-50%, -50%);
    animation-delay: -10s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(50px, 50px) scale(1.1);
    }
}

.app-layout {
    min-height: 100vh;
    display: flex;
    position: relative;
    z-index: 1;
}

.sidebar {
    width: 260px;
    background: rgba(0, 155, 58, 0.15);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--brasil-branco);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    z-index: 2;
}

.brand-title {
    font-size: 1.4rem;
    font-weight: 800;
}

.brand-subtitle {
    color: var(--brasil-amarelo);
    margin-top: 0.25rem;
}

.menu-nav {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.menu-item {
    display: flex;
    align-items: center;
    min-height: 44px;
    text-decoration: none;
    color: var(--brasil-branco);
    background: rgba(255, 255, 255, 0.14);
    padding: 0.72rem 0.85rem;
    border-radius: 8px;
    font-weight: 700;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.24);
}

.menu-item.active {
    background: var(--brasil-amarelo);
    color: var(--brasil-azul);
}

.menu-exit {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    margin-top: auto;
    text-decoration: none;
    text-align: center;
    background: var(--brasil-azul);
    color: var(--brasil-branco);
    border-radius: 8px;
    padding: 0.75rem 0.85rem;
    font-weight: 700;
    transition: filter 0.2s ease;
}

.menu-exit:hover {
    filter: brightness(1.08);
}

.main-content {
    flex: 1;
    height: 100vh;
    padding: 1.25rem;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header h4 {
    color: var(--brasil-amarelo);
    margin-bottom: 0.35rem;
    font-weight: 800;
}

.menu-toggle {
    display: none;
    margin-bottom: 0.75rem;
    border: none;
    border-radius: 8px;
    padding: 0.65rem 0.9rem;
    font-weight: 700;
    color: var(--brasil-branco);
    background: var(--brasil-azul);
    cursor: pointer;
}

.main-header p {
    color: var(--texto-secundario);
}

.content-card {
    margin-top: 1rem;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 6px solid var(--brasil-amarelo);
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.content-card h3 {
    margin-bottom: 0.85rem;
    color: var(--brasil-amarelo);
}

.filtros-form {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.filtros-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.55rem 0.7rem;
}

.filtros-grid label {
    display: block;
    margin-bottom: 0.2rem;
    font-weight: 700;
    color: var(--texto-secundario);
    font-size: 0.82rem;
}

.filtros-grid input,
.filtros-grid select {
    width: 100%;
    min-width: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 0.7rem 1rem;
    background: rgba(255, 255, 255, 0.04);
    color: #ffffff;
    font-size: 1.05rem;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.filtros-grid input:focus,
.filtros-grid select:focus {
    border-color: var(--brasil-amarelo);
    outline: none;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px rgba(255, 217, 0, 0.15), inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.filtros-grid select option {
    background: #0f172a;
    color: #ffffff;
}

.autocomplete-sugestoes {
    position: absolute;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 220px;
    overflow-y: auto;
    z-index: 1000;
    width: 100%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    border-radius: 10px;
    margin-top: 2px;
    animation: fadeIn 0.25s;
}

.autocomplete-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 1.05rem;
    color: var(--texto-principal);
    background: transparent;
    transition: background 0.18s, color 0.18s;
}

.autocomplete-item:hover {
    background: rgba(255, 217, 0, 0.15);
    color: var(--brasil-amarelo);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


.filtros-acoes {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn-primario,
.btn-secundario {
    border: none;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.85rem;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primario {
    color: var(--brasil-branco);
    background: linear-gradient(135deg, var(--brasil-verde), var(--brasil-azul));
    box-shadow: 0 4px 12px rgba(0, 39, 118, 0.4);
}

.btn-primario:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 39, 118, 0.5);
}

.btn-secundario {
    color: #0f172a;
    background: linear-gradient(135deg, var(--brasil-amarelo), #fde047);
    box-shadow: 0 4px 12px rgba(255, 217, 0, 0.2);
}

.btn-secundario:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 217, 0, 0.3);
}

.table-wrap {
    width: 100%;
    overflow: auto;
    flex: 1;
    min-height: 0;
}

.table-wrap-pedidos {
    height: clamp(220px, 36vh, 420px);
    min-height: 220px;
    max-height: 420px;
}

.resumo-table {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
    border-collapse: collapse;
    margin-top: 0.35rem;
}

.table-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
}

.resumo-table th,
.resumo-table td {
    border: 2px solid rgba(255, 255, 255, 0.4);
    padding: 0.45rem 0.42rem;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
}

.resumo-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(0, 39, 118, 0.85);
    backdrop-filter: blur(12px);
    color: var(--brasil-branco);
    font-size: 0.85rem;
    padding: 0.6rem 0.5rem;
    border-color: rgba(255, 255, 255, 0.4);
}

.resumo-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.resumo-table th.sortable::after {
    content: ' ⇅';
    font-size: 0.75rem;
    opacity: 0.6;
}

.resumo-table th.sortable[data-order="asc"]::after {
    content: ' ↑';
    opacity: 1;
}

.resumo-table th.sortable[data-order="desc"]::after {
    content: ' ↓';
    opacity: 1;
}

.resumo-table td {
    font-size: 0.8rem;
}

.resumo-table tbody tr.resumo-clickable {
    cursor: pointer;
}

.resumo-table tbody tr.resumo-clickable:hover td {
    outline: 1px solid rgba(0, 39, 118, 0.35);
    outline-offset: -1px;
}

.resumo-table tbody tr.resumo-selected td {
    box-shadow: inset 0 0 0 2px rgba(0, 39, 118, 0.55);
}

.resumo-table tbody tr:nth-child(even):not(.row-selecionar-s):not(.row-selecionar-a):not(.row-selecionar-v):not(.row-selecionar-p) td {
    background: rgba(255, 255, 255, 0.02);
}

.resumo-table td.filial-color-cell {
    background: var(--filial-bg) !important;
    color: var(--filial-fg) !important;
    font-weight: 700;
}

.resumo-table tbody tr.row-selecionar-s td {
    background: #2563eb;
    color: #ffffff;
}

.resumo-table tbody tr.row-selecionar-a td {
    background: #facc15;
    color: #1d4ed8;
}

.resumo-table tbody tr.row-selecionar-v td {
    background: #dc2626;
    color: #fef08a;
}

.resumo-table tbody tr.row-selecionar-p td {
    background: #111827;
    color: #ffffff;
}

.resumo-table td.cell-risco-alto {
    background: #dc2626 !important;
    color: #ffffff !important;
}

.resumo-table td.cell-risco-alto-texto-escuro {
    background: #dc2626 !important;
    color: #111827 !important;
}

.resumo-table td.cell-risco-medio {
    background: #facc15 !important;
    color: #1e3a8a !important;
}

.resumo-table td.cell-risco-baixo {
    background: #16a34a !important;
    color: #fef08a !important;
}

.resumo-table td.cell-info {
    background: #7dd3fc !important;
    color: #0f172a !important;
}

.resumo-table td.cell-neutro {
    background: #a3a3a3 !important;
    color: #111827 !important;
}

.resumo-table td.cell-prod-gasolina-comum {
    background: #f3c50c !important;
    color: #111827 !important;
}

.resumo-table td.cell-prod-s10 {
    background: #afafaf !important;
    color: #111827 !important;
}

.resumo-table td.cell-prod-s500 {
    background: #dc2626 !important;
    color: #ffffff !important;
}

.resumo-table td.cell-prod-s500-adt {
    background: #16a34a !important;
    color: #ffffff !important;
}

.resumo-table td.cell-prod-etanol {
    background: #84cc16 !important;
    color: #111827 !important;
}

.resumo-table td.cell-prod-gasolina-aditivada {
    background: #38bdf8 !important;
    color: #111827 !important;
}

.sem-dados {
    text-align: center;
    color: var(--texto-secundario);
}

.pedidos-info {
    margin: 0.25rem 0 0.6rem;
    color: var(--texto-secundario);
    font-weight: 700;
    font-size: 0.9rem;
}

.modal-pedidos {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
}

.modal-pedidos.is-open {
    display: block;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    margin: 2.5vh auto;
    width: min(96vw, 1400px);
    height: min(94vh, 400px);
    max-height: 400px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--texto-principal);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.modal-header h3 {
    color: var(--brasil-amarelo);
}

.modal-close {
    border: none;
    border-radius: 8px;
    padding: 0.45rem 0.7rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--brasil-branco);
    background: var(--brasil-azul);
}

.modal-content .table-wrap {
    height: auto;
    min-height: 0;
    max-height: none;
    flex: 1;
}

#pedidosTable tbody tr:nth-child(even):not(.pedido-row-obs):not(.pedido-row-s):not(.pedido-row-g):not(.pedido-row-y):not(.pedido-row-r) td {
    background: rgba(255, 255, 255, 0.05);
}

#pedidosTable tbody tr.pedido-row-obs td {
    background: #facc15;
    color: #111827;
}

#pedidosTable tbody tr.pedido-row-s td {
    background: #2563eb;
    color: #ffffff;
}

#pedidosTable tbody tr.pedido-row-g td {
    background: #84cc16;
    color: #111827;
}

#pedidosTable tbody tr.pedido-row-y td {
    background: #facc15;
    color: #111827;
}

#pedidosTable tbody tr.pedido-row-r td {
    background: #dc2626;
    color: #ffffff;
}

#pedidosTable td.cell-status-a-carregar {
    background: #dc2626 !important;
    color: #ffffff !important;
}

#pedidosTable td.cell-status-cancelado {
    background: #ff8000 !important;
    color: #111827 !important;
}

#pedidosTable td.cell-status-em-movimento {
    background: #facc15 !important;
    color: #1d4ed8 !important;
}

#pedidosTable td.cell-status-confirmado {
    background: #16a34a !important;
    color: #fef08a !important;
}

@media (max-width: 900px) {
    .app-layout {
        flex-direction: column;
    }

    .sidebar {
        width: min(82vw, 320px);
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        border-bottom: 6px solid var(--brasil-amarelo);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        padding: 1rem 0.9rem 0.9rem;
        gap: 0.8rem;
    }

    .app-layout.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 0.75rem;
        right: 0.75rem;
        left: auto;
        z-index: 1100;
    }

    .main-content {
        height: auto;
        padding-top: 4.25rem;
        overflow: visible;
    }

    .menu-nav {
        flex-direction: column;
        gap: 0.5rem;
    }

    .menu-item,
    .menu-exit {
        width: 100%;
        min-height: 46px;
        border-radius: 10px;
    }

    .filtros-grid {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .filtros-grid input,
    .filtros-grid select {
        width: 100%;
    }

    .filtros-acoes {
        justify-content: flex-start;
    }

    .table-card {
        flex: initial;
        min-height: auto;
        overflow: visible;
    }

    .table-wrap {
        height: 55vh;
        min-height: 260px;
        max-height: none;
        overflow-x: auto;
        overflow-y: auto;
    }

    .resumo-table {
        min-width: 980px;
        width: 980px;
    }

    .table-wrap-pedidos {
        height: 42vh;
        min-height: 220px;
    }

    .modal-content {
        margin: 1.5vh auto;
        width: 98vw;
        height: min(96vh, 400px);
        max-height: 400px;
        padding: 0.75rem;
        border-radius: 10px;
    }

    .resumo-table.resumo-table-fixar-filial th:first-child {
        left: 0;
        z-index: 5;
    }

    .resumo-table.resumo-table-fixar-filial td:first-child {
        position: sticky;
        left: 0;
        z-index: 3;
        white-space: nowrap;
        box-shadow: 2px 0 0 rgba(15, 23, 42, 0.12);
    }
}

@media (max-width: 560px) {
    .filtros-grid {
        grid-template-columns: 1fr;
    }
}