:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #8a8a8e;
  --separator: #e6e6eb;
  --accent: #5b5bd6;
  --accent-soft: #ecebfb;
  --danger: #ff3b30;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.05);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --surface: #1c1c1e; --text: #f2f2f7; --muted: #8e8e93;
    --separator: #2c2c2e; --accent: #7c7cff; --accent-soft: #26264a;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; }
html, body {
  height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 17px; -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:active { transform: scale(0.98); }
input, textarea, select { font: inherit; color: var(--text); }

.btn-primary { background: var(--accent); color: #fff; border-radius: 12px; padding: 0.85rem 1rem; font-weight: 600; }
.btn-danger { background: transparent; color: var(--danger); border-radius: 12px; padding: 0.85rem 1rem; font-weight: 600; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 22px; padding: 2.25rem 1.5rem; text-align: center; box-shadow: var(--shadow); }
.login-card .logo { font-size: 2.8rem; }
.login-card h1 { font-size: 1.6rem; margin-top: 0.4rem; letter-spacing: -0.02em; }
.login-card p { margin: 0.2rem 0 1.4rem; }
.login-card input, .login-card .btn-primary { width: 100%; }
.login-card input { padding: 0.9rem 1rem; background: var(--bg); border: 1px solid var(--separator); border-radius: 12px; outline: none; margin-bottom: 0.8rem; }
.login-card input:focus { border-color: var(--accent); }
.error { color: var(--danger); margin-top: 0.8rem; font-size: 0.9rem; }

/* ---------- App shell (mobile-first) ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.sidebar { display: none; }
.main { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
#tasks-pane, #expenses-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.app-header { display: flex; align-items: flex-end; justify-content: space-between; padding: max(1rem, env(safe-area-inset-top)) 1.1rem 0.5rem; }
.app-header h1 { font-size: 2rem; letter-spacing: -0.03em; font-weight: 800; }
.app-header .muted { text-transform: capitalize; margin-top: 2px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--surface); color: var(--muted); font-size: 1.1rem; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; }

/* ---------- Mobile chips ---------- */
.chips { order: 1; display: flex; gap: 0.5rem; padding: 0.4rem 1.1rem 0.7rem; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.45rem 0.85rem; border-radius: 100px; background: var(--surface); font-size: 0.9rem; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip .ct { color: var(--muted); }
.chip.active { background: var(--accent); color: #fff; }
.chip.active .ct { color: rgba(255,255,255,.75); }

/* ---------- List ---------- */
.list { order: 2; flex: 1; overflow-y: auto; padding: 0 1.1rem 1.5rem; -webkit-overflow-scrolling: touch; }
.group-title { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 1.1rem 0.3rem 0.5rem; display: flex; align-items: center; gap: 0.45rem; }
.group-title .dot { width: 10px; height: 10px; border-radius: 50%; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

.task { display: flex; align-items: center; gap: 0.8rem; padding: 0.85rem 0.95rem; border-bottom: 1px solid var(--separator); transition: opacity .3s, transform .3s, background .15s; cursor: pointer; }
.task:last-child { border-bottom: none; }
.task:hover { background: var(--bg); }
.task.removing { opacity: 0; transform: translateX(40px); }
.check { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--c, var(--muted)); position: relative; background: transparent; transition: background .2s, border-color .2s; }
.check::after { content: ""; position: absolute; inset: 0; margin: auto; width: 7px; height: 12px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) scale(0); transition: transform .2s; top: -2px; }
.task.removing .check { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); }
.task.removing .check::after { transform: rotate(45deg) scale(1); }
.task-main { flex: 1; min-width: 0; }
.task-text { font-size: 1rem; line-height: 1.25; word-break: break-word; }
.task-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; margin-top: 3px; }
.task-meta .cat { font-size: 0.78rem; }
.pill { font-size: 0.78rem; font-weight: 600; color: var(--muted); padding: 1px 8px; border-radius: 100px; background: var(--bg); }
.pill.today { color: var(--accent); background: var(--accent-soft); }
.pill.over { color: var(--danger); background: rgba(255,59,48,.1); }
.empty { text-align: center; color: var(--muted); padding: 4rem 1.5rem; font-size: 0.95rem; }
.empty .big { font-size: 2.6rem; display: block; margin-bottom: 0.6rem; }

/* ---------- Composer ---------- */
.composer { order: 3; background: var(--surface); border-top: 1px solid var(--separator); padding: 0.55rem 0.8rem; }
.composer-bar { display: flex; align-items: center; gap: 0.5rem; }
.composer-bar input { flex: 1; min-width: 0; background: var(--bg); border: none; outline: none; padding: 0.7rem 1rem; border-radius: 100px; font-size: 1rem; }
.send-btn { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 1.3rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.composer-opts { padding: 0.7rem 0.2rem 0.3rem; }
.opt-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: 0.05em; margin: 0.5rem 0.2rem 0.4rem; }
.chip-pick { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pick { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.4rem 0.7rem; border-radius: 100px; background: var(--bg); font-size: 0.82rem; font-weight: 600; border: 1.5px solid transparent; }
.pick .dot { width: 8px; height: 8px; border-radius: 50%; }
.pick.sel { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.date-field { display: inline-flex; align-items: center; gap: 0.4rem; margin-top: 0.6rem; background: var(--bg); padding: 0.45rem 0.7rem; border-radius: 100px; font-size: 0.85rem; }
.date-field input { background: transparent; border: none; outline: none; color: var(--text); }

/* ---------- Tab bar (móvil) ---------- */
.tabbar { display: flex; background: var(--surface); border-top: 1px solid var(--separator); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0.5rem 0 0.55rem; color: var(--muted); font-size: 0.7rem; font-weight: 600; }
.tab .ti { font-size: 1.25rem; line-height: 1; }
.tab.active { color: var(--accent); }

/* ---------- Expenses ---------- */
.exp-total-card { order: 1; margin: 0.3rem 1.1rem 0.8rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: 4px; }
.exp-total { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; }
.exp-row { display: flex; align-items: center; justify-content: space-between; padding: 0.8rem 0.95rem; border-bottom: 1px solid var(--separator); }
.exp-row:last-child { border-bottom: none; }
.exp-amt { font-weight: 700; }

/* ---------- Sidebar nav (compartido) ---------- */
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.7rem; border-radius: 10px; font-size: 0.95rem; font-weight: 600; color: var(--text); width: 100%; text-align: left; }
.nav-item .ni { width: 1.3rem; text-align: center; }
.nav-item .dot { width: 10px; height: 10px; border-radius: 50%; margin: 0 0.3rem 0 0.15rem; }
.nav-item .ct { margin-left: auto; color: var(--muted); font-size: 0.82rem; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.active .ct { color: var(--accent); }
.nav-sep { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: 0.06em; margin: 1rem 0.7rem 0.4rem; }

/* ---------- Sheet / modal ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; transition: opacity .2s; }
.sheet-backdrop.closing { opacity: 0; }
.sheet { width: 100%; max-width: 680px; margin: 0 auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 0.6rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom)); box-shadow: 0 -8px 40px rgba(0,0,0,.25); animation: slideUp .26s cubic-bezier(.2,.9,.3,1); }
.sheet-backdrop.closing .sheet { animation: slideDown .2s ease forwards; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideDown { to { transform: translateY(100%); } }
.sheet-handle { width: 38px; height: 5px; border-radius: 3px; background: var(--separator); margin: 0.3rem auto 1rem; }
.sheet textarea { width: 100%; background: var(--bg); border: none; outline: none; border-radius: 12px; padding: 0.8rem 0.9rem; font-size: 1.05rem; resize: none; }
.sheet-date { display: flex; }
.sheet-actions { display: flex; gap: 0.7rem; align-items: center; margin-top: 1.4rem; }
.sheet-actions .btn-primary { flex: 1; }

/* ====================================================== */
/* ESCRITORIO                                              */
/* ====================================================== */
@media (min-width: 900px) {
  .app { flex-direction: row; }
  .tabbar { display: none; }
  .chips { display: none; }

  .sidebar {
    display: flex; flex-direction: column; width: 268px; flex: 0 0 268px;
    background: var(--bg); border-right: 1px solid var(--separator);
    padding: 1.4rem 0.9rem 1rem; overflow-y: auto;
  }
  .side-brand { font-size: 1.3rem; font-weight: 800; display: flex; align-items: center; gap: 0.4rem; padding: 0 0.6rem; margin-bottom: 1.4rem; }
  .side-nav { flex: 1; }
  .side-logout { margin-top: 1rem; padding: 0.55rem 0.7rem; border-radius: 10px; color: var(--muted); font-weight: 600; text-align: left; }
  .side-logout:hover { background: var(--bg); color: var(--danger); }

  .main { max-width: 920px; }
  .app-header { padding: 1.6rem 2rem 0.6rem; }
  .app-header .icon-btn.logout { display: none; }

  .composer { order: 0; background: transparent; border-top: none; padding: 0.4rem 2rem 0.8rem; }
  .composer-bar input { background: var(--surface); box-shadow: var(--shadow); }
  .composer-opts { padding: 0.7rem 0.2rem 0; }
  .list { padding: 0 2rem 2rem; }
  .exp-total-card { margin: 0.3rem 2rem 0.9rem; }

  .sheet-backdrop { align-items: center; padding: 1rem; }
  .sheet { max-width: 460px; border-radius: 20px; animation: pop .2s ease; }
  .sheet-backdrop.closing .sheet { animation: none; }
  .sheet-handle { display: none; }
  @keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
}
