/* ============================================
   Mis Finanzas — estilos mobile-first
   ============================================ */

:root {
    --primary: #3B82F6;
    --primary-dark: #2563EB;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --bg: #F3F4F6;
    --card-bg: #FFFFFF;
    --text: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --radius: 16px;
    --radius-sm: 10px;
    --topbar-h: 56px;
    --bottomnav-h: 64px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; }

/* ---------- Layout general ---------- */

.app-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Barra superior: visible solo en móvil */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-h);
    padding: 0 16px;
    background: #111827;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar .brand { font-weight: 700; font-size: 17px; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.topbar-user .user-name { color: #9CA3AF; }
.topbar-user .logout-link {
    color: var(--danger);
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 20px;
    background: rgba(239, 68, 68, 0.12);
}

/* Sidebar: oculto en móvil, visible en escritorio */
.sidebar {
    display: none;
}

.content {
    flex: 1;
    width: 100%;
    padding: 16px;
    padding-bottom: calc(var(--bottomnav-h) + 20px);
    max-width: 1200px;
    margin: 0 auto;
}

/* Nav inferior fija: solo en móvil */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: #111827;
    border-top: 1px solid #1F2937;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    z-index: 30;
    overflow-x: auto;
}

.bottom-nav a {
    flex: 1 0 auto;
    min-width: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    color: #9CA3AF;
    border-radius: var(--radius-sm);
    font-size: 10px;
    text-align: center;
}

.bottom-nav a .nav-icon { font-size: 19px; line-height: 1; }
.bottom-nav a.active, .bottom-nav a:active {
    color: #fff;
    background: rgba(59, 130, 246, 0.18);
}

/* ---------- Encabezados y textos ---------- */

h1 { margin: 0 0 16px; font-size: 21px; }
h2 { font-size: 15px; color: var(--text-muted); margin: 0 0 12px; }

/* ---------- Tarjetas de resumen ---------- */

.cards-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.card .label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.card .value { font-size: 19px; font-weight: 700; word-break: break-word; }
.card.income .value { color: var(--success); }
.card.expense .value { color: var(--danger); }
.card.balance .value { color: var(--primary); }
.card.debt .value { color: var(--warning); }

/* ---------- Gráficos ---------- */

.charts-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 20px;
}

.chart-box {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    overflow: hidden;
}

.chart-box canvas { max-width: 100%; }

/* ---------- Tablas responsivas ---------- */

.table-wrapper {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
}

table {
    width: 100%;
    min-width: 560px;
    border-collapse: collapse;
    background: var(--card-bg);
    font-size: 13px;
}

th, td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td:nth-child(5), th:nth-child(5) { white-space: normal; }

th { background: #F9FAFB; color: var(--text-muted); font-weight: 600; font-size: 12px; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}

.badge.ingreso { background: var(--success); }
.badge.gasto { background: var(--danger); }
.badge.activa { background: var(--warning); }
.badge.pagada { background: var(--success); }

/* ---------- Botones ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px;
    min-height: 44px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.btn:active { background: var(--primary-dark); }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 12px; }
.btn.danger { background: var(--danger); }
.btn.secondary { background: #6B7280; }

/* ---------- Barra superior de sección ---------- */

.top-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.top-bar h1 { margin-bottom: 0; }
.top-bar .btn { flex-shrink: 0; }

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ---------- Formularios ---------- */

form.card {
    max-width: 520px;
    width: 100%;
}

.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13px; }

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px; /* evita zoom automático en iOS */
    background: #fff;
    color: var(--text);
}

.form-group input[type="color"] { padding: 4px; height: 44px; }

/* Filtro de fechas: apilado en móvil */
.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 16px;
}

.filter-form .form-group { margin: 0; flex: 1 1 140px; }

/* ---------- Autenticación ---------- */

.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #3B82F6, #1E293B);
}

.auth-card {
    background: #fff;
    padding: 32px 24px;
    border-radius: 20px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.auth-card h1 { text-align: center; font-size: 20px; }
.auth-card .btn { width: 100%; margin-top: 8px; }
.auth-card p { text-align: center; font-size: 14px; margin-top: 16px; }

.error-msg {
    background: #FEE2E2;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

/* ---------- Listas: recordatorios, pagos de deuda ---------- */

.reminder-item, .list-item {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.reminder-item.done { opacity: 0.55; text-decoration: line-through; }
.calendar-link {
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
}

.pay-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    background: #F9FAFB;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
}

.pay-form input { width: auto; flex: 1 1 100px; }

/* ============================================
   Escritorio (>= 900px): sidebar fija, sin nav inferior
   ============================================ */

@media (min-width: 900px) {
    .topbar, .bottom-nav { display: none; }

    .app-layout { flex-direction: row; }

    .sidebar {
        display: flex;
        flex-direction: column;
        width: 230px;
        background: #111827;
        color: #E5E7EB;
        padding: 20px 0;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        height: 100vh;
    }

    .sidebar .brand {
        font-size: 20px;
        font-weight: 700;
        color: #fff;
        padding: 0 20px 20px;
        border-bottom: 1px solid #1F2937;
        margin-bottom: 10px;
    }

    .sidebar nav { display: flex; flex-direction: column; flex: 1; }

    .sidebar nav a {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 12px 20px;
        color: #9CA3AF;
        font-size: 15px;
        border-radius: 0;
    }

    .sidebar nav a:hover, .sidebar nav a.active {
        background: #1F2937;
        color: #fff;
        border-left: 3px solid var(--primary);
    }

    .sidebar-footer {
        padding: 15px 20px;
        border-top: 1px solid #1F2937;
        font-size: 13px;
    }

    .sidebar-footer .user-name { color: #fff; margin-bottom: 8px; font-weight: 600; }
    .sidebar-footer .logout-link { color: var(--danger); }

    .content { padding: 30px; padding-bottom: 30px; }

    .cards-row { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
    .charts-row { grid-template-columns: 1fr 1fr; gap: 20px; }

    h1 { font-size: 26px; }
    h2 { font-size: 18px; }
}
