/* ============================================================
   Hábitos — sistema de diseño (inspirado en Notion)
   Minimalismo cálido · tipografía Inter · sombras en capas
   ============================================================ */

:root {
  /* neutros cálidos */
  --bg: #ffffff;
  --bg-soft: #f6f5f4;
  --text: rgba(0, 0, 0, 0.95);
  --text-2: #615d59;
  --text-3: #a39e98;
  --border: rgba(0, 0, 0, 0.10);
  --border-soft: rgba(0, 0, 0, 0.06);

  /* acento */
  --accent: #0075de;
  --accent-hover: #005bab;
  --accent-soft: #f2f9ff;
  --accent-soft-text: #097fe8;
  --focus: #097fe8;

  /* semánticos */
  --done: #1aae39;
  --done-soft: rgba(26, 174, 57, 0.12);
  --danger: #dd5b00;

  /* superficies */
  --card: #ffffff;

  /* sombras en capas (opacidad máx. 0.05) */
  --shadow-card: 0 1px 1px rgba(0, 0, 0, 0.02), 0 2px 4px rgba(0, 0, 0, 0.02),
                 0 4px 12px rgba(0, 0, 0, 0.03);
  --shadow-float: 0 2px 4px rgba(0, 0, 0, 0.02), 0 6px 16px rgba(0, 0, 0, 0.04),
                  0 12px 32px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08), 0 24px 64px rgba(0, 0, 0, 0.14);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 9999px;

  --heat-empty: #ecebe9;
  --heat-off: #f6f5f4;

  --font: 'Inter', -apple-system, 'Segoe UI', system-ui, Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #191919;
  --bg-soft: #202020;
  --text: #f6f5f4;
  --text-2: #9b968f;
  --text-3: #6b6660;
  --border: rgba(255, 255, 255, 0.12);
  --border-soft: rgba(255, 255, 255, 0.07);

  --accent: #62aef0;
  --accent-hover: #7fbbf4;
  --accent-soft: rgba(98, 174, 240, 0.14);
  --accent-soft-text: #62aef0;
  --focus: #62aef0;

  --done: #34d97b;
  --done-soft: rgba(52, 217, 123, 0.16);
  --danger: #ff7a3d;

  --card: #222222;

  --shadow-card: 0 1px 1px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-float: 0 4px 12px rgba(0, 0, 0, 0.45), 0 10px 28px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5), 0 24px 64px rgba(0, 0, 0, 0.55);

  --heat-empty: #2c2a27;
  --heat-off: #252525;
}

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

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.25s ease, color 0.25s ease;
}

/* ============ cabecera ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.brand-text { line-height: 1.1; }
.brand-text h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.brand-sub { font-size: 11.5px; color: var(--text-3); font-weight: 500; }

.actions { display: flex; gap: 2px; }
.icon-btn {
  position: relative;
  background: transparent;
  border: none;
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }

/* ============ hero ============ */
.hero {
  background: linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border-soft);
}
.hero-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 26px 20px 22px;
}
.today-label {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: capitalize;
}
.hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.hero-greeting h2 {
  margin: 0 0 4px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
}
.progress-line {
  margin: 0;
  font-size: 15px;
  color: var(--text-2);
  font-weight: 500;
}
.progress-line b { color: var(--text); font-weight: 700; }

/* anillo de progreso */
.ring-wrap { position: relative; flex-shrink: 0; }
.ring { transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--border-soft); stroke-width: 8; }
.ring-bar {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 226.19; /* 2πr, r=36 */
  stroke-dashoffset: 226.19;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.ring-done { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.ring-total { font-size: 11px; color: var(--text-3); font-weight: 600; margin-top: 2px; }

/* puntos de la semana */
.day-dots { display: flex; gap: 6px; margin-top: 20px; }
.day-dot { flex: 1; text-align: center; }
.day-dot .dot {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--border-soft);
  transition: background 0.25s ease;
}
.day-dot .dot.today { background: var(--border); }
.day-dot .dot.done { background: var(--done); }
.day-dot .ddl {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.day-dot .ddl.today { color: var(--text-2); }

/* ============ main / lista ============ */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 26px 20px 120px;
}
.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.list-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.habit-count { font-size: 13px; color: var(--text-3); font-weight: 500; }

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

.habit {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.2s ease, border-color 0.2s ease;
}
.habit:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-float);
  transform: translateY(-1px);
}
.habit:active { transform: scale(0.99); }

.habit-emoji {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  border: 1px solid var(--border-soft);
}
.habit-main { flex: 1; min-width: 0; }
.habit-name {
  font-weight: 650;
  font-size: 16px;
  margin: 0 0 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.2px;
}
.habit-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.streak {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-2);
  font-weight: 500;
}
.streak b { color: var(--text); font-weight: 700; }
.streak.record b { color: var(--accent-soft-text); }

.habit-days { display: flex; gap: 4px; }
.day-chip {
  font-size: 10px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  color: var(--text-2);
  text-transform: uppercase;
}
.day-chip.off { opacity: 0.3; }

/* botón de check */
.habit-check {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: transparent;
  transition: all 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}
.habit-check:hover { border-color: var(--accent); }
.habit-check.done {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 117, 222, 0.3);
}
.habit-check svg { opacity: 0; transition: opacity 0.15s ease, transform 0.2s ease; }
.habit-check.done svg { opacity: 1; transform: scale(1); }
.habit-check:not(.done) svg { transform: scale(0.4); }

/* ============ vacío ============ */
.empty { text-align: center; padding: 60px 20px; }
.empty-emoji { font-size: 52px; margin-bottom: 14px; }
.empty-title { font-weight: 700; font-size: 18px; margin: 0 0 4px; letter-spacing: -0.3px; }
.empty-sub { color: var(--text-2); margin: 0 0 24px; font-size: 14.5px; }

.hidden { display: none !important; }

/* ============ botones ============ */
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  letter-spacing: -0.1px;
  transition: filter 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: var(--bg-soft); color: var(--text); }
.btn.ghost:hover { filter: brightness(0.96); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.danger:hover { background: rgba(221, 91, 0, 0.08); }
.btn.block { width: 100%; }

/* ============ FAB ============ */
.fab {
  position: fixed;
  right: 22px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 117, 222, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.2s ease;
  z-index: 30;
}
.fab:hover { background: var(--accent-hover); transform: translateY(-2px); }
.fab:active { transform: scale(0.94); }

/* ============ modal ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; padding: 24px; }
}
.modal {
  background: var(--card);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@media (min-width: 560px) { .modal { border-radius: 20px; } }
@keyframes slideUp {
  from { transform: translateY(36px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  position: sticky;
  top: 0;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 14px;
  z-index: 1;
}
.modal-header h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.3px; }
.close {
  background: transparent;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.close:hover { background: var(--bg-soft); }
.modal-body { padding: 6px 22px 26px; }

/* ============ formulario ============ */
.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.field input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input[type="text"]:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input[type="text"]::placeholder { color: var(--text-3); }

.emoji-input { display: flex; gap: 10px; align-items: center; }
.emoji-input input[type="text"] { width: 60px; text-align: center; font-size: 22px; padding: 8px; }
.emoji-preview { font-size: 26px; }

.color-row { display: flex; gap: 9px; flex-wrap: wrap; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.selected { border-color: var(--text); box-shadow: 0 0 0 3px var(--bg); }

.days-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.day-toggle {
  flex: 1;
  min-width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-2);
  transition: all 0.14s ease;
}
.day-toggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.form-actions { display: flex; gap: 10px; margin-top: 24px; }
.form-actions .btn { flex: 1; }

/* ============ heatmap ============ */
.heatmap-wrap { overflow-x: auto; padding: 4px 0; }
.heatmap { display: flex; gap: 4px; }
.heat-col { display: flex; flex-direction: column; gap: 4px; }
.heat-cell {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--heat-empty);
  transition: transform 0.1s ease;
}
.heat-cell.filled:hover, .heat-cell:not(.filled):not(.future):hover { transform: scale(1.25); }
.heat-cell.off { background: var(--heat-off); opacity: 0.7; }
.heat-cell.future { background: transparent; border: 1px dashed var(--border-soft); }
.heat-legend { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12.5px; color: var(--text-2); }
.heat-legend .heat-cell { display: inline-block; }

/* ============ estadísticas ============ */
.stat-block { margin-bottom: 24px; }
.stat-block h3 { font-size: 13px; margin: 0 0 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card {
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 18px;
}
.stat-pct { font-size: 32px; font-weight: 800; letter-spacing: -1.5px; }
.stat-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.progress { height: 8px; background: var(--heat-empty); border-radius: var(--radius-pill); margin-top: 14px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: var(--radius-pill); transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1); }

.best-worst { display: flex; flex-direction: column; gap: 10px; }
.bw-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 14px;
}
.bw-emoji {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
}
.bw-info { flex: 1; }
.bw-name { font-weight: 650; font-size: 15px; letter-spacing: -0.2px; }
.bw-pct { font-size: 12px; color: var(--text-3); }
.bw-badge { font-weight: 800; font-size: 17px; letter-spacing: -0.5px; }

.detail-actions { display: flex; gap: 10px; margin-top: 22px; }
.detail-actions .btn { flex: 1; }

/* ============ toast ============ */
.toast {
  position: fixed;
  bottom: 98px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 550;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: toastIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes toastIn {
  from { transform: translate(-50%, 12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ============ responsive ============ */
@media (min-width: 720px) {
  .hero-inner, main { max-width: 680px; }
  .hero-greeting h2 { font-size: 34px; }
}
@media (max-width: 400px) {
  .brand-sub { display: none; }
  .brand-text h1 { font-size: 16px; }
  .habit { padding: 13px 14px; gap: 12px; }
  .habit-emoji { width: 44px; height: 44px; font-size: 22px; }
  .day-chip { display: none; }
}
