:root {
    --azul: #2563eb;
    --azul-escuro: #1e3a8a;
    --azul-claro: #eff6ff;
    --cinza-50: #f8fafc;
    --cinza-100: #f1f5f9;
    --cinza-200: #e2e8f0;
    --cinza-300: #cbd5e1;
    --cinza-400: #94a3b8;
    --cinza-600: #475569;
    --cinza-700: #334155;
    --cinza-800: #1e293b;
    --cinza-900: #0f172a;
    --verde: #15803d;
    --verde-bg: #dcfce7;
    --vermelho: #b91c1c;
    --vermelho-bg: #fee2e2;
    --amarelo: #b45309;
    --amarelo-bg: #fef3c7;
    --branco: #fff;
    --radius: 10px;
    --radius-sm: 6px;
    --sombra: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 8px rgba(15, 23, 42, .05);
    --sombra-hover: 0 4px 16px rgba(15, 23, 42, .10);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--cinza-100);
    color: var(--cinza-800);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 64px;
}

/* ---------- Topbar ---------- */

.topbar {
    background: var(--azul-escuro);
    color: var(--branco);
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}

.topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}

.topbar-brand {
    color: var(--branco) !important;
    font-weight: 700;
    font-size: 1.05rem;
    text-decoration: none !important;
    letter-spacing: .2px;
}

.topbar-collapse {
    display: flex;
    align-items: center;
    gap: 24px;
    flex: 1;
    margin-left: 32px;
}

.topbar-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar-nav a {
    color: rgba(255, 255, 255, .85);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: .92rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.topbar-nav a:hover { background: rgba(255, 255, 255, .12); color: var(--branco); }

.topbar-user { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.topbar-user span { color: rgba(255, 255, 255, .8); }
.topbar-user a { color: var(--branco); font-weight: 500; }
.topbar-user a:hover { text-decoration: underline; }

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
}
.nav-toggle span {
    display: block;
    height: 2px;
    width: 22px;
    margin: 0 auto;
    background: var(--branco);
    border-radius: 2px;
    transition: transform .15s, opacity .15s;
}

/* ---------- Tipografia / cards ---------- */

h1, h2, h3 { color: var(--cinza-900); font-weight: 700; }
h1 { font-size: 1.4rem; margin: 4px 0 16px; }
h2 { font-size: 1.05rem; margin: 0 0 14px; }

.card {
    background: var(--branco);
    border: 1px solid var(--cinza-200);
    border-radius: var(--radius);
    box-shadow: var(--sombra);
    padding: 20px;
    margin-bottom: 18px;
}

.flash {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: .92rem;
    font-weight: 500;
}
.flash-sucesso { background: var(--verde-bg); color: var(--verde); border: 1px solid #86efac; }
.flash-erro { background: var(--vermelho-bg); color: var(--vermelho); border: 1px solid #fca5a5; }
.flash-aviso { background: var(--amarelo-bg); color: var(--amarelo); border: 1px solid #fcd34d; }

.login-wrap { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.login-wrap h1 { text-align: center; }

/* ---------- Formulários ---------- */

label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: .88rem; color: var(--cinza-700); }
label:first-child { margin-top: 0; }

input[type=text], input[type=password], input[type=email], input[type=date],
select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--cinza-300);
    border-radius: var(--radius-sm);
    font-size: 16px; /* evita zoom automático no iOS */
    font-family: inherit;
    background: var(--branco);
    color: var(--cinza-900);
    min-height: 42px;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 70px; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--azul);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

/* ---------- Botões ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--azul);
    color: var(--branco);
    cursor: pointer;
    font-size: .92rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    min-height: 42px;
    transition: background .15s, box-shadow .15s;
}
.btn:hover { background: var(--azul-escuro); text-decoration: none; }
.btn-secundario { background: var(--cinza-600); }
.btn-secundario:hover { background: var(--cinza-800); }
.btn-perigo { background: var(--vermelho); }
.btn-perigo:hover { background: #7f1d1d; }
.btn-sm { padding: 6px 12px; font-size: .82rem; min-height: 32px; }

/* ---------- Tabelas ---------- */

table { width: 100%; border-collapse: collapse; background: var(--branco); font-size: .9rem; }
th, td {
    border-bottom: 1px solid var(--cinza-200);
    padding: 10px 12px;
    text-align: left;
    white-space: nowrap;
    vertical-align: top;
}
th {
    background: var(--cinza-50);
    color: var(--cinza-600);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
}
tbody tr:hover { background: var(--azul-claro); }

.tabela-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 14px;
    border: 1px solid var(--cinza-200);
    border-radius: var(--radius);
}
.tabela-wrap table { border: none; }
.tabela-wrap tr:last-child td { border-bottom: none; }

/* Ação em destaque nas listas (bem visível, fácil de tocar) */
.acao-linha {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    background: var(--azul);
    color: var(--branco) !important;
    font-weight: 600;
    font-size: .85rem;
    text-decoration: none !important;
    white-space: nowrap;
}
.acao-linha:hover { background: var(--azul-escuro); }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: .76rem;
    font-weight: 700;
    white-space: nowrap;
}
.badge-aberto { background: var(--amarelo-bg); color: var(--amarelo); }
.badge-retornado { background: var(--verde-bg); color: var(--verde); }
.badge-divergencia { background: var(--vermelho-bg); color: var(--vermelho); }

/* ---------- Layout utilitário ---------- */

.filtros { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 18px; }
.filtros > div { min-width: 160px; flex: 1 1 160px; }
.filtros .btn { width: 100%; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }

.campo-tamanho { width: 64px; min-width: 64px; text-align: center; padding: 8px; }
.campo-cor { width: 140px; min-width: 140px; }
.campo-data { width: 150px; min-width: 150px; }

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 12px;
}
.toolbar h1 { margin: 0; }

.form-actions { margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; }

.texto-mudo { color: var(--cinza-400); font-size: .88rem; }

details summary { cursor: pointer; user-select: none; }
details[open] summary { margin-bottom: 4px; }

/* ---------- Responsivo (celular / tablet) ---------- */

@media (max-width: 800px) {
    .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
    .nav-toggle { display: flex; }

    .topbar-collapse {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        margin: 0 -20px;
        padding: 10px 20px 16px;
        background: var(--azul-escuro);
        border-top: 1px solid rgba(255, 255, 255, .12);
    }
    .topbar-collapse.open { display: flex; }

    .topbar-nav { flex-direction: column; gap: 2px; }
    .topbar-nav a { padding: 10px 8px; }

    .topbar-user {
        flex-direction: row;
        justify-content: space-between;
        padding-top: 10px;
        margin-top: 6px;
        border-top: 1px solid rgba(255, 255, 255, .12);
    }

    .container { padding: 16px 12px 48px; }

    .card { padding: 16px; border-radius: var(--radius-sm); }

    h1 { font-size: 1.2rem; }

    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .btn { width: 100%; }

    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; }

    .filtros { flex-direction: column; align-items: stretch; }
    .filtros > div { width: 100%; }

    .login-wrap { margin-top: 8vh; }

    /* Listas (romaneios, prestadores, usuários) viram cartões empilhados
       em vez de tabela com rolagem lateral — mais fácil pra quem não tem
       prática com sistema, principalmente no celular do prestador. As
       tabelas de lançamento (data/cor/tamanhos) continuam como tabela de
       verdade, com rolagem, porque ali a grade faz sentido. */
    table.lista-cartoes,
    table.lista-cartoes thead,
    table.lista-cartoes tbody,
    table.lista-cartoes tr,
    table.lista-cartoes td {
        display: block;
        width: 100%;
    }
    table.lista-cartoes thead { display: none; }
    .tabela-wrap:has(table.lista-cartoes) {
        border: none;
        overflow: visible;
    }
    table.lista-cartoes tr {
        background: var(--branco);
        border: 1px solid var(--cinza-200);
        border-radius: var(--radius);
        box-shadow: var(--sombra);
        padding: 4px 14px;
        margin-bottom: 12px;
    }
    table.lista-cartoes td {
        border: none;
        white-space: normal;
        padding: 8px 0;
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        border-bottom: 1px solid var(--cinza-100);
    }
    table.lista-cartoes td::before { padding-top: 2px; }
    table.lista-cartoes td > details { flex: 1; text-align: right; }
    table.lista-cartoes td > details form { text-align: left; margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
    table.lista-cartoes tr td:last-child { border-bottom: none; }
    table.lista-cartoes td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: .72rem;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--cinza-400);
        flex-shrink: 0;
    }
    table.lista-cartoes td:empty,
    table.lista-cartoes td[data-label=""] { display: none; }
    table.lista-cartoes td.celula-acao {
        justify-content: center;
        padding-top: 12px;
    }
    table.lista-cartoes td.celula-acao::before { display: none; }
    table.lista-cartoes td.celula-acao .acao-linha { width: 100%; padding: 12px; font-size: .95rem; }
    table.lista-cartoes td.celula-titulo {
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--cinza-900);
    }
    table.lista-cartoes td.celula-titulo::before { display: none; }
}
