/* ─── BASE (igual que fase 2) ──────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:#F5F0E8; --surface:#EDE7D9; --card:#FFFDF9;
  --text:#1A1714; --muted:#6B6560; --faint:#B0A89E; --border:rgba(26,23,20,0.10);
  --acento:#C2610A; --radius:14px; --safe-bottom:env(safe-area-inset-bottom,0px);
}
html,body { height:100%; background:var(--bg); color:var(--text);
  font-family:ui-sans-serif,-apple-system,BlinkMacSystemFont,sans-serif;
  font-size:16px; -webkit-font-smoothing:antialiased; }

/* SETUP */
#setup-screen { min-height:100vh; display:flex; flex-direction:column; align-items:center;
  justify-content:center; padding:32px 24px; gap:16px; }
#setup-screen h1 { font-family:Georgia,serif; font-size:28px; font-weight:normal; }
#setup-screen p  { font-size:14px; color:var(--muted); text-align:center; line-height:1.5; }
#setup-screen input { width:100%; max-width:360px; padding:12px 14px;
  border:1.5px solid var(--border); border-radius:10px; font-size:14px;
  background:var(--card); color:var(--text); font-family:monospace; }
#setup-screen input:focus { outline:none; border-color:var(--acento); }

/* APP SHELL */
#app { display:none; flex-direction:column; height:100dvh; }
#app.visible { display:flex; }

/* HEADER */
.header { padding:20px 16px 0; display:flex; justify-content:space-between; align-items:flex-start; flex-shrink:0; }
.h-date { font-family:Georgia,serif; font-size:26px; line-height:1.1; }
.h-day  { font-size:11px; color:var(--muted); letter-spacing:.06em; text-transform:uppercase; margin-top:2px; }
.h-year { font-family:Georgia,serif; font-size:22px; text-align:right; }
.h-sub  { font-size:10px; color:var(--muted); letter-spacing:.04em; margin-top:2px; text-align:right; }

/* BADGES */
.badges { display:flex; gap:6px; padding:10px 16px 0; flex-shrink:0; flex-wrap:wrap; }
.badge  { display:flex; align-items:center; gap:4px; font-size:11px; color:var(--muted);
  background:var(--surface); border-radius:999px; padding:4px 10px;
  border:.5px solid var(--border); cursor:pointer; }
.badge.warn { background:#FEF3C7; color:#92400E; border-color:#F59E0B44; }
.bdot { width:6px; height:6px; border-radius:50%; background:#6D28D9; }

/* TABS */
.tabs { display:flex; margin:12px 16px 0; background:var(--surface); border-radius:10px;
  padding:3px; gap:2px; flex-shrink:0; }
.tab { flex:1; padding:8px 4px; text-align:center; font-size:12px; font-weight:500;
  color:var(--muted); border-radius:8px; cursor:pointer; border:none;
  background:transparent; transition:all .15s; }
.tab.active { background:var(--card); color:var(--text); box-shadow:0 1px 3px rgba(0,0,0,.08); }

/* SCROLL */
.scroll-area { flex:1; overflow-y:auto; -webkit-overflow-scrolling:touch;
  padding-bottom:calc(16px + var(--safe-bottom)); }

/* HÁBITOS HOY */
.habitos { margin:12px 16px 0; background:var(--card); border-radius:var(--radius);
  padding:12px 14px; border:.5px solid var(--border); display:flex; align-items:center; }
.hab-item { flex:1; display:flex; flex-direction:column; align-items:center; gap:5px;
  cursor:pointer; padding:2px; }
.hab-circle { width:34px; height:34px; border-radius:50%; border:1.5px solid var(--border);
  display:flex; align-items:center; justify-content:center; transition:all .15s; }
.hab-circle.on { background:var(--text); border-color:var(--text); }
.hab-circle.on::after { content:'✓'; color:var(--bg); font-size:13px; font-weight:700; }
.hab-lbl { font-size:10px; color:var(--muted); text-align:center; line-height:1.2; max-width:66px; }
.hab-div { width:.5px; height:38px; background:var(--border); }

/* VENTANAS */
.ventanas { margin:10px 16px 0; display:flex; flex-direction:column; gap:7px; }
.vcard { background:var(--card); border-radius:12px; border:.5px solid var(--border); overflow:hidden; }
.vcard-head { display:flex; align-items:center; justify-content:space-between;
  padding:9px 12px; cursor:pointer; user-select:none; }
.vtime { font-size:11px; font-weight:600; color:var(--muted); letter-spacing:.04em; font-variant-numeric:tabular-nums; }
.vbars { display:flex; gap:2px; align-items:center; }
.vbar  { height:14px; border-radius:3px; }
.vpend { font-size:11px; color:var(--faint); font-style:italic; }
.vrpt-btn { font-size:10px; font-weight:700; color:#fff; background:var(--acento);
  border:none; border-radius:6px; padding:5px 11px; cursor:pointer;
  -webkit-tap-highlight-color:transparent; }
.vbloques { padding:0 12px 9px; display:flex; flex-direction:column; gap:3px; }
.vblq { display:flex; align-items:center; gap:8px; padding:4px 0; border-top:.5px solid var(--border); }
.vblq-dot  { width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.vblq-name { flex:1; font-size:12px; font-weight:500; }
.vblq-dur  { font-size:11px; color:var(--muted); }
.vfuturo   { opacity:.35; pointer-events:none; }

/* SEMANA GRID */
.sec { margin:10px 16px 0; background:var(--card); border-radius:var(--radius); border:.5px solid var(--border); }
.sec-title { padding:10px 12px 6px; font-size:10px; font-weight:700; letter-spacing:.06em; text-transform:uppercase; color:var(--muted); }
.grid-scroll { overflow-x:auto; padding:0 12px 10px; }
.sg { display:grid; grid-template-columns:28px repeat(7,1fr); min-width:280px; }
.sg-h { text-align:center; padding:3px 1px; font-size:9px; font-weight:600; color:var(--muted); letter-spacing:.04em; }
.sg-h.hoy { color:var(--text); font-weight:800; }
.sg-t { font-size:8px; color:var(--faint); text-align:right; padding:0 3px 0 0; line-height:14px; font-variant-numeric:tabular-nums; }
.sg-c { height:14px; border-left:.5px solid var(--border); border-top:.5px solid rgba(0,0,0,.03); }
.sg-c.hmark { border-top-color:rgba(0,0,0,.12); }

/* STATS */
.stats-cols { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin:8px 16px 0; }
.stats-card { background:var(--card); border-radius:var(--radius); border:.5px solid var(--border); padding:12px; }
.sc-title   { font-size:10px; font-weight:700; letter-spacing:.06em; text-transform:uppercase; color:var(--muted); margin-bottom:10px; }
.sc-total   { font-family:Georgia,serif; font-size:32px; line-height:1; margin-bottom:2px; }
.sc-total-sub { font-size:10px; color:var(--muted); }
.abar-row  { display:flex; align-items:center; gap:6px; margin-bottom:7px; }
.abar-dot  { width:7px; height:7px; border-radius:50%; flex-shrink:0; }
.abar-info { flex:1; }
.abar-top  { display:flex; justify-content:space-between; align-items:baseline; margin-bottom:2px; }
.abar-name { font-size:10px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:70px; }
.abar-hrs  { font-size:9px; color:var(--muted); }
.abar-track { height:5px; background:var(--surface); border-radius:99px; overflow:hidden; }
.abar-fill  { height:5px; border-radius:99px; transition:width .5s; }

/* HÁBITOS CADENA */
.hab-sec { margin:8px 16px 0; background:var(--card); border-radius:var(--radius); border:.5px solid var(--border); padding:12px; }
.hab-sec-head { display:flex; justify-content:space-between; align-items:baseline; margin-bottom:10px; }
.hab-sec-title { font-size:10px; font-weight:700; letter-spacing:.06em; text-transform:uppercase; color:var(--muted); }
.hab-streak    { font-size:12px; color:var(--acento); font-weight:700; }
.hcal-header   { display:grid; grid-template-columns:repeat(7,1fr); gap:2px; margin-bottom:4px; }
.hcal-dh       { font-size:9px; text-align:center; color:var(--faint); font-weight:600; letter-spacing:.04em; }
.hcal-week     { display:grid; grid-template-columns:repeat(7,1fr); gap:2px; margin-bottom:2px; }
.hcal-day      { position:relative; display:flex; align-items:center; justify-content:center; height:26px; }
.hline         { position:absolute; top:50%; height:2px; z-index:0; transform:translateY(-50%); }
.hline.l       { right:50%; left:0; background:var(--acento); opacity:.45; }
.hline.r       { left:50%; right:0; background:var(--acento); opacity:.45; }
.hd { width:20px; height:20px; border-radius:50%; display:flex; align-items:center; justify-content:center;
  font-size:9px; z-index:1; position:relative; cursor:pointer; -webkit-tap-highlight-color:transparent; transition:all .15s; }
.hd.done   { background:var(--acento); color:#fff; font-weight:700; }
.hd.miss   { background:var(--surface); color:var(--faint); border:.5px solid var(--border); }
.hd.future { background:transparent; border:.5px dashed var(--border); color:var(--faint); opacity:.35; cursor:default; }
.hd.today-ring { box-shadow:0 0 0 2px var(--acento); }
.hab-popup { position:absolute; bottom:28px; left:50%; transform:translateX(-50%);
  background:var(--text); color:var(--bg); border-radius:8px; padding:6px 10px;
  font-size:10px; white-space:nowrap; z-index:10; pointer-events:none;
  opacity:0; transition:opacity .15s; line-height:1.5; }
.hab-popup.show { opacity:1; }
.hab-popup::after { content:''; position:absolute; top:100%; left:50%; transform:translateX(-50%);
  border:4px solid transparent; border-top-color:var(--text); }

/* NAV SEMANA */
.semana-nav { display:flex; align-items:center; justify-content:space-between; padding:10px 16px 0; }
.snav-btn   { background:var(--surface); border:.5px solid var(--border); border-radius:8px;
  padding:6px 12px; font-size:12px; color:var(--muted); cursor:pointer; }
.snav-label { font-size:12px; color:var(--text); font-weight:500; }

/* ─── AJUSTES ───────────────────────────────────────── */
.ajustes-sec { margin:10px 16px 0; background:var(--card); border-radius:var(--radius);
  border:.5px solid var(--border); padding:14px; }
.ajustes-sec-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.ajustes-sec-title { font-size:10px; font-weight:700; letter-spacing:.06em;
  text-transform:uppercase; color:var(--muted); }
.ajustes-add-btn { font-size:12px; font-weight:600; color:var(--acento);
  background:transparent; border:1.5px solid var(--acento); border-radius:8px;
  padding:5px 12px; cursor:pointer; }
.ajustes-form { display:flex; flex-direction:column; gap:10px; }
.ajustes-field { display:flex; flex-direction:column; gap:4px; flex:1; }
.ajustes-row   { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.ajustes-label { font-size:11px; color:var(--muted); font-weight:500; }
.ajustes-input { padding:10px 12px; border:1.5px solid var(--border); border-radius:10px;
  font-size:13px; background:var(--surface); color:var(--text); width:100%; }
.ajustes-input:focus { outline:none; border-color:var(--acento); background:var(--card); }
.ajustes-save-btn { padding:11px; background:var(--text); color:var(--bg); border:none;
  border-radius:10px; font-size:13px; font-weight:600; cursor:pointer; width:100%; }
.ajustes-danger-btn { padding:11px; background:transparent; color:#DC2626;
  border:1.5px solid #FECACA; border-radius:10px; font-size:13px; font-weight:600;
  cursor:pointer; width:100%; }

/* Lista de afanes en ajustes */
.afan-item { display:flex; align-items:center; gap:10px; padding:10px 0;
  border-top:.5px solid var(--border); cursor:pointer; }
.afan-item:first-child { border-top:none; }
.afan-item-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
.afan-item-info { flex:1; }
.afan-item-nombre { font-size:13px; font-weight:600; }
.afan-item-meta   { font-size:10px; color:var(--muted); margin-top:1px; }
.afan-item-arrow  { font-size:14px; color:var(--faint); }

/* Toggle push */
.toggle { width:42px; height:24px; background:var(--surface); border-radius:999px;
  position:relative; cursor:pointer; transition:background .2s;
  border:.5px solid var(--border); flex-shrink:0; }
.toggle.on { background:var(--acento); border-color:var(--acento); }
.toggle-knob { position:absolute; top:2px; left:2px; width:18px; height:18px;
  border-radius:50%; background:#fff; box-shadow:0 1px 3px rgba(0,0,0,.2);
  transition:left .2s; }
.toggle.on .toggle-knob { left:20px; }

/* Tipo selector en modal afán */
.tipo-selector { display:grid; grid-template-columns:1fr 1fr; gap:6px; }
.tipo-opt { padding:10px 12px; border-radius:10px; border:1.5px solid var(--border);
  cursor:pointer; transition:all .15s; background:var(--surface); }
.tipo-opt.active { border-color:var(--text); background:var(--card); }
.tipo-opt-name { font-size:12px; font-weight:600; }
.tipo-opt-desc { font-size:10px; color:var(--muted); margin-top:2px; }

/* Color picker */
.color-picker { display:flex; flex-wrap:wrap; gap:8px; }
.color-swatch { width:28px; height:28px; border-radius:50%; cursor:pointer;
  border:2px solid transparent; transition:all .15s; }
.color-swatch.selected { border-color:var(--text); transform:scale(1.15); }

/* MODAL */
.overlay { position:fixed; inset:0; background:rgba(0,0,0,.4); display:flex;
  align-items:flex-end; justify-content:center; z-index:100; opacity:0;
  pointer-events:none; transition:opacity .2s; }
.overlay.open { opacity:1; pointer-events:all; }
.modal { background:var(--card); border-radius:20px 20px 0 0; width:100%; max-width:480px;
  padding:20px 20px calc(32px + var(--safe-bottom));
  transform:translateY(100%); transition:transform .26s cubic-bezier(.32,.72,0,1);
  max-height:90dvh; overflow-y:auto; }
.overlay.open .modal { transform:translateY(0); }
.mhandle { width:36px; height:4px; background:var(--surface); border-radius:99px; margin:0 auto 16px; }
.mtitle  { font-family:Georgia,serif; font-size:19px; margin-bottom:2px; }
.msub    { font-size:11px; color:var(--muted); margin-bottom:14px; }
.chips   { display:flex; flex-wrap:wrap; gap:7px; margin-bottom:14px; }
.chip { padding:8px 14px; border-radius:999px; font-size:12px; font-weight:600;
  cursor:pointer; border:1.5px solid transparent; transition:all .12s;
  user-select:none; -webkit-user-select:none; -webkit-tap-highlight-color:transparent; }
.prev-box { background:var(--surface); border-radius:10px; padding:10px 12px; margin-bottom:16px; min-height:38px; }
.pbars   { display:flex; height:18px; border-radius:5px; overflow:hidden; gap:2px; }
.pbar    { border-radius:3px; transition:flex .18s; }
.plabel  { font-size:10px; color:var(--muted); margin-top:5px; text-align:center; line-height:1.4; }
.pempty  { font-size:11px; color:var(--faint); font-style:italic; text-align:center; line-height:38px; }
.mbtn { width:100%; padding:14px; background:var(--text); color:var(--bg); border:none;
  border-radius:12px; font-size:14px; font-weight:600; cursor:pointer; transition:background .1s;
  -webkit-tap-highlight-color:transparent; }
.mbtn:disabled { background:var(--faint); cursor:default; }
.btn-primary { display:block; width:100%; max-width:360px; padding:13px; background:var(--text);
  color:var(--bg); border:none; border-radius:12px; font-size:14px; font-weight:600;
  cursor:pointer; text-align:center; }

/* MISC */
.loader { display:flex; align-items:center; justify-content:center; padding:40px;
  color:var(--faint); font-size:13px; gap:8px; }
.spinner { width:16px; height:16px; border:2px solid var(--border); border-top-color:var(--acento);
  border-radius:50%; animation:spin .7s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
.error-state { margin:16px; padding:14px; background:#FEF2F2; border:.5px solid #FCA5A5;
  border-radius:10px; font-size:12px; color:#991B1B; line-height:1.5; }
.toast { position:fixed; bottom:calc(24px + var(--safe-bottom)); left:50%;
  transform:translateX(-50%) translateY(16px); background:var(--text); color:var(--bg);
  padding:9px 18px; border-radius:999px; font-size:12px; font-weight:500;
  z-index:200; opacity:0; transition:all .2s; pointer-events:none; white-space:nowrap; }
.toast.on { opacity:1; transform:translateX(-50%) translateY(0); }
