/* =====================================================================
   Peculia — portal web
   Mismo lenguaje visual que la app móvil: verde ingreso, coral egreso,
   azul profundo de base. Móvil primero, con navegación inferior en
   pantallas chicas y lateral en escritorio.
   ===================================================================== */

:root {
  --green: #22C55E;
  --green-dark: #16A34A;
  --coral: #F43F5E;
  --amber: #F59E0B;
  --violet: #8B5CF6;
  --sky: #38BDF8;

  --bg: #0B1120;
  --bg-elevated: #111A2E;
  --card: #151F36;
  --card-alt: #1B2742;
  --border: #22304F;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --text-faint: #64748B;
  --primary-text: #04240F;
  --overlay: rgba(3, 7, 18, .72);

  --r-sm: 8px;  --r-md: 14px;  --r-lg: 20px;  --r-xl: 28px;  --r-pill: 999px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .28);
  --sidebar: 248px;
  --tabbar: 64px;
}

:root[data-theme="light"] {
  --bg: #F5F7FB;
  --bg-elevated: #FFFFFF;
  --card: #FFFFFF;
  --card-alt: #EEF2F9;
  --border: #DFE5EF;
  --text: #0F172A;
  --text-muted: #5A6782;
  --text-faint: #94A3B8;
  --primary-text: #FFFFFF;
  --overlay: rgba(15, 23, 42, .45);
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--green); text-decoration: none; }
svg { display: block; }

/* ---------------------------- utilidades --------------------------- */

.muted   { color: var(--text-muted); }
.faint   { color: var(--text-faint); }
.income  { color: var(--green); }
.expense { color: var(--coral); }
.center  { text-align: center; }
.right   { text-align: right; }
.hidden  { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }
.row     { display: flex; align-items: center; gap: 12px; }
.grow    { flex: 1; min-width: 0; }
.wrap    { display: flex; flex-wrap: wrap; gap: 8px; }
.stack   { display: flex; flex-direction: column; gap: 16px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 1.3rem;  font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 1.02rem; font-weight: 700; }
small { font-size: .82rem; }

.label {
  font-size: .69rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
}

/* ------------------------------ marca ------------------------------ */

.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 1.35rem; font-weight: 800; letter-spacing: -.03em; }
.brand-name span { color: var(--green); }

/* ---------------------------- componentes -------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
}
.card + .card { margin-top: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--r-md);
  font-weight: 700; font-size: .94rem;
  background: var(--green); color: var(--primary-text);
  border: 1px solid transparent;
  transition: filter .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.07); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--coral); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-sm { padding: 8px 14px; font-size: .84rem; border-radius: var(--r-sm); }

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; }
.control {
  display: flex; align-items: center; gap: 10px;
  background: var(--card-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 14px;
  transition: border-color .15s;
}
.control:focus-within { border-color: var(--green); }
.control.invalid { border-color: var(--coral); }
.control input, .control select, .control textarea {
  flex: 1; min-width: 0; background: none; border: none; outline: none;
  padding: 12px 0; font-size: .95rem;
}
.control textarea { resize: vertical; min-height: 76px; }
.control select { cursor: pointer; }
.control .icon { color: var(--text-faint); flex-shrink: 0; }
.field .error { color: var(--coral); font-size: .82rem; margin-top: 6px; display: block; }
.field .hint  { color: var(--text-faint); font-size: .82rem; margin-top: 6px; display: block; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--card-alt);
  color: var(--text-muted); font-size: .84rem; font-weight: 600;
  transition: .15s;
}
.chip:hover { border-color: var(--text-faint); }
.chip.active { border-color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.chip.active.expense-tone { border-color: var(--coral); background: color-mix(in srgb, var(--coral) 14%, transparent); color: var(--coral); }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: var(--r-pill);
  font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
}

.segmented {
  display: flex; gap: 4px; padding: 4px;
  background: var(--card-alt); border-radius: var(--r-md);
}
.segmented button {
  flex: 1; padding: 9px 12px; border-radius: var(--r-sm);
  font-size: .87rem; font-weight: 700; color: var(--text-muted);
}
.segmented button.active { background: var(--green); color: var(--primary-text); }
.segmented button.active.expense-tone { background: var(--coral); color: #fff; }

.divider { height: 1px; background: var(--border); margin: 4px 0; }

.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.avatar {
  width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0;
  display: grid; place-items: center;
}

.progress { height: 8px; border-radius: 4px; background: var(--card-alt); overflow: hidden; }
.progress > div { height: 100%; border-radius: 4px; transition: width .4s; }

.empty { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty .avatar { margin: 0 auto 12px; width: 64px; height: 64px; border-radius: 32px; background: var(--card-alt); }

.skeleton {
  background: linear-gradient(90deg, var(--card-alt) 25%, var(--border) 50%, var(--card-alt) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ------------------------------ layout ----------------------------- */

.auth-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: 24px 20px;
}
.auth-card { width: 100%; max-width: 420px; }
.auth-head { text-align: center; margin-bottom: 28px; }
.auth-head .brand { justify-content: center; margin-bottom: 8px; }

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

.sidebar {
  display: none;
  width: var(--sidebar); flex-shrink: 0;
  background: var(--bg-elevated); border-right: 1px solid var(--border);
  padding: 22px 14px; position: sticky; top: 0; height: 100vh;
  flex-direction: column; gap: 4px;
}
.sidebar .brand { padding: 0 10px 22px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: var(--r-md);
  color: var(--text-muted); font-weight: 600; font-size: .93rem;
  width: 100%; text-align: left;
}
.nav-item:hover { background: var(--card-alt); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.nav-item .count {
  margin-left: auto; background: var(--coral); color: #fff;
  border-radius: var(--r-pill); font-size: .7rem; padding: 1px 7px; font-weight: 700;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.content { padding: 18px; padding-bottom: calc(var(--tabbar) + 28px); max-width: 1180px; width: 100%; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; height: var(--tabbar);
  background: var(--bg-elevated); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-faint); font-size: .66rem; font-weight: 600; position: relative;
}
.tabbar button.active { color: var(--green); }
.tabbar .count {
  position: absolute; top: 6px; right: 50%; transform: translateX(18px);
  background: var(--coral); color: #fff; border-radius: var(--r-pill);
  font-size: .6rem; padding: 0 5px; font-weight: 700;
}

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar) + 18px); z-index: 31;
  width: 56px; height: 56px; border-radius: 28px;
  background: var(--green); color: var(--primary-text);
  display: grid; place-items: center;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--green) 45%, transparent);
}

/* --------------------------- rejilla KPIs -------------------------- */

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.kpi { background: var(--card-alt); border-radius: var(--r-md); padding: 14px; }
.kpi .value { font-size: 1.16rem; font-weight: 800; margin-top: 4px; }

.balance-value { font-size: 2.1rem; font-weight: 800; letter-spacing: -.03em; margin: 6px 0 2px; }

/* ------------------------------ tablas ----------------------------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
  text-align: left; padding: 10px 8px; white-space: nowrap;
  font-size: .68rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
}
td { padding: 11px 8px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }

/* ------------------------------ modal ------------------------------ */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: var(--overlay); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--bg-elevated); width: 100%; max-width: 520px;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 20px; max-height: 92vh; overflow-y: auto;
  box-shadow: var(--shadow); animation: slideUp .22s cubic-bezier(.2, .8, .3, 1);
}
@keyframes slideUp { from { transform: translateY(28px); opacity: .6; } }
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 14px; }

/* ------------------------------ toasts ----------------------------- */

.toasts {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 8px;
  width: min(440px, calc(100vw - 28px));
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-radius: var(--r-md);
  background: var(--card); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: .9rem;
  animation: drop .2s ease;
}
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } }
.toast.ok    { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--coral); }
.toast.info  { border-left: 4px solid var(--sky); }

/* --------------------------- escritorio ---------------------------- */

@media (min-width: 900px) {
  .sidebar { display: flex; }
  .tabbar, .fab, .topbar .menu-only { display: none; }
  .content { padding: 26px 32px; }
  .grid-2 { grid-template-columns: repeat(4, 1fr); }
  .dash-split { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; align-items: start; }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--r-xl); max-height: 88vh; }
  h1 { font-size: 2rem; }
}

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

/* --------------------------- accesibilidad -------------------------- */

:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .sidebar, .tabbar, .fab, .topbar { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; color: #000; }
}
