:root {
    --nav-bg:       #0f172a;
    --nav-border:   #1e293b;
    --nav-text:     #94a3b8;
    --nav-active:   #3b82f6;
    --nav-hover:    #1e293b;

    --bg:           #0f172a;
    --surface:      #1e293b;
    --surface2:     #162032;
    --card-bg:      #1e293b;
    --text:         #e2e8f0;
    --text-muted:   #64748b;
    --border:       #334155;

    --success: #22c55e;
    --danger:  #ef4444;
    --warning: #f59e0b;
    --info:    #3b82f6;

    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-size: 14px;
}

/* ── Top Nav ── */
.topnav {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 24px;
    z-index: 100;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin-right: 16px;
    text-decoration: none;
}

.logo-icon {
    width: 32px; height: 32px;
    background: var(--nav-active);
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 800; color: #fff;
}

.logo-title { color: #fff; font-weight: 700; font-size: 14px; }
.logo-sub   { color: var(--nav-text); font-size: 10px; line-height: 1; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    border-radius: 7px;
    color: var(--nav-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    transition: all .15s;
    white-space: nowrap;
}

.nav-item:hover  { background: var(--nav-hover); color: #e2e8f0; }
.nav-item.active { background: var(--nav-active); color: #fff; }
.nav-item svg    { width: 16px; height: 16px; flex-shrink: 0; }

.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    flex-shrink: 0;
}

.nav-user-name {
    font-weight: 600;
    color: #e2e8f0;
    font-size: 13px;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-date { color: var(--nav-text); font-size: 12px; }

.nav-logout {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--nav-text);
    text-decoration: none;
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 6px;
    transition: all .15s;
}

.nav-logout:hover { background: var(--nav-hover); color: #e2e8f0; }

/* ── Main ── */
.main { margin-top: 56px; flex: 1; padding: 28px 32px; }

.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 22px; font-weight: 700; }
.page-header p  { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

.text-muted { color: var(--text-muted); }

/* ── Month selector ── */
.month-selector {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 20px;
}

/* ── Cards ── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card { background: var(--card-bg); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

.card-stat { border-left: 4px solid var(--border); }
.card-stat .stat-label { font-size: 11px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.card-stat .stat-value { font-size: 22px; font-weight: 700; margin-top: 6px; line-height: 1.2; }

.card-stat.receita { border-color: var(--success); }
.card-stat.receita .stat-value { color: var(--success); }
.card-stat.despesa { border-color: var(--danger); }
.card-stat.despesa .stat-value { color: var(--danger); }
.card-stat.saldo   { border-color: var(--info); }
.card-stat.saldo   .stat-value { color: var(--info); }
.card-stat.alerta  { border-color: var(--warning); }
.card-stat.alerta  .stat-value { color: var(--warning); }

/* ── Ações rápidas ── */
.quick-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.qa-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow);
    transition: background .15s, border-color .15s, color .15s;
}
.qa-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.qa-btn .qa-icon { font-size: 15px; font-weight: 700; line-height: 1; }

/* ── Charts ── */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.chart-card { background: var(--card-bg); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.chart-card h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 10px; }

/* ── Table card ── */
.table-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 24px; }

.table-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}

.table-card-header h3 { font-size: 15px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
thead th {
    padding: 10px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
small { font-size: 11px; color: var(--text-muted); }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.badge-receita  { background: #14532d; color: #86efac; }
.badge-despesa  { background: #450a0a; color: #fca5a5; }
.badge-pagar    { background: #450a0a; color: #fca5a5; }
.badge-receber  { background: #14532d; color: #86efac; }
.badge-pendente { background: #451a03; color: #fcd34d; }
.badge-pago     { background: #14532d; color: #86efac; }
.badge-cancelado{ background: #1e293b; color: #64748b; }
.badge-vencida  { background: #450a0a; color: #fca5a5; }

.cat-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 7px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all .15s;
    white-space: nowrap;
}
.btn-primary   { background: var(--info);    color: #fff; }
.btn-primary:hover   { background: #2563eb; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover   { background: #16a34a; }
.btn-danger    { background: var(--danger);  color: #fff; }
.btn-danger:hover    { background: #dc2626; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface2); }
.btn-ghost     { background: transparent; color: var(--text-muted); }
.btn-ghost:hover     { background: var(--surface); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 12px; }

.btn-icon {
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    background: transparent;
    color: var(--text-muted);
    transition: all .15s;
    text-decoration: none;
}
.btn-icon:hover { background: var(--surface); color: var(--text); }

/* ── Form ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text); }

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 14px;
    color: var(--text);
    background: var(--surface2);
    transition: border .15s;
}
.form-control:focus { outline: none; border-color: var(--info); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.form-control option { background: var(--surface); color: var(--text); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--text); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ── Progress ── */
.progress { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 4px; transition: width .4s; }
.progress-bar.ok      { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger  { background: var(--danger); }

/* ── Budget cards ── */
.budget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

.budget-card { background: var(--card-bg); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

.budget-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.budget-card-header .cat-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; }

.budget-amounts { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.budget-amounts .spent { font-weight: 700; color: var(--text); }

/* ── Alerts ── */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert a { font-weight: 600; margin-left: 8px; }
.alert-warning { background: #451a03; color: #fcd34d; border: 1px solid #78350f; }
.alert-danger  { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }
.alert-success { background: #14532d; color: #86efac; border: 1px solid #166534; }

/* ── Search input (compact, inline) ── */
.search-input {
    padding: 7px 10px 7px 32px;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 13px;
    color: var(--text);
    background: var(--surface2);
    width: 190px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 10px center;
    transition: border .15s, width .2s;
}
.search-input:focus {
    outline: none;
    border-color: var(--info);
    width: 220px;
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.search-input::placeholder { color: var(--text-muted); }

/* ── Pagination ── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}
.pagin-info {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 100px;
    text-align: center;
}
.pagin-disabled { opacity: .35; pointer-events: none; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state p { font-size: 14px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

/* ── Credit Cards ── */
.cc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.cc-card-visual {
    border-radius: 18px;
    padding: 22px;
    color: #fff;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: transform .2s, box-shadow .2s;
    box-shadow: 0 8px 32px rgba(0,0,0,.35);
    min-height: 190px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    user-select: none;
}

.cc-card-visual:hover { transform: translateY(-4px); box-shadow: 0 16px 48px rgba(0,0,0,.45); }

.cc-card-visual.selected {
    outline: 3px solid rgba(255,255,255,.9);
    outline-offset: 3px;
}

.cc-card-visual::before {
    content: '';
    position: absolute;
    top: -50px; right: -50px;
    width: 200px; height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,.08);
    pointer-events: none;
}

.cc-card-visual::after {
    content: '';
    position: absolute;
    bottom: -70px; left: -30px;
    width: 240px; height: 240px;
    border-radius: 50%;
    background: rgba(255,255,255,.05);
    pointer-events: none;
}

.cc-card-top { display: flex; justify-content: space-between; align-items: flex-start; z-index: 1; }

.cc-chip { z-index: 1; }
.cc-card-bandeira { font-size: 13px; font-weight: 700; opacity: .85; z-index: 1; }

.cc-card-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: .5px;
    z-index: 1;
    text-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.cc-card-info {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    margin-bottom: 8px;
    opacity: .85;
    z-index: 1;
}

.cc-value { font-size: 15px; font-weight: 700; opacity: 1; }

.cc-progress {
    height: 4px;
    background: rgba(255,255,255,.2);
    border-radius: 2px;
    overflow: hidden;
    z-index: 1;
}

.cc-progress-bar {
    height: 100%;
    border-radius: 2px;
    background: rgba(255,255,255,.85);
    transition: width .4s;
}

.cc-progress-bar.warning { background: #fbbf24; }
.cc-progress-bar.danger  { background: #f87171; }

.cc-card-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 10px;
    z-index: 2;
    position: relative;
}

.cc-btn-icon {
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    background: rgba(255,255,255,.2);
    color: #fff;
    transition: background .15s;
    text-decoration: none;
}

.cc-btn-icon:hover { background: rgba(255,255,255,.35); }

/* ── Login page ── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

/* ── Bottom Nav (mobile only, hidden on desktop) ── */
.bottom-nav {
    display: none;
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .charts-row { grid-template-columns: 1fr; }
    .nav-date   { display: none; }
}

@media (max-width: 768px) {
    /* Top nav: esconde links, mantém logo + user */
    .nav-links       { display: none; }
    .nav-user-name   { display: none; }
    .topnav          { padding: 0 16px; gap: 0; justify-content: space-between; }

    /* Main: menos padding, espaço para bottom nav + safe area */
    .main { padding: 16px 14px calc(80px + env(safe-area-inset-bottom, 0px)); }

    /* Formulários */
    .form-row { grid-template-columns: 1fr; }

    /* Cards: 2 colunas no tablet, padding menor */
    .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card          { padding: 14px 16px; }
    .card-stat .stat-value { font-size: 18px; }
    .card-stat .stat-label { font-size: 10px; }

    /* Charts em coluna única */
    .charts-row { grid-template-columns: 1fr; }

    /* Tabelas com scroll horizontal */
    .table-card {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-card table { min-width: 560px; }

    /* Modals: bottom sheet */
    .modal-overlay { align-items: flex-end; }
    .modal {
        border-radius: 20px 20px 0 0;
        max-width: 100%;
        width: 100%;
        max-height: 92vh;
        padding: 20px 16px;
    }

    /* CC grid: 1 coluna */
    .cc-grid { grid-template-columns: 1fr; }

    /* Budget grid: 1 coluna */
    .budget-grid { grid-template-columns: 1fr; }

    /* Page header menor */
    .page-header h2 { font-size: 18px; }

    /* Bottom nav visível */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: calc(60px + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--nav-bg);
        border-top: 1px solid var(--nav-border);
        z-index: 200;
        justify-content: space-around;
        align-items: stretch;
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        color: var(--nav-text);
        text-decoration: none;
        font-size: 10px;
        font-weight: 500;
        padding: 6px 4px;
        transition: color .15s;
        border-top: 2px solid transparent;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom-nav-item svg  { width: 20px; height: 20px; flex-shrink: 0; }
    .bottom-nav-item.active { color: var(--nav-active); border-top-color: var(--nav-active); }
    .bottom-nav-item:hover  { color: #e2e8f0; }

    /* Logout: só ícone no mobile */
    .nav-logout-label { display: none; }
    .nav-logout { padding: 6px 8px; }

    /* Filtros em wrap */
    .month-selector { flex-wrap: wrap; }

    /* Table card header em coluna */
    .table-card-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .table-card-header > :last-child { align-self: flex-end; }
}

@media (max-width: 480px) {
    /* Cards: 1 coluna em telas muito pequenas */
    .cards-grid { grid-template-columns: 1fr; }

    /* Cards menores */
    .card          { padding: 12px 14px; }
    .card-stat .stat-value { font-size: 16px; }
    .card-stat .stat-label { font-size: 10px; }

    /* Top nav: só logo */
    .nav-logo .logo-sub { display: none; }
}

/* ── Floating Action Button — Assistente IA ─────────────────────────────── */
.fab-agente {
    position: fixed;
    bottom: 24px;
    right: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--nav-active);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(59,130,246,.5);
    z-index: 1000;
    transition: transform .15s, box-shadow .15s;
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.fab-agente:hover { transform: scale(1.08); box-shadow: 0 6px 18px rgba(59,130,246,.6); }

@media (max-width: 768px) {
    .fab-agente {
        bottom: calc(60px + env(safe-area-inset-bottom, 0px) + 16px);
    }
}

/* ── Chat Popup ─────────────────────────────────────────────────────────── */
.chat-popup {
    position: fixed;
    bottom: 88px;
    right: 20px;
    width: 360px;
    max-height: 520px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    z-index: 999;
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
    overflow: hidden;
    transform: scale(0.92) translateY(16px);
    opacity: 0;
    pointer-events: none;
    transition: transform .2s ease, opacity .2s ease;
}
.chat-popup.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}
.chat-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-popup-header span { font-size: 14px; font-weight: 600; color: var(--text); }
.chat-popup-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.chat-popup-close:hover { background: var(--surface); color: var(--text); }
.chat-popup-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}
.chat-popup-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
.chat-popup-footer input { font-size: 16px !important; } /* previne zoom iOS */
.chat-popup-chips {
    padding: 0 12px 10px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .chat-popup {
        bottom: calc(60px + env(safe-area-inset-bottom, 0px) + 52px + 12px);
        right: 12px;
        left: 12px;
        width: auto;
        max-height: 55vh;
        border-radius: 16px;
    }
}
