/* ============================================================
   Sistema Financeiro — Tema "Grafite Premium"
   Substitui Content/site.css. Reestiliza TODO o sistema
   (dashboard, listas, formulários, detalhes, login, relatórios
   e todos os cadastros), pois as views usam estas classes.
   ============================================================ */
@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap");

:root {
    /* Sidebar */
    --sidebar-bg: #17181C;
    --sidebar-text: #9A9CA4;
    --sidebar-text-muted: #5A5C64;
    --sidebar-width: 252px;

    /* Marca / cores principais */
    --primary: #2F5BD0;
    --primary-dark: #2748A8;
    --primary-soft: #E8EEFB;

    --bg: #F7F7F4;
    --card-bg: #FFFFFF;
    --text: #1C1D21;
    --text-strong: #1C1D21;
    --text-muted: #6B6D76;
    --text-faint: #8A8C92;
    --border: #ECEAE4;
    --border-row: #F0EEE9;
    --hover: #FAFAF7;

    --success: #1F8A5B;
    --danger: #C2453D;
    --warning: #C56A2B;
    --info: #3D7E9B;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(20, 21, 25, .05);
    --shadow: 0 4px 18px rgba(20, 21, 25, .07);
    --shadow-lg: 0 24px 60px rgba(20, 21, 25, .22);

    /* Sobrescreve variáveis do Bootstrap p/ alinhar à marca */
    --bs-primary: #2F5BD0;
    --bs-primary-rgb: 47, 91, 208;
    --bs-link-color: #2F5BD0;
    --bs-link-hover-color: #2748A8;
    --bs-body-font-family: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --bs-border-radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
    font-variant-numeric: tabular-nums;
}

a { text-decoration: none; color: var(--primary); }
a:hover { color: var(--primary-dark); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #D8D6CF; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 1030;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex; align-items: center; gap: .65rem;
    padding: 1.35rem 1.25rem 1.15rem;
    font-size: 1.05rem; font-weight: 700; color: #fff;
    line-height: 1.1;
}
.sidebar-brand i {
    width: 34px; height: 34px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 9px; font-size: 1.1rem; color: #fff;
    background: linear-gradient(140deg, var(--primary), #5B8DEF);
}

.sidebar-nav { padding: .35rem .75rem 1.1rem; overflow-y: auto; flex: 1; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #2E3038; border-radius: 3px; }

.nav-section {
    font-size: .655rem; text-transform: uppercase; letter-spacing: .09em;
    color: var(--sidebar-text-muted); font-weight: 700;
    padding: 1rem .8rem .35rem;
}

.nav-link-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .56rem .8rem; margin: .08rem 0;
    border-radius: 9px;
    color: var(--sidebar-text); font-weight: 500; font-size: .855rem;
    transition: background .15s, color .15s, box-shadow .15s;
}
.nav-link-item i { font-size: 1rem; width: 1.25rem; text-align: center; opacity: .95; }
.nav-link-item:hover { background: rgba(255,255,255,.05); color: #E8E9ED; }
.nav-link-item.active {
    background: rgba(255,255,255,.08);
    color: #fff; font-weight: 600;
    box-shadow: inset 2.5px 0 0 var(--primary);
}

/* ----------------- Main ----------------- */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex; flex-direction: column;
    transition: margin .25s ease;
}

.topbar {
    height: 66px;
    background: rgba(247, 247, 244, .82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: .85rem;
    padding: 0 1.75rem;
    position: sticky; top: 0; z-index: 1020;
}
.topbar-title { font-size: 1.05rem; font-weight: 700; flex: 1; letter-spacing: -0.02em; }
.btn-toggle {
    border: none; background: transparent; font-size: 1.4rem; color: var(--text-muted);
    cursor: pointer; display: none;
}

.conta-chip {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .5rem .85rem; border-radius: var(--radius-sm);
    background: #fff; color: var(--text); font-weight: 500; font-size: .82rem;
    border: 1px solid #E7E5DF;
}
.conta-chip i:first-child { color: var(--text-faint); }
.conta-chip:hover { background: var(--hover); color: var(--text); border-color: #DDDBD4; }

.user-chip {
    display: flex; align-items: center; gap: .55rem;
    padding: .35rem .55rem .35rem .4rem; border-radius: var(--radius-sm);
    color: var(--text); border: 1px solid #E7E5DF; background: #fff;
}
.user-chip:hover { background: var(--hover); color: var(--text); }
.avatar {
    width: 36px; height: 36px; border-radius: 9px;
    background: #2A2C33;
    color: #D8DAE2; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta strong { font-size: .82rem; font-weight: 600; }
.user-meta small { color: var(--text-faint); font-size: .7rem; }

.content { padding: 1.65rem 1.75rem 2.5rem; flex: 1; }

/* ----------------- Auth (login) ----------------- */
.auth-shell {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1100px 560px at 18% -10%, #2A3247 0%, #17181C 52%, #0E0F12 100%);
    padding: 1.5rem;
}
.auth-card {
    width: 100%; max-width: 410px;
    background: #fff; border-radius: 18px;
    box-shadow: var(--shadow-lg);
    padding: 2.4rem 2.25rem;
}
.auth-logo { text-align: center; margin-bottom: 1.6rem; }
.auth-logo .badge-logo {
    width: 60px; height: 60px; border-radius: 16px; margin: 0 auto .85rem;
    background: linear-gradient(140deg, var(--primary), #5B8DEF);
    color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.8rem;
    box-shadow: 0 10px 24px rgba(47, 91, 208, .35);
}
.auth-logo h3 { font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.auth-logo p { color: var(--text-muted); margin: .3rem 0 0; font-size: .85rem; }

/* ----------------- Cards ----------------- */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--card-bg);
}
.card-header {
    background: transparent; border-bottom: 1px solid var(--border-row);
    font-weight: 700; font-size: .92rem; padding: .95rem 1.25rem;
    letter-spacing: -0.01em;
}
.card-header i { color: var(--text-faint); }
.card-body { padding: 1.25rem; }
.card-footer {
    background: #FCFCFA; border-top: 1px solid var(--border-row);
    padding: .9rem 1.25rem;
}

/* KPI cards */
.card-kpi {
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); overflow: hidden; position: relative;
}
.card-kpi .card-body { padding: 1.25rem; }
.card-kpi .kpi-label {
    color: var(--text-faint); font-size: .72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .03em;
}
.card-kpi .kpi-valor {
    font-size: 1.7rem; font-weight: 700; margin-top: .55rem;
    font-family: "Geist Mono", ui-monospace, monospace; letter-spacing: -0.02em;
}
.card-kpi .kpi-icon {
    position: absolute; top: 1.1rem; right: 1.25rem;
    width: 34px; height: 34px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
}
.kpi-icon.bg-primary-soft { background: var(--primary-soft); color: var(--primary); }
.kpi-icon.bg-success-soft { background: #E6F4EC; color: var(--success); }
.kpi-icon.bg-danger-soft  { background: #FBE9E7; color: var(--danger); }
.kpi-icon.bg-warning-soft { background: #FCEBDD; color: var(--warning); }

/* ----------------- Page header ----------------- */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.35rem; gap: 1rem; flex-wrap: wrap;
}
.page-header h2 { font-size: 1.3rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.page-header h2 i { color: var(--primary); }

.form-section-title,
.card-body h6.text-muted {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-faint) !important; font-weight: 700; margin: .25rem 0 .5rem;
}

/* Detail lists */
dl.detail-list { margin: 0; }
dl.detail-list dt, dl.row dt { color: var(--text-faint); font-weight: 600; font-size: .8rem; }
dl.detail-list dd, dl.row dd { font-weight: 500; margin-bottom: .35rem; color: var(--text); }

/* ----------------- Tables ----------------- */
.table { --bs-table-bg: transparent; margin-bottom: 0; color: var(--text); }
.table > :not(caption) > * > * { padding: .7rem .7rem; }
.table thead th {
    background: #FAFAF7; color: var(--text-faint);
    font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
    border-bottom: 1px solid var(--border-row); font-weight: 700;
    white-space: nowrap;
}
.table tbody tr { border-color: var(--border-row); }
.table tbody td { border-top: 1px solid var(--border-row); vertical-align: middle; }
.table-hover tbody tr:hover { background: var(--hover); }
/* valores monetários alinhados à direita em fonte mono */
.table td.text-end, .table .fw-bold.text-end { font-family: "Geist Mono", ui-monospace, monospace; }

.table-responsive {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}
.card .table-responsive { border: none; border-radius: 0; box-shadow: none; margin-bottom: 0; }
.table-card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}

/* ----------------- Buttons ----------------- */
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: .855rem; padding: .5rem .9rem; }
.btn i { font-size: .95rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-success:hover { background: #1A744C; border-color: #1A744C; }
.btn-outline-secondary {
    color: var(--text-muted); border-color: #E7E5DF; background: #fff;
}
.btn-outline-secondary:hover { background: var(--hover); color: var(--text); border-color: #DDDBD4; }
.btn-light { background: #fff; border: 1px solid #E7E5DF; color: var(--text-muted); }
.btn-light:hover { background: var(--hover); color: var(--text); }
.btn-group .btn-light { border: 1px solid #E7E5DF; }
.btn-group .btn-light:hover { background: var(--hover); }
.btn-group-sm > .btn { padding: .35rem .55rem; }

/* ----------------- Inputs ----------------- */
.form-control, .form-select {
    border-radius: var(--radius-sm); border-color: #E7E5DF; padding: .55rem .8rem;
    font-size: .875rem; color: var(--text); background-color: #fff;
}
.form-control::placeholder { color: #A8AAB0; }
.form-control:focus, .form-select:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 91, 208, .14);
}
.form-label { font-weight: 600; font-size: .8rem; color: #44454C; margin-bottom: .3rem; }
.input-group-text {
    background: #fff; border-color: #E7E5DF; color: var(--text-faint);
    border-radius: var(--radius-sm);
}
.input-group .form-control { border-radius: var(--radius-sm); }
.input-group > :not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-group > :not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.form-control.border-start-0 { border-left: 0; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 91, 208, .14); }

/* ----------------- Badges de status ----------------- */
[class^="status-"], [class*=" status-"] {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .25rem .6rem; border-radius: 999px;
    font-size: .72rem; font-weight: 600; white-space: nowrap;
}
[class^="status-"]::before, [class*=" status-"]::before {
    content: ""; width: .42rem; height: .42rem; border-radius: 50%; background: currentColor;
}
.status-aberto      { background: #E8EEFB; color: #2F5BD0; }
.status-vencido     { background: #FBE9E7; color: #C2453D; }
.status-pago        { background: #E6F4EC; color: #1F8A5B; }
.status-parcial     { background: #FBF1DF; color: #B5832B; }
.status-prorrogado,
.status-prorrogada  { background: #FCEBDD; color: #C56A2B; }

/* Badges "subtle" do Bootstrap usados nas listas */
.badge.bg-primary-subtle { background: var(--primary-soft) !important; }
.badge.text-primary { color: var(--primary) !important; }
.badge.bg-danger-subtle { background: #FBE9E7 !important; }
.badge.bg-danger-subtle.text-danger { color: var(--danger) !important; }
.badge { font-weight: 600; padding: .3rem .55rem; border-radius: 999px; }

/* Cores utilitárias alinhadas à marca */
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-muted   { color: var(--text-muted) !important; }

/* ----------------- Validação ----------------- */
.required:after { content: " *"; color: var(--danger); }
.field-validation-error { color: var(--danger); font-size: .8rem; }
.validation-summary-errors { color: var(--danger); }
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }

/* ----------------- Paginação ----------------- */
.pagination { margin: 0; gap: 3px; }
.pagination .page-link {
    color: var(--text-muted); border-radius: 8px !important; border-color: #E7E5DF;
    font-size: .82rem; font-weight: 600; padding: .4rem .7rem;
}
.pagination .page-link:hover { background: var(--hover); color: var(--text); }
.pagination .page-item.active .page-link {
    background: #1C1D21; border-color: #1C1D21; color: #fff;
}

/* ----------------- Misc ----------------- */
.alert { border: none; border-radius: 12px; }
.alert-success { background: #E6F4EC; color: #176544; }
.alert-danger { background: #FBE9E7; color: #97342C; }
hr { border-color: var(--border-row); opacity: 1; }
footer.app-footer { color: var(--text-faint); font-size: .78rem; text-align: center; padding: 1.5rem; }
.fs-5 { font-family: "Geist Mono", ui-monospace, monospace; }

/* ----------------- Tom Select (combos com busca) ----------------- */
.ts-wrapper .ts-control {
    border-radius: var(--radius-sm); border-color: #E7E5DF;
    min-height: calc(1.5em + 1.1rem + 2px); padding: .45rem .7rem;
    font-size: .875rem; color: var(--text); background-color: #fff;
}
.ts-wrapper.focus .ts-control {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 91, 208, .14);
}
.ts-dropdown {
    border-color: #E7E5DF; border-radius: var(--radius-sm);
    box-shadow: var(--shadow); font-size: .875rem;
}
.ts-dropdown .active { background: var(--primary-soft); color: var(--primary); }
.ts-dropdown .option { padding: .5rem .7rem; }

/* ----------------- Responsivo ----------------- */
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .app-main { margin-left: 0; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .btn-toggle { display: inline-block; }
}

/* ===== Mobile: cada linha da tabela vira um cartão empilhado ===== */
@media (max-width: 768px) {
    /* trava qualquer rolagem horizontal acidental da página */
    html, body { overflow-x: hidden; max-width: 100%; }
    .app-main, .topbar, main, .content, .container, .container-fluid { max-width: 100%; }

    /* a barra de filtros/cabeçalho não deve estourar a largura */
    .page-header { flex-wrap: wrap; gap: .75rem; align-items: stretch; }
    .page-header form { width: 100%; flex-wrap: wrap; }
    .page-header .input-group,
    .page-header .form-select,
    .page-header .btn-tabs,
    .page-header .btn-primary,
    .page-header .btn-outline-secondary { width: 100% !important; }
    .page-header .btn-tabs .btn { flex: 1; }
    /* inputs de data/seleção/busca encolhem em vez de estourar */
    .page-header .input-group .form-control,
    .page-header .input-group .form-select {
        width: auto !important; flex: 1 1 0; min-width: 0;
    }

    /* Relatórios densos (com linha de totais) continuam rolando na horizontal */
    .table-responsive.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-responsive.table-scroll > .table { min-width: 720px; }
    .table-responsive.table-scroll::-webkit-scrollbar { height: 8px; }
    .table-responsive.table-scroll::-webkit-scrollbar-thumb { background: #D9D7D0; border-radius: 999px; }

    /* o contêiner deixa de ser "moldura" e os cartões assumem o visual */
    .table-responsive:not(.table-scroll),
    .card .table-responsive:not(.table-scroll),
    .table-card:not(.table-scroll) {
        overflow: visible; border: none; box-shadow: none;
        background: transparent; border-radius: 0;
    }
    .table-responsive:not(.table-scroll) > .table { min-width: 0; }

    /* esconde o cabeçalho da tabela (os rótulos vão para cada célula) */
    .table-responsive:not(.table-scroll) .table thead { display: none; }
    .table-responsive:not(.table-scroll) .table,
    .table-responsive:not(.table-scroll) .table tbody { display: block; width: 100%; }

    .table-responsive:not(.table-scroll) .table tbody tr {
        display: block;
        background: var(--card-bg);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-sm);
        padding: .35rem .9rem .6rem;
        margin-bottom: .75rem;
        overflow: hidden;
    }
    .table-responsive:not(.table-scroll) .table-hover tbody tr:hover { background: var(--card-bg); }

    /* todas as células: bloco que pode quebrar linha (nunca corta o conteúdo) */
    .table-responsive:not(.table-scroll) .table tbody td {
        display: block; width: 100%;
        padding: .5rem 0 !important;
        border: 0 !important;
        border-top: 1px solid var(--border-row) !important;
        text-align: left;
        white-space: normal !important;
        overflow-wrap: anywhere; word-break: break-word;
    }

    /* 1ª célula = título do cartão (sem rótulo, em destaque) */
    .table-responsive:not(.table-scroll) .table tbody tr td:first-child {
        border-top: 0 !important; font-weight: 600; font-size: .95rem;
    }
    .table-responsive:not(.table-scroll) .table tbody tr td:first-child::before { content: none; }

    /* demais células = rótulo à esquerda, valor à direita */
    .table-responsive:not(.table-scroll) .table tbody td:not(:first-child):not(.cell-acoes) {
        display: flex; align-items: baseline; justify-content: space-between; gap: .85rem;
        text-align: right;
    }
    .table-responsive:not(.table-scroll) .table tbody td::before {
        content: attr(data-label);
        font-weight: 700; font-size: .68rem; text-transform: uppercase;
        letter-spacing: .04em; color: var(--text-faint);
        text-align: left; flex: 0 0 auto; white-space: nowrap;
    }
    .table-responsive:not(.table-scroll) .table tbody td[data-label=""]::before,
    .table-responsive:not(.table-scroll) .table tbody td:not([data-label])::before { content: none; }

    /* célula de ações: botões alinhados à direita, quebram linha se faltar espaço */
    .table-responsive:not(.table-scroll) .table tbody td.cell-acoes { padding-top: .7rem !important; }
    .table-responsive:not(.table-scroll) .table tbody td.cell-acoes::before { content: none; }
    .table-responsive:not(.table-scroll) .table tbody td.cell-acoes .btn-group {
        width: 100%; display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 4px;
    }
    .table-responsive:not(.table-scroll) .table tbody td.cell-acoes .btn-group > .btn {
        border-radius: var(--radius-sm) !important;
    }

    /* linha de "nenhum registro" volta a ser centralizada */
    .table-responsive:not(.table-scroll) .table tbody td[colspan] { display: block; text-align: center; border-top: 0 !important; }
    .table-responsive:not(.table-scroll) .table tbody td[colspan]::before { content: none; }
}
