/* ============================================
   PISOS · VallaReforma
   Paleta: ladrillo cálido + crema + tinta oscura
   Tipografía: Fraunces (titulares) + Inter (UI) + IBM Plex Mono (cifras)
   ============================================ */

:root {
  --cream: #0f172a;
  --cream-deep: #1e293b;
  --ink: #e2e8f0;
  --ink-soft: #94a3b8;
  --ink-faint: #64748b;
  --brick: #38bdf8;
  --brick-deep: #0ea5e9;
  --brick-pale: #1e3a5f;
  --olive: #4ade80;
  --olive-pale: #1a3a1a;
  --emerald-soft: #22c55e;
  --emerald-pale: #163322;
  --sand: #eab308;
  --sand-pale: #2a2a1a;
  --rosewood: #f97316;
  --rosewood-pale: #3b1a0a;
  --slate-accent: #94a3b8;
  --slate-accent-pale: #334155;
  --line: #334155;
  --line-soft: #1e293b;
  --white: #0f172a;
  --danger: #ef4444;
  --danger-strong: #f87171;
  --danger-pale: #3b1212;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.24), 0 10px 28px rgba(0, 0, 0, 0.22);
  --shadow-pop: 0 16px 44px rgba(0, 0, 0, 0.46);

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

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

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

body {
  font-family: var(--font-body);
  background: #0f172a;
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

::selection { background: var(--gold-pale); color: var(--ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid var(--cream); }

.loading-screen {
  height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--ink);
}
.loading-mark {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.4em;
  color: var(--cream);
  opacity: 0.7;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 0.35; } 50% { opacity: 0.85; } }

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

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: #1e293b;
  color: var(--ink);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid #334155;
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.02);
}

.brand {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--ink);
}
.brand-dot { color: var(--brick); font-size: 22px; }
.brand-sub {
  font-size: 11px;
  color: var(--slate-accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 28px;
}

.nav-section { margin-bottom: 24px; }
.nav-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6f7a8c;
  margin-bottom: 10px;
  padding: 0 12px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 13px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 500;
  color: #b9c1cf;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: #334155; color: var(--ink); border-color: #334155; transform: translateX(1px); }
.nav-item.active { background: #1e3a5f; color: #38bdf8; border-color: #38bdf8; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03); }
.nav-item .nav-ic { width: 16px; text-align: center; opacity: 0.9; font-family: var(--font-mono); font-size: 12px; }

.nav-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.nav-user {
  font-size: 12.5px;
  color: #8b95a7;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #141a24;
  border: 1px solid #232b38;
  border-radius: 12px;
}
.logout-btn {
  background: none; border: none; color: #aeb7c4;
  font-size: 12px; text-decoration: none; cursor: pointer;
}
.logout-btn:hover { color: #fff; }

.main {
  flex: 1;
  min-width: 0;
  padding: 36px 44px 80px;
  max-width: 1180px;
}

.mobile-topbar { display: none; }
.mobile-tabbar { display: none; }

@media (max-width: 880px) {
  .sidebar { display: none; }
  .main { padding: 20px 16px 100px; max-width: 100%; }
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20;
    background: rgba(15,17,21,0.92); padding: 14px 16px;
    border-bottom: 1px solid var(--line-soft);
    margin: -20px -16px 20px;
    backdrop-filter: blur(8px);
  }
  .mobile-topbar .brand { font-size: 18px; margin-bottom: 0; }
  .mobile-tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: rgba(23,28,37,0.96); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(0,0,0,0.28);
    backdrop-filter: blur(8px);
  }
  .mobile-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: none; padding: 6px 2px;
    font-size: 10.5px; color: var(--ink-faint); font-weight: 500;
  }
  .mobile-tab.active { color: #f1f5f9; }
  .mobile-tab .tab-ic { font-family: var(--font-mono); font-size: 15px; }
  .fab {
    position: fixed; right: 16px; bottom: 78px; z-index: 31;
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--brick); color: var(--white); border: none;
    font-size: 24px; box-shadow: var(--shadow-pop);
    display: flex; align-items: center; justify-content: center;
  }
}

.page-eyebrow {
  font-size: 12px; color: var(--slate-accent); margin-bottom: 2px;
  text-transform: capitalize;
}
.page-title {
  font-family: var(--font-display);
  font-size: 30px; font-weight: 600; letter-spacing: -0.02em;
  margin-bottom: 4px;
  line-height: 1.1;
  color: var(--rosewood);
}
.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 26px; flex-wrap: wrap; gap: 14px;
}
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink-soft); cursor: pointer;
  margin-bottom: 6px; background: none; border: none; padding: 0;
}
.back-link:hover { color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent;
  transition: transform 0.06s ease, background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: #38bdf8; color: #0f172a; box-shadow: 0 10px 24px rgba(56,189,248,0.22); }
.btn-primary:hover { background: #0ea5e9; }
.btn-brick { background: #f97316; color: #0f172a; box-shadow: 0 10px 24px rgba(249,115,22,0.22); }
.btn-brick:hover { background: #ea580c; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { border-color: var(--brick); color: var(--ink); }
.btn-danger-text { background: transparent; border: none; color: var(--danger); font-weight: 500; font-size: 13px; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.stat-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-bottom: 22px;
}
@media (max-width: 700px) { .stat-grid { grid-template-columns: 1fr 1fr; } }
.stat-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-md); padding: 17px 18px;
  box-shadow: var(--shadow-card);
}
.stat-label { font-size: 11.5px; color: #9fb0c7; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-family: var(--font-mono); font-size: 24px; font-weight: 500; letter-spacing: -0.02em; color: var(--ink); }
.stat-value.positive { color: #7ed8b7; }
.stat-value.income { color: var(--sand); }
.stat-value.negative { color: var(--danger-strong); }
.stat-value.monthly-purple { color: #c084fc; }
.stat-value.warn { color: var(--rosewood); }
.stat-subvalue { margin-top: 6px; font-size: 12px; color: var(--sand); }

.alert-bar {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, rgba(47,38,22,0.96) 0%, rgba(36,29,18,0.96) 100%); border: 1px solid rgba(226,187,111,0.22);
  border-radius: var(--radius-md); padding: 11px 16px;
  margin-bottom: 22px; cursor: pointer; font-size: 13px; color: #f3d48a;
}
.alert-bar:hover { filter: brightness(0.98); }
.alert-bar .alert-arrow { margin-left: auto; opacity: 0.6; }

.prop-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
@media (max-width: 700px) { .prop-grid { grid-template-columns: 1fr; } }
.prop-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-lg); padding: 18px 20px;
  cursor: pointer; transition: border-color 0.12s ease, transform 0.08s ease, box-shadow 0.12s ease;
  box-shadow: var(--shadow-card);
}
.prop-card:hover { border-color: var(--brick); transform: translateY(-2px); box-shadow: 0 16px 34px rgba(0,0,0,0.28); }
.prop-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.prop-name { font-family: var(--font-display); font-size: 19px; font-weight: 600; line-height: 1.15; color: var(--brick); }
.prop-meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; }
.tag {
  font-size: 10.5px; font-weight: 600; padding: 4px 9px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
}
.tag-olive { background: var(--olive-pale); color: var(--olive); }
.tag-gold { background: #1e3a5f; color: #38bdf8; }
.tag-brick { background: var(--rosewood-pale); color: var(--rosewood); }
.prop-card-metrics {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px 0 14px;
}
.metric-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.prop-card-bottom {
  display: flex; justify-content: space-between; font-size: 13px;
  border-top: 1px solid var(--line-soft); padding-top: 12px;
}
.prop-card-bottom .label, .metric-line .label { color: #9fb0c7; }
.prop-card-bottom .val, .metric-line .val { font-family: var(--font-mono); font-weight: 500; color: #dfe8f5; }
.metric-line .val.in { color: var(--sand); }
.metric-line .beneficio-mensual { color: var(--ink) !important; }
.prop-card-bottom .val.in { color: var(--emerald-soft); }
.metric-line .val.out, .prop-card-bottom .val.out { color: var(--danger-strong); }

.prop-summary-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-lg);
  padding: 18px 18px 8px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-card);
}
.prop-summary-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--line);
  margin-bottom: 22px; overflow-x: auto;
}
.tab-btn {
  background: none; border: none; padding: 10px 14px;
  font-size: 13.5px; font-weight: 500; color: var(--ink-soft);
  border-bottom: 2px solid transparent; white-space: nowrap;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--ink); border-bottom-color: var(--brick); font-weight: 600; }
.tab-btn:hover:not(.active) { color: var(--ink); }

.list { display: flex; flex-direction: column; gap: 8px; }
.row-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-md); padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
}
.row-card:hover { border-color: var(--brick); }
.row-card.dashed { border-style: dashed; cursor: pointer; }
.row-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(180deg, rgba(201,139,46,0.24) 0%, rgba(94,67,23,0.3) 100%); color: #f1d199;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.avatar.empty { background: transparent; border: 1.5px dashed var(--line); color: var(--ink-faint); }
.row-title { font-size: 14.5px; font-weight: 600; line-height: 1.25; color: var(--ink); }
.row-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; line-height: 1.35; }
.row-amount { font-family: var(--font-mono); font-size: 14px; font-weight: 500; white-space: nowrap; }
.row-amount.in { color: var(--olive); }
.row-amount.out { color: var(--danger-strong); }

.mov-row { padding: 11px 14px; }
.mov-cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.field-label {
  display: block; font-size: 11.5px; font-weight: 700; color: #a2b0c4;
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em;
}
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 11px 13px;
  border: 1px solid #3a485c; border-radius: 12px;
  background: #141b25; font-size: 14px; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brick);
  box-shadow: 0 0 0 3px rgba(197,100,88,0.18);
}
textarea { resize: vertical; min-height: 70px; }

.type-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.type-toggle button {
  flex: 1; padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid #364356; background: var(--white);
  font-size: 13.5px; font-weight: 600; color: var(--ink-soft);
}
.type-toggle button.active.gasto { background: var(--danger-pale); border-color: var(--danger); color: var(--danger-strong); }
.type-toggle button.active.ingreso { background: var(--olive-pale); border-color: var(--olive); color: var(--olive); }

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip {
  font-size: 12.5px; padding: 6px 12px; border-radius: 20px;
  border: 1px solid #364356; background: var(--white); color: var(--ink-soft);
}
.chip.selected { background: linear-gradient(180deg, #cf776b 0%, var(--brick) 100%); border-color: rgba(197,100,88,0.38); color: #fff4f2; font-weight: 700; }
.chip.add-chip { border-style: dashed; color: var(--ink-faint); }

.hint-text { font-size: 11.5px; color: var(--ink-faint); margin-bottom: 14px; display: flex; gap: 5px; align-items: center; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-top: 1px solid var(--line-soft); margin-bottom: 14px;
}
.switch-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #98a7ba; }
.switch { width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; border: none; flex-shrink: 0; }
.switch.on { background: var(--olive); }
.switch-knob { width: 18px; height: 18px; background: var(--white); border-radius: 50%; position: absolute; top: 2px; left: 2px; transition: left 0.15s ease; }
.switch.on .switch-knob { left: 18px; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.58);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.sheet {
  background: #121924; border: 1px solid #364356;
  border-radius: var(--radius-lg);
  width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto;
  padding: 22px 22px 24px; box-shadow: var(--shadow-pop);
}
.sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.sheet-title { font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.sheet-close { background: none; border: none; font-size: 18px; color: var(--ink-faint); padding: 4px; }
.sheet-close:hover { color: var(--ink); }

@media (max-width: 600px) {
  .overlay { align-items: flex-end; padding: 0; }
  .sheet { max-width: 100%; border-radius: 18px 18px 0 0; max-height: 92vh; }
}

.empty-state {
  text-align: center; padding: 50px 20px; color: var(--ink-faint);
}
.empty-state .em-title { font-family: var(--font-display); font-size: 16px; color: var(--ink-soft); margin-bottom: 4px; }
.empty-state .em-sub { font-size: 13px; }

.badge-fianza { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px; }
.badge-fianza.pendiente { background: var(--gold-pale); color: #8A6A1E; }
.badge-fianza.devuelta { background: var(--olive-pale); color: var(--olive); }
.badge-fianza.vivo { background: var(--olive-pale); color: var(--olive); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0b0e13; color: var(--ink); padding: 11px 20px;
  border: 1px solid var(--line); border-radius: 30px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-pop); z-index: 100;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity:0; transform: translateX(-50%) translateY(8px);} to {opacity:1; transform: translateX(-50%) translateY(0);} }

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--ink); padding: 20px;
}
.login-card {
  background: #121924; border: 1px solid #364356; border-radius: var(--radius-lg); padding: 36px 32px;
  width: 100%; max-width: 360px; box-shadow: var(--shadow-pop);
}
.login-brand { font-family: var(--font-display); font-size: 28px; font-weight: 600; margin-bottom: 6px; text-align: center; letter-spacing: -0.02em; }
.login-sub { font-size: 13px; color: var(--ink-soft); text-align: center; margin-bottom: 28px; }
.login-error { background: var(--brick-pale); color: #ffb4a1; font-size: 13px; padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; }

details.cat-group summary { cursor: pointer; list-style: none; }
details.cat-group summary::-webkit-details-marker { display: none; }
.cat-summary-row { display: flex; align-items: center; justify-content: space-between; }
.cat-summary-row .chev { transition: transform 0.15s ease; color: var(--ink-faint); }
details[open] .chev { transform: rotate(90deg); }
.cat-line {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 0; font-size: 13px; border-top: 1px solid var(--line-soft);
}
.cat-line:first-of-type { border-top: 1px solid var(--line-soft); margin-top: 10px; }

.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-select {
  padding: 7px 10px; border-radius: var(--radius-sm); border: 1px solid #3a485c;
  background: var(--white); font-size: 12.5px; color: var(--ink);
}

.spinner-inline {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: var(--white);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
