:root {
  --bg: #000000;
  --card: #1c1c1e;
  --text: #ffffff;
  --subtext: #8e8e93;
  --border: #2c2c2e;
  --accent: #0a84ff;
  --danger: #ff453a;
  --success: #32d74b;
  --modal-bg: rgba(30, 30, 30, 0.98);
  --group-bg: rgba(120, 120, 128, 0.12);
  --ios-ease: cubic-bezier(0.32, 0.72, 0, 1);
  --content-width: 96%; 
  --max-width: 1200px; 
}

body.light {
  --bg: #f2f2f7;      
  --card: #ffffff;    
  --text: #000000;    
  --subtext: #8e8e93; 
  --border: #e5e5ea;  
  --modal-bg: rgba(255, 255, 255, 0.98);
  --group-bg: rgba(120, 120, 128, 0.08); 
}

* { box-sizing: border-box; font-family: 'Inter', sans-serif; -webkit-tap-highlight-color: transparent; }
body { 
  margin: 0; 
  background: var(--bg); 
  color: var(--text); 
  
  /* Agrega esto para proteger la parte de abajo en móviles */
  padding-bottom: calc(40px + env(safe-area-inset-bottom)); 
  
  transition: background 0.3s, color 0.3s; 
}

/* LOGIN SCREEN (NUEVO) */
.login-screen {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s;
    opacity: 1; visibility: visible;
}
.login-screen.hidden { opacity: 0; visibility: hidden; }
.login-box { width: 90%; max-width: 350px; text-align: center; }
.login-input {
    width: 100%; padding: 15px; margin-bottom: 10px;
    border-radius: 12px; border: 1px solid var(--border);
    background: var(--card); color: var(--text);
    font-size: 1rem; outline: none;
}

/* ESTILOS PIN PAD */
.btn-numpad {
    width: 65px; height: 65px; border-radius: 50%;
    background: rgba(120,120,128,0.1); color: var(--text);
    border: none; font-size: 1.5rem; font-weight: 500;
    cursor: pointer; transition: background 0.2s;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto;
}
.btn-numpad:active { background: var(--text); color: var(--bg); }
.pin-dot.active { background: var(--text) !important; }

/* ANIMACIONES BASE */
@keyframes fadeInSlide { 
    from { opacity: 0; transform: translateY(20px) scale(0.98); } 
    to { opacity: 1; transform: translateY(0) scale(1); } 
}
.anim-fade-in { 
    animation: fadeInSlide 0.6s cubic-bezier(0.32, 0.72, 0, 1) forwards; 
    opacity: 0; 
}

/* Busca esta sección en tu style.css y reemplázala */

header.sticky { 
  position: sticky; 
  top: 0; 
  background: rgba(0,0,0,0.85); /* Un poco más oscuro para legibilidad */
  backdrop-filter: blur(20px); 
  -webkit-backdrop-filter: blur(20px); 
  z-index: 50; 
  border-bottom: 1px solid var(--border); 
  
  /* --- ESTA ES LA MAGIA PARA IPHONE Y ANDROID --- */
  padding-top: env(safe-area-inset-top); 
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

body.light header.sticky { 
  background: rgba(255,255,255,0.9); 
}
.header-content { width: var(--content-width); max-width: var(--max-width); margin: 0 auto; padding: 1rem 0; display: flex; justify-content: space-between; align-items: center; }
h1 { font-size: 1.5rem; margin: 0; font-weight: 700; }
.header-controls { display: flex; gap: 12px; align-items: center; }

main { width: var(--content-width); max-width: var(--max-width); margin: 0 auto; padding-top: 1.5rem; }

.apple-date-wrapper { position: relative; background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 6px 16px; font-weight: 500; font-size: 0.95rem; cursor: pointer; display: flex; align-items: center; justify-content: center; user-select: none; transition: background 0.3s; z-index:10;}
.apple-date-wrapper input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; z-index: 10; cursor: pointer; }
.icon-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text); padding: 5px; } 

.resumen { display: grid; grid-template-columns: 1fr; gap: 1rem; padding: 0; margin-bottom: 1.5rem; }
@media(min-width: 800px) { .resumen { grid-template-columns: 1fr 1fr; } }

.balance-hero { 
  grid-column: 1 / -1; 
  background: linear-gradient(135deg, #0a84ff, #5e5ce6); 
  border: none; color: #ffffff !important; 
  display: flex; flex-direction: row; align-items: center; justify-content: space-between; 
  padding: 1.8rem 2rem; border-radius: 24px; 
  box-shadow: 0 8px 25px rgba(10, 132, 255, 0.3); min-height: 120px;
}
.balance-info { display: flex; flex-direction: column; text-align: left; position: relative; }
.balance-hero span, .balance-hero strong, 
body.light .balance-hero span, body.light .balance-hero strong { color: #ffffff !important; }
.balance-hero span { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 5px; opacity: 0.9; }
.balance-hero strong { font-size: 2.5rem; line-height: 1; }
.balance-chart { width: 70px; height: 70px; position: relative; }

.balance-warning {
    background: rgba(255, 204, 0, 0.25);
    color: #ffd60a !important;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 214, 10, 0.5);
    display: inline-block;
    width: fit-content;
    margin-bottom: 8px;
    animation: slideDownFade 0.3s ease-out;
}
@keyframes slideDownFade { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

.mini-card { background: var(--card); padding: 1.2rem; border-radius: 20px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--border); transition: background 0.3s; }
.text-green { color: var(--success); } .text-red { color: var(--danger); }

.acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; padding: 0; margin-bottom: 1.5rem; }
@media(max-width: 500px) { .acciones { gap: 10px; } }
.btn-ios { width: 100%; height: 50px; border-radius: 14px; border: none; font-weight: 600; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.1s; }
.btn-ios:active { transform: scale(0.96); opacity: 0.8; }
.btn-gasto { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-ingreso { background: var(--text); color: var(--bg); }

.cards { display: flex; flex-direction: column; gap: 1.5rem; padding: 0; padding-bottom: 1.5rem; }
@media(min-width: 800px) { .cards { display: grid; grid-template-columns: 1fr 1fr; align-items: stretch; } }
.card { background: var(--card); border-radius: 20px; border: 1px solid var(--border); overflow: hidden; transition: background 0.3s; display: flex; flex-direction: column;}
.card-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); background: rgba(120,120,128,0.05); }
.card-header h2 { margin: 0; font-size: 1.1rem; }
.table-container { flex-grow: 1; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--subtext); font-size: 0.8rem; padding: 1rem 1rem; text-transform: uppercase; letter-spacing: 0.5px; }
td { padding: 1.1rem 1rem; border-bottom: 1px solid var(--border); font-size: 1rem; vertical-align: middle; transition: background 0.2s; }
tr:last-child td { border-bottom: none; }
tr:active td { background-color: rgba(120,120,128,0.1); }

.th-action { width: 70px; text-align: right; }
.actions-cell { display: flex; gap: 4px; justify-content: flex-end; align-items: center; padding-right: 0.5rem; }
.action-btn { background: transparent; border: none; width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--subtext); padding: 0; transition: background 0.2s; flex-shrink: 0; }
.action-btn:hover { background: rgba(120,120,128,0.15); color: var(--text); }
.action-btn.del:hover { background: rgba(255, 69, 58, 0.15); color: var(--danger); }
.action-btn svg { width: 18px; height: 18px; display: block; stroke-width: 2; }

/* MODALES */
.modal { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; z-index: 100; visibility: hidden; transition: visibility 0.3s, opacity 0.3s; opacity: 0;}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); opacity: 0; transition: opacity 0.3s var(--ios-ease); }
.modal-box { background: var(--modal-bg); width: 100%; max-width: 450px; border-radius: 24px 24px 0 0; padding: 1.8rem; transform: translateY(100%); transition: transform 0.4s var(--ios-ease); box-shadow: 0 -10px 40px rgba(0,0,0,0.2); }
.modal.show-modal { visibility: visible; opacity: 1; }
.modal.show-modal .modal-backdrop { opacity: 1; }
.modal.show-modal .modal-box { transform: translateY(0); }
@media(min-width: 600px) { .modal { align-items: center; } .modal-box { border-radius: 24px; width: 400px; transform: scale(0.95); opacity: 0; transition: all 0.3s var(--ios-ease);} .modal.show-modal .modal-box { transform: scale(1); opacity: 1; } }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.close-btn { background: rgba(120,120,128,0.15); border: none; width: 30px; height: 30px; border-radius: 50%; color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; transition: background 0.2s;}

.stepper-container { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2rem; padding: 0 5px; gap: 20px; }
.stepper-btn { width: 55px; height: 55px; border-radius: 50%; border: none; background: rgba(255,255,255,0.15); color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: transform 0.1s; flex-shrink: 0; }
body.light .stepper-btn { background: rgba(0,0,0,0.06); color: #000; } 
.stepper-btn:active { transform: scale(0.9); }

.main-input { flex-grow: 1; display: flex; justify-content: center; align-items: center; }
.main-input input { background: transparent; border: none; font-size: 3.5rem; color: var(--text); width: 100%; text-align: center; outline: none; font-weight: 700; }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.form-body { background: var(--group-bg); border-radius: 14px; overflow: hidden; margin-bottom: 1.5rem; }
.input-row { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem; border-bottom: 1px solid rgba(120,120,128,0.1); }
body.light .input-row { border-bottom: 1px solid rgba(0,0,0,0.06); }
.input-row select, .input-row input { background: transparent; border: none; text-align: left; color: var(--accent); font-size: 1rem; outline: none;}

.full-width { width: 100%; margin-top: 0.5rem; background: var(--accent); color: white; border: none; padding: 1.1rem; font-size: 1.1rem; border-radius: 14px; font-weight: 600; cursor: pointer; transition: transform 0.1s; }
.full-width:active { transform: scale(0.98); opacity: 0.9; }
.hidden { display: none; }

.detail-amount { text-align: center; margin-bottom: 2rem; }
.detail-amount span { font-size: 2.5rem; font-weight: 700; display: block; }
.detail-amount small { font-size: 0.9rem; color: var(--subtext); text-transform: uppercase; }
.detail-list { background: var(--group-bg); border-radius: 16px; overflow: hidden; margin-bottom: 2rem; }
.detail-row { display: flex; align-items: center; padding: 1rem; border-bottom: 1px solid rgba(120,120,128,0.15); }
body.light .detail-row { border-bottom: 1px solid rgba(0,0,0,0.06); }
.detail-row:last-child { border-bottom: none; }
.icon-sq { width: 36px; height: 36px; background: rgba(120,120,128,0.3); border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-right: 12px; }
body.light .icon-sq { background: rgba(120,120,128,0.15); } 
.det-text { display: flex; flex-direction: column; }
.det-text label { font-size: 0.8rem; color: var(--subtext); }
.det-text span { font-size: 1rem; font-weight: 500; }

.confirm-box { text-align: center; }
.confirm-actions { display: flex; gap: 10px; margin-top: 1.5rem; }
.confirm-actions button { flex: 1; }
.btn-ios.danger { background: var(--danger); color: white; border:none;}
.btn-ios.secondary { background: rgba(120,120,128,0.2); color: var(--text); border:none;}
body.light .btn-ios.secondary { background: rgba(120,120,128,0.1); }

.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px); background: #ff453a; color: white; padding: 12px 24px; border-radius: 16px; transition: 0.4s; z-index: 3000; }
.toast.show { transform: translateX(-50%) translateY(0); }

/* UTILIDADES EXTRAS */
.budget-container { margin-top: 15px; width: 100%; max-width: 250px; }
.budget-bar { background: rgba(255,255,255,0.2); height: 6px; border-radius: 3px; overflow: hidden; }
.budget-fill { background: #32d74b; height: 100%; width: 0%; transition: width 1s ease; }
.search-wrapper { background: var(--card); border-radius: 14px; padding: 12px; border: 1px solid var(--border); margin: 10px 0; }
.search-wrapper input { background: transparent; border: none; color: var(--text); width: 100%; outline: none; }
.export-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 1.5rem; padding-bottom: 2rem; }
#chartCategorias { max-height: 250px; }

/* TITULOS Y LISTAS */
.section-label { margin: 15px 0 8px 15px; display: block; }
.section-label small { color: var(--subtext); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.5px; }
.empty-state-row { justify-content: center; color: var(--subtext); padding: 1.5rem; font-size: 0.9rem; }
.input-right { text-align: right; color: var(--accent); }
.input-day { width: 23%; text-align: center; }
.vertical-sep { width: 1px; height: 20px; background: var(--border); margin: 0 10px; }
.select-category { width: 60%; text-align: right; direction: rtl; -webkit-appearance: none; appearance: none; background: transparent; color: var(--accent); font-weight: 500; cursor: pointer; }

/* FIJOS / LISTA */
.fijo-row { padding: 0.9rem 1.1rem; display: flex; justify-content: space-between; align-items: center; }
.fijo-info { display: flex; flex-direction: column; gap: 3px; }
.fijo-name { font-weight: 500; color: var(--text); font-size: 1rem; }
.fijo-details { font-size: 0.8rem; color: var(--subtext); }
.text-danger { color: var(--danger) !important; }
.fijo-actions { display: flex; align-items: center; gap: 12px; }
.badge-pagado { font-size: 0.75rem; color: var(--success); font-weight: 600; }
.btn-pay { background: var(--accent); color: white; border: none; padding: 6px 14px; border-radius: 14px; font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: transform 0.1s; }
.btn-pay:active { transform: scale(0.95); }
.btn-del { background: none; border: none; color: var(--subtext); font-size: 1.4rem; padding: 0; cursor: pointer; display: flex; align-items: center; line-height: 1; }
.btn-del:hover { color: var(--danger); }

/* METAS */
.metas-scroll-container { display: flex; gap: 15px; overflow-x: auto; padding: 5px 2px 15px 2px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.metas-scroll-container::-webkit-scrollbar { display: none; }
.meta-card { background: var(--card); min-width: 260px; border-radius: 18px; padding: 18px; border: 1px solid var(--border); box-shadow: 0 4px 10px rgba(0,0,0,0.03); display: flex; flex-direction: column; justify-content: space-between; position: relative; transition: transform 0.2s; cursor: pointer; }
.meta-card:active { transform: scale(0.98); }
.meta-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 15px; }
.meta-icon { font-size: 2rem; background: var(--group-bg); width: 45px; height: 45px; display: flex; align-items: center; justify-content: center; border-radius: 12px; }
.meta-info h4 { margin: 0 0 5px 0; font-size: 1rem; color: var(--text); }
.meta-info small { color: var(--subtext); font-size: 0.8rem; }
.meta-progress-bg { height: 8px; background: var(--group-bg); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.meta-progress-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.6s ease; }
.meta-footer { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; font-weight: 600; color: var(--text); }

/* PRIVACIDAD */
.blur-hidden { color: transparent !important; text-shadow: 0 0 8px rgba(255, 255, 255, 0.8); user-select: none; cursor: default; transition: all 0.3s ease; }
#balance.blur-hidden { color: transparent !important; text-shadow: 0 0 12px rgba(255, 255, 255, 1); }
body.light .blur-hidden { text-shadow: 0 0 8px rgba(0, 0, 0, 0.4); }
body.light #balance.blur-hidden { text-shadow: 0 0 12px rgba(255, 255, 255, 1); }

/* Item de categoría en gestión */
.cat-item { display:flex; justify-content:space-between; align-items:center; padding:10px; border-bottom:1px solid rgba(120,120,128,0.1); }
.cat-item:last-child { border-bottom:none; }

/* FIX Z-INDEX PARA MODAL APILADO */
#modalAbonar { z-index: 2000 !important; }
#modalAbonar .modal-backdrop { background: rgba(0,0,0,0.7); }