/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
    --bg: #0F1117;
    --bg-card: #1A1D27;
    --border: #2A2D3A;
    --text: #F0F2F8;
    --text-muted: #8B8FA8;
    --accent: #6C63FF;
    --accent-2: #8B83FF;
    --positive: #2DD4A0;
    --negative: #FF6B6B;
    --warning: #FFB347;
    --radius: 16px;
    --radius-sm: 10px;
    --sidebar: 260px;
    --bottom-nav-h: 64px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --gradient: linear-gradient(135deg, #6C63FF 0%, #8B5CF6 100%);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Contenedor maestro: fijo al viewport, oculta todo desbordamiento */
html {
    height: 100dvh;
    overflow: hidden;
    width: 100vw;
}

body {
    font-family: 'DM Sans', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    height: 100dvh;
    overflow: hidden;
    width: 100vw;
}

body.modal-open { overflow: hidden; }

.mono { font-family: 'JetBrains Mono', monospace; }
.brand-title, .page-title, .login-brand h1 {
    font-family: 'Playfair Display', Georgia, serif;
}

/* ── App layout — shell fijo al viewport ────────────────────────────────── */
.app {
    display: flex;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;   /* el desbordamiento lo maneja .main */
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar);
    flex-shrink: 0;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow-y: auto;
    position: sticky;       /* ya no necesita fixed; el app shell lo contiene */
    top: 0;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    gap: 0.65rem;
    align-items: center;
    padding-bottom: 1.1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.brand-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient);
    border-radius: var(--radius-sm);
    font-size: 1.4rem;
    flex-shrink: 0;
}

.brand-title { font-size: 1rem; font-weight: 600; line-height: 1.2; }
.brand-sub { font-size: 0.7rem; color: var(--text-muted); }

.user-chip {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 0.6rem 0.75rem;
    background: rgba(108, 99, 255, 0.08);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    min-width: 0;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--user-color, var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
    color: #fff;
}

.user-name { font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.vista-toggle {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    background: var(--bg);
    padding: 0.2rem;
    border-radius: var(--radius-sm);
}

.vista-btn {
    flex: 1;
    text-align: center;
    padding: 0.4rem 0.3rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: 0.2s;
    white-space: nowrap;
}

.vista-btn.active { background: var(--gradient); color: #fff; font-weight: 600; }

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

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: 0.2s;
    font-size: 0.875rem;
    white-space: nowrap;
}

.nav-link:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-link.active { background: rgba(108,99,255,0.15); color: var(--accent-2); font-weight: 600; }
.nav-icon { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-footer { padding-top: 0.75rem; border-top: 1px solid var(--border); margin-top: auto; flex-shrink: 0; }
.logout-link:hover { color: var(--negative); }

/* ── Main content — único elemento que hace scroll ──────────────────────── */
.main {
    flex: 1;
    min-width: 0;
    height: 100dvh;
    overflow-y: auto;           /* scroll vertical aquí */
    overflow-x: hidden;
    padding: 1.75rem 2rem 2.5rem;
    -webkit-overflow-scrolling: touch;
}

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

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.25rem;
    background: radial-gradient(ellipse at top, rgba(108,99,255,0.12), transparent 60%), var(--bg);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem 1.75rem;
    box-shadow: var(--shadow);
}

.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-icon { font-size: 2.25rem; display: block; margin-bottom: 0.4rem; }
.login-brand h1 { font-size: 1.65rem; margin-bottom: 0.2rem; }
.login-brand p { color: var(--text-muted); font-size: 0.875rem; }
.login-hint { margin-top: 1.25rem; font-size: 0.78rem; color: var(--text-muted); text-align: center; line-height: 1.7; }
.login-hint code { background: var(--bg); padding: 0.12rem 0.38rem; border-radius: 4px; font-size: 0.73rem; }
.login-hint a { color: var(--accent); }

/* Auth tabs */
.auth-tabs {
    display: flex;
    gap: 0.3rem;
    background: var(--bg);
    padding: 0.2rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.1rem;
}

.auth-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
}

.auth-tab.active { background: var(--gradient); color: #fff; }
.auth-panel { display: none; }
.auth-panel.shown { display: flex; flex-direction: column; gap: 0.85rem; }

.registro-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 0.55rem 0.7rem;
    background: rgba(108,99,255,0.08);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    line-height: 1.5;
}

/* ── Page header ────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.page-title { font-size: 1.6rem; font-weight: 600; }
.page-sub { color: var(--text-muted); font-size: 0.875rem; margin-top: 0.2rem; }

/* ── Month picker / selects ─────────────────────────────────────────────── */
.month-picker { overflow: hidden; }
.month-picker input,
.filters-form input[type="month"],
.filters-form select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.875rem;
    max-width: 100%;
}

/* ── Stats grid ─────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    min-width: 0;
}

.stat-card.highlight {
    border-color: rgba(108,99,255,0.4);
    background: linear-gradient(145deg, var(--bg-card), rgba(108,99,255,0.06));
}

.stat-label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.stat-value { font-size: 1.4rem; font-weight: 600; word-break: break-word; }
.stat-hint { display: block; font-size: 0.68rem; color: var(--text-muted); margin-top: 0.3rem; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }

/* ── Dashboard grids ────────────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.1rem;
}

.dashboard-grid .span-2 { grid-column: span 2; }

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.1rem;
}

.page-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.1rem;
    align-items: start;
}

.flex-grow { min-width: 0; }

/* ── Card ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow);
    min-width: 0;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.9rem;
    gap: 0.5rem;
}

.card-header h3, .card-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.card-title { margin-bottom: 1rem; }

.badge {
    font-size: 0.72rem;
    padding: 0.18rem 0.55rem;
    background: rgba(108,99,255,0.2);
    color: var(--accent-2);
    border-radius: 999px;
    white-space: nowrap;
}

/* ── Progress bar ───────────────────────────────────────────────────────── */
.progress-bar-wrap {
    height: 5px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.4rem;
}

.progress-bar {
    height: 100%;
    background: var(--gradient);
    border-radius: 999px;
    transition: width 0.5s ease;
}

.progress-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.9rem; }

/* ── Charts ─────────────────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 200px; }
.charts-grid canvas { max-height: 220px; }

/* ── Pagos list ─────────────────────────────────────────────────────────── */
.pago-list { list-style: none; }

.pago-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    min-width: 0;
}

.pago-item:last-child { border-bottom: none; }
.pago-item.paid .pago-name { text-decoration: line-through; opacity: 0.6; }
.pago-item.urgent { background: rgba(255,179,71,0.06); margin: 0 -0.5rem; padding: 0.75rem 0.5rem; border-radius: 8px; }

.pago-check { position: relative; cursor: pointer; flex-shrink: 0; }
.pago-check input { position: absolute; opacity: 0; width: 0; height: 0; }

.checkmark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: 2px solid var(--border);
    border-radius: 6px;
    transition: 0.2s;
    font-size: 13px;
    font-weight: 700;
    color: transparent;
}

.pago-check input:checked + .checkmark {
    background: var(--positive);
    border-color: var(--positive);
    color: #0F1117;
}

.pago-check input:checked + .checkmark::after { content: '✓'; }
.pago-check.readonly { font-size: 1.1rem; }

.pago-info { flex: 1; min-width: 0; }
.pago-name { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pago-meta { font-size: 0.72rem; color: var(--text-muted); }
.pago-monto { font-weight: 600; white-space: nowrap; font-size: 0.9rem; }
.link-more { display: inline-block; margin-top: 0.65rem; font-size: 0.82rem; color: var(--accent); text-decoration: none; }

/* ── Transactions ───────────────────────────────────────────────────────── */
.transaction-list { list-style: none; }

.transaction-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    min-width: 0;
}

.transaction-item:last-child { border-bottom: none; }

.tx-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.tx-icon.ingreso { background: rgba(45,212,160,0.15); color: var(--positive); }
.tx-icon.egreso  { background: rgba(255,107,107,0.15); color: var(--negative); }

.tx-body { flex: 1; min-width: 0; }
.tx-title { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta  { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-weight: 600; white-space: nowrap; font-size: 0.9rem; }
.tx-amount.ingreso { color: var(--positive); }
.tx-amount.egreso  { color: var(--negative); }

@keyframes txSlideIn {
    from { opacity: 0; transform: translateX(-12px); }
    to   { opacity: 1; transform: translateX(0); }
}
.tx-new { animation: txSlideIn 0.35s ease; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-stack { display: flex; flex-direction: column; gap: 0.9rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.form-stack-row { display: flex; gap: 0.65rem; }

.form-group label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    font-weight: 500;
}

.label-opt { font-weight: 400; opacity: 0.7; font-size: 0.72rem; }

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108,99,255,0.18);
}

/* Tipo toggle */
.tipo-toggle {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1px solid var(--border);
}

.tipo-toggle input { display: none; }

.toggle-opt {
    flex: 1;
    text-align: center;
    padding: 0.55rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: 0.2s;
    user-select: none;
}

#tipoIngreso:checked + .toggle-opt.ingreso { background: rgba(45,212,160,0.18); color: var(--positive); }
#tipoEgreso:checked  + .toggle-opt.egreso  { background: rgba(255,107,107,0.18); color: var(--negative); }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

.pass-wrap { position: relative; display: flex; }
.pass-wrap input { flex: 1; border-radius: var(--radius-sm) 0 0 var(--radius-sm) !important; }
.btn-eye {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: none;
    color: var(--text-muted);
    padding: 0 0.7rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    cursor: pointer;
    font-size: 0.9rem;
}

.field-hint { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.25rem; display: block; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.6rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: 0.2s;
    white-space: nowrap;
}

.btn-primary { background: var(--gradient); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; }

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.2rem 0.45rem;
    line-height: 1;
    border-radius: 6px;
    transition: 0.15s;
}

.btn-icon:hover { color: var(--negative); background: rgba(255,107,107,0.1); }

/* ── FAB ─────────────────────────────────────────────────────────────────── */
.fab {
    display: none;
    position: fixed;
    bottom: calc(var(--bottom-nav-h) + 1rem);
    right: 1.25rem;
    z-index: 150;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--gradient);
    color: #fff;
    font-size: 1.6rem;
    font-weight: 400;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(108,99,255,0.5);
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    line-height: 1;
}

.fab:active { transform: scale(0.93); }

/* ── Filters ─────────────────────────────────────────────────────────────── */
.filters-bar { margin-bottom: 0.9rem; }
.filters-form { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-error { background: rgba(255,107,107,0.1); border: 1px solid rgba(255,107,107,0.3); color: var(--negative); }
.alert-success { background: rgba(45,212,160,0.1); border: 1px solid rgba(45,212,160,0.3); color: var(--positive); }

.alert-banner {
    display: flex;
    gap: 0.85rem;
    padding: 0.9rem 1.1rem;
    background: rgba(255,179,71,0.08);
    border: 1px solid rgba(255,179,71,0.35);
    border-radius: var(--radius);
    margin-bottom: 1.1rem;
    align-items: flex-start;
}

.alert-list { list-style: none; font-size: 0.82rem; color: var(--text-muted); margin-top: 0.3rem; }

.empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-muted); font-size: 0.9rem; }
.empty-state button { margin-top: 1rem; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    padding: 1.25rem;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-overlay[hidden] { display: none; }

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    transform: scale(0.96) translateY(8px);
    opacity: 0;
    transition: transform 0.28s ease, opacity 0.28s ease;
}

.modal-card.show { transform: scale(1) translateY(0); opacity: 1; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.1rem;
}

.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
    line-height: 1;
}

.modal-close:hover { color: var(--text); background: rgba(255,255,255,0.06); }

/* ── Tabs análisis ───────────────────────────────────────────────────────── */
.tabs-hint {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.tabs-hint a {
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    border: 1px solid var(--border);
    transition: 0.2s;
}

.tabs-hint a.active { background: var(--gradient); color: #fff; border-color: transparent; }

/* ── Metrics ─────────────────────────────────────────────────────────────── */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    min-width: 0;
}

.metric-label { font-size: 0.72rem; color: var(--text-muted); display: block; }
.metric-value { font-size: 1.2rem; font-weight: 600; margin-top: 0.2rem; display: block; word-break: break-word; }
.metric-hint { font-size: 0.78rem; color: var(--text-muted); }

/* ── Table ───────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.data-table th, .data-table td { padding: 0.55rem 0.45rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text-muted); font-weight: 500; font-size: 0.72rem; }

/* ── Color picker ────────────────────────────────────────────────────────── */
.color-picker { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.color-opt { cursor: pointer; }
.color-opt input { display: none; }
.color-dot {
    display: block;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 3px solid transparent;
    transition: 0.15s;
}
.color-opt input:checked + .color-dot { border-color: #fff; transform: scale(1.15); }

/* ── Miembros ────────────────────────────────────────────────────────────── */
.miembro-list { list-style: none; }

.miembro-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    min-width: 0;
}

.miembro-item:last-child { border-bottom: none; }
.miembro-item.inactivo { opacity: 0.45; }

.miembro-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
    color: #fff;
}

.miembro-info { flex: 1; min-width: 100px; }
.miembro-nombre { display: block; font-weight: 600; }
.miembro-email { font-size: 0.72rem; color: var(--text-muted); word-break: break-all; }

.rol-badge {
    font-size: 0.7rem;
    padding: 0.18rem 0.5rem;
    border-radius: 999px;
    font-weight: 500;
    white-space: nowrap;
}
.rol-badge.admin { background: rgba(108,99,255,0.18); color: var(--accent-2); }
.rol-badge.miembro { background: rgba(139,143,168,0.15); color: var(--text-muted); }

.miembro-acciones { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
.campo-hint { font-size: 0.72rem; color: var(--text-muted); }

/* ── Form misc ───────────────────────────────────────────────────────────── */
.form-msg { font-size: 0.82rem; margin-top: 0.25rem; }
.form-msg.ok { color: var(--positive); }
.form-msg.err { color: var(--negative); }

/* ── Responsive 1200px ───────────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .dashboard-grid .span-2 { grid-column: span 1; }
    .dashboard-grid, .charts-grid { grid-template-columns: 1fr; }
    .page-grid { grid-template-columns: 1fr; }
}

/* ── Responsive 900px ────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    :root { --sidebar: 220px; }
    .main { padding: 1.25rem; }
}

/* ── Responsive 768px — Mobile ───────────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --bottom-nav-h: 62px; }

    /* Shell maestro: 100dvh, sin overflow */
    html, body {
        height: 100dvh;
        width: 100vw;
        overflow: hidden;
    }

    .app {
        height: 100dvh;
        width: 100vw;
        overflow: hidden;
    }

    /* Ocultar sidebar */
    .sidebar { display: none; }

    /* Main: ocupa todo el dvh, scroll interno, padding-bottom para no quedar bajo el nav */
    .main {
        flex: 1;
        width: 100vw;
        height: 100dvh;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 0.9rem 0.85rem calc(var(--bottom-nav-h) + 1rem) !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Bottom nav: fixed al fondo del viewport */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100vw;
        height: var(--bottom-nav-h);
        background: var(--bg-card);
        border-top: 1px solid var(--border);
        z-index: 300;
        justify-content: space-around;
        align-items: stretch;
        padding: 0;
    }

    /* Ocultar "Mi Familia" en bottom nav */
    .bottom-nav a[href*="familia"] { display: none !important; }

    .bottom-nav .nav-link {
        flex: 1;
        flex-direction: column;
        gap: 0.1rem;
        padding: 0.4rem 0.1rem;
        font-size: 0.55rem;
        justify-content: center;
        align-items: center;
        min-width: 0;
        border-radius: 0;
        overflow: hidden;
    }

    .bottom-nav .nav-icon { font-size: 1.2rem; width: auto; line-height: 1; }
    .bottom-nav .nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
    .bottom-nav .nav-link.active {
        background: rgba(108,99,255,0.1);
        border-top: 2px solid var(--accent);
        color: var(--accent-2);
    }

    /* Page header: título + mes apilados */
    .page-header {
        flex-direction: column;
        gap: 0.6rem;
        margin-bottom: 1rem;
    }
    .page-header > div,
    .page-header .month-picker { width: 100%; }
    .page-header .month-picker input[type="month"] { width: 100%; display: block; }
    .page-header .btn-primary { display: flex; width: 100%; }

    /* Stats: 2×2 siempre */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.6rem;
        margin-bottom: 1rem;
    }
    .stats-grid .stat-card.highlight { grid-column: span 2; }

    /* Cards compactas */
    .card { padding: 0.85rem 0.95rem; }
    .stat-card { padding: 0.75rem 0.9rem; }
    .stat-label { font-size: 0.72rem; }
    .stat-value { font-size: 1.1rem; }
    .page-title { font-size: 1.25rem; }
    .page-sub { font-size: 0.78rem; }

    /* Grids de una columna */
    .dashboard-grid, .charts-grid { grid-template-columns: 1fr; gap: 0.7rem; }
    .page-grid { grid-template-columns: 1fr; gap: 0.7rem; }
    .form-row { grid-template-columns: 1fr 1fr; gap: 0.65rem; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
    .metric-card { padding: 0.75rem 0.9rem; }
    .metric-value { font-size: 1rem; }

    /* FAB */
    .fab { display: flex; }

    /* Modal bottom sheet */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-card.modal-sheet {
        border-radius: var(--radius) var(--radius) 0 0;
        width: 100vw;
        max-width: 100vw;
        max-height: 92vh;
        transform: translateY(100%);
        opacity: 1;
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1.25rem);
    }
    .modal-card.modal-sheet.show { transform: translateY(0); }

    /* Filters */
    .filters-form { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .filters-form input[type="month"],
    .filters-form select { min-width: 0; flex-shrink: 1; }

    /* Listas */
    .pago-item, .transaction-item { padding: 0.65rem 0; gap: 0.5rem; }
    .tx-icon { width: 30px; height: 30px; font-size: 0.85rem; }

    /* Tablas */
    .data-table { font-size: 0.78rem; }
    .data-table th, .data-table td { padding: 0.45rem 0.35rem; }
}

/* ── Responsive 480px — Muy pequeño ─────────────────────────────────────── */
@media (max-width: 480px) {
    .main { padding-left: 0.7rem !important; padding-right: 0.7rem !important; }
    .stats-grid { gap: 0.5rem; }
    .form-row { grid-template-columns: 1fr; }

    /* Solo íconos en bottom nav */
    .bottom-nav .nav-label { display: none; }
    .bottom-nav .nav-link { padding: 0.5rem 0; }
    .bottom-nav .nav-icon { font-size: 1.4rem; }
}
