/* =========================================================
   Hábitos — estilos
   Estética: oscura, minimalista, con profundidad.
   ========================================================= */

:root {
  --bg: #050506;
  --card: rgba(255, 255, 255, 0.035);
  --card-border: rgba(255, 255, 255, 0.06);
  --field: rgba(255, 255, 255, 0.05);
  --field-border: rgba(255, 255, 255, 0.08);
  --text: #F2F2F2;
  --text-2: #8A8A8E;
  --text-3: #55555A;
  --empty: #1C1C1F;
  --danger: #FF4D6D;
  --radius: 22px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro", system-ui, sans-serif;
  color-scheme: dark;
}

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

.ico { width: 22px; height: 22px; flex: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Fondo con profundidad ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg);
}
.blob {
  position: absolute;
  width: 90vmax;
  height: 90vmax;
  border-radius: 50%;
  background: radial-gradient(circle, var(--col) 0%, transparent 62%);
  filter: blur(40px);
  opacity: 0.09;
  transition: background 0.6s;
}
.b1 { --col: var(--blob1, #6E7BFF); top: -40vmax; left: -35vmax; }
.b2 { --col: var(--blob2, #A66BFF); top: 15vh; right: -50vmax; opacity: 0.07; }
.b3 { --col: var(--blob3, #2DD4BF); bottom: -55vmax; left: -15vmax; opacity: 0.06; }

/* ---------- Contenedor principal (respeta zonas seguras del iPhone) ---------- */
.app {
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 20px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 112px)
    calc(env(safe-area-inset-left) + 16px);
}

/* ---------- Cabecera de Inicio ---------- */
.top { padding: 8px 4px 20px; }
.top .date {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.top h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ---------- Tarjetas de cristal ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.habits { display: flex; flex-direction: column; gap: 12px; }

.habit {
  position: relative;
  padding: 16px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.habit-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.habit-icon {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
}
.habit-icon.big { width: 48px; height: 48px; border-radius: 14px; }
.habit-icon.big .ico { width: 26px; height: 26px; }
.habit-icon.small { width: 32px; height: 32px; border-radius: 10px; }
.habit-icon.small .ico { width: 18px; height: 18px; }

.habit-title { flex: 1; min-width: 0; }
.habit-name {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.habit-sub {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.flag { display: inline-flex; align-items: center; gap: 2px; color: var(--text-3); vertical-align: -2px; }
.flag .ico { width: 13px; height: 13px; }

.streak { flex: none; text-align: right; line-height: 1.1; }
.streak-num {
  display: block;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.streak-num.zero { color: var(--text-3); }
.streak-label { font-size: 11px; color: var(--text-2); }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-2);
}
.icon-btn .ico { width: 20px; height: 20px; }
.icon-btn:active { background: rgba(255, 255, 255, 0.06); }
.habit-head .edit { margin: -8px -10px -8px -6px; color: var(--text-3); }
.habit-head .edit .ico { width: 17px; height: 17px; }

.hint {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
}

/* Reordenar */
.reordering .habit:not(.dragging) { transition: transform 0.18s ease; }
.habit.dragging {
  z-index: 5;
  background: rgba(32, 32, 36, 0.92);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
}

/* ---------- Mapa de calor ---------- */
.heatmap {
  display: grid;
  grid-template-columns: repeat(var(--weeks), 1fr);
  grid-template-rows: repeat(7, auto);
  grid-auto-flow: column;
  gap: 2.5px;
}
.cell {
  display: block;
  aspect-ratio: 1;
  border-radius: 2.5px;
  background: var(--empty);
}
.cell.done { background: var(--c); }
.cell.part { background: color-mix(in srgb, var(--c) var(--p), var(--empty)); }
.cell.off { opacity: 0.35; }
.cell.future { background: transparent; }

/* El cuadrado de hoy: se puede tocar. Su zona táctil invisible mide ~44px. */
.cell.today {
  position: relative;
  opacity: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}
.cell.today::after {
  content: "";
  position: absolute;
  inset: -18px;
}
.cell.today.done {
  box-shadow: 0 0 8px color-mix(in srgb, var(--c) 55%, transparent);
}
.cell.today:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* Animación al completar: pequeño "pop" con brillo */
.cell.today.pop { animation: pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes pop {
  0%   { transform: scale(0.4); }
  60%  { transform: scale(1.6); box-shadow: 0 0 16px 4px var(--c); }
  100% { transform: scale(1);   box-shadow: 0 0 8px color-mix(in srgb, var(--c) 55%, transparent); }
}

/* ---------- Inicio vacío ---------- */
.empty {
  padding: 32px 24px 28px;
  text-align: center;
}
.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  color: #4ADE80;
  background: rgba(74, 222, 128, 0.12);
}
.empty-icon .ico { width: 32px; height: 32px; }
.empty h2 { margin: 0 0 6px; font-size: 20px; }
.empty p { margin: 0 auto 20px; max-width: 300px; color: var(--text-2); font-size: 15px; }

/* ---------- Archivados ---------- */
.archived { margin-top: 24px; }
.archived summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  list-style: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-2);
}
.archived summary::-webkit-details-marker { display: none; }
.archived summary .ico { width: 16px; height: 16px; }
.archived-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.archived-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px 8px 12px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
}
.archived-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  font-weight: 600;
  transition: transform 0.12s;
}
.btn:active { transform: scale(0.97); }
.btn .ico { width: 20px; height: 20px; }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.ghost { background: rgba(255, 255, 255, 0.07); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { min-height: 36px; padding: 0 16px; border-radius: 999px; font-size: 15px; position: relative; }
.btn.small::after { content: ""; position: absolute; inset: -4px; }

.fab {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 20px);
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  transition: transform 0.15s;
  z-index: 4;
}
.fab:active { transform: scale(0.94); }
.fab .ico { width: 26px; height: 26px; }
@media (min-width: 600px) {
  .fab { right: calc(50% - 280px + 20px); }
}

/* ---------- Formulario ---------- */
.form-top {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: calc(-1 * (env(safe-area-inset-top) + 20px)) -16px 16px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 6px;
  background: rgba(5, 5, 6, 0.72);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--card-border);
}
.form-top h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-align: center; }

.form { display: flex; flex-direction: column; gap: 12px; }
.group { padding: 16px; }
.label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.field { display: block; margin-top: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.input {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  font: inherit;
  font-size: 16px; /* 16px evita el zoom automático en iPhone */
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-border);
  border-radius: 12px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--c, var(--text-2)); }
input[type="time"].input { display: block; }

.name-row { display: flex; align-items: center; gap: 12px; }

.error { margin: 8px 2px 0; font-size: 13px; color: var(--danger); }
.hint-text { margin: 10px 2px 0; font-size: 13px; color: var(--text-2); }
.hint-text.note { color: var(--text-3); }

/* Iconos a elegir */
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
}
.icon-grid button {
  aspect-ratio: 1;
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--text-2);
  background: rgba(255, 255, 255, 0.04);
}
.icon-grid button.on {
  color: var(--c);
  background: color-mix(in srgb, var(--c) 16%, transparent);
  box-shadow: inset 0 0 0 1.5px var(--c);
}

/* Colores */
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; justify-items: center; }
.swatch {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.swatch span {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--sw);
  transition: transform 0.15s;
}
.swatch.on { box-shadow: inset 0 0 0 2px var(--sw); }
.swatch.on span { transform: scale(0.8); }

/* Selector segmentado */
.seg {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 2px;
  padding: 3px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.05);
}
.seg button {
  min-height: 40px;
  padding: 0 4px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
}
.seg button.on { background: rgba(255, 255, 255, 0.12); color: var(--text); font-weight: 600; }

/* Días de la semana */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 14px; }
.chip {
  min-height: 44px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  background: rgba(255, 255, 255, 0.05);
}
.chip.on { color: var(--bg); background: var(--c); }

/* Contador − / + */
.stepper { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.step {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
}
.step .ico { width: 20px; height: 20px; }
.step-value {
  min-width: 32px;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.step-label { color: var(--text-2); font-size: 15px; }

/* Interruptor */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  cursor: pointer;
}
.switch-label { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.switch-label .ico { width: 20px; height: 20px; color: var(--text-2); }
.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 999px;
  background: #39393D;
  cursor: pointer;
  transition: background 0.2s;
}
.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch:checked { background: var(--c, #4ADE80); }
.switch:checked::before { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* Archivar / borrar */
.manage { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.btn-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border-radius: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-border);
}
.btn-row .ico { width: 19px; height: 19px; }
.btn-row.danger { color: var(--danger); margin-top: 12px; }
.manage .hint-text { text-align: center; margin: 4px 0 0; }

/* ---------- Panel inferior (hoja) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.22s;
}
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
  border-radius: 22px 22px 0 0;
  background: rgba(24, 24, 28, 0.9);
  border: 1px solid var(--card-border);
  border-bottom: 0;
  -webkit-backdrop-filter: blur(30px);
  backdrop-filter: blur(30px);
  transform: translateY(100%);
  transition: transform 0.22s ease-out;
}
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: translateY(0); }
.sheet-grip {
  width: 36px;
  height: 5px;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.sheet-title { margin: 0; font-size: 18px; font-weight: 600; }
.sheet-sub { margin: 2px 0 0; font-size: 13px; color: var(--text-2); }
.sheet-sub.center { text-align: center; margin-top: 10px; }
.sheet-text { margin: 8px 0 20px; color: var(--text-2); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }

.value-stepper { display: flex; align-items: center; gap: 12px; }
.step.big { width: 52px; height: 52px; }
.value-field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}
.value-input {
  width: 100%;
  min-width: 0;
  max-width: 140px;
  padding: 0;
  border: 0;
  outline: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 44px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.value-input::placeholder { color: var(--text-3); }
.value-unit { flex: none; max-width: 40%; color: var(--text-2); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal-bar {
  height: 6px;
  margin-top: 16px;
  border-radius: 999px;
  background: var(--empty);
  overflow: hidden;
}
.goal-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--c);
  transition: width 0.2s;
}

/* ---------- Aviso breve ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 48px);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  text-align: center;
  color: var(--text);
  background: rgba(40, 40, 44, 0.72);
  border: 1px solid var(--card-border);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  animation: toast 2.6s ease forwards;
  z-index: 30;
}
@keyframes toast {
  0%   { opacity: 0; transform: translate(-50%, 8px); }
  10%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; }
}

/* ---------- Enlace del nombre en las tarjetas ---------- */
.habit { cursor: pointer; }
.habit-link { color: inherit; text-decoration: none; }
.habit-link:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 4px; }

/* ---------- Detalle del hábito ---------- */
.top-spacer { flex: 1; }
.icon-btn:disabled { opacity: 0.25; cursor: default; }
.detail-hero { display: flex; align-items: center; gap: 14px; padding: 0 4px 18px; }
.detail-hero h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.detail-hero .habit-sub { white-space: normal; }

.map-card { padding: 8px 14px 16px; }
.period-nav { display: flex; align-items: center; justify-content: space-between; margin: 0 -8px 6px; }
.period-range { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: center; }

.bigmap {
  display: grid;
  grid-template-columns: 22px repeat(var(--weeks), 1fr);
  gap: 3px;
  align-items: center;
}
.bm-month {
  height: 16px;
  font-size: 10px;
  line-height: 16px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: visible;
  text-transform: capitalize;
}
.bm-day { font-size: 10px; color: var(--text-3); }
.bigmap .cell { position: relative; border-radius: 4px; }
.bigmap .cell.today::after { display: none; }
.bigmap button.cell:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
/* Punto: el día tiene nota o imagen */
.cell.dot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.85);
}
.cell.done.dot::before { background: rgba(5, 5, 6, 0.75); }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px; min-width: 0; }
.stat-label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-2);
}
.stat-num {
  margin-top: 4px;
  font-size: 32px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--c);
}
.stat-sub { font-size: 12.5px; color: var(--text-2); }
.stat-bar { display: block; height: 5px; margin-top: 8px; border-radius: 999px; background: var(--empty); overflow: hidden; }
.stat-bar span { display: block; height: 100%; border-radius: inherit; background: var(--c); }

.section-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.chart-card { padding: 14px 14px 8px; }
.chart { display: block; width: 100%; height: auto; }
.chart .grid { stroke: rgba(255, 255, 255, 0.07); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 9px; font-family: var(--font); }
.chart .goal { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .goal-label {
  fill: var(--text);
  font-size: 9px;
  font-family: var(--font);
  paint-order: stroke;
  stroke: #111114;
  stroke-width: 3px;
  stroke-linejoin: round;
}

.history { margin-top: 22px; }
.history .section-title { margin-left: 4px; }
.empty-note { margin: 0 4px; color: var(--text-2); font-size: 14px; }
.month-card { padding: 4px 6px 6px; margin-bottom: 10px; }
.month-head { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 10px 4px; }
.month-name { display: inline-block; font-weight: 600; }
.month-name::first-letter { text-transform: uppercase; }
.month-count { font-size: 13px; color: var(--text-2); }
.history-row {
  width: 100%;
  min-height: 44px;
  display: grid;
  grid-template-columns: 64px 52px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 0 10px;
  border-radius: 12px;
  text-align: left;
  font-size: 14px;
}
.history-row:active { background: rgba(255, 255, 255, 0.05); }
.history-row:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }
.h-date::first-letter { text-transform: uppercase; }
.h-time { color: var(--text-2); font-variant-numeric: tabular-nums; }
.h-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-value.muted { color: var(--text-3); }
.h-icons { display: flex; gap: 6px; color: var(--text-3); }
.h-icons .ico { width: 15px; height: 15px; }

/* ---------- Hoja del día ---------- */
.sheet {
  max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.day-date::first-letter { text-transform: uppercase; }
.day-block { margin-top: 18px; }
.day-block:first-child { margin-top: 0; }
.textarea { min-height: 88px; resize: vertical; line-height: 1.4; display: block; }
.photo { display: flex; align-items: center; gap: 14px; }
.photo-thumb {
  width: 96px;
  height: 96px;
  flex: none;
  overflow: hidden;
  border-radius: 14px;
  background: var(--empty);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-actions.single { grid-template-columns: 1fr; }
.hint-text.center { text-align: center; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: rgba(0, 0, 0, 0.94);
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; object-fit: contain; }
.lightbox-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  right: calc(env(safe-area-inset-right) + 8px);
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

/* =========================================================
   Ordenador y ratón
   ========================================================= */

/* Piezas que solo se ven en ordenador */
.sidebar { display: none; }
.top-add { display: none; }

/* Etiqueta al pasar el ratón */
.tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  max-width: 280px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.3;
  white-space: nowrap;
  color: var(--text);
  background: rgba(32, 32, 36, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.tooltip::first-letter { text-transform: uppercase; }

/* Mientras se arrastra una tarjeta */
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

/* Ventana centrada (Añadir / Editar en ordenador) */
.modal {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.modal-box {
  position: relative;
  width: min(640px, 100%);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 20px 24px;
  border-radius: 22px;
  background: rgba(18, 18, 22, 0.94);
  border: 1px solid var(--card-border);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(30px);
  backdrop-filter: blur(30px);
}
.modal-box .form-top {
  margin: 0 -20px 16px;
  padding: 12px 16px 12px 10px;
  border-radius: 22px 22px 0 0;
  background: rgba(18, 18, 22, 0.92);
}

/* ---------- Efectos al pasar el ratón ---------- */
@media (hover: hover) and (pointer: fine) {
  .btn, .btn-row, .icon-btn, .step, .chip, .seg button, .icon-grid button,
  .history-row, .archived-row, .nav-item, .avatar {
    transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.12s, filter 0.15s;
  }
  /* Las tarjetas solo animan el color (el movimiento al reordenar lo controla .reordering) */
  .card.habit:not(.dragging) { transition: background-color 0.15s, border-color 0.15s; }
  .reordering .card.habit:not(.dragging) { transition: transform 0.18s ease, background-color 0.15s; }
  .card.habit:hover { background: rgba(255, 255, 255, 0.055); border-color: rgba(255, 255, 255, 0.1); }
  .btn.primary:hover { filter: brightness(0.9); }
  .btn.ghost:hover, .btn-row:hover { background: rgba(255, 255, 255, 0.1); }
  .icon-btn:not(:disabled):hover, .step:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
  .chip:not(.on):hover, .seg button:not(.on):hover, .icon-grid button:not(.on):hover { background: rgba(255, 255, 255, 0.09); color: var(--text); }
  .history-row:hover { background: rgba(255, 255, 255, 0.05); }
  .fab:hover { transform: scale(1.05); }

  .heatmap .cell:not(.future), .bigmap .cell:not(.future) { transition: transform 0.1s; }
  .heatmap .cell:not(.future):hover, .bigmap button.cell:hover { transform: scale(1.35); position: relative; z-index: 1; }
  .bigmap button.cell:hover { transform: scale(1.15); }
}

/* ---------- Pantalla de ordenador (≥ 900 px) ---------- */
@media (min-width: 900px) {
  :root { --sidebar-w: 232px; }

  body { padding-left: var(--sidebar-w); }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 8;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 24px 14px 20px;
    background: rgba(255, 255, 255, 0.02);
    border-right: 1px solid var(--card-border);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 20px;
    color: var(--text);
    text-decoration: none;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
  }
  .brand img { border-radius: 9px; }
  .nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 12px;
    color: var(--text-2);
    text-decoration: none;
    font-weight: 500;
  }
  .nav-item .ico { width: 20px; height: 20px; }
  .nav-item.active { color: var(--text); background: rgba(255, 255, 255, 0.07); }
  a.nav-item:not(.active):hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
  .nav-item.disabled { color: var(--text-3); cursor: default; }
  .soon {
    margin-left: auto;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    background: rgba(255, 255, 255, 0.05);
  }
  .avatar {
    margin-top: auto;
    width: 44px;
    height: 44px;
    margin-left: 6px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--text-2);
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--card-border);
  }
  .avatar:disabled { cursor: default; }
  .avatar .ico { width: 22px; height: 22px; }

  /* Contenido: ancho máximo ~1200 px, centrado en el espacio que deja la barra */
  .app {
    max-width: 1200px;
    padding: 36px 40px 64px;
  }

  /* Inicio */
  .top {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 0 4px 24px;
  }
  .top-add { display: inline-flex; }
  .fab { display: none; }
  .habits {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
  }
  .habit { padding: 18px 20px 20px; }
  .heatmap { gap: 3px; }
  .cell { border-radius: 3px; }
  .empty { max-width: 520px; margin: 40px auto 0; }
  .archived { max-width: 560px; margin-left: auto; margin-right: auto; }

  /* Barra superior del detalle y del formulario a pantalla completa */
  .form-top {
    position: static;
    margin: 0 0 12px;
    padding: 0;
    background: none;
    border: 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .modal-box .form-top {
    position: sticky;
    top: 0;
    padding: 12px 16px 12px 10px;
    margin: 0 -20px 16px;
    background: rgba(18, 18, 22, 0.92);
    border-bottom: 1px solid var(--card-border);
  }

  /* Detalle */
  .detail-hero h1 { font-size: 30px; }
  .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 16px 0; }
  .map-card { padding: 12px 20px 20px; }
  .bigmap { gap: 4px; }

  /* Paneles (hoja del día, valor, confirmar): ventana centrada en vez de panel desde abajo */
  .sheet {
    top: 50%;
    bottom: auto;
    left: 50%;
    right: auto;
    width: min(520px, calc(100vw - 48px));
    max-height: calc(100dvh - 48px);
    padding: 22px 24px 24px;
    border-radius: 22px;
    border-bottom: 1px solid var(--card-border);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    opacity: 0;
    transform: translate(-50%, -48%) scale(0.98);
    transition: transform 0.18s ease-out, opacity 0.18s ease-out;
  }
  .sheet-wrap.open .sheet { opacity: 1; transform: translate(-50%, -50%); }
  .sheet-grip { display: none; }

  .toast { bottom: 32px; left: calc(50% + var(--sidebar-w) / 2); }
}

/* Pantallas muy anchas: 3 columnas */
@media (min-width: 1600px) {
  .habits { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Menos movimiento si el sistema lo pide ---------- */
@media (prefers-reduced-motion: reduce) {
  .cell.today.pop, .toast { animation: none; }
  .fab, .btn, .sheet, .sheet-backdrop, .switch, .switch::before, .swatch span, .goal-bar span, .blob,
  .reordering .habit:not(.dragging) { transition: none; }
  .sheet, .heatmap .cell, .bigmap .cell { transition: none !important; }
}
