/* ==========================================================================
   BRAVA CENTRAL OPERACIONAL
   CSS CONSOLIDADO
   --------------------------------------------------------------------------
   - Layout claro / moderno
   - Sidebar compacta
   - Logo sem fundo amarelo
   - Cards de indicadores
   - Mapa Leaflet
   - Pins de clientes por status
   - Marcadores GPS
   - Painel do cliente
   - Responsividade
   ========================================================================== */

:root {
    --yellow: #f2c428;
    --yellow-hover: #e5b817;

    --white: #ffffff;
    --bg: #f4f6f8;
    --border: #e2e6ea;
    --border-strong: #d4d9de;

    --text: #252a2f;
    --text-2: #5f6870;
    --muted: #8a939b;

    --blue: #2f80ed;
    --orange: #f59e0b;
    --red: #e54848;
    --green: #27ae60;
    --gray: #858b90;

    --sidebar-width: 290px;
    --shadow: 0 3px 14px rgba(30, 40, 50, .08);
    --shadow-strong: 0 8px 28px rgba(30, 40, 50, .13);
}

/* ==========================================================================
   BASE
   ========================================================================== */

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: default;
    opacity: .65;
}

/* ==========================================================================
   APLICAÇÃO
   ========================================================================== */

.app {
    width: 100%;
    height: 100vh;
    display: flex;
    background: var(--bg);
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 2000;

    background: var(--white);
    color: var(--text);
    border-right: 1px solid var(--border);
    box-shadow: 1px 0 8px rgba(30, 40, 50, .03);
}

/* ==========================================================================
   MARCA
   ========================================================================== */

.brand {
    height: 82px;
    padding: 17px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;

    border-bottom: 1px solid var(--border);
}

.brand strong {
    display: block;
    color: var(--text);
    font-size: 20px;
    line-height: 1.15;
    letter-spacing: -.2px;
}

.brand span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.2;
}

/*
 * Importante:
 * O container da logo NÃO possui fundo amarelo.
 * O amarelo que eventualmente existir dentro da imagem pertence ao próprio
 * arquivo da logo e não ao CSS.
 */

.brand-mark {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.brand-mark img {
    width: 38px;
    height: 38px;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

/* ==========================================================================
   PESQUISA
   ========================================================================== */

.search {
    height: 44px;
    margin: 14px 16px 10px;
    padding: 0 13px;

    display: flex;
    align-items: center;
    gap: 9px;

    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fafbfc;
}

.search span {
    font-size: 20px;
    color: var(--muted);
}

.search input {
    width: 100%;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    font-size: 13px;
}

.search input::placeholder {
    color: #a1a8ae;
}

/* ==========================================================================
   FILTROS
   ========================================================================== */

.filters {
    padding: 0 16px;
}

.filter-title {
    margin: 8px 0 6px;
    color: var(--muted);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .8px;
}

.date-control {
    height: 38px;
    display: grid;
    grid-template-columns: 38px 1fr 38px;

    overflow: hidden;

    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--white);
}

.date-control button {
    border: 0;
    background: transparent;
    color: var(--text-2);
    font-size: 20px;
}

.date-control button:hover {
    background: var(--bg);
}

.date-control input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-2);
    text-align: center;
    font-size: 12px;
}

.filters select {
    width: 100%;
    height: 38px;
    padding: 0 10px;

    border: 1px solid var(--border);
    border-radius: 8px;
    outline: 0;

    background: var(--white);
    color: var(--text-2);
    font-size: 12px;
}

/* ==========================================================================
   CARDS
   ========================================================================== */

.cards {
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
}

.card {
    min-height: 74px;
    padding: 9px 10px;

    border: 1px solid var(--border);
    border-radius: 10px;

    background: var(--white);
    color: var(--text);

    text-align: left;

    box-shadow: 0 2px 7px rgba(30, 40, 50, .045);

    transition:
        background-color .15s ease,
        border-color .15s ease,
        box-shadow .15s ease,
        transform .15s ease;
}

.card:hover {
    background: #fafbfc;
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.card.active,
.card-principal.active {
    border-color: var(--yellow);
    box-shadow:
        0 0 0 1px var(--yellow),
        0 2px 7px rgba(30, 40, 50, .045);
}

.card strong {
    display: block;
    color: var(--text);
    font-size: 22px;
    line-height: 1;
}

.card span {
    display: block;
    margin-top: 7px;
    color: var(--text-2);
    font-size: 10px;
}

.card[data-filter="agendada"] strong {
    color: var(--blue);
}

.card[data-filter="andamento"] strong {
    color: var(--orange);
}

.card[data-filter="impedida"] strong {
    color: var(--red);
}

.card[data-filter="concluida"] strong {
    color: var(--green);
}

.card-alert {
    grid-column: 1 / -1;
}

.card-alert strong {
    color: var(--red);
}

.active-filter {
    margin: 4px 16px 7px;
    padding: 8px 10px;

    border: 1px solid rgba(242, 196, 40, .28);
    border-radius: 7px;

    background: rgba(242, 196, 40, .10);
    color: #8a6900;
    font-size: 10px;
}

/* ==========================================================================
   LISTA DE CLIENTES
   ========================================================================== */

.client-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 5px;
}

.client-list::-webkit-scrollbar {
    width: 4px;
}

.client-list::-webkit-scrollbar-thumb {
    background: #cfd5da;
    border-radius: 4px;
}

.client-row {
    min-height: 62px;
    margin: 0 10px;
    padding: 9px 10px;

    display: flex;
    align-items: center;
    gap: 10px;

    border-bottom: 1px solid var(--border);

    cursor: pointer;
}

.client-row:hover,
.client-row.active {
    background: var(--bg);
}

.client-status {
    width: 9px;
    height: 9px;
    min-width: 9px;
    border-radius: 50%;
}

.client-status.agendada {
    background: var(--blue);
}

.client-status.andamento {
    background: var(--yellow);
}

.client-status.impedida {
    background: var(--red);
}

.client-status.concluida {
    background: var(--green);
}

.client-status.sem-os {
    background: var(--gray);
}

.client-info {
    min-width: 0;
    flex: 1;
}

.client-info strong {
    display: block;
    color: var(--text);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.client-info span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 10px;
}

.client-count {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;

    display: grid;
    place-items: center;

    border-radius: 11px;
    background: #eef1f3;
    color: var(--text-2);

    font-size: 10px;
    font-weight: 700;
}

/* ==========================================================================
   RODAPÉ / STATUS DA API
   ========================================================================== */

.sidebar-footer {
    height: 42px;
    min-height: 42px;
    padding: 0 16px;

    display: flex;
    align-items: center;
    gap: 7px;

    border-top: 1px solid var(--border);
    background: var(--white);

    color: var(--text-2);
    font-size: 10px;
}

.status-dot {
    width: 7px;
    height: 7px;
    min-width: 7px;
    border-radius: 50%;
    background: var(--green);
}

.last-update {
    margin-left: auto;
    color: var(--muted);
}

/* ==========================================================================
   MAPA
   ========================================================================== */

.map-area {
    position: relative;
    flex: 1;
    height: 100vh;
    min-width: 0;
    background: var(--bg);
}

#map {
    position: absolute;
    inset: 0;
}

.leaflet-control-zoom {
    display: none !important;
}

.leaflet-control-attribution {
    color: #7c858d;
    font-size: 8px;
    opacity: .7;
}

/* ==========================================================================
   TOPO DO MAPA
   ========================================================================== */

.map-top {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 1000;

    display: flex;
    justify-content: space-between;
    align-items: center;

    pointer-events: none;
}

.map-title,
.refresh {
    pointer-events: auto;
}

.map-title {
    padding: 10px 13px;

    border: 1px solid rgba(0, 0, 0, .06);
    border-radius: 10px;

    background: rgba(255, 255, 255, .95);
    box-shadow: var(--shadow);

    backdrop-filter: blur(8px);
}

.map-title strong {
    display: block;
    color: var(--text);
    font-size: 13px;
}

.map-title span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 10px;
}

/* ==========================================================================
   BOTÃO ATUALIZAR
   ========================================================================== */

.refresh {
    height: 38px;
    min-width: 92px;
    padding: 0 15px;

    border: 1px solid var(--border);
    border-radius: 8px;

    background: var(--white);
    color: var(--text-2);

    box-shadow: var(--shadow);

    font-size: 12px;
    font-weight: 600;

    transition:
        background-color .15s ease,
        border-color .15s ease,
        color .15s ease,
        box-shadow .15s ease;
}

.refresh:hover:not(:disabled) {
    background: var(--yellow);
    border-color: var(--yellow);
    color: #202326;
    box-shadow: 0 4px 12px rgba(242, 196, 40, .20);
}

.refresh:disabled {
    background: #f4f5f6;
    color: var(--muted);
}

/* ==========================================================================
   CONTROLES DO MAPA
   ========================================================================== */

.map-controls {
    position: absolute;
    top: 70px;
    right: 16px;
    z-index: 1000;

    display: flex;
    flex-direction: column;
    gap: 7px;
}

.map-controls button {
    width: 42px;
    height: 42px;

    border: 1px solid rgba(0, 0, 0, .07);
    border-radius: 8px;

    background: rgba(255, 255, 255, .95);
    color: var(--text-2);

    font-size: 19px;

    box-shadow: var(--shadow);
}

.map-controls button:hover {
    background: var(--yellow);
    border-color: var(--yellow);
    color: #222;
}

/* ==========================================================================
   LEGENDA
   ========================================================================== */

.legend {
    position: absolute;
    left: 16px;
    bottom: 16px;
    z-index: 1000;

    padding: 9px 12px;

    display: flex;
    gap: 13px;

    border: 1px solid rgba(0, 0, 0, .06);
    border-radius: 10px;

    background: rgba(255, 255, 255, .95);
    box-shadow: var(--shadow);

    backdrop-filter: blur(8px);

    font-size: 10px;
}

.legend span {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-2);
}

.legend i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.legend .blue {
    background: var(--blue);
}

.legend .orange {
    background: var(--orange);
}

.legend .red {
    background: var(--red);
}

.legend .green {
    background: var(--green);
}

.legend .gray {
    background: var(--gray);
}

/* ==========================================================================
   MARCADORES DE CLIENTES
   ========================================================================== */

.brava-cliente-marker {
    background: transparent !important;
    border: 0 !important;
}

.cliente-pin {
    position: relative;
    width: 46px;
    height: 58px;

    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.cliente-pin-corpo {
    position: relative;

    width: 38px;
    height: 38px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 3px solid var(--white);
    border-radius: 50% 50% 50% 0;

    background: var(--blue);
    box-shadow: 0 3px 8px rgba(0, 0, 0, .20);

    transform: rotate(-45deg);

    transition: background-color .15s ease;
}

.cliente-status-icone {
    display: flex;
    align-items: center;
    justify-content: center;

    transform: rotate(45deg);

    color: var(--white);
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
}

.marker-badge {
    position: absolute;
    top: 0;
    right: 0;

    min-width: 23px;
    height: 23px;
    padding: 0 5px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 2px solid var(--white);
    border-radius: 50%;

    color: var(--white);

    font-size: 11px;
    font-weight: 800;
    line-height: 1;

    z-index: 10;

    box-shadow: 0 2px 5px rgba(0, 0, 0, .14);

    transition: background-color .15s ease;
}

/* ==========================================================================
   CORES DOS PINS / BADGES
   ========================================================================== */

.cliente-pin.agendada .cliente-pin-corpo,
.marker-badge.agendada {
    background: var(--blue);
}

.cliente-pin.andamento .cliente-pin-corpo,
.marker-badge.andamento {
    background: var(--orange);
}

.cliente-pin.andamento .cliente-status-icone {
    color: #071f31;
}

.cliente-pin.impedida .cliente-pin-corpo,
.marker-badge.impedida {
    background: var(--red);
}

.cliente-pin.concluida .cliente-pin-corpo,
.marker-badge.concluida {
    background: var(--green);
}

.marker-badge.sem-os {
    background: var(--gray);
}

/* ==========================================================================
   CLIENTE SEM OS
   ========================================================================== */

.cliente-sem-os {
    width: 14px;
    height: 14px;

    display: flex;
    align-items: center;
    justify-content: center;
}

.cliente-sem-os span {
    width: 9px;
    height: 9px;

    border: 2px solid var(--white);
    border-radius: 50%;

    background: var(--gray);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

/* ==========================================================================
   VEÍCULOS GPS
   ========================================================================== */

.veiculo-gps-marker {
    width: 120px !important;
    height: 90px !important;

    background: transparent !important;
    border: 0 !important;
}

.veiculo-gps-wrapper {
    position: relative;

    width: 120px;
    height: 90px;

    display: flex;
    flex-direction: column;
    align-items: center;

    pointer-events: none;
}

.veiculo-gps-nome {
    position: relative;
    z-index: 10;

    max-width: 110px;
    padding: 3px 7px;
    margin-bottom: 2px;

    border: 1px solid rgba(0, 0, 0, .07);
    border-radius: 5px;

    background: rgba(255, 255, 255, .97);
    color: var(--text);

    font-size: 10px;
    font-weight: 600;
    line-height: 14px;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    box-shadow: 0 1px 5px rgba(0, 0, 0, .14);
}

.veiculo-gps-imagem {
    display: block !important;

    width: 19px !important;
    height: auto !important;

    max-width: 19px !important;
    max-height: 37px !important;

    object-fit: contain;
    transform-origin: center center;

    transition: transform .3s ease;
}

/* Marcador GPS legado, caso algum JS ainda utilize */
.veiculo-gps {
    width: 32px;
    height: 32px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 2px solid var(--white);
    border-radius: 50%;

    background: rgba(255, 255, 255, .96);

    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.veiculo-gps.movimento {
    border-color: var(--green);
}

.veiculo-gps.parado {
    border-color: var(--blue);
}

.veiculo-gps.offline {
    border-color: var(--gray);
    opacity: .75;
}

.veiculo-svg {
    font-size: 20px;
    line-height: 1;
}

/* ==========================================================================
   POPUP GPS
   ========================================================================== */

.gps-popup {
    min-width: 170px;
    color: var(--text-2);
    font-size: 11px;
    line-height: 1.6;
}

.gps-popup > strong,
.gps-popup strong {
    display: block;
    color: var(--text);
    font-size: 13px;
}

/* ==========================================================================
   PAINEL DO CLIENTE
   ========================================================================== */

.client-panel {
    position: absolute;

    top: 18px;
    right: 78px;
    bottom: 18px;

    width: 350px;
    z-index: 1500;

    padding: 22px;

    border: 1px solid var(--border);
    border-radius: 12px;

    background: rgba(255, 255, 255, .98);
    box-shadow: var(--shadow-strong);

    overflow-y: auto;

    transform: translateX(calc(100% + 30px));
    transition: transform .2s ease;
}

.client-panel.open {
    transform: translateX(0);
}

.panel-close {
    position: absolute;
    top: 10px;
    right: 10px;

    width: 30px;
    height: 30px;

    border: 0;
    border-radius: 50%;

    background: #eef1f3;
    color: var(--text-2);

    font-size: 20px;
}

.panel-close:hover {
    background: #e3e7ea;
}

.panel-name {
    padding-right: 30px;

    color: var(--text);
    font-size: 17px;
    line-height: 1.25;
}

.panel-address {
    margin-top: 8px;

    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

.panel-summary {
    margin-top: 16px;
    padding: 12px;

    display: flex;
    justify-content: space-between;

    border: 1px solid var(--border);
    border-radius: 8px;

    background: var(--bg);
}

.panel-summary strong {
    display: block;
    color: var(--text);
    font-size: 20px;
}

.panel-summary span {
    color: var(--muted);
    font-size: 9px;
}

.os-title {
    margin-top: 18px;

    color: var(--muted);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .8px;
}

/* ==========================================================================
   CARDS DE OS
   ========================================================================== */

.os-card {
    margin-top: 8px;
    padding: 12px;

    border: 1px solid var(--border);
    border-radius: 8px;

    background: var(--white);
    box-shadow: 0 2px 7px rgba(30, 40, 50, .04);
}

.os-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.os-time {
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.os-status {
    padding: 3px 7px;

    border-radius: 8px;

    color: var(--white);

    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
}

.os-status.agendada {
    background: var(--blue);
}

.os-status.andamento {
    background: var(--orange);
    color: #333;
}

.os-status.impedida {
    background: var(--red);
}

.os-status.concluida {
    background: var(--green);
}

.os-type {
    margin-top: 8px;

    color: var(--text);
    font-size: 11px;
    font-weight: 700;
}

.os-description {
    margin-top: 5px;

    color: var(--text-2);
    font-size: 10px;
    line-height: 1.45;
}

.os-tech {
    margin-top: 8px;

    color: var(--muted);
    font-size: 9px;
}

.empty {
    padding: 20px 15px;

    text-align: center;

    color: var(--muted);
    font-size: 11px;
}

/* ==========================================================================
   LEAFLET / POPUPS
   ========================================================================== */

.leaflet-popup-content-wrapper {
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.leaflet-popup-content {
    color: var(--text-2);
}

/* ==========================================================================
   RESPONSIVIDADE
   ========================================================================== */

@media (max-width: 1100px) {

    :root {
        --sidebar-width: 270px;
    }

    .sidebar {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
    }

    .client-panel {
        width: 340px;
    }
}

@media (max-width: 900px) {

    :root {
        --sidebar-width: 320px;
    }

    .sidebar {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
    }

    .client-panel {
        width: 320px;
        right: 15px;
    }
}

@media (max-width: 650px) {

    .sidebar {
        width: 100%;
        min-width: 0;
        max-width: 100%;

        height: 43vh;

        position: absolute;
        bottom: 0;
        left: 0;

        z-index: 3000;
    }

    .brand {
        height: 55px;
        padding: 8px 14px;
    }

    .brand-mark {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
    }

    .brand-mark img {
        width: 32px;
        height: 32px;
    }

    .brand strong {
        font-size: 16px;
    }

    .brand span {
        font-size: 9px;
    }

    .search,
    .filters,
    .cards,
    .client-list {
        display: none;
    }

    .sidebar-footer {
        display: none;
    }

    .map-area {
        width: 100%;
        height: 100vh;
    }

    .client-panel {
        top: 15px;
        right: 15px;
        bottom: auto;

        width: calc(100% - 30px);
        max-height: 70vh;
    }

    .legend {
        display: none;
    }

    .map-top {
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .map-title {
        max-width: calc(100% - 110px);
    }

    .refresh {
        min-width: 86px;
        padding: 0 11px;
    }

    .map-controls {
        top: 70px;
        right: 10px;
    }
}

/* Clientes com contrato: o contador continua indicando o status da OS. */
.legend .purple,
.cliente-pin.com-contrato .cliente-pin-corpo,
.cliente-sem-os.com-contrato span {
    background: #7c3aed;
}

.cliente-pin.com-contrato .cliente-status-icone {
    color: #fff;
}

.popup-contrato {
    display: inline-block;
    margin: 6px 0;
    padding: 3px 8px;
    border-radius: 6px;
    background: #ede9fe;
    color: #5b21b6;
    font-weight: 700;
    font-size: 12px;
}

/* Identificação visual dos clientes com contrato. */
.cliente-contrato-selo {
    display: block;
    width: 22px;
    height: 22px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}

.cliente-pin > .cliente-contrato-selo {
    position: absolute;
    top: 0;
    left: -3px;
    z-index: 11;
}

.cliente-sem-os.com-contrato {
    width: 26px;
    height: 26px;
}

.legend .contrato-legenda {
    width: 18px;
    height: 18px;
    object-fit: contain;
    border-radius: 4px;
}
