:root {
  --bg: var(--tg-theme-bg-color, #0f1419);
  --surface: var(--tg-theme-secondary-bg-color, #182028);
  --surface-2: #222d38;
  --text: var(--tg-theme-text-color, #eff3f8);
  --muted: var(--tg-theme-hint-color, #8b9bb0);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 84px;
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  background: rgba(15, 20, 25, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { margin: 0; font-size: 1.2rem; letter-spacing: 0.3px; }
.badge-demo {
  display: inline-block; font-size: 0.7rem; color: var(--warn);
  background: rgba(245, 158, 11, 0.14); padding: 2px 8px; border-radius: 99px;
  border: none; cursor: pointer;
}
.badge-demo.badge-online {
  color: var(--ok);
  background: rgba(34, 197, 94, 0.16);
}

.container { padding: 14px 16px; max-width: 640px; margin: 0 auto; }

.section-title {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 18px 0 10px;
  display: flex; justify-content: space-between; align-items: center;
}

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 6px; text-align: center;
}
.stat-num { font-size: 1.15rem; font-weight: 700; }
.stat-lbl { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

.card-list { display: flex; flex-direction: column; gap: 8px; }
.item-card {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 12px;
}
.item-card.done { opacity: 0.55; }
.item-card.done .item-title { text-decoration: line-through; }

.check-btn {
  width: 24px; height: 24px; min-width: 24px; border-radius: 50%;
  border: 2px solid var(--muted); background: transparent; color: #fff;
  display: grid; place-items: center; font-size: 0.8rem; cursor: pointer; margin-top: 2px;
}
.item-card.done .check-btn { background: var(--ok); border-color: var(--ok); }

.item-body { flex: 1; min-width: 0; cursor: pointer; }
.item-title { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; word-break: break-word; }
.item-meta { display: flex; flex-wrap: wrap; gap: 5px; font-size: 0.73rem; color: var(--muted); align-items: center; }

.pill {
  padding: 2px 7px; border-radius: 99px; background: var(--surface-2);
  color: var(--text); font-size: 0.69rem;
}
.pill-prio-3 { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.pill-prio-4 { background: rgba(239, 68, 68, 0.22); color: #f87171; }
.pill-ok { background: rgba(34, 197, 94, 0.18); color: #4ade80; }

.btn-mini {
  background: rgba(59, 130, 246, 0.18); color: #93c5fd; border: none;
  border-radius: 8px; padding: 6px 10px; font-size: 0.75rem; font-weight: 600; cursor: pointer;
}

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); padding: 6px 12px; border-radius: 99px; font-size: 0.8rem; cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Calendario */
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cal-month { font-weight: 700; text-transform: capitalize; font-size: 1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 0.72rem; color: var(--muted); padding-bottom: 4px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 10px; background: var(--surface); border: 1px solid transparent;
  color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 0.86rem; cursor: pointer;
}
.cal-cell.empty { background: transparent; pointer-events: none; }
.cal-cell.today { border-color: var(--accent); font-weight: 700; }
.cal-cell.selected { background: var(--accent); color: var(--accent-text); }
.cal-dots { display: flex; gap: 2px; margin-top: 3px; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; }

/* Alertas */
.alert-card {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
}
.alert-body { flex: 1; min-width: 0; cursor: pointer; }
.alert-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.alert-desc { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.card-alert { border-color: rgba(239, 68, 68, 0.55); }

.switch {
  width: 44px; height: 24px; border-radius: 99px; background: var(--surface-2);
  border: none; position: relative; cursor: pointer; transition: background 0.2s; flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: transform 0.2s;
}
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(20px); }

/* Compras y Tasa */
.rate-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px;
}
.rate-val { font-weight: 700; font-size: 0.95rem; margin-top: 2px; }
.purchase-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.purchase-top { display: flex; justify-content: space-between; gap: 10px; cursor: pointer; }
.price-box { text-align: right; flex-shrink: 0; }
.price-usd { font-weight: 700; font-size: 1.05rem; color: var(--ok); }
.price-bs { font-size: 0.72rem; color: var(--muted); }
.purchase-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  background: rgba(0, 0, 0, 0.18); border-radius: 10px; padding: 8px 10px; cursor: pointer;
}
.meta-lbl { display: block; font-size: 0.68rem; color: var(--muted); }
.meta-val { font-size: 0.78rem; margin-top: 2px; }
.purchase-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.progress-track { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.progress-fill.bar-warn { background: var(--warn); }
.progress-fill.bar-danger { background: var(--danger); }

.bs-preview { font-size: 0.72rem; color: var(--ok); margin-top: 2px; }

/* FAB y navegación 5 pestañas */
.fab {
  position: fixed; right: 16px; bottom: 78px; z-index: 20;
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-text); font-size: 1.55rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45); cursor: pointer;
}

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 2px 10px;
}
.nav-btn {
  position: relative; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.67rem; cursor: pointer; padding: 2px;
}
.nav-btn.active { color: var(--accent); font-weight: 600; }
.nav-icon { font-size: 1.15rem; }
.nav-badge {
  position: absolute; top: -2px; right: 12%; background: var(--danger);
  color: #fff; font-size: 0.62rem; padding: 1px 5px; border-radius: 99px;
}

/* Modales */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.72);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%; max-width: 540px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-header h2 { margin: 0; font-size: 1.05rem; }

.form { display: flex; flex-direction: column; gap: 10px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.76rem; color: var(--muted); min-width: 0; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px; font-size: 0.88rem; font-family: inherit;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; padding: 4px 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

.btn {
  border: none; border-radius: 10px; padding: 10px 14px;
  font-weight: 600; font-size: 0.86rem; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-text); flex: 1; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: rgba(239, 68, 68, 0.18); color: #f87171; }
.icon-btn {
  background: var(--surface-2); color: var(--text); border: none;
  border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 0.95rem;
}

.empty-state {
  text-align: center; color: var(--muted); padding: 26px 12px;
  background: var(--surface); border-radius: var(--radius); font-size: 0.86rem;
}
.toast {
  position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: #111827; color: #fff; border: 1px solid var(--border);
  padding: 9px 14px; border-radius: 99px; font-size: 0.82rem;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.pill-btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 99px; padding: 6px 11px; font-size: 0.78rem; font-weight: 600; cursor: pointer;
}
.pill-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Historial unificado */
.range-bar {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; margin-top: 4px;
}
.log-card {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 11px;
}
.log-date {
  min-width: 54px; text-align: center; background: var(--surface-2);
  border-radius: 10px; padding: 6px 4px;
}
.log-day { display: block; font-size: 0.76rem; font-weight: 700; }
.log-year { display: block; font-size: 0.65rem; color: var(--muted); }
.log-body { flex: 1; min-width: 0; }
.log-sub { font-size: 0.8rem; color: var(--muted); margin: 2px 0 6px; word-break: break-word; }

/* Notas por vuelta */
.notes-history { display: flex; flex-direction: column; gap: 6px; max-height: 140px; overflow-y: auto; }
.note-entry {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 9px; font-size: 0.8rem;
}
.note-entry small { display: block; color: var(--muted); font-size: 0.7rem; margin-bottom: 2px; }

/* Gráficas SVG y ciclos */
.chart-block {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; margin-bottom: 10px;
}
.svg-chart { width: 100%; height: auto; display: block; }
.chart-empty { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 18px 8px; }
.cycle-row {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 10px; display: flex; flex-direction: column; gap: 5px;
}
.cycle-head { display: flex; justify-content: space-between; font-size: 0.84rem; }