/* ==========================================================================
   Controle de Fretes - Cara da Riqueza Beauty
   Paleta: roxo sofisticado + rosa, grafite, fundo branco/cinza claro.
   ========================================================================== */
:root {
    --bg: #F7F6F9;
    --card: #FFFFFF;
    --ink: #23212B;
    --muted: #6F6B7A;
    --muted-2: #9A95A6;
    --line: #EAE6EE;
    --line-2: #F1EEF4;
    --roxo: #7B2D6E;
    --roxo-esc: #5E2154;
    --roxo-soft: #F6EBF3;
    --rosa: #D6336C;
    --rosa-soft: #FDEDF2;
    --grafite: #241B2B;
    --ok: #0F7B57;
    --ok-soft: #E8F6EF;
    --neg: #C2263B;
    --neg-soft: #FDECEF;
    --sombra: 0 1px 2px rgba(35, 33, 43, .04), 0 8px 24px rgba(35, 33, 43, .05);
    --sombra-alta: 0 12px 32px rgba(35, 33, 43, .12);
    --raio: 14px;
    --raio-sm: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--roxo); text-decoration: none; }
a:hover { color: var(--rosa); }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

.ico {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.ico.mini { width: 15px; height: 15px; opacity: .55; }

/* ---------------------------------------------------------------- Layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 248px;
    flex: 0 0 248px;
    background: linear-gradient(180deg, #2E2135 0%, #1C1622 100%);
    color: #CFC7D6;
    display: flex;
    flex-direction: column;
    padding: 20px 14px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }

.brand-mark {
    width: 38px; height: 38px;
    flex: 0 0 38px;
    border-radius: 11px;
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px; letter-spacing: .5px;
    color: #fff;
    background: linear-gradient(135deg, var(--rosa), #8E3BA6);
    box-shadow: 0 6px 16px rgba(214, 51, 108, .32);
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.25; }
.brand-txt strong { color: #fff; font-size: 14.5px; font-weight: 650; }
.brand-txt small { color: #A79BB0; font-size: 11.5px; letter-spacing: .2px; }

.nav { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; padding-bottom: 8px; }

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #C6BCCD;
    font-size: 13.8px;
    position: relative;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.ativo { background: rgba(255, 255, 255, .10); color: #fff; font-weight: 600; }
.nav-item.ativo::before {
    content: "";
    position: absolute; left: 0; top: 9px; bottom: 9px;
    width: 3px; border-radius: 3px;
    background: linear-gradient(180deg, var(--rosa), #B44CA8);
}
.nav-item .ico { opacity: .85; }

.nav-cta {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin: 6px 0 12px;
    padding: 11px 12px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--rosa), #A93C97);
    color: #fff;
    font-weight: 650;
    font-size: 13.8px;
    box-shadow: 0 8px 20px rgba(214, 51, 108, .28);
}
.nav-cta:hover { color: #fff; filter: brightness(1.05); }

.sidebar-foot {
    margin-top: auto;
    display: flex; flex-direction: column; gap: 8px;
    padding: 14px 10px 4px;
    border-top: 1px solid rgba(255, 255, 255, .08);
    font-size: 11.5px; color: #8E8497;
}
.sidebar-foot .sair { display: flex; align-items: center; gap: 7px; color: #C6BCCD; font-size: 13px; }
.sidebar-foot .sair:hover { color: #fff; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 16px 28px;
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 30;
}
.topbar-title h1 { font-size: 19px; }
.topbar-sub { margin: 1px 0 0; font-size: 12.5px; color: var(--muted-2); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.menu-btn {
    display: none;
    background: #fff; border: 1px solid var(--line);
    border-radius: 10px; padding: 8px; color: var(--ink); cursor: pointer;
}

.conteudo { padding: 24px 28px 56px; max-width: 1400px; width: 100%; }

/* ---------------------------------------------------------------- Botões */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 15px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-size: 13.8px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.btn:hover { border-color: #D9D1E0; color: var(--ink); background: #FCFBFD; }
.btn.primario {
    background: linear-gradient(135deg, var(--roxo), #9A3585);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 6px 16px rgba(123, 45, 110, .22);
}
.btn.primario:hover { color: #fff; filter: brightness(1.06); }
.btn.rosa { background: linear-gradient(135deg, var(--rosa), #B03A8F); border-color: transparent; color: #fff; }
.btn.rosa:hover { color: #fff; filter: brightness(1.05); }
.btn.perigo { color: var(--neg); border-color: #F3CBD2; background: #fff; }
.btn.perigo:hover { background: var(--neg-soft); color: var(--neg); }
.btn.pequeno { padding: 7px 11px; font-size: 12.8px; border-radius: 9px; }
.btn.bloco { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------------------------------------------------------------- Cards */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--raio);
    box-shadow: var(--sombra);
}

.grade { display: grid; gap: 14px; }
.grade.metricas { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grade.duas { grid-template-columns: 1fr 1fr; }
.grade.tres { grid-template-columns: repeat(3, 1fr); }
.mb { margin-bottom: 16px; }
.mt { margin-top: 16px; }

.metrica { padding: 16px 18px; position: relative; overflow: hidden; }
.metrica-top {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font-size: 12.3px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600;
}
.metrica-valor { margin-top: 7px; font-size: 23px; font-weight: 700; letter-spacing: -.02em; }
.metrica-sub { margin-top: 3px; font-size: 12.3px; color: var(--muted-2); }
.tom-pos .metrica-valor { color: var(--ok); }
.tom-neg .metrica-valor { color: var(--neg); }
.tom-roxo .metrica-valor { color: var(--roxo); }
.metrica.destaque { background: linear-gradient(135deg, #fff 0%, #FDF7FB 100%); }

/* ---------------------------------------------------------------- Filtro */
.filtro { padding: 12px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.filtro-form { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; margin: 0; }
.campo-inline { display: flex; flex-direction: column; gap: 3px; }
.campo-inline span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 600; }
.campo-inline select, .campo-inline input {
    padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px;
    background: #fff; color: var(--ink); font-family: inherit; min-width: 92px;
}
.filtro-atalhos { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.pill {
    padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line);
    font-size: 12.3px; color: var(--muted); background: #fff; font-weight: 600;
}
.pill:hover { border-color: #DCD3E3; color: var(--roxo); }
.pill.on { background: var(--roxo-soft); border-color: #E4CFDD; color: var(--roxo); }
.filtro-resumo {
    display: flex; align-items: center; gap: 7px;
    font-size: 12.8px; color: var(--muted); font-weight: 600;
    padding-left: 14px; border-left: 1px solid var(--line);
}

/* ---------------------------------------------------------------- Tabelas */
.tabela-wrap { overflow-x: auto; border-radius: var(--raio); }
.tabela { width: 100%; border-collapse: collapse; font-size: 13.6px; }
.tabela thead th {
    text-align: left; padding: 11px 14px;
    background: #FAF8FB; color: var(--muted);
    font-size: 11.6px; text-transform: uppercase; letter-spacing: .045em; font-weight: 650;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.tabela tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tabela tbody tr:last-child td { border-bottom: none; }
.tabela tbody tr:hover { background: #FCFAFD; }
.tabela .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabela .total td { background: #FAF7FB; font-weight: 700; border-top: 1px solid var(--line); }
.tabela .total td.num { color: var(--ink); }
.tabela a.linha-link { font-weight: 600; }
.tabela .vazio-linha td { text-align: center; color: var(--muted-2); padding: 26px 14px; }
.tabela.compacta tbody td { padding: 8px 12px; }

.dif { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dif.pos { color: var(--ok); }
.dif.neg { color: var(--neg); }
.dif.zero { color: var(--muted-2); }

.badge {
    display: inline-block; padding: 3px 9px; border-radius: 999px;
    font-size: 11.6px; font-weight: 650; background: var(--line-2); color: var(--muted);
    white-space: nowrap;
}
.badge.roxo { background: var(--roxo-soft); color: var(--roxo); }
.badge.rosa { background: var(--rosa-soft); color: var(--rosa); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.neg { background: var(--neg-soft); color: var(--neg); }

.tag-plat { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--roxo); display: inline-block; }

/* ---------------------------------------------------------------- Formulários */
.form { padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.campo { display: flex; flex-direction: column; gap: 5px; }
.campo.full { grid-column: 1 / -1; }
.campo label { font-size: 12.6px; font-weight: 650; color: #4A4553; }
.campo label .req { color: var(--rosa); }
.campo .dica { font-size: 11.6px; color: var(--muted-2); }
.campo input, .campo select, .campo textarea {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    background: #fff;
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
.campo input:focus, .campo select:focus, .campo textarea:focus {
    outline: none; border-color: #C9A6C6; box-shadow: 0 0 0 3px rgba(123, 45, 110, .10);
}
.campo input.moeda { font-variant-numeric: tabular-nums; font-weight: 600; }
.campo textarea { resize: vertical; min-height: 74px; }
.campo.com-erro input, .campo.com-erro select { border-color: #E9A9B4; background: #FFF9FA; }
.form-acoes { display: flex; gap: 10px; align-items: center; margin-top: 18px; flex-wrap: wrap; }

/* Cálculo automático */
.calculo {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
    padding: 14px 16px; margin-top: 4px;
    border-radius: 12px;
    background: linear-gradient(135deg, #FBF7FC, #FDF8FA);
    border: 1px dashed #E6D3E4;
}
.calculo .rot { font-size: 11.4px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 650; }
.calculo .val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.calculo .val.pos { color: var(--ok); }
.calculo .val.neg { color: var(--neg); }
.calculo .val.zero { color: var(--muted); }
.calculo .avisos { grid-column: 1 / -1; font-size: 12.3px; color: var(--muted); }

/* ---------------------------------------------------------------- Alertas */
.alert {
    padding: 12px 15px; border-radius: 11px; font-size: 13.6px; margin-bottom: 16px;
    border: 1px solid transparent; display: flex; gap: 9px; align-items: flex-start;
}
.alert.ok { background: var(--ok-soft); border-color: #CFEDE0; color: #0B5E43; }
.alert.erro { background: var(--neg-soft); border-color: #F6CDD4; color: #8E1B2A; }
.alert.aviso { background: #FFF7E8; border-color: #F5E0B8; color: #7A5410; }

.vazio { padding: 44px 24px; text-align: center; color: var(--muted); }
.vazio p { margin: 0 0 14px; }

/* ---------------------------------------------------------------- Gráficos */
.chart-card { padding: 16px 18px 18px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.chart-head h3 { font-size: 14.2px; }
.chart-head small { color: var(--muted-2); font-size: 11.8px; }
.chart-box { width: 100%; height: 240px; }
.chart-box.alto { height: 300px; }
.chart-box svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-vazio { display: grid; place-items: center; height: 100%; color: var(--muted-2); font-size: 13px; }

/* ---------------------------------------------------------------- Paginação */
.paginacao { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); }
.paginacao .info { margin-right: auto; font-size: 12.6px; color: var(--muted); }
.pag-btn {
    min-width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
    padding: 0 9px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
    font-size: 13px; color: var(--muted); font-weight: 600;
}
.pag-btn.on { background: var(--roxo); border-color: var(--roxo); color: #fff; }
.pag-btn.disabled { opacity: .45; pointer-events: none; }

/* ---------------------------------------------------------------- Detalhes */
.dl { display: grid; grid-template-columns: 190px 1fr; gap: 0; font-size: 13.8px; }
.dl dt { padding: 9px 0; color: var(--muted); border-bottom: 1px solid var(--line-2); }
.dl dd { padding: 9px 0; margin: 0; border-bottom: 1px solid var(--line-2); font-weight: 600; }

.secao-titulo {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin: 26px 0 12px; flex-wrap: wrap;
}
.secao-titulo h2 { font-size: 16px; }
.secao-titulo .acoes { display: flex; gap: 8px; flex-wrap: wrap; }
.subtitulo { font-size: 12.5px; color: var(--muted); margin: 2px 0 0; }

/* cabecalho de card: titulo a esquerda, legenda a direita, quebrando quando falta espaco */
.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 2px 16px;
    padding: 15px 16px 0;
    margin-bottom: 12px;
}
.card-head h2 { font-size: 17px; min-width: 0; }
.card-head .subtitulo { margin: 0; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }

@media (max-width: 720px) {
    .card-head { flex-direction: column; align-items: flex-start; gap: 2px; }
}

.migalha { font-size: 12.8px; color: var(--muted-2); margin-bottom: 10px; }
.migalha a { color: var(--muted); }

/* ---------------------------------------------------------------- Login */
.tela-login {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background:
        radial-gradient(circle at 15% 15%, rgba(214, 51, 108, .10), transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(123, 45, 110, .12), transparent 45%),
        var(--bg);
}
.login-card {
    width: 100%; max-width: 400px; background: #fff; border-radius: 18px;
    box-shadow: var(--sombra-alta); border: 1px solid var(--line); overflow: hidden;
}
.login-top {
    padding: 28px 28px 22px; text-align: center;
    background: linear-gradient(160deg, #2E2135, #1D1623); color: #fff;
}
.login-top .brand-mark { margin: 0 auto 12px; width: 46px; height: 46px; border-radius: 13px; font-size: 15px; }
.login-top h1 { font-size: 18px; color: #fff; }
.login-top p { margin: 4px 0 0; font-size: 12.5px; color: #B6A9BE; }
.login-form { padding: 24px 28px 28px; }
.login-form .campo { margin-bottom: 14px; }
.login-foot { text-align: center; font-size: 11.6px; color: var(--muted-2); padding: 0 28px 22px; }

/* ---------------------------------------------------------------- Instalador */
.instalador { max-width: 860px; margin: 0 auto; padding: 32px 20px 60px; }
.passos { display: flex; gap: 8px; margin: 0 0 22px; flex-wrap: wrap; }
.passo {
    flex: 1 1 120px; padding: 10px 12px; border-radius: 10px; background: #fff;
    border: 1px solid var(--line); font-size: 12.4px; color: var(--muted);
}
.passo strong { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); }
.passo.on { border-color: #D9BFD6; background: var(--roxo-soft); color: var(--roxo); }
.passo.ok { border-color: #CFEDE0; background: var(--ok-soft); color: #0B5E43; }
.check-lista { list-style: none; margin: 0; padding: 0; }
.check-lista li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 13.6px; }
.check-lista li:last-child { border-bottom: none; }
.check-lista .st { font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.check-lista .st.ok { background: var(--ok-soft); color: var(--ok); }
.check-lista .st.err { background: var(--neg-soft); color: var(--neg); }
.check-lista .st.warn { background: #FFF7E8; color: #7A5410; }
.check-lista small { display: block; color: var(--muted-2); font-size: 11.8px; }

/* ---------------------------------------------------------------- Impressão */
@media print {
    .sidebar, .topbar, .filtro, .paginacao, .btn, .nav-cta, .menu-btn { display: none !important; }
    body { background: #fff; }
    .conteudo { padding: 0; max-width: none; }
    .card { box-shadow: none; border-color: #ddd; break-inside: avoid; }
    .tabela thead th { background: #f1f1f1 !important; }
    .grade.metricas { grid-template-columns: repeat(3, 1fr); }
}

/* ---------------------------------------------------------------- Responsivo */
@media (max-width: 1080px) {
    .grade.tres { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; height: 100vh;
        transform: translateX(-100%); transition: transform .22s ease;
        box-shadow: var(--sombra-alta);
    }
    .sidebar.aberta { transform: translateX(0); }
    .menu-btn { display: inline-flex; }
    .overlay {
        display: none; position: fixed; inset: 0; background: rgba(20, 15, 24, .45); z-index: 35;
    }
    .overlay.on { display: block; }
    .conteudo { padding: 18px 16px 48px; }
    .topbar { padding: 12px 16px; }
    .topbar-title h1 { font-size: 16.5px; }
    .grade.duas, .grade.tres { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .calculo { grid-template-columns: 1fr 1fr; }
    .filtro-resumo { padding-left: 0; border-left: none; width: 100%; }
    .filtro-atalhos { margin-left: 0; }
    .chart-box { height: 220px; }
    .dl { grid-template-columns: 1fr; }
    .dl dt { padding-bottom: 0; border-bottom: none; }
    .dl dd { padding-top: 2px; }
}

@media (max-width: 560px) {
    .metricas { grid-template-columns: 1fr 1fr; }
    .metrica-valor { font-size: 19px; }
    .calculo { grid-template-columns: 1fr; }
    .topbar-actions .btn span { display: none; }
    .tabela { font-size: 12.8px; }
    .tabela thead th, .tabela tbody td { padding: 9px 10px; }
    .filtro { gap: 8px; }
    .campo-inline select, .campo-inline input { min-width: 78px; }
}

/* seletor de periodo com intervalo */
.campos-periodo { display: flex; align-items: flex-end; gap: 8px; }
.campos-periodo.oculto { display: none; }
