/* Habit tracker personal — mobile-first, sin dependencias externas. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #14161a;
  --muted: #6b7280;
  --accent: #4f8cff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 12px rgba(0, 0, 0, .04);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --border: #262b34;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: .55rem .9rem;
  background: var(--accent);
  color: #fff;
}
button:disabled { opacity: .35; cursor: default; }

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button.linkish {
  background: none;
  color: var(--accent);
  padding: 0;
  font-size: .85rem;
}

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .6rem .75rem;
  width: 100%;
}
input[type="color"] { padding: .2rem; width: 3rem; flex: 0 0 auto; }

.muted { color: var(--muted); }
.error { color: #e0533d; font-size: .9rem; }

/* ---------- login ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.5rem;
  width: min(360px, 100%);
  display: grid;
  gap: .8rem;
}
.login-card h1 { margin: 0; font-size: 1.6rem; }
.login-card p { margin: 0; }

/* ---------- estructura ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .9rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.badge { margin-left: auto; font-size: .85rem; color: var(--muted); }

.tabs {
  display: flex;
  gap: .25rem;
  padding: .5rem;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.tab {
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}
.tab.is-active { background: var(--accent); color: #fff; }

main { padding: 1rem; max-width: 720px; margin: 0 auto; }
.view { display: none; }
.view.is-active { display: block; }

.daynav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  text-align: center;
}
.daynav > div { flex: 1; }
.day-label { font-weight: 600; text-transform: capitalize; }

/* ---------- tarjetas de hábito ---------- */

.cards { display: grid; gap: .7rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.is-done { border-color: var(--habit-color); }
.card.is-done .card-main { background: color-mix(in srgb, var(--habit-color) 12%, transparent); }
.card.is-freeze .card-main { background: color-mix(in srgb, var(--habit-color) 6%, transparent); }

.card-main {
  display: flex;
  align-items: center;
  gap: .9rem;
  width: 100%;
  padding: 1rem;
  background: transparent;
  color: var(--text);
  border-radius: 0;
  text-align: left;
}
.card-emoji { font-size: 1.7rem; line-height: 1; }
.card-text { display: grid; flex: 1; }
.card-name { font-weight: 600; }
.card-streak { font-size: .85rem; color: var(--muted); }
.card-check {
  font-size: 1.5rem;
  color: var(--habit-color);
  width: 1.5rem;
  text-align: center;
}
.card-freeze {
  display: block;
  width: 100%;
  background: transparent;
  color: var(--muted);
  border-top: 1px solid var(--border);
  border-radius: 0;
  font-size: .8rem;
  padding: .45rem;
}

.milestone {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem .9rem;
  margin-bottom: .9rem;
  font-size: .9rem;
}

/* ---------- notas ---------- */

.note-block { margin-top: 1.5rem; display: grid; gap: .4rem; }
.note-block label { font-weight: 600; font-size: .9rem; }
.note-status { font-size: .8rem; color: var(--muted); min-height: 1.2em; }

/* ---------- calendario ---------- */

.weekdays, .calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .3rem;
}
.weekdays {
  color: var(--muted);
  font-size: .75rem;
  text-align: center;
  margin-bottom: .3rem;
}

.cal-day {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  align-content: start;
  justify-items: center;
  gap: .2rem;
  padding: .3rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}
.cal-day.is-today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day.is-perfect { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.cal-day.is-future { opacity: .35; cursor: default; }
.cal-num { font-size: .8rem; }
.cal-dots { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; }
.cal-note { position: absolute; bottom: 2px; right: 4px; font-size: .65rem; color: var(--muted); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}
.dot.is-freeze { opacity: .35; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .9rem;
  margin-top: 1rem;
  font-size: .8rem;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: .35rem; }

/* ---------- progreso ---------- */

.progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
.progress-card h3 { margin: 0 0 .8rem; font-size: 1.05rem; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.stat { text-align: center; }
.stat b { display: block; font-size: 1.3rem; color: var(--habit-color); }
.stat span { font-size: .7rem; color: var(--muted); }

.goal { font-size: .85rem; color: var(--muted); margin: .8rem 0 0; }

.heatmap-wrap { overflow-x: auto; margin-top: .9rem; padding-bottom: .3rem; }
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 10px);
  grid-auto-columns: 10px;
  gap: 3px;
}
.hm { background: var(--border); border-radius: 2px; }
.hm.is-freeze { opacity: .4; }

/* ---------- ajustes ---------- */

.habit-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: .5rem;
}
.habit-row .ghost { padding: .3rem .5rem; font-size: .8rem; }
.habit-name { flex: 1; }

.habit-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1.2rem 0;
  display: grid;
  gap: .7rem;
}
.habit-form h3 { margin: 0; font-size: 1rem; }
.habit-form .row { display: flex; gap: .5rem; align-items: center; }
.emoji-input { width: 3.5rem; flex: 0 0 auto; text-align: center; }

.warn {
  background: color-mix(in srgb, #e8a33d 18%, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem .9rem;
  font-size: .85rem;
  margin-bottom: 1rem;
}

#archived-block { margin-top: 1rem; color: var(--muted); font-size: .9rem; }
#archived-block summary { cursor: pointer; padding: .4rem 0; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #14161a;
  color: #fff;
  padding: .6rem 1rem;
  border-radius: 999px;
  font-size: .85rem;
  box-shadow: var(--shadow);
  z-index: 20;
  max-width: 90vw;
  text-align: center;
}
