/* ============================================================
   Sistema de Ingresos y Egresos — Hoja de estilos
   Paleta: fondo neutro frío, sidebar verde-tinta profundo,
   verde esmeralda para ingresos, coral para egresos.
   Tipografía: Space Grotesk (títulos) + Inter (texto) +
   JetBrains Mono (cifras, estilo "libro contable").
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600;700&display=swap');

:root {
    --bg: #f4f6f5;
    --surface: #ffffff;
    --surface-muted: #eef1f0;
    --border: #e1e6e4;
    --text: #16211d;
    --text-muted: #5b6b64;

    --tinta: #0e2a24;
    --tinta-2: #163b32;
    --tinta-text: #dce9e4;

    --ingreso: #1f9d6b;
    --ingreso-bg: #e5f7ee;
    --egreso: #e2574c;
    --egreso-bg: #fdeceb;
    --saldo: #1f6f9d;

    --radius: 10px;
    --radius-lg: 16px;
    --shadow: 0 1px 2px rgba(14, 42, 36, 0.06), 0 4px 16px rgba(14, 42, 36, 0.05);
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .font-display { font-family: var(--font-display); letter-spacing: -0.01em; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.cifra, .money, table td.money { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

:focus-visible {
    outline: 2px solid var(--saldo);
    outline-offset: 2px;
}

/* ============ LAYOUT ============ */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--tinta) 0%, var(--tinta-2) 100%);
    color: var(--tinta-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 40;
    transition: transform 0.25s ease;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar__brand-mark {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: var(--ingreso);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-mono); font-weight: 700; color: #fff; font-size: 15px;
}

.sidebar__brand-text { font-family: var(--font-display); font-weight: 600; font-size: 16px; color: #fff; line-height: 1.2; }
.sidebar__brand-text small { display: block; font-family: var(--font-body); font-weight: 400; font-size: 11px; color: rgba(255,255,255,0.55); }

.sidebar__nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.sidebar__section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: rgba(255,255,255,0.4); padding: 14px 10px 6px; }

.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px;
    border-radius: 9px;
    font-size: 14px; font-weight: 500;
    color: rgba(255,255,255,0.78);
    margin-bottom: 2px;
    transition: background 0.15s ease, color 0.15s ease;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.12); color: #fff; }
.nav-link.active svg { opacity: 1; color: var(--ingreso); }

.sidebar__user {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 14px 18px;
    display: flex; align-items: center; gap: 10px;
}
.sidebar__user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: rgba(255,255,255,0.1);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px; color: #fff;
}
.sidebar__user-info { flex: 1; min-width: 0; }
.sidebar__user-info strong { display: block; font-size: 13px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-info span { font-size: 11px; color: rgba(255,255,255,0.5); text-transform: capitalize; }
.sidebar__logout { color: rgba(255,255,255,0.55); }
.sidebar__logout:hover { color: var(--egreso); }

.main {
    margin-left: 250px;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 62px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-family: var(--font-display); font-size: 18px; font-weight: 600; }
.topbar__menu-btn { display: none; background: none; border: none; padding: 6px; }
.topbar__menu-btn svg { width: 22px; height: 22px; }

.content { padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(14,42,36,0.45); z-index: 39; }

/* ============ COMPONENTES ============ */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.card__header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card__header h2, .card__header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.card__body { padding: 20px; }

.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.kpi--ingreso::before { background: var(--ingreso); }
.kpi--egreso::before { background: var(--egreso); }
.kpi--saldo::before { background: var(--saldo); }
.kpi__label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi__value { font-family: var(--font-mono); font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi--ingreso .kpi__value { color: var(--ingreso); }
.kpi--egreso .kpi__value { color: var(--egreso); }
.kpi--saldo .kpi__value { color: var(--saldo); }
.kpi__hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge--ingreso { background: var(--ingreso-bg); color: var(--ingreso); }
.badge--egreso { background: var(--egreso-bg); color: var(--egreso); }
.badge--activo { background: var(--ingreso-bg); color: var(--ingreso); }
.badge--inactivo { background: var(--surface-muted); color: var(--text-muted); }
.badge--admin { background: #eaf1fb; color: var(--saldo); }
.badge--usuario { background: var(--surface-muted); color: var(--text-muted); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px;
    border-radius: 9px;
    font-size: 14px; font-weight: 600;
    border: 1px solid transparent;
    transition: filter 0.15s ease, background 0.15s ease;
    white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { filter: brightness(0.95); }
.btn-primary { background: var(--tinta); color: #fff; }
.btn-ingreso { background: var(--ingreso); color: #fff; }
.btn-egreso { background: var(--egreso); color: #fff; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-muted); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { background: var(--egreso); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-group { margin-bottom: 4px; display: flex; flex-direction: column; gap: 6px; }
.form-group--full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; color: var(--text); }
label .req { color: var(--egreso); }

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=search], select, textarea {
    font-family: var(--font-body);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 14px;
    color: var(--text);
    width: 100%;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--saldo);
    box-shadow: 0 0 0 3px rgba(31,111,157,0.12);
}
textarea { resize: vertical; min-height: 70px; }
.hint { font-size: 12px; color: var(--text-muted); }
.error-text { font-size: 12.5px; color: var(--egreso); font-weight: 500; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; }

.filters-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 18px; }
.filters-bar .form-group { min-width: 150px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    text-align: left; padding: 10px 14px;
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em;
    white-space: nowrap;
}
thead th:first-child { border-radius: 8px 0 0 8px; }
thead th:last-child { border-radius: 0 8px 8px 0; }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-muted); }
td.money { font-weight: 600; text-align: right; }
td.money.ingreso { color: var(--ingreso); }
td.money.egreso { color: var(--egreso); }
.acciones-col { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); }
.icon-btn:hover { background: var(--surface-muted); color: var(--text); }
.icon-btn svg { width: 15px; height: 15px; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state svg { width: 42px; height: 42px; margin-bottom: 10px; opacity: 0.35; }
.empty-state p { margin: 4px 0 0; font-size: 14px; }

.alert { padding: 12px 16px; border-radius: 9px; font-size: 13.5px; font-weight: 500; margin-bottom: 18px; display: flex; align-items: center; gap: 10px; }
.alert-exito { background: var(--ingreso-bg); color: #146c48; }
.alert-error { background: var(--egreso-bg); color: #a53229; }

.paginacion { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 16px 20px; border-top: 1px solid var(--border); }
.paginacion__info { font-size: 13px; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.btn.disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.pill-tabs { display: inline-flex; background: var(--surface-muted); border-radius: 9px; padding: 3px; gap: 2px; }
.pill-tabs a { padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.pill-tabs a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ============ LOGIN ============ */

.login-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: var(--tinta);
    background-image: radial-gradient(circle at 20% 20%, rgba(31,157,107,0.18), transparent 40%),
                       radial-gradient(circle at 85% 80%, rgba(31,111,157,0.18), transparent 40%);
    padding: 20px;
}
.login-card {
    width: 100%; max-width: 380px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    padding: 34px 30px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-brand .sidebar__brand-mark { width: 42px; height: 42px; font-size: 18px; }
.login-brand h1 { font-size: 19px; margin: 0; }
.login-brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-muted); }
.login-footer { margin-top: 20px; text-align: center; font-size: 12px; color: var(--text-muted); }

/* ============ RESPONSIVE ============ */

@media (max-width: 960px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.abierto { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.3); }
    .main { margin-left: 0; }
    .topbar__menu-btn { display: inline-flex; align-items: center; }
    .sidebar-overlay.abierto { display: block; }
    .content { padding: 16px; }
    .filters-bar { flex-direction: column; align-items: stretch; }
    .filters-bar .form-group { min-width: 0; }
    thead { display: none; }
    table, tbody, tr, td { display: block; width: 100%; }
    tbody tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 4px; background: var(--surface); }
    tbody td { border-bottom: none; display: flex; justify-content: space-between; gap: 12px; padding: 7px 12px; text-align: right; }
    tbody td::before { content: attr(data-label); font-weight: 600; color: var(--text-muted); font-size: 12px; text-align: left; }
    td.money { text-align: right; }
    .acciones-col { justify-content: flex-end; }
}
