/* ============================================================
   FinZen — app.css
   Breakpoints: xs<390 | sm<640 | md<900 | lg<1200 | xl≥1200
   ============================================================ */

/* ── TOKENS ──────────────────────────────────────────────── */
:root {
  --bg:        #0d0f14;
  --surface:   #161921;
  --card:      #1c2030;
  --border:    #252a3a;
  --text:      #e2e8f0;
  --muted:     #7a869a;
  --accent:    #22c55e;
  --danger:    #f87171;
  --warning:   #fbbf24;
  --info:      #60a5fa;
  --purple:    #a78bfa;
  --font-h:    'Arial Rounded MT Bold', 'Nunito', ui-rounded, sans-serif;
  --font-b:    'Arial Rounded MT Bold', 'Nunito', ui-rounded, sans-serif;
  --radius:    12px;
  --radius-lg: 18px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
  --sidebar-w: 240px;
  --sidebar-collapsed: 64px;
  --topbar-h:  60px;
  --bn-h:      64px;

  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 14px;
  --text-lg:   clamp(14px,1.5vw,16px);
  --text-xl:   clamp(16px,2vw,20px);
  --text-2xl:  clamp(18px,2.5vw,24px);
  --text-3xl:  clamp(22px,3vw,30px);
}

/* ── LIGHT MODE ───────────────────────────────────────────── */
[data-theme="light"] {
  --bg:      #f1f5f9;
  --surface: #ffffff;
  --card:    #ffffff;
  --border:  #e2e8f0;
  --text:    #1e293b;
  --muted:   #64748b;
  --shadow:  0 4px 24px rgba(0,0,0,.08);
}

/* ── BASE ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: var(--font-b);
  font-size: var(--text-base);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}

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

/* ── LAYOUT ───────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: width .25s, transform .25s;
  overflow: hidden;
}

.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin-left .25s;
  display: flex;
  flex-direction: column;
}

/* Sidebar collapsed (lg: 900–1200px) */
.sidebar-collapsed {
  width: var(--sidebar-collapsed) !important;
}
.sidebar-collapsed .main-content,
.main-content.collapsed {
  margin-left: var(--sidebar-collapsed);
}
.sidebar-collapsed .nav-item span,
.sidebar-collapsed .sidebar-footer > div,
.sidebar-collapsed .sidebar-brand span {
  display: none;
}
.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 10px 0;
}
.sidebar-collapsed .nav-item i { margin: 0; }
.sidebar-collapsed .nav-item:hover::after {
  content: attr(data-label);
  position: absolute;
  left: calc(var(--sidebar-collapsed) + 8px);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 300;
}

/* ── TOPBAR ───────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-title {
  font-family: var(--font-h);
  font-size: var(--text-lg);
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.menu-btn, .theme-btn, .sidebar-toggle-btn, .logout-btn {
  width: 36px; height: 36px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.menu-btn:hover, .theme-btn:hover, .sidebar-toggle-btn:hover, .logout-btn:hover {
  background: var(--border);
  color: var(--text);
}

.btn-fab {
  width: 36px; height: 36px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter .15s;
}
.btn-fab:hover { filter: brightness(1.1); }

/* ── PAGE BODY ────────────────────────────────────────────── */
.page-body {
  padding: 20px;
  flex: 1;
}

/* ── SIDEBAR NAV ──────────────────────────────────────────── */
.sidebar-brand { flex-shrink: 0; overflow: hidden; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background .15s, color .15s;
  position: relative;
  white-space: nowrap;
}
.nav-item i { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--border); color: var(--text); }
.nav-item.active { background: rgba(34,197,94,.12); color: var(--accent); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
}

/* ── OVERLAY (móvil sidebar) ──────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 190;
}
.overlay.active { display: block; }

/* ── BOTTOM NAV (≤640px) ──────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 150;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-inner {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  height: var(--bn-h);
}
.bn-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  color: var(--muted);
  text-decoration: none;
  flex: 1;
  height: 100%;
  border: none;
  background: none;
  cursor: pointer;
  padding: 8px 0;
  transition: color .15s;
}
.bn-item i { width: 20px; height: 20px; }
.bn-item.active, .bn-item:hover { color: var(--accent); }

.bn-fab-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  font-size: 10px;
  color: var(--muted);
  flex: 1;
  height: 100%;
  border: none;
  background: none;
  cursor: pointer;
  padding-bottom: 8px;
}
.bn-fab-circle {
  width: 46px; height: 46px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  margin-bottom: -6px;
  box-shadow: 0 4px 12px rgba(34,197,94,.4);
}
.bn-fab-circle i { width: 22px; height: 22px; }

/* ── MOBILE DRAWER ────────────────────────────────────────── */
.mobile-drawer { display: none; }

.mobile-drawer.open { display: block; }

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 250;
}
.drawer-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  z-index: 260;
  padding: 12px 16px 24px;
  max-height: 80vh;
  overflow-y: auto;
}
.drawer-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.drawer-section {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
}
.drawer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.drawer-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 12px;
  background: var(--card);
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  text-align: center;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.drawer-item i { width: 20px; height: 20px; }
.drawer-item:hover, .drawer-item.active { background: var(--border); color: var(--text); }
.drawer-divider { height: 1px; background: var(--border); margin: 12px 0; }

/* ── CARDS ────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-title {
  font-family: var(--font-h);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 12px;
}
.mb-3 { margin-bottom: 16px; }
.mb-2 { margin-bottom: 10px; }

.section-title {
  font-family: var(--font-h);
  font-size: clamp(14px,2vw,16px);
  font-weight: 700;
  margin-bottom: 14px;
}

/* ── LAYOUT GRIDS ─────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

/* ── STATS GRID ───────────────────────────────────────────── */
.grid-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat-card { text-align: center; padding: 16px 12px; }
.stat-label {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}
.stat-val {
  font-family: var(--font-h);
  font-size: clamp(18px,2.5vw,24px);
  font-weight: 800;
  line-height: 1.1;
}
.stat-val.red,  .red  { color: var(--danger); }
.stat-val.green,.green{ color: var(--accent); }
.stat-val.yellow{ color: var(--warning); }

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: filter .15s, background .15s;
  min-height: 36px;
  white-space: nowrap;
}
.btn i { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-cancel {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 500;
  min-height: 36px;
}
.btn-cancel:hover { background: var(--border); }
.btn-save {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 700;
  min-height: 36px;
  transition: filter .15s;
}
.btn-save:hover { filter: brightness(1.1); }

/* ── FORMS ────────────────────────────────────────────────── */
label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 5px;
  margin-top: 12px;
}
label:first-child { margin-top: 0; }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=color],
select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
input::placeholder { color: var(--muted); }
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.input-big {
  font-size: 24px !important;
  font-family: var(--font-h) !important;
  font-weight: 700 !important;
  text-align: center;
  padding: 14px !important;
}

/* ── MODALS ───────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 400;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }

.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-box--wide { max-width: 680px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 {
  font-family: var(--font-h);
  font-weight: 700;
  font-size: 16px;
}
.modal-header > button {
  width: 30px; height: 30px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.modal-header > button:hover { background: var(--border); color: var(--text); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── TABLES ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; min-width: 500px; }
thead { background: var(--bg); }
th {
  padding: 10px 12px;
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 11px 12px;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg); }

.tx-monto {
  font-family: var(--font-h);
  font-size: var(--text-base);
  font-weight: 700;
  white-space: nowrap;
}
.cuenta-saldo {
  font-family: var(--font-h);
  font-size: clamp(18px,3vw,22px);
  font-weight: 800;
  color: #fff;
}
.deuda-monto {
  font-family: var(--font-h);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--danger);
}
.meta-pct { font-family: var(--font-h); font-weight: 700; color: var(--purple); white-space: nowrap; }

/* ── PROGRESS BARS ────────────────────────────────────────── */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width .4s;
}
.progress-fill.ok  { background: var(--accent); }
.progress-fill.warn{ background: var(--warning); }
.progress-fill.bad { background: var(--danger); }

/* ── BADGES ───────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: .03em;
}
.badge-green { background: rgba(34,197,94,.15); color: var(--accent); }
.badge-red   { background: rgba(248,113,113,.15); color: var(--danger); }
.badge-yellow{ background: rgba(251,191,36,.15); color: var(--warning); }

/* ── EMPTY STATE ──────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--muted);
  text-align: center;
  gap: 8px;
}
.empty-state i { opacity: .3; width: 40px; height: 40px; }
.empty-state p { font-size: var(--text-sm); }

/* ── TIPO TABS ────────────────────────────────────────────── */
.tipo-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}
.tipo-tab {
  flex: 1;
  padding: 7px 6px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tipo-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

/* ── LOGIN PAGE ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { margin-bottom: 16px; }
.login-sub  { font-size: var(--text-sm); color: var(--muted); margin-bottom: 24px; }
.login-title {
  font-family: var(--font-h);
  font-size: var(--text-2xl);
  font-weight: 800;
  margin-bottom: 6px;
}
.btn-login {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 10px;
  font-size: var(--text-lg);
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-h);
  transition: filter .15s;
  margin-top: 16px;
}
.btn-login:hover { filter: brightness(1.1); }

/* ── UTILITIES ────────────────────────────────────────────── */
.flex          { display: flex; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.font-bold     { font-family: var(--font-h); font-weight: 700; }
.text-muted    { color: var(--muted); }
.text-danger   { color: var(--danger); }
.text-accent   { color: var(--accent); }
.text-warning  { color: var(--warning); }
.gap-2         { gap: 8px; }

/* ── RESPONSIVE ───────────────────────────────────────────── */

/* lg: 900–1199px → sidebar colapsado, sin bottom nav */
@media (max-width: 1199px) and (min-width: 901px) {
  .sidebar { width: var(--sidebar-collapsed); }
  .main-content { margin-left: var(--sidebar-collapsed); }
  .nav-item span, .sidebar-footer > div { display: none; }
  .nav-item { justify-content: center; padding: 10px 0; }
  .sidebar-toggle-btn { display: none; }
  .menu-btn { display: none; }
}

/* md: ≤900px → sidebar oculto, sin bottom nav aún */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    z-index: 210;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; }
  .sidebar-toggle-btn { display: none; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .grid-3     { grid-template-columns: 1fr; }
  .form-grid  { grid-template-columns: 1fr; }
}

/* pantallas de altura reducida (laptops ≤800px alto) */
@media (max-height: 800px) {
  .modal-box { max-height: 96vh; }
  .modal { padding: 10px; }
}

/* sm: ≤640px → bottom nav, bottom-sheet modals */
@media (max-width: 640px) {
  .bottom-nav { display: block; }
  .btn-fab    { display: none; }
  .page-body  { padding: 12px 12px calc(var(--bn-h) + 12px + env(safe-area-inset-bottom,0)); }

  .modal { align-items: flex-end; padding: 0; }
  .modal-box {
    border-radius: 22px 22px 0 0;
    max-height: 92vh;
    max-width: 100%;
    border-bottom: none;
  }

  input, select, textarea { font-size: 16px !important; } /* prevent iOS zoom */
  .btn, .btn-save, .btn-cancel, .btn-login { min-height: 44px; }

  .grid-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .grid-2     { grid-template-columns: 1fr; }
  .grid-3     { grid-template-columns: 1fr; }

  .col-hide-mobile { display: none !important; }

  .topbar { padding: 0 14px; }
  .page-title { font-size: 15px; }
}

/* xs: <390px */
@media (max-width: 389px) {
  .grid-stats { grid-template-columns: 1fr 1fr; }
  .login-box { padding: 24px 18px; }
  .drawer-grid { grid-template-columns: repeat(3, 1fr); }
}
