/* ============================================================
   MEU CONTROLE — custom.css
   Arquitetura de shell (sidebar + topbar + conteúdo) inspirada
   num site de referência do cliente, com a paleta do Meu Controle.
   Carregado depois do main.css no header.php.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    /* marca / ação primária */
    --cor-primaria:        #3559e0;
    --cor-primaria-escura: #25409e;
    --cor-primaria-clara:  #eaf0ff;
    --gradiente-marca:     linear-gradient(180deg, #3559e0 0%, #1e2f66 100%);

    /* semântica financeira */
    --cor-receita:         #0f9d6c;
    --cor-receita-clara:   #e3f7ef;
    --cor-despesa:         #e4483f;
    --cor-despesa-clara:   #fdecec;
    --cor-alerta:          #7c5cf2;
    --cor-alerta-clara:    #f1eefd;

    /* neutros */
    --cor-texto:           #1f2933;
    --cor-texto-suave:     #67707c;
    --cor-borda:           #e3e8ef;
    --cor-fundo:           #f3f5f9;
    --cor-fundo-cartao:    #ffffff;

    --raio:                14px;
    --raio-pequeno:        8px;
    --raio-pill:           999px;
    --sombra:              0 2px 10px rgba(20, 30, 60, 0.06);
    --sombra-hover:        0 8px 22px rgba(20, 30, 60, 0.12);
    --transicao:           all 0.15s ease-in-out;

    --fonte: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;

    --sidebar-largura: 240px;
}

/* ============================================================
   1. BASE
   ============================================================ */
body {
    background: var(--cor-fundo) !important;
    color: var(--cor-texto);
    font-family: var(--fonte) !important;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--fonte);
    font-weight: 700;
    color: var(--cor-texto);
}

a { transition: var(--transicao); }

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

/* ============================================================
   2. APP SHELL — estrutura geral (sidebar + topbar + conteúdo)
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
    width: var(--sidebar-largura);
    flex-shrink: 0;
    background: var(--gradiente-marca);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    overflow-y: auto;
    transition: transform .25s ease;
}

.sidebar-brand {
    padding: 22px 18px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}
.sidebar-brand-link img { width: 40px; height: 40px; flex-shrink: 0; }
.sidebar-brand-text {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff !important;
    white-space: nowrap;
}
.sidebar-brand-text strong {
    color: #cfdcff !important;
    font-weight: 800;
}
.sidebar-brand a { text-decoration: none; }

.sidebar-nav {
    flex: 1;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-nav a {
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--raio-pequeno);
    color: rgba(255, 255, 255, 0.75) !important;
    font-weight: 600;
    font-size: 14px;
    transition: background .15s ease, color .15s ease;
}

.sidebar-nav a i { font-size: 17px; width: 20px; text-align: center; }

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.10);
    color: #fff !important;
}

.sidebar-nav a.active {
    background: #ffffff;
    color: var(--cor-primaria-escura) !important;
}

/* item "Relatórios" — abre/fecha um submenu */
.sidebar-submenu-toggle {
    cursor: pointer;
}
.sidebar-submenu-toggle .sidebar-chevron {
    margin-left: auto;
    font-size: 12px !important;
    width: auto !important;
    transition: transform .18s ease;
}
.sidebar-submenu-toggle.aberto .sidebar-chevron {
    transform: rotate(180deg);
}
.sidebar-nav a.sidebar-submenu-toggle.active {
    background: rgba(255, 255, 255, 0.10);
    color: #fff !important;
}

.sidebar-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height .2s ease;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sidebar-submenu.aberto {
    /* era 220px: com 4 relatórios (ou o submenu Opções) o último item ficava
       cortado, sem barra de rolagem. Valor alto só para a animação funcionar. */
    max-height: 600px;
    margin-top: 2px;
    margin-bottom: 4px;
}
.sidebar-submenu a {
    padding-left: 40px;
    font-size: 13px;
}

.sidebar-footer {
    padding: 14px 18px 20px;
    font-size: 11.5px;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
}

/* ---------------- Área principal ---------------- */
.main-area {
    margin-left: var(--sidebar-largura);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--cor-borda);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 30;
    box-shadow: var(--sombra);
}

.btn-menu {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--cor-primaria);
    cursor: pointer;
    padding: 4px;
}

.topbar-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* cores fixas (não dependem de var()) — evita o texto/ícone sumirem
   se alguma cascata de variável falhar */
.topbar-user .btn,
.topbar-user a.btn {
    background: #ffffff !important;
    color: #3559e0 !important;
    border: 1.5px solid #eaf0ff !important;
}
.topbar-user .btn i,
.topbar-user .btn .bi,
.topbar-user .btn span {
    color: #3559e0 !important;
}
.topbar-user .btn:hover {
    background: #eaf0ff !important;
    color: #25409e !important;
}
.topbar-user .btn:hover i,
.topbar-user .btn:hover .bi,
.topbar-user .btn:hover span {
    color: #25409e !important;
}

.content {
    padding: 26px 28px 40px;
    max-width: 1400px;
    width: 100%;
    box-sizing: border-box;
}

/* ============================================================
   3. CARDS (box-typical) — mapeado pro visual de "card-app"
   ============================================================ */
.box-typical {
    background: var(--cor-fundo-cartao) !important;
    border: none !important;
    border-radius: var(--raio) !important;
    box-shadow: var(--sombra) !important;
    margin-bottom: 20px;
}

.box-typical-padding {
    padding: 22px !important;
}

h5.with-border {
    padding-bottom: 14px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--cor-borda);
    font-size: 17px;
}

/* ============================================================
   4. CARDS DE RESUMO (KPI) — reutilizável em dashboards
   ============================================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.kpi-card,
.card-resumo {
    background: #fff;
    border-radius: var(--raio);
    box-shadow: var(--sombra);
    padding: 18px 22px;
    border-left: 5px solid var(--cor-primaria);
}
.kpi-card.is-receita,
.card-resumo.is-receita { border-left-color: var(--cor-receita); }
.kpi-card.is-despesa,
.card-resumo.is-despesa { border-left-color: var(--cor-despesa); }

.kpi-card .kpi-label,
.card-resumo .titulo {
    font-size: 12.5px;
    color: var(--cor-texto-suave);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.kpi-card .kpi-value,
.card-resumo .valor {
    font-size: 26px;
    font-weight: 700;
    color: var(--cor-texto);
    margin-top: 4px;
}
.card-resumo .valor.receita { color: var(--cor-receita); }
.card-resumo .valor.despesa { color: var(--cor-despesa); }

/* ============================================================
   5. FORMULÁRIOS
   ============================================================ */
.form-label,
label.form-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--cor-texto-suave);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 6px;
    display: inline-block;
}

.form-control,
select.form-control,
input.form-control {
    border: 1px solid var(--cor-borda) !important;
    border-radius: var(--raio-pequeno) !important;
    padding: 9px 12px !important;
    height: auto !important;
    font-size: 14px;
    color: var(--cor-texto);
    background: #fbfcfe !important;
    box-shadow: none !important;
    transition: var(--transicao);
}

.form-control:focus {
    border-color: var(--cor-primaria) !important;
    background: #ffffff !important;
    box-shadow: 0 0 0 3px rgba(53, 89, 224, 0.15) !important;
}

.form-control[disabled] {
    background: #f0f2f5 !important;
    color: var(--cor-texto-suave);
}

fieldset.form-group { margin-bottom: 16px; }

.form-check-input { accent-color: var(--cor-primaria); width: 16px; height: 16px; }
.form-check-label { font-size: 13.5px; color: var(--cor-texto-suave); }

/* ============================================================
   6. BOTÕES — cantos totalmente arredondados (pill)
   ============================================================ */
.btn {
    text-decoration: none;
    border-radius: var(--raio-pill) !important;
    font-weight: 600;
    font-size: 13.5px;
    padding: 9px 20px;
    border: none;
    transition: var(--transicao);
    box-shadow: none !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.btn:active { transform: translateY(1px); }

.btn-inline { padding: 7px 16px; font-size: 13px; }

.btn-primary,
.btn.btn-primary {
    background: var(--cor-primaria) !important;
    color: #fff !important;
}
.btn-primary:hover { background: var(--cor-primaria-escura) !important; }

.btn-danger,
.btn.btn-danger {
    background: var(--cor-despesa) !important;
    color: #fff !important;
}
.btn-danger:hover { background: #c93a32 !important; }

.btn-danger-outline {
    background: var(--cor-despesa-clara) !important;
    color: var(--cor-despesa) !important;
    border: 1px solid #f6c6c3 !important;
}
.btn-danger-outline:hover { background: var(--cor-despesa) !important; color: #fff !important; }

.btn-secondary,
.btn.btn-secondary {
    background: #ffffff !important;
    color: #3559e0 !important;
    border: 1.5px solid #eaf0ff !important;
    box-shadow: inset 0 0 0 1px rgba(53, 89, 224, 0.08) !important;
}
.btn-secondary:hover,
.btn.btn-secondary:hover { background: #eaf0ff !important; color: #25409e !important; }
.btn-secondary i,
.btn-secondary .bi,
.btn-secondary span,
.btn.btn-secondary i,
.btn.btn-secondary .bi,
.btn.btn-secondary span { color: inherit !important; }

.btn-success {
    background: var(--cor-receita) !important;
    color: #fff !important;
}

.btn:disabled,
.btn[disabled] { opacity: .6; cursor: not-allowed; transform: none !important; }

.btn i, .btn .bi { font-size: 14px; line-height: 1; }

/* ============================================================
   7. AÇÕES DA TABELA (Editar / Excluir) — ícone circular
   ============================================================ */
.acoes-tabela { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-icone {
    width: 32px;
    height: 32px;
    padding: 0 !important;
    border-radius: var(--raio-pequeno) !important;
}

.btn-editar { background: var(--cor-primaria-clara) !important; color: var(--cor-primaria-escura) !important; }
.btn-editar:hover { background: var(--cor-primaria) !important; color: #fff !important; }

.btn-excluir { background: var(--cor-despesa-clara) !important; color: var(--cor-despesa) !important; }
.btn-excluir:hover { background: var(--cor-despesa) !important; color: #fff !important; }

/* ============================================================
   8. BADGES
   ============================================================ */
.valor-badge {
    display: inline-block;
    width: 100%;
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.valor-receita { color: var(--cor-receita); }
.valor-despesa { color: var(--cor-despesa); }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--raio-pill);
    font-size: 11.5px;
    font-weight: 700;
}
.pill-receita { background: var(--cor-receita-clara); color: var(--cor-receita); }
.pill-despesa { background: var(--cor-despesa-clara); color: var(--cor-despesa); }
.pill-parcelado { background: var(--cor-alerta-clara); color: var(--cor-alerta); }
.pill-pagamento { background: var(--cor-alerta-clara); color: var(--cor-alerta); }

/* ============================================================
   9. TABELAS — cabeçalho sólido na cor da marca
   ============================================================ */
table.table,
#tabelaParcelas {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

table.table thead th,
#tabelaParcelas thead th {
    background: var(--cor-primaria-escura);
    color: #fff;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border: none !important;
    padding: 15px 16px !important;
    white-space: nowrap;
}
table.table thead th:first-child,
#tabelaParcelas thead th:first-child { border-top-left-radius: var(--raio-pequeno); }
table.table thead th:last-child,
#tabelaParcelas thead th:last-child { border-top-right-radius: var(--raio-pequeno); }

table.table tbody td,
#tabelaParcelas tbody td {
    padding: 16px !important;
    border: none !important;
    border-top: 1px solid var(--cor-borda) !important;
    vertical-align: middle;
    font-size: 13.5px;
}

table.table tbody tr:hover,
#tabelaParcelas tbody tr:hover { background: var(--cor-primaria-clara); }

#tabelaParcelas tfoot td {
    padding: 16px !important;
    background: #f8f9fc;
    font-size: 13.5px;
}

.fixed-table-container {
    border: 1px solid var(--cor-borda) !important;
    border-radius: var(--raio) !important;
    overflow: hidden;
}

.fixed-table-toolbar { margin-bottom: 14px; }

.fixed-table-pagination { padding: 12px 4px; font-size: 13px; color: var(--cor-texto-suave); }

.fixed-table-pagination .page-link {
    border-radius: 6px !important;
    margin: 0 2px;
    border: 1px solid var(--cor-borda);
    color: var(--cor-texto);
}
.fixed-table-pagination .page-item.active .page-link {
    background: var(--cor-primaria) !important;
    border-color: var(--cor-primaria) !important;
    color: #fff !important;
}

/* cabeçalho ordenável: espaço pra seta não colar no texto */
table.table thead th.sortable,
#tabelaParcelas thead th.sortable {
    padding-right: 28px !important;
    background-position: right 10px center !important;
    background-size: 10px 12px !important;
    cursor: pointer;
}
table.table thead th.both,
#tabelaParcelas thead th.both {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='12' viewBox='0 0 10 12'%3E%3Cpath d='M1 4L5 0.5L9 4' stroke='%23ffffff' stroke-opacity='0.55' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M1 8L5 11.5L9 8' stroke='%23ffffff' stroke-opacity='0.55' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
}
table.table thead th.asc,
#tabelaParcelas thead th.asc {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 5L5 1L9 5' stroke='%23ffffff' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
}
table.table thead th.desc,
#tabelaParcelas thead th.desc {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23ffffff' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
}

.fixed-table-toolbar .search input {
    border: 1px solid var(--cor-borda) !important;
    border-radius: var(--raio-pequeno) !important;
    padding: 9px 14px 9px 34px !important;
    font-size: 13.5px;
    height: auto !important;
    background: #fbfcfe url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16'%3E%3Cpath fill='%2367707c' d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0'/%3E%3C/svg%3E") no-repeat 12px center !important;
    transition: var(--transicao);
}
.fixed-table-toolbar .search input:focus {
    border-color: var(--cor-primaria) !important;
    background-color: #fff !important;
    box-shadow: 0 0 0 3px rgba(53, 89, 224, 0.15) !important;
    outline: none;
}

.no-records-found td {
    padding: 40px 20px !important;
    text-align: center;
    color: var(--cor-texto-suave);
    font-size: 13.5px;
    font-style: italic;
    border-top: none !important;
}

.fixed-table-loading {
    background-color: rgba(255, 255, 255, 0.85) !important;
    font-size: 13.5px;
    color: var(--cor-texto-suave);
    padding-top: 20px;
}

#carregando {
    text-align: center;
    padding: 30px;
    color: var(--cor-texto-suave);
    font-size: 13.5px;
}

@keyframes girar {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ============================================================
   10. SWEETALERT
   ============================================================ */
.sweet-alert button.confirm { background-color: var(--cor-primaria) !important; }
.sweet-alert button.confirm:hover { background-color: var(--cor-primaria-escura) !important; }
.sweet-alert h2 { font-family: var(--fonte); color: var(--cor-texto); }

/* ============================================================
   10b. ALERTAS (mensagens de sucesso/erro em formulários)
   ============================================================ */
.alerta-app {
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: var(--raio-pequeno);
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 18px;
}
.alerta-app.sucesso {
    background: var(--cor-receita-clara);
    color: var(--cor-receita);
    border: 1px solid #c7ecd9;
}
.alerta-app.erro {
    background: var(--cor-despesa-clara);
    color: var(--cor-despesa);
    border: 1px solid #f6c6c3;
}
.alerta-app i { font-size: 16px; }

/* ============================================================
   11. RESPONSIVO — TABLET (≤ 991px)
   ============================================================ */
@media (max-width: 991px) {
    .box-typical-padding { padding: 16px !important; }
    h5.with-border { font-size: 16px; }

    table.table thead th,
    #tabelaParcelas thead th { font-size: 11px; padding: 10px !important; }

    table.table tbody td,
    #tabelaParcelas tbody td { font-size: 13px; padding: 10px !important; }
}

/* ============================================================
   12. RESPONSIVO — SIDEBAR VIRA OFF-CANVAS (≤ 880px)
   ============================================================ */
@media (max-width: 880px) {
    .sidebar { transform: translateX(-100%); }
    .app-shell.sidebar-open .sidebar { transform: translateX(0); }
    .main-area { margin-left: 0; }
    .btn-menu { display: inline-block; }
    .content { padding: 20px 16px 32px; }
    .topbar { padding: 12px 16px; }

    /* fundo escurecido atrás da sidebar aberta, pra fechar tocando fora */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 20, 35, 0.45);
        z-index: 39;
    }
    .app-shell.sidebar-open .sidebar-overlay { display: block; }
}

/* ============================================================
   13. RESPONSIVO — CELULAR (≤ 576px)
   ============================================================ */
@media (max-width: 576px) {
    body { font-size: 13.5px; }

    .box-typical-padding { padding: 14px !important; }

    h5.with-border {
        font-size: 15px;
        padding-bottom: 10px;
        margin-bottom: 14px;
    }

    #toolbar .row,
    .box-typical .row { row-gap: 8px; }

    .btn, .btn-inline { width: 100%; text-align: center; padding: 10px 16px; }

    .acoes-tabela .btn,
    .acoes-tabela .btn-inline { width: auto; }

    .topbar-user .btn-inline span.texto-btn { display: none; }

    .form-control { font-size: 16px !important; }

    .fixed-table-body,
    #tabelaParcelas { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    table.table thead th,
    #tabelaParcelas thead th { font-size: 10.5px; padding: 8px !important; }

    table.table tbody td,
    #tabelaParcelas tbody td { font-size: 12.5px; padding: 8px !important; }
}
