/* ── Variables ──────────────────────────────────────────────── */
:root {
  --accent:       #0066FF;
  --accent-light: rgba(0,102,255,.1);
  --accent-dark:  #0052CC;
  --green:        #00B37D;
  --green-light:  rgba(0,179,125,.1);
  --red:          #E53935;
  --red-light:    rgba(229,57,53,.1);
  --orange:       #F59E0B;
  --orange-light: rgba(245,158,11,.1);
  --purple:       #7C3AED;
  --purple-light: rgba(124,58,237,.1);

  --bg:        #F5F7FA;
  --bg2:       #FFFFFF;
  --bg3:       #F0F2F5;
  --bg4:       #E4E7EC;

  --text:      #0D1117;
  --text2:     #4B5563;
  --text3:     #9CA3AF;
  --text4:     #D1D5DB;

  --border:    rgba(0,0,0,0.07);
  --border2:   rgba(0,0,0,0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow:    0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.12);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --sidebar-w: 240px;
  --header-h:  56px;
  --nav-h:     64px; /* bottom nav móvil */
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;

  /* safe areas iOS */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

[data-theme="dark"] {
  --bg:     #0D1117;
  --bg2:    #161B22;
  --bg3:    #1C2128;
  --bg4:    #242B35;
  --text:   #E6EDF3;
  --text2:  #8B949E;
  --text3:  #484F58;
  --text4:  #30363D;
  --border:  rgba(255,255,255,.06);
  --border2: rgba(255,255,255,.10);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow:    0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100%;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; }
a { text-decoration: none; color: inherit; cursor: pointer; }
img, svg { display: block; }

/* ── Auth ───────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: max(1.5rem, var(--safe-top)) 1.25rem max(1.5rem, var(--safe-bottom));
  background: var(--bg);
}
.auth-container { width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 2rem; }
.auth-logo { display: inline-flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: .5rem; }
.auth-tagline { font-size: 13px; color: var(--text3); }
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-xl);
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow);
}
.auth-banner { display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 1.25rem; line-height: 1.4; }
.auth-banner.setup   { background: var(--accent-light); color: var(--accent-dark); }
.auth-banner.warning { background: var(--orange-light); color: #92400E; }
.auth-banner.error   { background: var(--red-light);    color: #991B1B; }
.auth-banner svg     { flex-shrink: 0; margin-top: 1px; }
.auth-tabs { display: flex; background: var(--bg3); border-radius: var(--radius); padding: 3px; margin-bottom: 1.5rem; gap: 3px; }
.auth-tab { flex: 1; padding: 9px; font-size: 13px; font-weight: 500; border: none; background: none; border-radius: 7px; cursor: pointer; color: var(--text2); transition: all .15s; }
.auth-tab.active { background: var(--bg2); color: var(--text); box-shadow: var(--shadow-sm); }
.auth-fields { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1.25rem; }
.btn-auth {
  width: 100%; padding: 13px;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-auth:hover { opacity: .88; }
.btn-auth:disabled { opacity: .5; cursor: not-allowed; }
.auth-version { text-align: center; margin-top: 1.5rem; font-size: 11px; color: var(--text3); }

/* ── App layout ─────────────────────────────────────────────── */
#mainApp { display: flex; height: 100dvh; overflow: hidden; }

/* Sidebar oculto por defecto en móvil — CRÍTICO */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .sidebar.open {
    display: flex !important;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 40;
    width: min(280px, 85vw);
    box-shadow: var(--shadow-lg);
  }
}

/* ── Sidebar (desktop) ──────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1rem; border-bottom: 1px solid var(--border); }
.sidebar-logo { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 700; color: var(--text); }
.sidebar-close { display: none; background: none; border: none; cursor: pointer; color: var(--text2); padding: 6px; border-radius: var(--radius-sm); -webkit-tap-highlight-color: transparent; }
.sidebar-nav { flex: 1; padding: .75rem .75rem 0; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; color: var(--text2);
  cursor: pointer; transition: all .12s;
  border: none; background: none; width: 100%; text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover  { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent-light); color: var(--accent); }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }
.nav-item svg    { flex-shrink: 0; opacity: .65; }
.admin-link      { color: var(--purple) !important; }
.admin-link svg  { stroke: var(--purple) !important; opacity: 1 !important; }
.admin-link:hover, .admin-link.active { background: var(--purple-light) !important; }
.sidebar-footer { padding: .75rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.sidebar-user { display: flex; align-items: center; gap: 9px; padding: 8px 10px; margin-top: 4px; }
.sidebar-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-light); color: var(--accent); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info span { display: block; font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-plan { font-size: 10px !important; color: var(--text3) !important; font-weight: 400 !important; text-transform: uppercase; letter-spacing: .05em; }
.logout-btn { background: none; border: none; cursor: pointer; color: var(--text3); padding: 6px; flex-shrink: 0; transition: color .15s; border-radius: var(--radius-sm); -webkit-tap-highlight-color: transparent; }
.logout-btn:hover { color: var(--red); }

/* Profile selector */
.profile-selector { padding: .75rem; border-bottom: 1px solid var(--border); position: relative; }
.profile-current { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius); cursor: pointer; text-align: left; transition: all .12s; -webkit-tap-highlight-color: transparent; }
.profile-current:hover { background: var(--bg4); }
.profile-icon { font-size: 18px; flex-shrink: 0; line-height: 1; }
.profile-info { flex: 1; min-width: 0; }
.profile-name { display: block; font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-type { display: block; font-size: 10px; color: var(--text3); text-transform: capitalize; }
.profile-chevron { flex-shrink: 0; color: var(--text3); transition: transform .15s; }
.profile-menu { position: absolute; top: calc(100% - .25rem); left: .75rem; right: .75rem; background: var(--bg2); border: 1px solid var(--border2); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 100; padding: .5rem; }
.profile-menu-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text2); transition: all .1s; -webkit-tap-highlight-color: transparent; }
.profile-menu-item:hover { background: var(--bg3); color: var(--text); }
.profile-menu-item.active { background: var(--accent-light); color: var(--accent); }
.profile-add-btn { display: flex; align-items: center; gap: 6px; width: 100%; padding: 8px; border: none; background: none; border-top: 1px solid var(--border); margin-top: .25rem; padding-top: .625rem; cursor: pointer; font-size: 12px; color: var(--text3); font-weight: 500; transition: color .1s; -webkit-tap-highlight-color: transparent; }
.profile-add-btn:hover { color: var(--accent); }

/* ── Mobile header ──────────────────────────────────────────── */
.mobile-header {
  display: none;
  height: var(--header-h);
  padding-top: var(--safe-top);
  height: calc(var(--header-h) + var(--safe-top));
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding-left: max(1rem, var(--safe-left));
  padding-right: max(1rem, var(--safe-right));
  align-items: flex-end;
  padding-bottom: 0;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 30;
}
.mobile-header-inner { display: flex; align-items: center; justify-content: space-between; width: 100%; height: var(--header-h); }
.menu-btn { background: none; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius); color: var(--text); -webkit-tap-highlight-color: transparent; }
.mobile-logo { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; color: var(--text); }
.mobile-profile-icon { font-size: 22px; cursor: pointer; line-height: 1; }

/* Overlay sidebar móvil */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }

/* ── Bottom navigation (móvil) ──────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 30;
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.bottom-nav-inner { display: flex; align-items: stretch; height: var(--nav-h); }
.bnav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; cursor: pointer; color: var(--text3);
  font-size: 10px; font-weight: 500;
  border: none; background: none;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
  padding: 0 2px;
}
.bnav-item svg   { opacity: .6; transition: opacity .15s; }
.bnav-item.active { color: var(--accent); }
.bnav-item.active svg { opacity: 1; stroke: var(--accent); }
.bnav-more { position: relative; }

/* More menu (bottom nav) */
.more-menu {
  position: fixed; bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
  left: 50%; transform: translateX(-50%);
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: .5rem; z-index: 50; min-width: 200px;
}
.more-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; color: var(--text2);
  cursor: pointer; border: none; background: none; width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.more-menu-item:hover, .more-menu-item.active { background: var(--bg3); color: var(--accent); }
.more-menu-item.active { color: var(--accent); }
.more-menu-item.admin-item { color: var(--purple); }
.more-menu-item.admin-item:hover { background: var(--purple-light); }

/* FAB — botón flotante nuevo movimiento */
.fab {
  display: none;
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  right: max(16px, var(--safe-right));
  width: 52px; height: 52px;
  background: var(--accent); color: white;
  border: none; border-radius: 50%;
  box-shadow: 0 4px 16px rgba(0,102,255,.4);
  cursor: pointer; z-index: 31;
  align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: scale(.93); box-shadow: 0 2px 8px rgba(0,102,255,.3); }

/* ── Main content ───────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.view { display: none; padding: 1.75rem 2rem; max-width: 1100px; margin: 0 auto; }
.view.active { display: block; }

/* ── Common components ──────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.75rem; flex-wrap: wrap; gap: 1rem; }
.page-title    { font-size: 22px; font-weight: 700; }
.page-subtitle { font-size: 13px; color: var(--text3); margin-top: 2px; }

.card    { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow-sm); }
.card-sm { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);    padding: 1.25rem; box-shadow: var(--shadow-sm); }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; position: relative; overflow: hidden; box-shadow: var(--shadow-sm); }
.kpi-card::before { content:''; position:absolute; top:0; left:0; right:0; height:3px; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.kpi-card.income::before  { background: var(--green); }
.kpi-card.expense::before { background: var(--red); }
.kpi-card.balance::before { background: var(--accent); }
.kpi-card.savings::before { background: var(--orange); }
.kpi-label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .5rem; display: flex; align-items: center; gap: 5px; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -.4px; line-height: 1.1; }
.kpi-value.positive { color: var(--green); }
.kpi-value.negative { color: var(--red); }
.kpi-delta { font-size: 11px; color: var(--text3); margin-top: 4px; }
.kpi-delta.up   { color: var(--green); }
.kpi-delta.down { color: var(--red); }

/* Buttons */
.btn-primary   { display:inline-flex; align-items:center; gap:6px; padding:9px 18px; background:var(--accent); color:#fff; border:none; border-radius:var(--radius); font-size:13px; font-weight:600; cursor:pointer; transition:opacity .15s; letter-spacing:.01em; -webkit-tap-highlight-color:transparent; }
.btn-primary:hover { opacity:.88; }
.btn-secondary { display:inline-flex; align-items:center; gap:6px; padding:8px 16px; background:var(--bg3); color:var(--text); border:1px solid var(--border2); border-radius:var(--radius); font-size:13px; font-weight:500; cursor:pointer; transition:background .12s; -webkit-tap-highlight-color:transparent; }
.btn-secondary:hover { background:var(--bg4); }
.btn-ghost     { display:inline-flex; align-items:center; gap:6px; padding:8px 16px; background:none; color:var(--text2); border:none; border-radius:var(--radius); font-size:13px; font-weight:500; cursor:pointer; transition:background .12s; -webkit-tap-highlight-color:transparent; }
.btn-ghost:hover { background:var(--bg3); }
.btn-danger    { display:inline-flex; align-items:center; gap:6px; padding:8px 16px; background:var(--red-light); color:var(--red); border:1px solid rgba(229,57,53,.2); border-radius:var(--radius); font-size:13px; font-weight:500; cursor:pointer; -webkit-tap-highlight-color:transparent; }
.btn-icon      { display:inline-flex; align-items:center; justify-content:center; width:32px; height:32px; background:var(--bg3); border:1px solid var(--border2); border-radius:var(--radius-sm); cursor:pointer; color:var(--text2); transition:all .12s; -webkit-tap-highlight-color:transparent; }
.btn-icon:hover { background:var(--bg4); color:var(--text); }
.btn-icon.danger:hover { background:var(--red-light); color:var(--red); border-color:transparent; }
.btn-row { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }

/* Form elements */
.field-wrap { display:flex; flex-direction:column; gap:5px; }
.field-wrap.full { grid-column:1/-1; }
.field-wrap label { font-size:12px; font-weight:600; color:var(--text2); }
.label-hint { font-weight:400; color:var(--text3); }

input[type=text], input[type=number], input[type=date],
input[type=password], input[type=email], select, textarea {
  width:100%; padding:11px 13px;
  background:var(--bg3); border:1px solid var(--border2); border-radius:var(--radius);
  font-size:15px; color:var(--text); outline:none;
  transition:border-color .15s, box-shadow .15s;
  -webkit-appearance:none; appearance:none;
}
input:focus, select:focus, textarea:focus {
  border-color:var(--accent);
  box-shadow:0 0 0 3px rgba(0,102,255,.1);
  background:var(--bg2);
}
textarea { resize:vertical; min-height:80px; font-family:inherit; line-height:1.5; }
select {
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position:right 12px center; padding-right:34px;
}
.input-icon-wrap { position:relative; }
.input-icon-wrap input { padding-right:42px; }
.input-icon-btn { position:absolute; right:11px; top:50%; transform:translateY(-50%); background:none; border:none; cursor:pointer; color:var(--text3); padding:6px; -webkit-tap-highlight-color:transparent; }

/* Type selector */
.type-selector { display:flex; background:var(--bg3); border-radius:var(--radius); padding:3px; gap:3px; margin-bottom:1.25rem; }
.type-btn { flex:1; display:flex; align-items:center; justify-content:center; gap:6px; padding:10px; font-size:14px; font-weight:600; border:none; background:none; border-radius:7px; cursor:pointer; color:var(--text2); transition:all .15s; -webkit-tap-highlight-color:transparent; }
.type-btn.active.expense { background:var(--bg2); color:var(--red);   box-shadow:var(--shadow-sm); }
.type-btn.active.income  { background:var(--bg2); color:var(--green); box-shadow:var(--shadow-sm); }

/* Amount input */
.amount-input-wrap { display:flex; align-items:center; background:var(--bg3); border:1px solid var(--border2); border-radius:var(--radius-lg); padding:.625rem 1rem; margin-bottom:1.25rem; gap:6px; }
.amount-currency { font-size:26px; font-weight:700; color:var(--text2); }
.amount-input { flex:1; background:none; border:none; font-size:30px; font-weight:700; color:var(--text); outline:none; padding:0; min-width:0; }
.amount-input::placeholder { color:var(--text4); }
.amount-input:focus { box-shadow:none; background:none; border:none; }
.modal-grid { display:grid; grid-template-columns:1fr 1fr; gap:1rem; }

/* Tag suggestions */
.tag-suggestions { display:flex; flex-wrap:wrap; gap:4px; margin-top:6px; }
.tag-pill { display:inline-flex; align-items:center; gap:3px; padding:4px 10px; background:var(--bg3); border:1px solid var(--border2); border-radius:20px; font-size:12px; font-weight:500; color:var(--text2); cursor:pointer; transition:all .1s; -webkit-tap-highlight-color:transparent; }
.tag-pill:hover { background:var(--accent-light); color:var(--accent); border-color:transparent; }

/* Transaction list */
.tx-list { display:flex; flex-direction:column; }
.tx-item { display:flex; align-items:center; gap:12px; padding:13px 16px; border-bottom:1px solid var(--border); transition:background .1s; }
.tx-item:first-child { border-radius:var(--radius) var(--radius) 0 0; }
.tx-item:last-child  { border-radius:0 0 var(--radius) var(--radius); border-bottom:none; }
.tx-item:only-child  { border-radius:var(--radius); border-bottom:none; }
.tx-item:active { background:var(--bg3); }
.tx-icon { width:38px; height:38px; border-radius:11px; display:flex; align-items:center; justify-content:center; font-size:16px; flex-shrink:0; }
.tx-icon.income  { background:var(--green-light); }
.tx-icon.expense { background:var(--red-light); }
.tx-body { flex:1; min-width:0; }
.tx-desc { font-size:14px; font-weight:600; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.tx-meta { font-size:12px; color:var(--text3); margin-top:2px; }
.tx-tags { display:flex; gap:3px; margin-top:4px; flex-wrap:wrap; }
.tx-tag  { font-size:10px; padding:2px 7px; background:var(--bg3); border-radius:10px; color:var(--text3); border:1px solid var(--border); }
.tx-amount { font-size:14px; font-weight:700; white-space:nowrap; flex-shrink:0; }
.tx-amount.income  { color:var(--green); }
.tx-amount.expense { color:var(--red); }
.tx-actions { display:flex; gap:4px; flex-shrink:0; }

/* Charts */
.chart-wrap          { position:relative; width:100%; }
.chart-wrap.h220     { height:220px; }
.chart-wrap.h200     { height:200px; }
.chart-wrap.h180     { height:180px; }
.chart-row-2         { display:grid; grid-template-columns:1fr 1fr; gap:1.5rem; }

/* Progress bars */
.progress-wrap { margin-bottom:1rem; }
.progress-label { display:flex; justify-content:space-between; align-items:center; margin-bottom:5px; }
.progress-name  { font-size:13px; font-weight:500; color:var(--text); }
.progress-info  { font-size:12px; color:var(--text3); }
.progress-bar-bg { height:7px; background:var(--bg4); border-radius:4px; overflow:hidden; }
.progress-bar { height:100%; border-radius:4px; transition:width .4s ease; }

/* Badges */
.badge { display:inline-flex; align-items:center; padding:2px 8px; border-radius:20px; font-size:11px; font-weight:600; letter-spacing:.02em; }
.badge.green  { background:var(--green-light);  color:#065F46; }
.badge.red    { background:var(--red-light);    color:#991B1B; }
.badge.blue   { background:var(--accent-light); color:var(--accent-dark); }
.badge.orange { background:var(--orange-light); color:#92400E; }
.badge.purple { background:var(--purple-light); color:var(--purple); }

/* Filter bar */
.filter-bar { display:flex; gap:8px; margin-bottom:1.25rem; flex-wrap:wrap; }
.filter-bar select, .filter-bar input { flex:1; min-width:120px; }
.search-wrap { position:relative; flex:2; min-width:180px; }
.search-wrap svg { position:absolute; left:11px; top:50%; transform:translateY(-50%); color:var(--text3); pointer-events:none; }
.search-wrap input { padding-left:36px; }

/* Modal */
.modal-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:50; backdrop-filter:blur(3px); -webkit-backdrop-filter:blur(3px); }
.modal {
  position:fixed; top:50%; left:50%; transform:translate(-50%,-50%);
  z-index:51; width:100%; max-width:520px;
  background:var(--bg2); border-radius:var(--radius-xl);
  box-shadow:var(--shadow-lg); max-height:90dvh;
  display:flex; flex-direction:column;
  border:1px solid var(--border2);
}
.modal-header { display:flex; align-items:center; justify-content:space-between; padding:1.25rem 1.5rem; border-bottom:1px solid var(--border); }
.modal-header h3 { font-size:16px; font-weight:700; }
.modal-close { background:none; border:none; cursor:pointer; color:var(--text3); padding:6px; border-radius:var(--radius-sm); transition:all .1s; -webkit-tap-highlight-color:transparent; }
.modal-close:hover { background:var(--bg3); color:var(--text); }
.modal-body   { flex:1; overflow-y:auto; padding:1.5rem; -webkit-overflow-scrolling:touch; }
.modal-footer { display:flex; align-items:center; justify-content:flex-end; gap:8px; padding:1rem 1.5rem; border-top:1px solid var(--border); }

/* Color picker */
.color-picker-row { display:flex; gap:7px; flex-wrap:wrap; }
.color-dot { width:26px; height:26px; border-radius:50%; cursor:pointer; border:2px solid transparent; transition:transform .1s; -webkit-tap-highlight-color:transparent; }
.color-dot:hover  { transform:scale(1.15); }
.color-dot.active { border-color:var(--text); }

/* Section header */
.section-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:1rem; }
.section-title  { font-size:14px; font-weight:700; color:var(--text); }
.section-link   { font-size:12px; color:var(--accent); font-weight:500; }

/* Empty state */
.empty-state { text-align:center; padding:3rem 1rem; color:var(--text3); }
.empty-state svg   { margin:0 auto 1rem; opacity:.3; }
.empty-state p     { font-size:14px; }
.empty-state small { font-size:12px; margin-top:4px; display:block; }

/* Admin */
.user-row { display:flex; align-items:center; gap:12px; padding:13px 16px; border-bottom:1px solid var(--border); }
.user-row:last-child { border-bottom:none; }
.user-avatar { width:38px; height:38px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:13px; font-weight:700; flex-shrink:0; }
.user-info { flex:1; min-width:0; }
.user-name { font-size:13px; font-weight:600; }
.user-meta { font-size:11px; color:var(--text3); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.user-actions { display:flex; gap:4px; flex-shrink:0; }

/* Settings */
.settings-section { margin-bottom:2rem; }
.settings-title { font-size:11px; font-weight:700; color:var(--text3); text-transform:uppercase; letter-spacing:.08em; margin-bottom:.75rem; padding-left:2px; }
.settings-row { display:flex; align-items:center; justify-content:space-between; padding:14px 0; border-bottom:1px solid var(--border); gap:1rem; }
.settings-row:last-child { border-bottom:none; }
.settings-row-label { font-size:13px; font-weight:500; color:var(--text); }
.settings-row-desc  { font-size:12px; color:var(--text3); margin-top:2px; }
.settings-row-right { flex-shrink:0; }
.settings-row input[type=text],.settings-row input[type=number],.settings-row select { width:auto; min-width:160px; }

/* Toggle */
.toggle { position:relative; width:44px; height:24px; flex-shrink:0; cursor:pointer; -webkit-tap-highlight-color:transparent; }
.toggle input { opacity:0; width:0; height:0; position:absolute; }
.toggle-track { position:absolute; inset:0; background:var(--bg4); border-radius:12px; transition:background .2s; border:1px solid var(--border2); }
.toggle-thumb { position:absolute; top:3px; left:3px; width:16px; height:16px; background:white; border-radius:50%; transition:transform .2s; box-shadow:0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked ~ .toggle-track { background:var(--accent); border-color:var(--accent); }
.toggle input:checked ~ .toggle-thumb { transform:translateX(20px); }

/* Toast */
.toast-container { position:fixed; bottom:calc(1.5rem + var(--safe-bottom)); right:1.5rem; display:flex; flex-direction:column; gap:6px; z-index:200; }
.toast { display:flex; align-items:center; gap:8px; padding:11px 16px; background:var(--text); color:var(--bg2); border-radius:var(--radius-lg); font-size:13px; font-weight:500; box-shadow:var(--shadow-lg); transform:translateX(120%); transition:transform .25s cubic-bezier(.34,1.56,.64,1); max-width:320px; }
.toast.show { transform:translateX(0); }
.toast.success svg { color:#4ADE80; }
.toast.error   svg { color:#F87171; }
.toast.info    svg { color:#60A5FA; }

/* Loader */
.global-loader { position:fixed; inset:0; background:var(--bg); display:flex; align-items:center; justify-content:center; z-index:999; }
.loader-spinner { width:36px; height:36px; border:3px solid var(--border2); border-top-color:var(--accent); border-radius:50%; animation:spin .7s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

/* Goal card */
.goal-card { background:var(--bg2); border:1px solid var(--border); border-radius:var(--radius-lg); padding:1.25rem; position:relative; overflow:hidden; }
.goal-card-accent { position:absolute; top:0; left:0; right:0; height:3px; border-radius:var(--radius-lg) var(--radius-lg) 0 0; }
.goal-name { font-size:14px; font-weight:700; margin-bottom:2px; }
.goal-sub  { font-size:12px; color:var(--text3); margin-bottom:1rem; }
.goal-pct  { font-size:22px; font-weight:800; }
.goal-add-row { display:flex; gap:6px; margin-top:.75rem; }
.goal-add-row input { flex:1; }

/* Invite code */
.invite-code { display:inline-flex; align-items:center; gap:6px; padding:6px 12px; background:var(--bg3); border:1px solid var(--border2); border-radius:var(--radius); font-family:'SF Mono','Fira Code',monospace; font-size:14px; font-weight:700; letter-spacing:.1em; color:var(--accent); cursor:pointer; -webkit-tap-highlight-color:transparent; }

/* ══════════════════════════════════════════
   RESPONSIVE — TABLET (≤900px)
══════════════════════════════════════════ */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns:repeat(2,1fr); }
  .chart-row-2 { grid-template-columns:1fr; }
}

/* ══════════════════════════════════════════
   RESPONSIVE — MOBILE (≤768px)
══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Sidebar como drawer lateral */
  .sidebar {
    position:fixed; left:-100%; top:0; bottom:0; z-index:40;
    width:min(280px, 85vw);
    transition:left .25s cubic-bezier(.4,0,.2,1);
    box-shadow:var(--shadow-lg);
  }
  .sidebar.open { left:0; }
  .sidebar-close { display:flex; }
  .sidebar-overlay.show { display:block; }

  /* Header móvil visible */
  .mobile-header { display:flex; flex-direction:column; }

  /* Bottom nav visible */
  .bottom-nav { display:block; }
  .fab { display:flex; }

  /* Contenido principal con padding por bottom nav */
  .main-content { padding-bottom:calc(var(--nav-h) + var(--safe-bottom)); }
  .view { padding:1rem; padding-bottom:1.5rem; }

  /* Ocultar botón "Nuevo movimiento" en page-header en móvil (usa FAB) */
  .hide-mobile { display:none !important; }

  /* KPIs: 2 columnas compactas */
  .kpi-grid { grid-template-columns:1fr 1fr; gap:.625rem; margin-bottom:1rem; }
  .kpi-card { padding:.875rem 1rem; }
  .kpi-value { font-size:17px; letter-spacing:-.3px; }
  .kpi-delta { font-size:10px; }
  .kpi-label { font-size:10px; }

  /* Page header */
  .page-header { flex-direction:column; align-items:flex-start; gap:.5rem; margin-bottom:1.25rem; }
  .page-title  { font-size:19px; }

  /* Filtros en columna */
  .filter-bar { flex-direction:column; gap:.5rem; }
  .filter-bar select, .filter-bar input, .search-wrap { min-width:0; width:100%; flex:none; }

  /* Modal como sheet desde abajo */
  .modal {
    top:auto; bottom:0; left:0; right:0;
    transform:none; max-width:100%;
    border-radius:var(--radius-xl) var(--radius-xl) 0 0;
    max-height:92dvh;
    padding-bottom:var(--safe-bottom);
  }
  .modal-grid { grid-template-columns:1fr; }
  .modal-footer { padding-bottom:max(1rem, var(--safe-bottom)); }

  /* Toasts full width */
  .toast-container { bottom:calc(var(--nav-h) + var(--safe-bottom) + .75rem); right:1rem; left:1rem; }
  .toast { max-width:100%; transform:translateY(120%); }
  .toast.show { transform:translateY(0); }

  /* Tx actions siempre visibles en móvil */
  .tx-actions { opacity:1; }

  /* Settings: stack vertical */
  .settings-row { flex-wrap:wrap; }
  .settings-row input[type=text],
  .settings-row input[type=number],
  .settings-row select { width:100%; min-width:0; }

  /* Charts más bajos */
  .chart-wrap.h220 { height:180px; }
  .chart-wrap.h200 { height:160px; }

  /* Dashboard 2 col→ 1 col para cards de abajo */
  .dashboard-grid { grid-template-columns:1fr !important; }

  /* Admin user rows compactos */
  .user-row { flex-wrap:wrap; gap:8px; padding:12px; }
  .user-meta { white-space:normal; }

  /* Botones full-width en modales */
  .modal-footer { gap:8px; }
  .modal-footer .btn-primary,
  .modal-footer .btn-ghost { flex:1; justify-content:center; }
}

/* ══════════════════════════════════════════
   RESPONSIVE — SMALL MOBILE (≤400px)
══════════════════════════════════════════ */
@media (max-width: 400px) {
  .kpi-value  { font-size:15px; }
  .kpi-card   { padding:.75rem; }
  .page-title { font-size:17px; }
  .view       { padding:.875rem; }
  .tx-icon    { width:34px; height:34px; font-size:14px; }
  .tx-desc    { font-size:13px; }
  .amount-input { font-size:26px; }
  .bnav-item  { font-size:9px; }
}

/* ══════════════════════════════════════════
   CORRECCIONES CRÍTICAS MÓVIL
══════════════════════════════════════════ */

/* Asegurar que el sidebar NUNCA se muestre en móvil por defecto */
@media (max-width: 768px) {
  #mainApp {
    flex-direction: column !important;
  }

  /* Sidebar completamente fuera de pantalla por defecto */
  .sidebar {
    position: fixed !important;
    left: -100% !important;
    top: 0 !important;
    bottom: 0 !important;
    z-index: 40 !important;
    width: min(280px, 85vw) !important;
    transition: left .25s cubic-bezier(.4,0,.2,1) !important;
    height: 100dvh !important;
  }

  .sidebar.open {
    left: 0 !important;
  }

  /* Main content ocupa TODO el ancho */
  .main-content {
    width: 100% !important;
    flex: 1 !important;
    overflow-y: auto !important;
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px) !important;
  }

  /* Vistas full width */
  .view {
    width: 100% !important;
    max-width: 100% !important;
    padding: 1rem !important;
    box-sizing: border-box !important;
  }

  /* Filtros full width en columna */
  .filter-bar {
    display: flex !important;
    flex-direction: column !important;
    gap: .625rem !important;
    width: 100% !important;
  }

  .filter-bar > * {
    width: 100% !important;
    min-width: 0 !important;
    flex: none !important;
  }

  /* Cards full width */
  .card, .card-sm {
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* KPI grid 2x2 */
  .kpi-grid {
    grid-template-columns: 1fr 1fr !important;
    width: 100% !important;
  }

  /* Dashboard grid 1 columna */
  [style*="grid-template-columns:1.5fr"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
  }

  /* Charts row 1 columna */
  .chart-row-2 {
    grid-template-columns: 1fr !important;
  }

  /* Modal desde abajo */
  .modal {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    transform: none !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92dvh !important;
  }

  /* Settings grid 1 columna */
  [style*="grid-template-columns:1fr 1fr"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
  }

  /* Toasts sobre bottom nav */
  .toast-container {
    bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px) !important;
    left: 1rem !important;
    right: 1rem !important;
  }

  /* FAB sobre bottom nav */
  .fab {
    bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px) !important;
    right: 16px !important;
  }

  /* More menu sobre bottom nav */
  .more-menu {
    bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px) !important;
  }

  /* Page header sin botón desktop */
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: .5rem !important;
  }

  /* User rows en admin */
  .user-row {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* Ocultar sidebar-footer nav en móvil (usamos bottom nav) */
  .sidebar-footer .nav-item,
  .sidebar-footer .admin-link {
    display: flex !important;
  }
}

@media (max-width: 768px) {
  .dashboard-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
  }
  .settings-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
  }
}
