/* ============================================================
   meugasto — style.css
   Layout tipo app nativo focado em iPhone
   iPhone 11→17 Pro Max: 390px a 430px de largura
   Sem scroll horizontal. Tudo na tela.
   ============================================================ */

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

/* ── Reset e base ────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    /* Impede zoom acidental no iOS ao focar input */
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
    max-width: 100vw;
}

/* ── Variáveis — modo claro ──────────────────────────────────── */
:root {
    --accent:         #2563eb;
    --accent-hover:   #1d4ed8;
    --accent-light:   #eff6ff;

    --bg-page:        #f5f4f0;
    --bg-surface:     #ffffff;
    --bg-surface2:    #f1f0ec;

    --text-1:         #1a1917;
    --text-2:         #6b6a63;
    --text-3:         #a09f99;

    --border:         rgba(0,0,0,0.08);
    --border-md:      rgba(0,0,0,0.13);

    --card-radius:    16px;
    --radius-md:      10px;
    --radius-sm:      8px;

    --shadow-card:    0 1px 3px rgba(0,0,0,0.06);

    /* Alturas fixas do layout mobile */
    --topbar-h:       56px;
    --bottomnav-h:    72px;          /* inclui safe area iOS */
    --bottomnav-inner: 56px;

    /* Sidebar desktop */
    --sidebar-w:      240px;

    --sidebar-bg:     #ffffff;
    --sidebar-active: #eff4ff;
    --sidebar-active-text: #1d4ed8;
}

/* ── Variáveis — modo escuro ─────────────────────────────────── */
[data-bs-theme="dark"] {
    --bg-page:        #111110;
    --bg-surface:     #1c1c1a;
    --bg-surface2:    #252523;

    --text-1:         #f0efe8;
    --text-2:         #9e9d96;
    --text-3:         #5c5b56;

    --border:         rgba(255,255,255,0.07);
    --border-md:      rgba(255,255,255,0.13);

    --shadow-card:    0 1px 4px rgba(0,0,0,0.3);

    --sidebar-bg:     #161614;
    --sidebar-active: #1e2d4a;
    --sidebar-active-text: #93b8ff;
}

body {
    background: var(--bg-page);
    color: var(--text-1);
}

/* ════════════════════════════════════════════════════════════
   LAYOUT PRINCIPAL
   ════════════════════════════════════════════════════════════ */

.app-wrapper {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;         /* dynamic viewport — iOS Safari */
    overflow-x: hidden;
}

/* ── CONTEÚDO PRINCIPAL ──────────────────────────────────────── */
.main-content {
    flex: 1;
    min-width: 0;               /* impede overflow em flex */
    overflow-x: hidden;

    /* Desktop: empurra para direita da sidebar */
    margin-left: var(--sidebar-w);
    padding: 28px 28px 40px;
}

/* ════════════════════════════════════════════════════════════
   SIDEBAR — apenas desktop (≥992px)
   ════════════════════════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px 20px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 17px;
    flex-shrink: 0;
}

.logo-text { font-size: 16px; color: var(--text-1); letter-spacing: -0.3px; }
.logo-text strong { font-weight: 700; color: var(--accent); }

.sidebar-nav {
    list-style: none;
    padding: 12px;
    margin: 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-nav li { margin-bottom: 2px; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-2);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.sidebar-link i { font-size: 18px; flex-shrink: 0; }
.sidebar-link:hover { background: var(--bg-surface2); color: var(--text-1); }
.sidebar-link.active { background: var(--sidebar-active); color: var(--sidebar-active-text); }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sidebar-user {
    display: flex; align-items: center; gap: 8px;
    flex: 1; min-width: 0;
}

.user-info { display: flex; flex-direction: column; min-width: 0; }

.user-name {
    font-size: 13px; font-weight: 600; color: var(--text-1);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-logout {
    font-size: 11px; color: var(--text-3);
    text-decoration: none;
    display: flex; align-items: center; gap: 3px;
}
.user-logout:hover { color: #dc2626; }

.avatar-mini {
    width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
}

.btn-tema {
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-md);
    background: var(--bg-surface2);
    color: var(--text-2);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 16px;
    transition: all 0.15s;
    flex-shrink: 0;
}
.btn-tema:hover { color: var(--text-1); background: var(--bg-surface); }

/* ════════════════════════════════════════════════════════════
   MOBILE — iPhone (≤991px)
   Tudo reescrito para funcionar como app nativo
   ════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {

    /* Remove sidebar e reseta margem */
    .sidebar { display: none !important; }

    .main-content {
        margin-left: 0;
        /* Espaço: topbar em cima + bottom nav embaixo */
        padding: calc(var(--topbar-h) + 12px) 16px calc(var(--bottomnav-h) + 8px);
        /* Garante que nada sai da tela */
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Força todos os filhos a não ultrapassar a tela */
    .main-content * {
        max-width: 100%;
    }

    /* Tabelas: scroll interno, não na página toda */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius-md);
    }
}

/* ── TOPBAR MOBILE ───────────────────────────────────────────── */
.navbar-mobile {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    /* Safe area iOS (notch) */
    padding-top: env(safe-area-inset-top);
    height: calc(var(--topbar-h) + env(safe-area-inset-top));
}

.navbar-brand-mobile {
    display: flex; align-items: center; gap: 8px;
    text-decoration: none; color: var(--text-1);
    font-weight: 700; font-size: 15px;
}

.btn-menu-mobile, .btn-tema-mobile {
    background: none;
    border: 1px solid var(--border-md);
    border-radius: var(--radius-sm);
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-2); font-size: 18px; cursor: pointer;
    flex-shrink: 0;
}

/* ── MENU MOBILE DROPDOWN ────────────────────────────────────── */
.menu-mobile-overlay {
    position: fixed;
    top: calc(var(--topbar-h) + env(safe-area-inset-top));
    left: 0; right: 0;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    z-index: 190;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.menu-mobile-overlay.open { max-height: 70vh; overflow-y: auto; }

.menu-mobile-nav {
    list-style: none; margin: 0;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
}

.menu-mobile-nav li a {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 8px;
    color: var(--text-1); text-decoration: none;
    font-size: 15px; font-weight: 500;
    border-bottom: 1px solid var(--border);
}

.menu-mobile-nav li:last-child a { border-bottom: none; }

/* ── BOTTOM NAV — tipo app iOS ───────────────────────────────── */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    z-index: 200;
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    /* Safe area iOS (home indicator) */
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--bottomnav-inner) + env(safe-area-inset-bottom));
    /* Blur tipo iOS */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: rgba(255,255,255,0.88);
}

[data-bs-theme="dark"] .bottom-nav {
    background: rgba(28,28,26,0.92);
}

.bottom-nav-item {
    display: flex; flex-direction: column;
    align-items: center; gap: 2px;
    color: var(--text-3);
    text-decoration: none;
    font-size: 10px; font-weight: 500;
    padding: 2px 12px;
    min-width: 56px;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item i { font-size: 24px; line-height: 1; }
.bottom-nav-item span { line-height: 1.2; }
.bottom-nav-item.active { color: var(--accent); }

/* Botão central FAB — lançar gasto */
.bottom-nav-fab {
    width: 48px; height: 48px;
    background: var(--accent);
    border-radius: 50%;
    color: #fff !important;
    display: flex; align-items: center; justify-content: center;
    margin-top: -12px;
    flex-direction: row;
    box-shadow: 0 2px 12px rgba(37,99,235,0.4);
    padding: 0;
    min-width: unset;
}

.bottom-nav-fab i { font-size: 22px; }
.bottom-nav-fab span { display: none; }

/* ════════════════════════════════════════════════════════════
   CARDS E COMPONENTES
   Largura máxima relativa — nunca fixo em px no mobile
   ════════════════════════════════════════════════════════════ */

.card-mg {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    padding: 18px;
    box-shadow: var(--shadow-card);
    width: 100%;
    overflow: hidden;           /* impede filhos de vazar */
}

/* ── Cards de métricas ───────────────────────────────────────── */
.metric-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    padding: 16px;
    box-shadow: var(--shadow-card);
    transition: transform 0.15s;
    overflow: hidden;
    width: 100%;
}

@media (hover: hover) {
    .metric-card:hover { transform: translateY(-1px); }
}

.metric-label {
    font-size: 11px; font-weight: 500;
    color: var(--text-3);
    text-transform: uppercase; letter-spacing: 0.4px;
    margin-bottom: 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.metric-valor {
    font-size: 20px; font-weight: 700;
    color: var(--text-1); letter-spacing: -0.5px;
    line-height: 1.2;
    /* Evita overflow de valores grandes */
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Fonte menor em telas muito pequenas (iPhone SE) */
@media (max-width: 375px) {
    .metric-valor { font-size: 17px; }
}

.metric-icon {
    width: 36px; height: 36px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 17px; margin-bottom: 12px;
    flex-shrink: 0;
}

/* ── Grid de métricas: 2 colunas no mobile ───────────────────── */
@media (max-width: 991px) {
    .metrics-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
}

/* ── Cabeçalho de página ─────────────────────────────────────── */
.page-titulo {
    font-size: 20px; font-weight: 700;
    color: var(--text-1); letter-spacing: -0.4px;
    margin-bottom: 2px;
    /* Evita quebra estranha no iOS */
    word-break: break-word;
}

.page-sub {
    font-size: 13px; color: var(--text-2);
    margin-bottom: 20px;
}

@media (max-width: 991px) {
    .page-titulo { font-size: 18px; }
}

/* ── Tabelas ─────────────────────────────────────────────────── */
.table-mg {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    /* Mínimo para não ficar ilegível */
    min-width: 0;
}

.table-mg th {
    font-size: 11px; font-weight: 600;
    color: var(--text-3); text-transform: uppercase; letter-spacing: 0.4px;
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface2);
    white-space: nowrap;
}

.table-mg td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-1);
    vertical-align: middle;
}

.table-mg tr:last-child td { border-bottom: none; }
.table-mg tr:hover td { background: var(--bg-surface2); }

/* ── Badge categoria ─────────────────────────────────────────── */
.badge-categoria {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 500;
    white-space: nowrap;
    max-width: 130px; overflow: hidden; text-overflow: ellipsis;
}

/* ── Inputs ──────────────────────────────────────────────────── */
.input-icon-wrap { position: relative; }

.input-icon {
    position: absolute; left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-3); font-size: 17px;
    pointer-events: none;
}

.input-com-icone  { padding-left: 38px !important; }
.input-com-icone-dir { padding-right: 42px !important; }

/* Inputs no iOS: font-size mínimo 16px evita zoom automático */
@media (max-width: 991px) {
    .form-control, .form-select {
        font-size: 16px !important;
    }
}

.btn-olho {
    position: absolute; right: 10px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none;
    color: var(--text-3); cursor: pointer;
    padding: 4px; font-size: 17px;
    display: flex; align-items: center;
}
.btn-olho:hover { color: var(--text-1); }

/* ── Botões ──────────────────────────────────────────────────── */
.btn-primary {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    font-weight: 600;
}
.btn-primary:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
}

/* Botões touch-friendly no mobile */
@media (max-width: 991px) {
    .btn { min-height: 44px; }
    .btn-sm { min-height: 36px; }
}

/* ── Flash messages ──────────────────────────────────────────── */
.alert {
    border-radius: var(--radius-md);
    font-size: 14px; border: none;
}

/* ════════════════════════════════════════════════════════════
   TELA DE LOGIN
   ════════════════════════════════════════════════════════════ */
.login-body { padding: 0; overflow-x: hidden; }

.login-page {
    display: flex; min-height: 100vh; min-height: 100dvh;
}

/* Branding lateral — só desktop */
.login-branding {
    flex: 1;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex; align-items: center; justify-content: center;
    padding: 48px;
    position: relative; overflow: hidden;
}

.login-branding::before {
    content: ''; position: absolute;
    width: 400px; height: 400px; border-radius: 50%;
    background: rgba(37,99,235,0.12);
    top: -100px; right: -100px;
}

.login-branding::after {
    content: ''; position: absolute;
    width: 300px; height: 300px; border-radius: 50%;
    background: rgba(37,99,235,0.08);
    bottom: -80px; left: -80px;
}

.branding-content { position: relative; z-index: 1; max-width: 380px; }

.branding-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }
.logo-icon-lg {
    width: 44px; height: 44px;
    background: rgba(255,255,255,0.15); border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 22px; flex-shrink: 0;
}

.branding-nome { font-size: 22px; color: #fff; font-weight: 400; }
.branding-nome strong { font-weight: 700; color: #60a5fa; }

.branding-tagline {
    font-size: 36px; font-weight: 700; color: #fff;
    line-height: 1.2; letter-spacing: -1px; margin-bottom: 12px;
}

.branding-sub {
    font-size: 15px; color: rgba(255,255,255,0.6);
    line-height: 1.6; margin-bottom: 32px;
}

.familia-avatares { display: flex; align-items: center; gap: 4px; margin-bottom: 32px; }

.fam-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    border: 2px solid rgba(255,255,255,0.2);
}

.fam-texto { font-size: 12px; color: rgba(255,255,255,0.5); margin-left: 6px; }

.preview-cards { display: flex; flex-direction: column; gap: 8px; }

.preview-card {
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px; padding: 12px 16px;
    display: flex; align-items: center; gap: 12px; color: #fff;
}

.preview-card i { font-size: 18px; color: #60a5fa; }
.preview-label { font-size: 12px; color: rgba(255,255,255,0.5); }
.preview-valor { font-size: 15px; font-weight: 600; color: #fff; }

/* Formulário de login */
.login-form-side {
    width: 100%; max-width: 480px;
    display: flex; align-items: center; justify-content: center;
    padding: 40px 32px;
    background: var(--bg-page);
}

/* Mobile: formulário ocupa tela toda */
@media (max-width: 991px) {
    .login-branding { display: none !important; }

    .login-form-side {
        max-width: 100%;
        padding: 40px 24px;
        /* Safe area iOS */
        padding-top: calc(40px + env(safe-area-inset-top));
        padding-bottom: calc(40px + env(safe-area-inset-bottom));
        align-items: flex-start;
        padding-top: 60px;
    }

    .login-card { width: 100%; }
}

.login-card { width: 100%; max-width: 380px; }

.login-titulo {
    font-size: 24px; font-weight: 700; color: var(--text-1);
    letter-spacing: -0.5px; margin-bottom: 4px;
}

.login-sub { font-size: 14px; color: var(--text-2); margin-bottom: 28px; }

.link-esqueci { font-size: 12px; color: var(--accent); text-decoration: none; }

.btn-login { height: 48px; font-size: 15px; font-weight: 600; border-radius: var(--radius-md); }

.login-rodape {
    text-align: center; margin-top: 24px;
    font-size: 12px; color: var(--text-3);
}

.btn-tema-flutuante {
    position: fixed; top: 16px; right: 16px; z-index: 999;
    width: 38px; height: 38px; border-radius: 50%;
    border: 1px solid var(--border-md);
    background: var(--bg-surface); color: var(--text-2);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 17px;
    /* Safe area no topo */
    top: calc(16px + env(safe-area-inset-top));
}

/* ════════════════════════════════════════════════════════════
   AJUSTES ESPECÍFICOS POR TAMANHO DE TELA
   ════════════════════════════════════════════════════════════ */

/* iPhone SE (375px) — mais compacto */
@media (max-width: 375px) {
    .main-content { padding-left: 12px; padding-right: 12px; }
    .card-mg { padding: 14px; }
    .metric-card { padding: 12px; }
    .page-titulo { font-size: 16px; }
    .badge-categoria { max-width: 100px; }
}

/* iPhone 12/13/14/15 (390px) — base */
@media (min-width: 376px) and (max-width: 430px) {
    .metric-valor { font-size: 19px; }
}

/* iPhone Pro Max (430px) — mais espaço */
@media (min-width: 431px) and (max-width: 991px) {
    .main-content { padding-left: 20px; padding-right: 20px; }
    .metric-valor { font-size: 21px; }
}

/* ── Gráficos: altura adaptável no mobile ────────────────────── */
@media (max-width: 991px) {
    canvas {
        max-width: 100% !important;
    }

    /* Gráfico pizza menor no mobile */
    #graficoPizza { max-height: 180px; }
    #graficoBarra { max-height: 200px; }
}

/* ── Evita que imagens e iframes estourem ────────────────────── */
img, iframe, video, svg {
    max-width: 100%;
    height: auto;
}

/* ── Scrollbar mais fina (esteticamente agradável) ───────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 2px; }
