@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:wght@300;400;500&display=swap');

:root {
  --c0: #ffffff;
  --c1: #f9f6f2;
  --c2: #f0ebe3;
  --c3: #e0d5c5;
  --c4: #c4b49a;
  --c5: #8c7355;
  --c6: #5c4a32;
  --c7: #3a2e1e;
  --c8: #1e1a12;
  --accent: #c17f3e;
  --accent-l: #f5e6d0;
  --green: #4a7c59;
  --green-l: #e8f2ec;
  --red: #9c3a3a;
  --red-l: #faeaea;
  --gold: #b8860b;
  --gold-l: #fef9e7;
  --blue: #2d5f8a;
  --blue-l: #e8f0f8;
  --shadow-sm: 0 1px 3px rgba(30,26,18,0.06);
  --shadow: 0 4px 16px rgba(30,26,18,0.08);
  --shadow-lg: 0 12px 40px rgba(30,26,18,0.12);
  --r: 12px;
  --r-lg: 20px;
  --font-scale: 1;
}

/* Tamaño de letra (portal) */
html[data-font-size="large"] { --font-scale: 1.12; }
html[data-font-size="xlarge"] { --font-scale: 1.24; }

html[data-font-size="large"],
html[data-font-size="xlarge"] {
  font-size: calc(14px * var(--font-scale));
}

/* Modo oscuro */
html[data-theme="dark"] {
  color-scheme: dark;
  --c0: #1e1b17;
  --c1: #161310;
  --c2: #252019;
  --c3: #3a3228;
  --c4: #5c4f3d;
  --c5: #a89880;
  --c6: #d4c9b8;
  --c7: #f0ebe3;
  --c8: #faf6f0;
  --accent-l: #3d2e1e;
  --green-l: #1e3328;
  --red-l: #3d2222;
  --gold-l: #3d3518;
  --blue-l: #1a2a3d;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.35);
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
}

html[data-theme="dark"] body {
  color: var(--c8);
}

html[data-theme="dark"] .hero-card,
html[data-theme="dark"] .finanzas-hero {
  background: linear-gradient(135deg, #2a241c 0%, #1a1612 100%);
}

html[data-theme="dark"] .modal-pago,
html[data-theme="dark"] #modal-pagar .modal.modal-pago {
  background: var(--c0) !important;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--c1);
  color: var(--c8);
  border-color: var(--c3);
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--c1);
  color: var(--c8);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4 { font-family: 'DM Serif Display', serif; font-weight: 400; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: 8px;
  font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.2s; text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--c7); color: white; }
.btn-primary:hover { background: var(--c6); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: #a86c30; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--c6); border: 1.5px solid var(--c3); }
.btn-ghost:hover { background: var(--c2); border-color: var(--c4); }
.btn-sm { padding: 7px 14px; font-size: 12px; border-radius: 7px; }
.btn-lg { padding: 14px 32px; font-size: 15px; border-radius: 10px; }
.btn-green { background: var(--green); color: white; }
.btn-green:hover { background: #3a6347; }

/* PILLS */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 500;
}
.pill-green { background: var(--green-l); color: var(--green); }
.pill-red { background: var(--red-l); color: var(--red); }
.pill-gold { background: var(--gold-l); color: var(--gold); }
.pill-blue { background: var(--blue-l); color: var(--blue); }
.pill-gray { background: var(--c2); color: var(--c5); }
.pill-accent { background: var(--accent-l); color: var(--accent); }

/* CARDS */
.card {
  background: var(--c0); border-radius: var(--r);
  border: 1px solid var(--c3); box-shadow: var(--shadow-sm);
}
.card-p { padding: 24px; }

/* INPUTS */
input, select, textarea {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--c3); border-radius: 8px;
  font-family: 'DM Sans', sans-serif; font-size: 14px; color: var(--c8);
  background: var(--c0); outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(193,127,62,0.1);
}
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 11px; font-weight: 500; letter-spacing: 0.8px; text-transform: uppercase; color: var(--c5); margin-bottom: 6px; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(30,26,18,0.4);
  display: none; align-items: center; justify-content: center;
  z-index: 999; backdrop-filter: blur(6px); padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--c0); border-radius: var(--r-lg); padding: 36px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); animation: modalIn 0.25s ease;
}
@keyframes modalIn { from { opacity:0; transform:translateY(12px) scale(0.98); } to { opacity:1; transform:none; } }
.modal h3 { font-size: 24px; color: var(--c7); margin-bottom: 6px; }
.modal .modal-sub { font-size: 13px; color: var(--c5); margin-bottom: 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* GRID HELPERS */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; }

/* TABLE */
.table-wrap { background: var(--c0); border-radius: var(--r); border: 1px solid var(--c3); overflow: hidden; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--c7); }
thead th { padding: 12px 16px; text-align: left; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--c3); font-weight: 500; font-family: 'DM Sans', sans-serif; }
tbody tr { border-bottom: 1px solid var(--c2); transition: background 0.15s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--c1); }
td { padding: 13px 16px; font-size: 13px; }

/* SECTION HEADER */
.section-hdr { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-hdr h3 { font-size: 20px; color: var(--c7); }

/* DIVIDER */
.divider { height: 1px; background: var(--c2); margin: 24px 0; }

/* TOAST */
.toast {
  position: fixed; bottom: 32px; right: 32px;
  background: var(--c7); color: white;
  padding: 14px 24px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow-lg);
  transform: translateY(20px); opacity: 0;
  transition: all 0.3s; z-index: 9999;
  display: flex; align-items: center; gap: 10px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--green); }
.toast.celebration { background: var(--accent); }

/* NIVEL BADGES */
.nivel-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 14px; border-radius: 20px; font-size: 12px; font-weight: 500;
}
.nivel-nuevo { background: var(--c2); color: var(--c5); }
.nivel-rigel { background: var(--blue-l); color: var(--blue); }
.nivel-comprometido { background: var(--green-l); color: var(--green); }
.nivel-ejemplar { background: var(--gold-l); color: var(--gold); }
.nivel-embajador { background: linear-gradient(135deg, #fef9e7, #fff8e1); color: var(--gold); border: 1px solid rgba(184,134,11,0.3); }

/* PROGRESS BAR */
.progress-bar { height: 6px; background: var(--c2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.8s ease; }

/* ANIMATIONS */
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }
@keyframes pop { 0% { transform:scale(0.8); opacity:0; } 70% { transform:scale(1.1); } 100% { transform:scale(1); opacity:1; } }
@keyframes confetti { 0% { transform:translateY(-10px) rotate(0deg); opacity:1; } 100% { transform:translateY(60px) rotate(360deg); opacity:0; } }
.fade-in { animation: fadeIn 0.4s ease forwards; }
.pop { animation: pop 0.4s ease forwards; }

/* Preferencias UI */
.pref-toggle-group { display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
.pref-toggle-btn {
  padding:8px 14px; border-radius:8px; font-size:13px; font-weight:500;
  border:1.5px solid var(--c3); background:var(--c0); color:var(--c6);
  cursor:pointer; font-family:'DM Sans',sans-serif;
}
.pref-toggle-btn.active {
  border-color:var(--accent); background:var(--accent-l); color:var(--accent);
}
.prefs-sheet {
  position:fixed; left:0; right:0; bottom:0; z-index:200;
  background:var(--c0); border-radius:18px 18px 0 0;
  padding:16px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow:0 -8px 32px rgba(0,0,0,0.2);
  max-height:70vh; overflow-y:auto;
}
.prefs-overlay {
  position:fixed; inset:0; z-index:199;
  background:rgba(0,0,0,0.45);
}
body.prefs-open { overflow:hidden; }

@media(max-width:640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}
