:root {
  --bg: #08090a; --bg-elevated: #0f1011; --panel: #111214; --panel-hover: #17181a;
  --border: #1f2023; --border-strong: #2a2b2f;
  --text: #e9eaec; --text-muted: #9095a0; --text-faint: #6b7079;
  --accent: #7c6cff; --accent-hover: #8f82ff; --accent-soft: rgba(124,108,255,.14);
  --green: #4cc38a; --red: #f26d6d; --radius: 10px;
}
* { box-sizing: border-box; border-color: var(--border); }
[hidden] { display: none !important; } /* respeta el atributo hidden aunque haya display:flex */
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
/* Quita el zoom por doble toque y el retardo de 300ms en controles */
a, button, label, select, summary, .pick, .tab, .nav-item, .seg-btn, .chip {
  touch-action: manipulation;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 13px; font-weight: 600; margin: 0; }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
input, select, button { font: inherit; color: inherit; }
input::placeholder { color: var(--text-faint); }

/* ---- Layout ---- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; flex-shrink: 0; background: var(--bg-elevated);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 16px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent);
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 14px;
}
.brand-name { font-size: 14px; font-weight: 600; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 7px;
  font-size: 14px; color: var(--text-muted);
}
.nav-item:hover { background: var(--panel-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); }
.nav-ico { width: 16px; height: 16px; opacity: .9; background: currentColor;
  -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; }
.i-dashboard { -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'><rect x='3' y='3' width='7' height='7' rx='1'/><rect x='14' y='3' width='7' height='7' rx='1'/><rect x='3' y='14' width='7' height='7' rx='1'/><rect x='14' y='14' width='7' height='7' rx='1'/></svg>"); mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'><rect x='3' y='3' width='7' height='7' rx='1'/><rect x='14' y='3' width='7' height='7' rx='1'/><rect x='3' y='14' width='7' height='7' rx='1'/><rect x='14' y='14' width='7' height='7' rx='1'/></svg>"); }
.i-tasks { -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'><rect x='3' y='3' width='18' height='18' rx='2'/><path d='M9 12l2 2 4-4'/></svg>"); mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'><rect x='3' y='3' width='18' height='18' rx='2'/><path d='M9 12l2 2 4-4'/></svg>"); }
.i-finances { -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'><rect x='2' y='5' width='20' height='14' rx='2'/><path d='M2 10h20'/></svg>"); mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'><rect x='2' y='5' width='20' height='14' rx='2'/><path d='M2 10h20'/></svg>"); }
.i-logout { -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'><path d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/><path d='M16 17l5-5-5-5'/><path d='M21 12H9'/></svg>"); mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'><path d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/><path d='M16 17l5-5-5-5'/><path d='M21 12H9'/></svg>"); }
.sidebar-foot { margin-top: auto; padding: 16px; font-size: 12px; color: var(--text-faint); display: flex; flex-direction: column; gap: 10px; }
.logout { color: var(--text-muted); }
.logout:hover { color: var(--text); }
.main { flex: 1; min-width: 0; }

/* ---- Barra inferior (móvil) — oculta en escritorio ---- */
.tabbar { display: none; }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center;
  padding: 0 24px; border-bottom: 1px solid var(--border);
  background: rgba(8,9,10,.8); backdrop-filter: blur(8px);
}
.topbar .sub { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.wrap { max-width: 1000px; margin: 0 auto; padding: 24px; }

/* ---- KPIs ---- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; transition: .15s; }
a.kpi:hover { border-color: var(--border-strong); background: var(--panel-hover); }
.kpi-label { font-size: 12px; color: var(--text-muted); }
.kpi-value { font-size: 24px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.green { color: var(--green); } .red { color: var(--red); } .muted { color: var(--text-muted); }

/* ---- Cards & grids ---- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.card-body { padding: 20px; }
.link { font-size: 12px; color: var(--text-muted); } .link:hover { color: var(--text); }
.grid-2-3 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; margin-bottom: 24px; }
.grid-fin-bottom { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 24px; }
.section-title { font-size: 13px; font-weight: 600; margin: 0 0 12px; }
.empty { text-align: center; color: var(--text-muted); font-size: 14px; padding: 40px 0; }

/* ---- Lists / rows (dashboard focus) ---- */
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row-title { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 13px; height: 13px; border-radius: 50%; border: 2px solid; display: inline-grid; place-items: center; flex-shrink: 0; }
.dot.filled { color: var(--bg); font-size: 8px; }
.sq { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; display: inline-block; }
.due { font-size: 12px; flex-shrink: 0; }

/* ---- Donut / legend ---- */
.donut-wrap { max-width: 220px; margin: 0 auto; }
.legend { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.ldot { width: 10px; height: 10px; border-radius: 50%; }
.lcat { flex: 1; color: var(--text-muted); text-transform: capitalize; }
.lpct { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.lamt { font-weight: 500; font-variant-numeric: tabular-nums; }
.fin-cat { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: center; }

/* ---- Tasks ---- */
.tasks { padding-bottom: 60px; }
.composer-trigger { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: none; border: 0; padding: 14px 24px; color: var(--text-muted); font-size: 14px; cursor: pointer; }
.composer-trigger:hover { color: var(--text); }
.composer { margin: 16px 24px; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 12px; padding: 14px; }
.composer-title { width: 100%; background: none; border: 0; outline: none; font-size: 14px; }
.composer-desc { width: 100%; background: none; border: 0; outline: none; font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.composer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.chip, .chip-date { background: none; border: 1px solid var(--border-strong); border-radius: 7px; padding: 5px 9px; font-size: 12px; color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { color: var(--text); }
.chip-date { color-scheme: dark; }
.composer-actions { margin-left: auto; display: flex; gap: 8px; }
.btn-ghost { background: none; border: 0; color: var(--text-muted); font-size: 12px; padding: 5px 10px; cursor: pointer; }
.btn-ghost:hover { color: var(--text); }
.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: 7px; padding: 6px 14px; font-size: 12px; font-weight: 500; cursor: pointer; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary.block { width: 100%; padding: 10px; margin-top: 4px; }

.group-head { display: flex; align-items: center; gap: 8px; padding: 6px 24px; background: var(--bg-elevated); }
.dot-fill { width: 8px; height: 8px; border-radius: 50%; }
.group-label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.group-count { font-size: 12px; color: var(--text-faint); }
.task { display: flex; align-items: center; gap: 12px; padding: 10px 24px; border-bottom: 1px solid var(--border); }
.task:hover { background: var(--panel-hover); }
.pick { background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; }
.task-main { flex: 1; min-width: 0; }
.task-title { font-size: 14px; } .task-title.done { color: var(--text-faint); text-decoration: line-through; }
.task-desc { display: block; font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.del-form { display: flex; }
.del-btn { background: none; border: 0; color: var(--text-faint); cursor: pointer; opacity: 0; transition: .15s; font-size: 14px; }
.task:hover .del-btn, .tx:hover .del-btn { opacity: 1; }
.del-btn:hover { color: var(--red); }

/* ---- Tablero kanban (columnas horizontales) ---- */
.board {
  display: flex; gap: 14px; align-items: flex-start;
  overflow-x: auto; padding: 16px 24px 32px;
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
}
.board-col {
  flex: 0 0 290px; width: 290px; scroll-snap-align: start;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 12px; display: flex; flex-direction: column;
}
.col-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.col-cards { padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 64px; }
.col-empty { text-align: center; color: var(--text-faint); font-size: 12px; padding: 18px 0; }

/* ---- Tarjetas kanban ---- */
.kard {
  position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px 12px 16px; overflow: hidden;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.kard::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--pcolor);
}
.kard:hover { border-color: var(--border-strong); box-shadow: 0 6px 18px rgba(0,0,0,.28); }
.kard.is-done { opacity: .62; }
.kard { cursor: grab; }
.kard:active { cursor: grabbing; }
.kard-ghost { opacity: .35; }
.kard-chosen { box-shadow: 0 12px 30px rgba(0,0,0,.5); }
.kard-top { display: flex; align-items: center; gap: 10px; }
.kard-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.kard-title.done { text-decoration: line-through; color: var(--text-faint); }
.kard-desc { margin: 7px 0 0 24px; font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }
.kard-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0 0 24px; }
.prio-pill {
  display: inline-flex; align-items: center; gap: 6px; background: var(--bg-elevated);
  border: 1px solid var(--border-strong); border-radius: 999px; padding: 3px 10px;
  font-size: 11px; color: var(--text-muted); cursor: pointer; transition: .15s;
}
.prio-pill:hover { color: var(--text); border-color: var(--pcolor); }
.prio-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.due-chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted);
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 999px; padding: 3px 9px;
}
.due-chip.is-overdue { color: var(--red); border-color: rgba(242,109,109,.4); background: rgba(242,109,109,.08); }
.kard .del-btn { opacity: 0; }
.kard:hover .del-btn { opacity: 1; }

/* ---- Finance form & tx list ---- */
.grid-fin-bottom .section-title { margin-top: 0; }
.tx-form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 9px; padding: 4px; }
.seg-btn { flex: 1; background: none; border: 0; border-radius: 6px; padding: 7px; font-size: 12px; font-weight: 500; color: var(--text-muted); cursor: pointer; }
.seg-btn.active { background: var(--panel-hover); color: var(--text); }
.seg-btn.active[data-type="income"] { background: rgba(76,195,138,.15); color: var(--green); }
.seg-btn.active[data-type="expense"] { background: rgba(242,109,109,.15); color: var(--red); }
.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-muted); }
.fld input, .fld select { background: var(--bg); border: 1px solid var(--border-strong); border-radius: 7px; padding: 9px 11px; font-size: 14px; color: var(--text); outline: none; color-scheme: dark; }
.fld input:focus, .fld select:focus { border-color: var(--accent); }
.amount-input { font-size: 18px !important; font-weight: 600; }

.tx-list { overflow: hidden; }
.tx { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.tx:last-child { border-bottom: 0; }
.tx:hover { background: var(--panel-hover); }
.tx-ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; flex-shrink: 0; }
.tx-ico.in { background: rgba(76,195,138,.15); color: var(--green); }
.tx-ico.out { background: rgba(242,109,109,.15); color: var(--red); }
.tx-main { flex: 1; min-width: 0; }
.tx-top { display: flex; align-items: center; gap: 8px; }
.tag { font-size: 10px; font-weight: 500; padding: 2px 6px; border-radius: 4px; text-transform: capitalize; }
.tx-desc { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-date { font-size: 12px; color: var(--text-faint); }
.tx-amt { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.tx-ico.save { background: var(--accent-soft); color: var(--accent); }
.tx-sub { font-size: 11px; color: var(--text-muted); }
.accent { color: var(--accent); }

/* ---- Formulario: checkbox recurrente ---- */
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---- Lista de recurrentes ---- */
.rec-list { display: flex; flex-direction: column; }
.rec { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.rec:last-child { border-bottom: 0; }
.rec.off { opacity: .5; }
.rec-main { flex: 1; min-width: 0; }
.rec-title { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-sub { font-size: 11px; color: var(--text-faint); text-transform: capitalize; }
.rec-amt { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.inline-form { display: flex; }
.mini-btn { background: none; border: 0; color: var(--text-faint); cursor: pointer; padding: 4px; font-size: 13px; }
.mini-btn:hover { color: var(--text); }
.mini-btn.del:hover { color: var(--red); }

/* ---- Popover menu ---- */
.menu { position: absolute; z-index: 50; min-width: 170px; background: var(--panel);
  border: 1px solid var(--border-strong); border-radius: 10px; padding: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: none; border: 0; padding: 7px 10px; border-radius: 6px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.menu button:hover { background: var(--panel-hover); }
.menu button.sel { color: var(--text); }
.menu .m-dot { width: 10px; height: 10px; border-radius: 50%; }
.menu .m-sq { width: 10px; height: 10px; border-radius: 3px; }

/* ---- Login ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--border-strong); border-radius: 14px;
  padding: 28px; width: 300px; display: flex; flex-direction: column; gap: 12px; }
.login-card input { background: var(--bg); border: 1px solid var(--border-strong); border-radius: 8px; padding: 11px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 11px; font-weight: 500; cursor: pointer; }
.login-card button:hover { background: var(--accent-hover); }
.login-error { color: var(--red); font-size: 12px; margin: 0; text-align: center; }

/* ---- Accesibilidad y pulido ---- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus:not(:focus-visible), a:focus:not(:focus-visible) { outline: none; }
.nav-item:focus-visible { outline-offset: -2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Responsive / móvil: se siente como app nativa ---- */
@media (max-width: 860px) {
  .sidebar { display: none; }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid-2-3, .grid-2, .grid-fin-bottom, .fin-cat { grid-template-columns: minmax(0, 1fr); }

  /* Header con safe-area del notch */
  .topbar {
    height: auto; min-height: 52px;
    padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  }
  .topbar h1 { font-size: 17px; }

  .wrap { padding: 16px; }
  .composer-trigger, .task, .row, .group-head { padding-left: 16px; padding-right: 16px; }
  .board { padding: 14px 16px 24px; gap: 12px; scroll-snap-type: x mandatory; }
  .board-col { flex: 0 0 84vw; width: 84vw; }
  .kard .del-btn { opacity: 1; }
  .composer { margin: 12px 16px; }

  /* Espacio para la barra inferior */
  .main { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }

  /* Evita el zoom de iOS al enfocar un campo (fuente >= 16px) */
  input, select, textarea { font-size: 16px; }
  .amount-input { font-size: 20px !important; }

  /* Barra de navegación inferior (tab bar) */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: rgba(15, 16, 17, 0.92);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(env(safe-area-inset-bottom) + 4px);
  }
  .tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 2px; color: var(--text-faint); font-size: 10px; font-weight: 500;
    border-radius: 12px;
  }
  .tab .nav-ico { width: 22px; height: 22px; }
  .tab.active { color: var(--accent); }
  .tab:active { background: var(--panel-hover); transform: scale(0.94); }

  /* Áreas táctiles más amplias */
  .pick { padding: 8px; margin: -8px; }
  .del-btn { opacity: 1; padding: 8px; }
  .btn-primary, .seg-btn { padding-top: 10px; padding-bottom: 10px; }
  .link { padding: 4px; }
}
