/* ═══════════════════════════════════════════════════════
   GastosHogar – Estilos globales (mobile-first)
   ═══════════════════════════════════════════════════════ */
:root {
    --sidebar-width: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #f1f5f9;
    --sidebar-active-bg: #1e40af;
    --sidebar-active-text: #fff;
    --header-height: 56px;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --primary: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0ea5e9;
    --purple: #8b5cf6;
    --text-dark: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1);
    --radius: 10px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--body-bg);
    color: var(--text-dark);
    margin: 0;
    -webkit-text-size-adjust: 100%;
}

/* ── App Shell ─────────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    transition: transform .25s ease;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Mobile: sidebar hidden by default, slides in */
.sidebar { transform: translateX(-100%); }
.sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.4); }
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 999; }

/* Desktop: sidebar always visible */
@media (min-width: 992px) {
    .sidebar { transform: translateX(0); }
    .sidebar-overlay { display: none !important; }
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 12px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
}
.sidebar-logo i { color: var(--primary); font-size: 1.35rem; }

.sidebar-close {
    background: none; border: none; color: var(--sidebar-text);
    font-size: 1.2rem; cursor: pointer; padding: 4px 8px; touch-action: manipulation;
}
.sidebar-close:hover { color: #fff; }

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 14px 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-section-label {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--sidebar-text);
    opacity: .6;
    padding: 8px 10px 4px;
    margin-bottom: 2px;
}

.nav-divider { border-top: 1px solid var(--sidebar-border); margin: 10px 8px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    transition: background .15s, color .15s;
    margin-bottom: 2px;
    min-height: 40px;
    touch-action: manipulation;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: var(--sidebar-text-hover); }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }

.nav-icon { width: 18px; text-align: center; font-size: .88rem; flex-shrink: 0; }
.nav-icon-sm { width: 14px; font-size: .75rem; flex-shrink: 0; }

.nav-household-group { margin-bottom: 4px; }

.nav-household-name {
    display: flex; align-items: center; gap: 8px;
    font-size: .7rem; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--sidebar-text);
    opacity: .5; padding: 6px 10px 2px;
}

.nav-link-sub { padding-left: 26px; font-size: .82rem; }

/* Sidebar footer */
.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid var(--sidebar-border);
    background: rgba(0,0,0,.2);
    flex-shrink: 0;
}

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

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

.user-info { min-width: 0; }
.user-name { font-size: .82rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .68rem; color: var(--sidebar-text); }

.btn-logout {
    background: none; border: none; color: var(--sidebar-text);
    font-size: 1rem; cursor: pointer; padding: 8px; border-radius: 6px;
    transition: background .15s, color .15s; flex-shrink: 0;
    touch-action: manipulation; min-width: 36px; min-height: 36px;
    display: flex; align-items: center; justify-content: center;
}
.btn-logout:hover { background: rgba(239,68,68,.2); color: #ef4444; }

/* ── Main wrapper ──────────────────────────────────────── */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Mobile: no left margin (sidebar overlaps) */
    margin-left: 0;
    min-width: 0;
}

@media (min-width: 992px) {
    .main-wrapper { margin-left: var(--sidebar-width); }
}

/* ── Top bar ───────────────────────────────────────────── */
.top-bar {
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    box-shadow: var(--shadow-sm);
    position: sticky; top: 0; z-index: 100;
    flex-shrink: 0;
}

@media (min-width: 992px) {
    .top-bar { padding: 0 24px; gap: 16px; }
}

.hamburger {
    background: none; border: none; font-size: 1.2rem;
    color: var(--text-muted); cursor: pointer;
    padding: 8px; margin: -8px; border-radius: 6px;
    touch-action: manipulation; flex-shrink: 0;
}
.hamburger:hover { color: var(--text-dark); }

.top-bar-title { flex: 1; font-weight: 600; font-size: .9rem; color: var(--text-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (min-width: 576px) { .top-bar-title { font-size: 1rem; } }

.top-bar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Language switcher */
.lang-switch {
    display: flex;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
}

.lang-btn {
    background: none;
    border: none;
    border-radius: 4px;
    padding: 3px 7px;
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: background .15s, color .15s;
    touch-action: manipulation;
    letter-spacing: .04em;
}
.lang-btn.active { background: #fff; color: var(--text-dark); box-shadow: var(--shadow-sm); }
.lang-btn:hover:not(.active) { color: var(--text-dark); }

/* ── Page content ──────────────────────────────────────── */
.page-content { padding: 14px; flex: 1; }

@media (min-width: 576px) { .page-content { padding: 18px; } }
@media (min-width: 992px) { .page-content { padding: 24px; } }

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 12px 14px;
    font-weight: 600;
    font-size: .88rem;
    display: flex; align-items: center; gap: 8px;
    flex-wrap: wrap;
}

@media (min-width: 576px) {
    .card-header { padding: 14px 20px; font-size: .95rem; gap: 10px; }
}

.card-body { padding: 14px; }

@media (min-width: 576px) { .card-body { padding: 20px; } }

/* Stat cards */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }

@media (min-width: 576px) { .stat-card { padding: 18px; gap: 14px; } }
@media (min-width: 992px) { .stat-card { padding: 20px; gap: 16px; } }

.stat-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

@media (min-width: 992px) { .stat-icon { width: 52px; height: 52px; font-size: 1.4rem; border-radius: 12px; } }

.stat-icon.blue { background: #dbeafe; color: var(--primary); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.yellow { background: #fef3c7; color: var(--warning); }
.stat-icon.red { background: #fee2e2; color: var(--danger); }
.stat-icon.purple { background: #ede9fe; color: var(--purple); }
.stat-icon.cyan { background: #e0f2fe; color: var(--info); }

.stat-body { min-width: 0; flex: 1; }
.stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.2; color: var(--text-dark); }
.stat-label { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.stat-sub { font-size: .72rem; color: var(--text-muted); margin-top: 4px; }

@media (min-width: 992px) { .stat-value { font-size: 1.6rem; } }

/* ── Tables ─────────────────────────────────────────────── */
.table-responsive {
    border-radius: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.card > .table-responsive:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.card > .table-responsive:last-child  { border-radius: 0 0 var(--radius) var(--radius); }
.card > .table-responsive:only-child  { border-radius: var(--radius); }

.table { margin-bottom: 0; font-size: .83rem; white-space: nowrap; }

@media (min-width: 576px) { .table { font-size: .88rem; } }

.table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: .72rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding: 9px 12px;
    white-space: nowrap;
}

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

@media (min-width: 576px) {
    .table th { padding: 10px 14px; font-size: .78rem; }
    .table td  { padding: 12px 14px; }
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }

/* ── Login page ─────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
    display: flex; align-items: center; justify-content: center; padding: 16px;
}

.login-card {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    padding: 28px 20px;
    width: 100%; max-width: 420px;
}

@media (min-width: 480px) {
    .login-card { padding: 40px; border-radius: 16px; }
}

.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo i { font-size: 2.2rem; color: var(--primary); }
.login-logo h1 { font-size: 1.4rem; font-weight: 700; color: var(--text-dark); margin: 8px 0 4px; }
.login-logo p { font-size: .83rem; color: var(--text-muted); }

/* ── Badges & pills ──────────────────────────────────────── */
.badge-category {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 20px; font-size: .72rem; font-weight: 600;
    color: #fff; white-space: nowrap;
}

.status-dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}
.status-dot.active  { background: var(--success); }
.status-dot.inactive { background: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn { touch-action: manipulation; }

.btn-icon {
    width: 34px; height: 34px; border-radius: 8px;
    border: 1px solid var(--border-color); background: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background .15s; font-size: .82rem; color: var(--text-muted);
    touch-action: manipulation; flex-shrink: 0;
}
.btn-icon:hover { background: #f1f5f9; }
.btn-icon.danger:hover { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
.btn-icon.success:hover { background: #d1fae5; color: var(--success); border-color: #a7f3d0; }

/* ── Modals ───────────────────────────────────────────────── */
.modal-backdrop-custom {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 1050;
    display: flex;
    /* Mobile: bottom sheet */
    align-items: flex-end;
    padding: 0;
}

@media (min-width: 576px) {
    .modal-backdrop-custom {
        align-items: center;
        padding: 20px;
    }
}

.modal-panel {
    background: #fff;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Mobile: round top corners only */
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,.2);
    /* Smooth slide-up feel */
    animation: slideUp .2s ease;
}

@media (min-width: 576px) {
    .modal-panel {
        max-width: 560px;
        border-radius: 14px;
        box-shadow: 0 20px 60px rgba(0,0,0,.3);
        max-height: 90vh;
        animation: none;
    }
}

.modal-panel.modal-lg { max-width: 720px; }

@keyframes slideUp {
    from { transform: translateY(40px); opacity: .7; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* Mobile drag handle hint */
.modal-panel::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 10px auto 0;
}

@media (min-width: 576px) { .modal-panel::before { display: none; } }

.modal-header-custom {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header-custom h5 { font-size: .95rem; font-weight: 700; margin: 0; }

@media (min-width: 576px) {
    .modal-header-custom { padding: 18px 24px; }
    .modal-header-custom h5 { font-size: 1rem; }
}

.modal-body-custom { padding: 16px; }

@media (min-width: 576px) { .modal-body-custom { padding: 24px; } }

.modal-footer-custom {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex; justify-content: flex-end; gap: 8px;
    flex-wrap: wrap;
}

@media (min-width: 576px) { .modal-footer-custom { padding: 16px 24px; gap: 10px; } }

/* On mobile, modal action buttons fill width */
@media (max-width: 575px) {
    .modal-footer-custom { flex-direction: column-reverse; }
    .modal-footer-custom .btn { width: 100%; }
}

/* ── Forms ────────────────────────────────────────────────── */
.form-label { font-size: .82rem; font-weight: 600; color: var(--text-dark); margin-bottom: 5px; display: block; }

.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: 8px; font-size: .88rem;
    padding: 9px 12px; transition: border-color .15s, box-shadow .15s;
    min-height: 40px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
    outline: none;
}

/* ── Balance cards ────────────────────────────────────────── */
.balance-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px;
}

@media (min-width: 576px) { .balance-card { padding: 16px 20px; } }

.balance-positive { color: var(--success); font-weight: 700; }
.balance-negative { color: var(--danger); font-weight: 700; }
.balance-zero     { color: var(--text-muted); font-weight: 700; }

/* ── Color swatches ───────────────────────────────────────── */
.color-swatch {
    width: 32px; height: 32px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-size: .9rem;
}

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 36px 20px; color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 14px; opacity: .4; display: block; }
.empty-state p  { font-size: .88rem; margin: 0; }

@media (min-width: 576px) {
    .empty-state { padding: 48px 24px; }
    .empty-state i { font-size: 3rem; }
}

/* ── Page header ──────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

@media (min-width: 576px) { .page-header { margin-bottom: 20px; } }
@media (min-width: 992px) { .page-header { margin-bottom: 24px; } }

.page-header h2 { font-size: 1.2rem; font-weight: 700; margin: 0; color: var(--text-dark); }
.page-header p  { font-size: .82rem; color: var(--text-muted); margin: 3px 0 0; }

@media (min-width: 576px) {
    .page-header h2 { font-size: 1.35rem; }
    .page-header p  { font-size: .85rem; }
}

@media (min-width: 992px) { .page-header h2 { font-size: 1.4rem; } }

/* Page header action area — stacks and stretches on mobile */
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

@media (min-width: 576px) {
    .page-header-actions { width: auto; }
}

.page-header-actions .btn,
.page-header-actions .form-select {
    flex: 1 1 auto;
}

@media (min-width: 576px) {
    .page-header-actions .btn        { flex: 0 0 auto; }
    .page-header-actions .form-select { flex: 0 0 auto; }
}

/* ── Attachment chip ─────────────────────────────────────── */
.attachment-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 20px;
    background: #f1f5f9; border: 1px solid var(--border-color);
    font-size: .75rem; color: var(--text-muted); text-decoration: none;
    transition: background .15s;
}
.attachment-chip:hover { background: #e2e8f0; color: var(--text-dark); }

/* ── Responsive grid ──────────────────────────────────────── */
/* Mobile-first: 1 column always, then expand */
.grid-cols-4,
.grid-cols-3,
.grid-cols-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 480px) {
    .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 576px) {
    .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-cols-2 { grid-template-columns: repeat(2, 1fr); gap: 14px; }
    .grid-cols-3, .grid-cols-4 { gap: 14px; }
}

@media (min-width: 992px) {
    .grid-cols-4 { grid-template-columns: repeat(4, 1fr); gap: 16px; }
    .grid-cols-3 { grid-template-columns: repeat(3, 1fr); gap: 16px; }
    .grid-cols-2 { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}

/* ── Detail panel (used in CuentasCobrar split view) ─────── */
.detail-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

/* ── Blazor error UI ──────────────────────────────────────── */
#blazor-error-ui {
    background: #450a0a; bottom: 0; box-shadow: 0 -1px 8px rgba(0,0,0,.2);
    color: #fef2f2; display: none; left: 0; padding: 10px 20px;
    position: fixed; right: 0; z-index: 9999; font-size: .85rem;
}
#blazor-error-ui .reload { color: #fca5a5; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 50%; transform: translateY(-50%); }
