/* ============================================================
   DESPACHANTE — Design System "Registro"
   Mundo: documentação veicular (placas Mercosul, DUT, taxas).
   Tipos: Archivo (títulos) · IBM Plex Sans (corpo) · IBM Plex Mono (dados).
   ============================================================ */

:root {
    --ink: #0E2340;
    --navy: #123E74;
    --navy-700: #0C2C55;
    --navy-050: #E9EEF6;
    --bg: #E7EBF0;
    --surface: #FFFFFF;
    --surface-2: #F4F6F9;
    --line: #D3DAE3;
    --line-strong: #B9C4D2;
    --muted: #5C6B7E;
    --gain: #157347;
    --gain-050: #E4F1EA;
    --loss: #C0392B;
    --loss-050: #F7E7E4;
    --gold: #A9791C;

    --radius: 10px;
    --radius-sm: 7px;
    --shadow-sm: 0 1px 2px rgba(14, 35, 64, .06), 0 1px 3px rgba(14, 35, 64, .05);
    --shadow: 0 6px 18px rgba(14, 35, 64, .08);
    --sidebar-w: 236px;

    --sans: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    --display: 'Archivo', var(--sans);
    --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html { font-size: 15px; position: relative; min-height: 100%; }

body {
    margin: 0;
    font-family: var(--sans);
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

/* ---------- App shell / sidebar ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-700) 100%);
    color: #DCE6F4;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 6px 8px 18px;
    text-decoration: none;
    color: #fff;
}
.brand .seal {
    width: 38px; height: 38px; flex: 0 0 38px;
    border-radius: 9px;
    background: #fff;
    display: grid; place-items: center;
    box-shadow: inset 0 0 0 3px var(--gold);
    font-family: var(--mono);
    font-weight: 600;
    font-size: 15px;
    color: var(--navy);
    letter-spacing: -.5px;
}
.brand .wordmark { line-height: 1; }
.brand .wordmark b {
    font-family: var(--display);
    font-weight: 800;
    font-size: 15px;
    letter-spacing: .14em;
    display: block;
    text-transform: uppercase;
}
.brand .wordmark small {
    font-family: var(--mono);
    font-size: 9.5px;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: #8FA9CC;
}

.nav-group-label {
    font-family: var(--mono);
    font-size: 9.5px;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: #7A96BD;
    padding: 16px 10px 6px;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    color: #C6D5EA;
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    border-left: 2px solid transparent;
    transition: background .15s ease, color .15s ease;
}
.side-nav a .ico { width: 17px; height: 17px; flex: 0 0 17px; opacity: .85; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.active {
    background: rgba(255,255,255,.10);
    color: #fff;
    border-left-color: var(--gold);
}

.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.12); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.side-user .avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--gold); color: #23180a;
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px; flex: 0 0 30px;
}
.side-user .who { overflow: hidden; }
.side-user .who b { font-size: 12.5px; color: #fff; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who span { font-family: var(--mono); font-size: 9.5px; letter-spacing: .15em; text-transform: uppercase; color: #8FA9CC; }
.side-foot form { margin-top: 6px; }
.btn-signout {
    width: 100%;
    background: rgba(255,255,255,.06);
    color: #C6D5EA;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: var(--radius-sm);
    padding: 7px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s;
}
.btn-signout:hover { background: rgba(255,255,255,.14); color: #fff; }

/* ---------- Main area ---------- */

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.app-content { padding: 26px 34px 60px; width: 100%; }

.page-head { margin-bottom: 22px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.eyebrow {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 5px;
}
h1, h2, h3, h4 { font-family: var(--display); color: var(--ink); font-weight: 700; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 28px; }
h4 { font-size: 18px; }
.page-head h1 { line-height: 1.1; }

/* ---------- Placa chip (assinatura) ---------- */

.placa {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    background: #fff;
    border: 1.5px solid var(--ink);
    border-radius: 5px;
    overflow: hidden;
    line-height: 1;
    box-shadow: var(--shadow-sm);
    vertical-align: middle;
    min-width: 78px;
}
.placa .br {
    background: var(--navy);
    color: #fff;
    font-family: var(--mono);
    font-size: 6.5px;
    letter-spacing: .18em;
    text-transform: uppercase;
    padding: 2px 5px 1.5px;
    display: flex; align-items: center; justify-content: space-between;
}
.placa .br::after { content: ""; width: 6px; height: 4px; border-radius: 1px; background: linear-gradient(180deg, #1f9d55 50%, #f7d117 50%); display: inline-block; }
.placa .num {
    font-family: var(--mono);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: .12em;
    color: var(--ink);
    text-align: center;
    padding: 3px 7px 4px;
    white-space: nowrap;
}
.placa.placa-sm { min-width: 0; }
.placa.placa-sm .num { font-size: 11.5px; padding: 2px 6px 3px; }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: 18px 20px; }

/* Ledger stat cards (dashboard) */
.stat {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px 18px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.stat::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--line); }
.stat .label { font-family: var(--mono); font-size: 10.5px; letter-spacing: .17em; text-transform: uppercase; color: var(--muted); }
.stat .figure { font-family: var(--mono); font-weight: 600; font-size: 26px; margin-top: 8px; color: var(--ink); letter-spacing: -.02em; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat.is-gain::after { background: var(--gain); }
.stat.is-loss::after { background: var(--loss); }
.stat.is-navy::after { background: var(--navy); }
.stat.is-gold::after { background: var(--gold); }

/* ---------- Tables ---------- */

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }

.table { margin: 0; color: var(--ink); border-collapse: separate; border-spacing: 0; width: 100%; }
.table > thead > tr > th {
    background: var(--surface-2);
    font-family: var(--mono);
    font-weight: 600;
    font-size: 10.5px;
    letter-spacing: .11em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--line-strong);
    padding: 11px 14px;
    white-space: nowrap;
}
.table > tbody > tr > td { padding: 11px 14px; border-top: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
.table > tbody > tr:first-child > td { border-top: none; }
.table-striped > tbody > tr:nth-of-type(odd) > td { background: transparent; }
.table > tbody > tr:hover > td { background: var(--navy-050); }
.table tfoot td { padding: 12px 14px; border-top: 2px solid var(--line-strong); background: var(--surface-2); font-weight: 600; }

/* Números monetários */
.num, .money { font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.money, th.money, .text-end { text-align: right; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }

/* ---------- Buttons ---------- */

.btn { font-family: var(--sans); font-weight: 600; font-size: 13.5px; border-radius: var(--radius-sm); padding: 8px 15px; transition: filter .15s, background .15s, box-shadow .15s; }
.btn-lg { padding: 11px 20px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }

.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover, .btn-primary:focus { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.btn-success { background: var(--gain); border-color: var(--gain); color: #fff; }
.btn-success:hover { filter: brightness(.93); background: var(--gain); border-color: var(--gain); color: #fff; }
.btn-danger { background: var(--loss); border-color: var(--loss); color: #fff; }
.btn-danger:hover { filter: brightness(.93); background: var(--loss); border-color: var(--loss); color: #fff; }

.btn-outline-primary { color: var(--navy); border-color: var(--line-strong); background: #fff; }
.btn-outline-primary:hover { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-outline-secondary { color: var(--muted); border-color: var(--line-strong); background: #fff; }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }
.btn-outline-danger { color: var(--loss); border-color: var(--line-strong); background: #fff; }
.btn-outline-danger:hover { background: var(--loss); border-color: var(--loss); color: #fff; }

/* ---------- Forms ---------- */

.form-label { font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
.form-control, .form-select {
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    font-size: 14px;
    color: var(--ink);
    background: #fff;
}
.form-control:focus, .form-select:focus, .form-check-input:focus {
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(18, 62, 116, .15);
    outline: none;
}
input[type="number"].form-control, .money-input { font-family: var(--mono); text-align: right; }

/* ---------- Alerts / badges ---------- */

.alert { border-radius: var(--radius); border: 1px solid transparent; font-size: 14px; padding: 13px 16px; }
.alert-info { background: var(--navy-050); border-color: #C6D6EC; color: var(--navy-700); }
.alert-success { background: var(--gain-050); border-color: #BFDECB; color: #0f5132; }
.alert-warning { background: #FBF3DD; border-color: #ECD9A3; color: #6b5312; }
.alert-danger { background: var(--loss-050); border-color: #E8C4BE; color: #842029; }

.pill { display: inline-block; font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; padding: 3px 9px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.pill.folha { background: #F3ECFA; border-color: #E0CEF2; color: #6b3fa0; }
.pill.bancaria { background: var(--navy-050); border-color: #C6D6EC; color: var(--navy-700); }
.pill.operacional { background: var(--surface-2); }
.pill.outros { background: #FBF3DD; border-color: #ECD9A3; color: #6b5312; }

dl.row dt { color: var(--muted); font-weight: 600; font-size: 13px; }

/* ---------- Home cards ---------- */
.home-card { text-decoration: none; color: inherit; display: block; height: 100%; transition: transform .15s, box-shadow .15s, border-color .15s; }
.home-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line-strong); }

/* ============================================================
   Editor tipo planilha (Processos › Planilha)
   ============================================================ */

/* Mesma linguagem visual dos Processos (table-wrap claro), porém editável.
   Rolagem horizontal + larguras mínimas para nenhum valor ficar escondido. */
.grid-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: auto; max-height: calc(100vh - 240px); }

table.grid { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1240px; }
table.grid thead th {
    position: sticky; top: 0; z-index: 3;
    background: var(--surface-2); color: var(--muted);
    font-family: var(--mono); font-weight: 600; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
    padding: 11px 12px; white-space: nowrap; text-align: left;
    border-bottom: 1px solid var(--line-strong);
}
table.grid thead th.n { text-align: right; }
table.grid tbody td { background: #fff; padding: 0; border-top: none; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover td { background: var(--navy-050); }

/* células editáveis: parecem texto até receber foco */
.cell-input {
    width: 100%; min-width: 0; box-sizing: border-box;
    border: 1px solid transparent; background: transparent; border-radius: 6px;
    padding: 9px 11px; font-family: var(--sans); font-size: 13.5px; color: var(--ink);
    outline: none;
}
.cell-input.n { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.cell-input.placa-input { font-family: var(--mono); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.cell-input:hover { background: var(--surface-2); }
.cell-input:focus { background: #fff; border-color: var(--navy); box-shadow: 0 0 0 2px rgba(18, 62, 116, .16); }
/* remove as setinhas do number (que cortavam o valor) */
.cell-input[type=number]::-webkit-outer-spin-button,
.cell-input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell-input[type=number] { -moz-appearance: textfield; appearance: textfield; }

table.grid td.computed { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; padding: 9px 12px; background: var(--surface-2); color: var(--ink); font-weight: 600; white-space: nowrap; }
table.grid td.computed.gain { color: var(--gain); }
table.grid td.computed.loss { color: var(--loss); }

/* coluna de status/ação */
table.grid td.rowstat { text-align: center; width: 40px; padding: 0 6px; }
table.grid td.chk { text-align: center; padding: 0; }
table.grid td.chk input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--navy); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--line-strong); transition: background .2s; }
.dot.dirty { background: var(--gold); }
.dot.saving { background: var(--navy); animation: pulse 1s infinite; }
.dot.saved { background: var(--gain); }
.dot.error { background: var(--loss); }
tr.row-saved td { animation: flashsave 1s ease; }
.btn-del { border: none; background: transparent; color: var(--line-strong); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px; }
.btn-del:hover { color: var(--loss); }

tr.newrow td { background: var(--surface-2); }
tr.newrow .cell-input::placeholder { color: var(--muted); opacity: .55; font-style: italic; }

.grid-legend { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin-top: 12px; font-size: 12px; color: var(--muted); }
.grid-legend .dot { margin-right: 5px; }
.grid-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes flashsave { 0% { background: var(--gain-050); } 100% { background: #fff; } }

/* ---------- Responsivo ---------- */
@media (max-width: 991px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; flex-basis: auto; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 12px 16px; }
    .brand { padding: 0 16px 0 0; }
    .nav-group-label { display: none; }
    .side-nav { flex-direction: row; flex-wrap: wrap; }
    .side-nav a { border-left: none; border-bottom: 2px solid transparent; padding: 7px 10px; }
    .side-nav a.active { border-left: none; border-bottom-color: var(--gold); }
    .side-foot { margin: 0 0 0 auto; padding: 0; border: none; display: flex; align-items: center; gap: 10px; }
    .side-foot form { margin: 0; }
    .btn-signout { width: auto; padding: 6px 12px; }
    .app-content { padding: 18px 16px 50px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* Foco visível para teclado */
a:focus-visible, .btn:focus-visible, .side-nav a:focus-visible, .cell-input:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
