/* ---------- Design system ---------- */
:root {
  --bg: #f4f1f8;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-dim: #8a8a8e;
  --accent: #7c5cff;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);

  /* paleta pastel de tarjetas */
  --c-pink: #f9dcec;
  --c-peach: #f8dfc0;
  --c-yellow: #f5e27a;
  --c-green: #d9f2a8;
  --c-blue: #cfe4f7;
  --c-mint: #c9efe0;
  --c-lavender: #e7ddf7;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121016;
    --card: #1e1b24;
    --text: #f2f2f7;
    --text-dim: #9b98a3;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #121016;
  --card: #1e1b24;
  --text: #f2f2f7;
  --text-dim: #9b98a3;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px 140px;
  position: relative;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 12px;
}
.topbar h1 { font-size: 22px; font-weight: 700; }
.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: rgba(128, 128, 128, 0.12); }
.streak-pill {
  background: var(--card); box-shadow: var(--shadow);
  border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; gap: 6px;
}
.ring { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(128, 128, 128, 0.25); stroke-width: 4; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 100.53; stroke-dashoffset: 100.53;
  transition: stroke-dashoffset 0.35s ease;
}

/* ---------- Week strip ---------- */
.weekstrip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 18px;
}
.weekstrip .day {
  background: var(--card);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 0;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.weekstrip .day:hover { transform: translateY(-2px); }
.weekstrip .day .dow { font-size: 11px; color: var(--text-dim); }
.weekstrip .day .num { font-size: 15px; font-weight: 700; margin-top: 2px; }
.weekstrip .day.selected { background: var(--accent); color: #fff; }
.weekstrip .day.selected .dow { color: rgba(255, 255, 255, 0.8); }

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

.habit-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 16px;
  border-radius: var(--radius);
  background: var(--c-blue);
  cursor: grab;
  user-select: none;
  transition: opacity 0.15s ease, transform 0.12s ease;
}
.habit-card.dragging { opacity: 0.4; cursor: grabbing; }
.habit-card.drag-over { transform: scale(1.01); box-shadow: 0 0 0 2px var(--accent) inset; }
.habit-card .emoji { font-size: 26px; line-height: 1; }
.habit-card .body { flex: 1; min-width: 0; }
.habit-card .when { font-size: 12px; color: rgba(0, 0, 0, 0.45); }
.habit-card .title { font-size: 17px; font-weight: 700; color: #1c1c1e; }
.habit-card.done .title { text-decoration: line-through; opacity: 0.55; }

.check {
  width: 26px; height: 26px; border-radius: 999px;
  border: 2px solid rgba(0, 0, 0, 0.3);
  background: transparent; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center; font-size: 15px; color: transparent;
}
.habit-card.done .check {
  background: #1c1c1e; border-color: #1c1c1e; color: #fff;
}

.empty {
  text-align: center; color: var(--text-dim);
  padding: 60px 20px; font-size: 15px;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: calc(50% - 240px + 16px);
  bottom: 78px;
  width: 56px; height: 56px;
  border-radius: 999px; border: none;
  background: var(--accent); color: #fff;
  font-size: 28px; cursor: pointer;
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.45);
  z-index: 20;
}
@media (max-width: 512px) { .fab { right: 20px; } }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: 0;
  width: 100%; max-width: 480px;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--card);
  border-top: 1px solid rgba(128, 128, 128, 0.18);
  box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.05);
  z-index: 15;
}
.bottomnav button {
  background: none; border: none; cursor: pointer;
  padding: 10px 0 14px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600;
  color: var(--text-dim);
}
.bottomnav button .bn-ico { font-size: 20px; filter: grayscale(1) opacity(0.6); }
.bottomnav button.active { color: var(--accent); }
.bottomnav button.active .bn-ico { filter: none; }

/* ---------- Vista Metas ---------- */
.goals-view { display: flex; flex-direction: column; gap: 12px; }
.goals-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 2px;
}
.goals-head p { font-size: 12px; color: var(--text-dim); line-height: 1.4; }
.goals-count {
  flex-shrink: 0; background: var(--card); box-shadow: var(--shadow);
  border-radius: 999px; padding: 5px 11px; font-weight: 700; font-size: 13px;
}
.habit-card[data-gid] { cursor: pointer; }

/* ---------- Meta general: extras del modal ---------- */
.mg-desc {
  width: 100%; min-height: 70px; resize: vertical;
  font: inherit; padding: 10px; border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.2); background: #fff; color: #1c1c1e;
  margin: 6px 0 10px;
}
.ms-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(0,0,0,0.08); }
.ms-row:last-child { border-bottom: none; }
.ms-row .s-text {
  flex: 1; font: inherit; padding: 7px 9px; border-radius: 9px;
  border: 1px solid rgba(0, 0, 0, 0.2); background: #fff; color: #1c1c1e;
}
.ms-check {
  width: 24px; height: 24px; flex-shrink: 0; border-radius: 999px;
  border: 2px solid rgba(0, 0, 0, 0.3); background: #fff;
  cursor: pointer; font-size: 13px; color: transparent;
  display: grid; place-items: center;
}
.ms-check.on { background: #1c1c1e; border-color: #1c1c1e; color: #fff; }

/* ---------- Modal ---------- */
.hidden { display: none !important; }
.modal-root { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); }
.modal-card {
  position: relative;
  width: 100%; max-width: 480px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 16px 20px 32px;
  max-height: 90vh; overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.text-btn { background: none; border: none; color: var(--accent); font-size: 16px; font-weight: 600; cursor: pointer; }
.danger-btn { background: none; border: none; color: #e5484d; font-size: 15px; cursor: pointer; margin-top: 20px; width: 100%; }
.modal-emoji { text-align: center; margin: 8px 0; }
.emoji-big { font-size: 44px; background: none; border: none; cursor: pointer; }
.name-input {
  width: 100%; text-align: center; font-size: 22px; font-weight: 700;
  border: none; background: none; color: var(--text); padding: 6px; outline: none;
}
.name-input::placeholder { color: var(--text-dim); }

.swatches { display: flex; gap: 10px; justify-content: center; margin: 16px 0 8px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 999px; border: 3px solid var(--card); box-shadow: 0 0 0 1px rgba(0,0,0,0.1); cursor: pointer; }
.swatch.selected { box-shadow: 0 0 0 2px var(--accent); }

.field-group { background: rgba(128,128,128,0.06); border-radius: var(--radius-sm); padding: 4px 12px; margin-top: 14px; }
.field { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid rgba(128,128,128,0.12); }
.field:last-child { border-bottom: none; }
.field label { font-weight: 600; font-size: 14px; min-width: 60px; }
.field select, .field input[type="number"], .field input[type="text"], .field input[type="date"] {
  font: inherit; padding: 6px 8px; border-radius: 8px;
  border: 1px solid rgba(128,128,128,0.3); background: var(--card); color: var(--text);
}
.field input[type="number"] { width: 64px; }

.weekday-picker { display: flex; gap: 6px; }
.weekday-picker button {
  width: 32px; height: 32px; border-radius: 999px; border: 1px solid rgba(128,128,128,0.3);
  background: var(--card); color: var(--text); cursor: pointer; font-size: 12px;
}
.weekday-picker button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.dates-list { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.dates-list .chip { background: var(--card); border: 1px solid rgba(128,128,128,0.3); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; }

/* ---------- Emoji picker ---------- */
.emoji-popover {
  position: fixed; z-index: 60;
  width: 300px; max-height: 320px; overflow-y: auto;
  background: var(--card); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 10px;
}
.emoji-popover input {
  width: 100%; padding: 8px; border-radius: 8px; margin-bottom: 8px;
  border: 1px solid rgba(128,128,128,0.3); background: var(--card); color: var(--text); font: inherit;
}
.emoji-cat-title { font-size: 11px; color: var(--text-dim); margin: 8px 2px 4px; text-transform: uppercase; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-grid button { font-size: 20px; background: none; border: none; cursor: pointer; padding: 4px; border-radius: 6px; }
.emoji-grid button:hover { background: rgba(128,128,128,0.15); }

/* ---------- Login ---------- */
.login-root {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: var(--bg); padding: 24px;
}
.login-card {
  width: 100%; max-width: 320px;
  background: var(--card); box-shadow: var(--shadow);
  border-radius: var(--radius); padding: 28px 22px;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-logo { font-size: 40px; }
.login-card h2 { font-size: 20px; margin-bottom: 6px; }
.login-card input {
  font: inherit; padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px solid rgba(128, 128, 128, 0.3);
  background: var(--card); color: var(--text); outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  font: inherit; font-weight: 600; padding: 11px; margin-top: 4px;
  border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; cursor: pointer;
}
.login-error { color: #e5484d; font-size: 13px; margin: 0; }

/* ---------- Extras ---------- */
.field .sub { font-size: 12px; color: var(--text-dim); }
.settings-note { font-size: 12px; color: var(--text-dim); margin-top: 14px; line-height: 1.5; }

.habit-card .goalbar {
  height: 5px; border-radius: 999px; background: rgba(0, 0, 0, 0.12);
  margin-top: 6px; overflow: hidden;
}
.habit-card .goalbar > i {
  display: block; height: 100%; background: rgba(0, 0, 0, 0.45);
  transition: width 0.3s ease;
}

/* ---------- Animaciones ---------- */
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.28); } 100% { transform: scale(1); } }
.check.pop { animation: pop 0.3s ease; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.habit-card { animation: fadeUp 0.18s ease both; }

@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-card { animation: slideUp 0.22s ease both; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ================= Sheet estilo "New Task" ================= */
.modal-card.sheet {
  background: #c9efe0;               /* lo pisa el color del hábito por JS */
  color: #1c1c1e;
  border-radius: 24px 24px 0 0;
}
.sheet .text-btn { color: #3a2fb0; }
.sheet .text-btn.strong { font-weight: 700; }
.sheet .icon-btn { color: #1c1c1e; }
.sheet .name-input { color: #1c1c1e; }
.sheet .name-input::placeholder { color: rgba(0,0,0,0.35); }
.tap-hint { text-align: center; font-size: 12px; color: rgba(0,0,0,0.4); margin-top: 2px; }

/* filas tipo lista */
.rows {
  background: #fff;
  border-radius: 16px;
  padding: 4px 14px;
  margin-top: 14px;
}
.rows-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0 8px; font-weight: 700; color: #1c1c1e;
}
.rows-title small { color: rgba(0,0,0,0.4); font-weight: 600; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0; cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.rows .row:last-of-type { border-bottom: none; }
.row-ico { font-size: 17px; width: 22px; text-align: center; }
.row-label { flex: 1; font-weight: 600; color: #1c1c1e; }
.row-val { color: rgba(0,0,0,0.45); font-size: 14px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-chev { color: rgba(0,0,0,0.3); transition: transform 0.15s ease; }
.row.open .row-chev { transform: rotate(90deg); }

.row-editor {
  display: none;
  padding: 4px 0 14px 34px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.row-editor.open { display: block; }
.rows .row-editor:last-child { border-bottom: none; }
.row-editor select, .row-editor input[type="date"], .row-editor input[type="time"],
.row-editor input[type="text"], .row-editor input[type="number"] {
  font: inherit; padding: 7px 9px; border-radius: 9px;
  border: 1px solid rgba(0,0,0,0.2); background: #fff; color: #1c1c1e;
}
.row-editor input[type="number"] { width: 60px; }
.sub-block { margin-top: 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.note-inline { font-size: 11px; color: rgba(0,0,0,0.45); margin: 8px 0 4px; line-height: 1.4; }

.mini-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.2); background: #fff; color: #1c1c1e; cursor: pointer;
}
.mini-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.mini-btn.del { border: none; color: #e5484d; padding: 5px 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.chips .chip {
  background: rgba(0,0,0,0.06); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; color: #1c1c1e;
}

/* metas / subtareas en el editor */
.goal-row, .sub-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px solid rgba(0,0,0,0.08);
}
.goal-row:last-child, .sub-row:last-child { border-bottom: none; }
.goal-row label { font-size: 11px; color: rgba(0,0,0,0.5); display: flex; align-items: center; gap: 3px; }
.goal-row .g-label { flex: 1 1 100%; }
.goal-row input, .sub-row input {
  font: inherit; padding: 7px 9px; border-radius: 9px;
  border: 1px solid rgba(0,0,0,0.2); background: #fff; color: #1c1c1e;
}
.goal-row .g-target, .goal-row .g-step { width: 52px; }
.goal-row .g-unit { width: 90px; }
.sub-row .s-text { flex: 1; }

/* ================= Modal detalle / seguimiento ================= */
.detail-name { text-align: center; font-size: 22px; margin-top: 4px; color: #1c1c1e; }
.detail-meta { text-align: center; font-size: 12px; color: rgba(0,0,0,0.5); margin: 6px 0 16px; }

.goal-track { background: #fff; border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.gt-label { font-weight: 600; color: #1c1c1e; margin-bottom: 8px; font-size: 14px; }
.gt-label span { color: rgba(0,0,0,0.45); font-weight: 500; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 34px; height: 34px; border-radius: 999px; border: none;
  background: #1c1c1e; color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0;
}
.stepper .bar { flex: 1; height: 8px; border-radius: 999px; background: rgba(0,0,0,0.12); overflow: hidden; }
.stepper .bar > i { display: block; height: 100%; background: #1c1c1e; transition: width 0.25s ease; }

.subs-track { display: flex; flex-direction: column; gap: 8px; }
.sub-track {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 12px; padding: 12px 14px;
  color: #1c1c1e; font-size: 14px; cursor: pointer;
}
.sub-track .box {
  width: 22px; height: 22px; border-radius: 999px; flex-shrink: 0;
  border: 2px solid rgba(0,0,0,0.3); display: grid; place-items: center;
  font-size: 13px; color: transparent;
}
.sub-track .box.on { background: #1c1c1e; border-color: #1c1c1e; color: #fff; }

.done-btn {
  width: 100%; margin-top: 18px; padding: 14px;
  border: none; border-radius: 14px; cursor: pointer;
  font: inherit; font-weight: 700; background: #1c1c1e; color: #fff;
}
.done-btn.is-done { background: rgba(0,0,0,0.15); color: #1c1c1e; }
