/* ============================================================
   UI/UX Profesional - Gastos de Violetta
   ============================================================ */
:root {
  --violeta: #7c4dff;
  --violeta-osc: #5e35b1;
  --rosa: #ff4d94;
  --texto: #2b2b36;
  --gris: #757585;
  --fondo: #f8f9fc;
  --card: #ffffff;
  --borde: #ebebf2;
  --ok: #10b981;
  --ok-bg: #d1fae5;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 8px 24px rgba(124, 77, 255, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- SCROLLBAR ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--fondo); }
::-webkit-scrollbar-thumb { background: #d1d1d1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gris); }

/* ---------- TOPBAR ---------- */
.topbar {
  background: var(--card);
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 100;
  flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 1.3rem; color: var(--violeta); letter-spacing: -0.5px; }
.menu { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.menu a {
  text-decoration: none; color: var(--gris);
  padding: 8px 16px; border-radius: 12px; font-weight: 600; font-size: 0.95rem;
  transition: all 0.2s ease;
}
.menu a:hover { background: var(--fondo); color: var(--violeta); }
.menu a.active { background: rgba(124, 77, 255, 0.1); color: var(--violeta); }
.user-area { display: flex; align-items: center; gap: 16px; }
.user-name { font-weight: 500; font-size: 0.95rem; color: var(--gris); }

/* ---------- CONTENEDOR & TARJETAS ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 32px 20px 80px; }
.page-title { font-size: 1.7rem; font-weight: 800; margin-bottom: 24px; color: var(--texto); letter-spacing: -0.5px; }
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; margin-bottom: 24px; }
.page-head .page-title { margin-bottom: 0; }

.card {
  background: var(--card); border-radius: 20px;
  padding: 24px; margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--borde);
  transition: box-shadow 0.3s ease;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 18px; color: var(--texto); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media(max-width:800px){ .grid-2 { grid-template-columns: 1fr; } }

/* ---------- STATS ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
@media(max-width:800px){ .stats-grid { grid-template-columns: 1fr 1fr; } }
.stat-card {
  padding: 20px; border-radius: 18px; color: #fff;
  position: relative; overflow: hidden;
}
.stat-card::after { /* Efecto brillo */
  content: ''; position: absolute; top: 0; right: 0; width: 100px; height: 100%;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0) 100%);
  transform: skewX(-20deg) translateX(150px); transition: 0.5s;
}
.stat-card:hover::after { transform: skewX(-20deg) translateX(-150px); }
.stat-blue { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.stat-purple { background: linear-gradient(135deg, var(--violeta), var(--violeta-osc)); }
.stat-green { background: linear-gradient(135deg, #10b981, #059669); }
.stat-orange { background: linear-gradient(135deg, #f59e0b, #ea580c); }
.stat-label { font-size: 0.85rem; font-weight: 500; opacity: 0.9; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 1.6rem; font-weight: 800; margin-top: 8px; letter-spacing: -0.5px; }

/* ---------- FORMULARIOS UI ---------- */
.form-card { max-width: 680px; margin: 0 auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media(max-width:600px){ .form-row { grid-template-columns: 1fr; } }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 0.9rem; color: var(--texto); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 12px 16px; border: 1.5px solid var(--borde);
  border-radius: 12px; font-size: 1rem; font-family: inherit; 
  background: var(--fondo); color: var(--texto);
  transition: all 0.2s ease;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--violeta); background: var(--card);
  box-shadow: 0 0 0 4px rgba(124, 77, 255, 0.1);
}
.file-input-wrapper { position: relative; overflow: hidden; display: inline-block; width: 100%; }

/* ---------- BOTONES ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer; padding: 12px 20px; border-radius: 12px; 
  font-size: 0.95rem; font-weight: 700; text-decoration: none; 
  transition: all 0.2s ease; color: var(--texto); background: var(--borde);
}
.btn:hover { filter: brightness(0.95); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--violeta); color: #fff; box-shadow: 0 4px 12px rgba(124, 77, 255, 0.25); }
.btn-primary:hover { background: var(--violeta-osc); filter: brightness(1); }
.btn-danger { background: var(--error-bg); color: var(--error); }
.btn-danger:hover { background: #fecaca; }
.btn-block { width: 100%; margin-top: 10px; padding: 14px; font-size: 1.05rem; }
.btn-small { padding: 6px 14px; font-size: 0.85rem; border-radius: 8px; }

/* ---------- TABLAS Y BADGES ---------- */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; }
.tabla { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.95rem; }
.tabla th, .tabla td { padding: 14px 12px; text-align: left; border-bottom: 1px solid var(--borde); vertical-align: middle; }
.tabla th { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gris); background: var(--fondo); }
.tabla th:first-child { border-top-left-radius: 12px; }
.tabla th:last-child { border-top-right-radius: 12px; }
.tabla .right { text-align: right; }
.tabla tbody tr { transition: background 0.2s; }
.tabla tbody tr:hover { background: var(--fondo); }
.obs { max-width: 200px; font-size: 0.85rem; color: var(--gris); line-height: 1.4; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 10px; border: 1px solid var(--borde); transition: transform 0.2s; }
.thumb:hover { transform: scale(1.1); }

/* Badges de métodos de pago */
.badge { padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.b-efectivo { background: #d1fae5; color: #047857; }
.b-tarjeta { background: #dbeafe; color: #1d4ed8; }
.b-transfer { background: #f3e8ff; color: #7e22ce; }
.b-mama { background: #ffedd5; color: #c2410c; }

/* ---------- ALERTAS Y ESTADOS VACÍOS ---------- */
.alert { padding: 14px 18px; border-radius: 12px; margin-bottom: 20px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #a7f3d0; }
.alert-error { background: var(--error-bg); color: var(--error); border: 1px solid #fecaca; }
.empty-state { text-align: center; padding: 40px 20px; }
.empty-icon { font-size: 3rem; display: block; margin-bottom: 10px; opacity: 0.5; }

/* ---------- PRESUPUESTOS (BARRAS) ---------- */
.presupuestos-lista { display: flex; flex-direction: column; gap: 16px; }
.presupuesto-item { padding-bottom: 12px; border-bottom: 1px solid var(--borde); }
.presupuesto-item:last-child { border-bottom: none; padding-bottom: 0; }
.presupuesto-head { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.95rem; }
.presupuesto-cat { font-weight: 600; color: var(--texto); }
.progress-bg { background: var(--fondo); height: 8px; border-radius: 4px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,0.05); }
.progress-bar { height: 100%; border-radius: 4px; transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1); }
.presupuesto-total-foot { margin-top: 20px; padding-top: 16px; border-top: 2px dashed var(--borde); font-size: 1.1rem; }

/* ---------- FILTROS ---------- */
.filtros { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 16px; align-items: end; }
@media(max-width:800px){ .filtros { grid-template-columns: 1fr 1fr; } }
@media(max-width:500px){ .filtros { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; align-items: flex-end; }
.filtros .form-group { margin-bottom: 0; }
.resultado-total { margin-bottom: 16px; font-size: 1rem; color: var(--texto); font-weight: 500; }
.muted { color: var(--gris); font-size: 0.9rem; }
.footer { text-align: center; padding: 24px; border-top: 1px solid var(--borde); background: var(--card); }

/* ============================================================
   MODO OSCURO AUTOMÁTICO
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0f172a;
    --card: #1e293b;
    --texto: #f8fafc;
    --borde: #334155;
    --gris: #94a3b8;
    --ok-bg: rgba(16, 185, 129, 0.15); 
    --error-bg: rgba(239, 68, 68, 0.15);
    --shadow-sm: 0 4px 12px rgba(0,0,0,0.3);
  }
  .tabla th { background: #0f172a; color: #cbd5e1; }
  .tabla tbody tr:hover { background: #334155; }
  .btn { background: #334155; color: #fff; }
  
  /* Ajuste de badges para modo oscuro */
  .b-efectivo { background: rgba(4, 120, 87, 0.3); color: #34d399; }
  .b-tarjeta { background: rgba(29, 78, 216, 0.3); color: #60a5fa; }
  .b-transfer { background: rgba(126, 34, 206, 0.3); color: #c084fc; }
  .b-mama { background: rgba(194, 65, 12, 0.3); color: #fb923c; }
}

/* ============================================================
   NAVEGACIÓN MÓVIL APP-LIKE
   ============================================================ */
.bottom-nav { display: none; }

@media (max-width: 760px) {
  .topbar { padding: 12px 16px; }
  .topbar nav.menu { display: none; }
  .user-name { display: none; } /* Ocultar nombre para ahorrar espacio */
  .user-area { margin-left: auto; }
  
  .container { padding: 20px 16px 100px; }
  .footer { margin-bottom: 75px; }
  
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; width: 100%;
    background: var(--card); border-top: 1px solid var(--borde);
    padding: 12px 8px calc(12px + env(safe-area-inset-bottom));
    justify-content: space-around; z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  }
  
  .bottom-nav a {
    color: var(--gris); text-decoration: none;
    font-size: 1.5rem; padding: 10px 24px;
    border-radius: 16px; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative; display: flex; justify-content: center;
  }
  
  .bottom-nav a.active {
    color: var(--violeta); background: rgba(124, 77, 255, 0.1);
    transform: translateY(-4px);
  }
}