/* TKF · Tu Kambio Fit — hoja de estilos única */

:root {
  --bg:        #0E1116;
  --bg-elev:   #161A21;
  --surface:   #1B2029;
  --surface-2: #232935;
  --border:    #2A313D;
  --text:      #E9ECF1;
  --text-dim:  #9BA4B2;
  --text-faint:#6B7482;

  --green:     #3DD68C;
  --green-dim: #1E6E4A;
  --amber:     #FFB020;
  --violet:    #A78BFA;
  --red:       #F0616D;

  --accent:    var(--green);
  --on-accent: #06130D;

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --tap: 44px;

  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --ease: cubic-bezier(.22,.61,.36,1);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #F7F8FA;
    --bg-elev:   #FFFFFF;
    /* --surface va sobre --bg-elev (blanco): tiene que ser gris, no blanco,
       o las casillas del calendario y los campos se vuelven invisibles. */
    --surface:   #F0F3F7;
    --surface-2: #E2E7EF;
    --border:    #E1E5EC;
    --text:      #10141A;
    --text-dim:  #5C6675;
    --text-faint:#8A94A3;

    --green:     #12A362;
    --green-dim: #A7E8C8;
    --amber:     #C97A05;
    --violet:    #7C5CE0;
    --red:       #D93B4A;

    --on-accent: #FFFFFF;
    --shadow: 0 6px 24px rgba(16,20,26,.08);
  }
}

* { box-sizing: border-box; }

/* Varias reglas de abajo fijan display:flex/grid, que gana sobre el
   atributo `hidden`. Esta línea lo devuelve a su significado. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; border: none; background: none; }

/* ── Layout ─────────────────────────────────────────────── */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 620px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.topbar.scrolled { border-bottom-color: var(--border); }

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.topbar .sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.view {
  flex: 1;
  padding: 6px 18px 24px;
}

/* ── Tab bar ────────────────────────────────────────────── */

.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 8px 10px calc(var(--safe-bottom) + 8px);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  border-radius: var(--r-sm);
  color: var(--text-faint);
  transition: color .15s;
}
.tab-icon { font-size: 19px; line-height: 1; }
.tab-label { font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.tab[aria-selected="true"] { color: var(--accent); }
.tab:active { background: var(--surface); }

/* ── Cartas y bloques ───────────────────────────────────── */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  margin-bottom: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 2px 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
}
.section-title .count {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
  color: var(--text-faint);
}

.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Cabecera del día ───────────────────────────────────── */

.day-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.day-nav button {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text-dim);
  background: var(--surface);
  font-size: 15px;
}
.day-nav button:disabled { opacity: .3; }
.day-nav button:active { background: var(--surface-2); }

.hero {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 16px;
}

.ring { flex: none; position: relative; width: 92px; height: 92px; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring .track { stroke: var(--surface-2); }
.ring .fill {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset .55s var(--ease);
}
/* El contenido va dentro de un único <span>: si el número y el <small>
   fueran hijos directos, grid los trataría como dos ítems y los apilaría. */
.ring .pct {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 21px; font-weight: 700;
  letter-spacing: -.02em;
}
.ring .pct small { font-size: 12px; font-weight: 600; color: var(--text-dim); }

.hero-meta { min-width: 0; }
.hero-meta .big {
  font-size: 17px; font-weight: 650; letter-spacing: -.01em;
  margin: 0 0 4px;
}
.hero-meta .line {
  font-size: 13px; color: var(--text-dim); margin: 0;
  line-height: 1.5;
}
.flame { color: var(--amber); font-weight: 700; }

/* ── Hábito ─────────────────────────────────────────────── */

.habit {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  text-align: left;
  transition: border-color .18s, background .18s, transform .1s var(--ease);
}
.habit:active { transform: scale(.985); }
.habit.done {
  border-color: color-mix(in srgb, var(--green) 45%, var(--border));
  background: color-mix(in srgb, var(--green) 8%, var(--bg-elev));
}

.habit .emoji {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 20px;
  background: var(--surface);
  border-radius: 11px;
}
.habit.done .emoji { background: color-mix(in srgb, var(--green) 18%, var(--surface)); }

.habit .body { flex: 1; min-width: 0; }
.habit .name {
  display: block;
  font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.habit.done .name { color: var(--text-dim); }
.habit .meta {
  font-size: 12px; color: var(--text-faint); margin-top: 2px;
  display: flex; align-items: center; gap: 7px;
}

.check {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid; place-items: center;
  color: transparent;
  font-size: 14px; font-weight: 800;
  transition: all .18s var(--ease);
}
.habit.done .check {
  background: var(--green);
  border-color: var(--green);
  color: var(--on-accent);
}

/* contador */
.counter { flex: none; display: flex; align-items: center; gap: 4px; }
.counter button {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 17px; font-weight: 600;
  display: grid; place-items: center;
}
.counter button:active { background: var(--surface-2); color: var(--text); }
/* La cifra también es un botón (abre el teclado para escribirla exacta),
   así que anula el tamaño circular que .counter button impone. */
.counter .val {
  width: auto; height: auto;
  min-width: 52px;
  padding: 7px 6px;
  border-radius: 9px;
  background: var(--surface);
  text-align: center;
  font-size: 14px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.counter .val:active { background: var(--surface-2); }

.bar {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 7px;
}
.bar > i {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .35s var(--ease);
}

/* ── Ánimo ──────────────────────────────────────────────── */

.mood-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.mood {
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 24px;
  border: 2px solid transparent;
  transition: all .18s var(--ease);
}
.mood:active { transform: scale(.94); }
.mood[aria-pressed="true"] {
  border-color: var(--violet);
  background: color-mix(in srgb, var(--violet) 16%, var(--surface));
}

.note-input {
  width: 100%;
  margin-top: 12px;
  padding: 12px 13px;
  min-height: 76px;
  resize: vertical;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 14px;
  line-height: 1.55;
}
.note-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.note-input::placeholder { color: var(--text-faint); }

/* ── Calendario ─────────────────────────────────────────── */

.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.cal-head .month { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }

.icon-btn {
  width: 36px; height: 36px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 16px;
}
.icon-btn:active { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; }

.cal-dow, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-dow {
  margin-bottom: 6px;
  font-size: 11px; font-weight: 700;
  color: var(--text-faint);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cal-cell {
  aspect-ratio: 1;
  border-radius: 9px;
  background: var(--surface);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  color: var(--text-faint);
  position: relative;
  border: 1.5px solid transparent;
}
.cal-cell.blank { background: none; }
.cal-cell.future { opacity: .35; }
.cal-cell.today { border-color: var(--text-dim); }
.cal-cell.sel { border-color: var(--accent); }
.cal-cell[data-lvl="1"] { background: color-mix(in srgb, var(--green) 16%, var(--surface)); color: var(--text-dim); }
.cal-cell[data-lvl="2"] { background: color-mix(in srgb, var(--green) 34%, var(--surface)); color: var(--text); }
.cal-cell[data-lvl="3"] { background: color-mix(in srgb, var(--green) 58%, var(--surface)); color: var(--text); }
.cal-cell[data-lvl="4"] { background: var(--green); color: var(--on-accent); }

.legend {
  display: flex; align-items: center; gap: 6px;
  margin-top: 14px;
  font-size: 11px; color: var(--text-faint);
}
.legend i {
  width: 13px; height: 13px; border-radius: 4px;
  background: var(--surface); display: inline-block;
}
.legend i[data-lvl="1"] { background: color-mix(in srgb, var(--green) 16%, var(--surface)); }
.legend i[data-lvl="2"] { background: color-mix(in srgb, var(--green) 34%, var(--surface)); }
.legend i[data-lvl="3"] { background: color-mix(in srgb, var(--green) 58%, var(--surface)); }
.legend i[data-lvl="4"] { background: var(--green); }

/* ── Progreso ───────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
}
.stat .k {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-faint);
}
.stat .v {
  font-size: 27px; font-weight: 700; letter-spacing: -.03em;
  margin-top: 5px; font-variant-numeric: tabular-nums;
}
.stat .v small { font-size: 14px; font-weight: 600; color: var(--text-dim); margin-left: 2px; }
.stat.accent .v { color: var(--accent); }
.stat.amber .v { color: var(--amber); }

.hstat { padding: 12px 14px; }
.hstat + .hstat { margin-top: 8px; }
.hstat .top {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 600;
}
.hstat .top .pct {
  margin-left: auto; font-variant-numeric: tabular-nums;
  color: var(--text-dim); font-size: 13px; font-weight: 700;
}
.hstat .streak { font-size: 12px; color: var(--amber); font-weight: 700; }

.spark {
  display: flex; gap: 3px; margin-top: 9px;
}
.spark i {
  flex: 1; height: 22px; border-radius: 3px;
  background: var(--surface-2);
}
.spark i.on { background: var(--green); }
.spark i.partial { background: var(--green-dim); }

/* ── Ajustes ────────────────────────────────────────────── */

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: 8px;
  width: 100%;
  text-align: left;
}
.row .grow { flex: 1; min-width: 0; padding: 0; }
.row .t { display: block; font-size: 15px; font-weight: 600; }
.row .d { display: block; font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.row .chev { color: var(--text-faint); font-size: 16px; }
.row.danger .t { color: var(--red); }

.hint {
  margin: 10px 2px 4px;
  font-size: 13px; line-height: 1.55;
  color: var(--text-faint);
}

/* Mientras se arrastra, la fila se despega del resto. */
.row.dragging {
  opacity: .9;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  transform: scale(1.02);
}

.drag-handle {
  color: var(--text-faint);
  font-size: 16px;
  padding: 4px 2px;
  cursor: grab;
  touch-action: none;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: 12px;
  font-size: 15px; font-weight: 650;
  background: var(--surface);
  color: var(--text);
  transition: transform .1s var(--ease), opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.danger { background: transparent; border: 1px solid var(--red); color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }

/* ── Formularios ────────────────────────────────────────── */

.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint);
  margin-bottom: 7px;
}
.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 15px;
  appearance: none;
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 19px;
  background: var(--surface);
  border: 1.5px solid transparent;
  font-size: 13px; font-weight: 600;
  color: var(--text-dim);
}
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}
.chip.sq { width: 40px; padding: 0; display: grid; place-items: center; }

/* ── Sheet ──────────────────────────────────────────────── */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s var(--ease);
}
.sheet-backdrop[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-top: 1px solid var(--border);
  padding: 10px 18px calc(var(--safe-bottom) + 22px);
  box-shadow: var(--shadow);
  animation: rise .28s var(--ease);
}
.sheet::before {
  content: "";
  display: block;
  width: 38px; height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 14px;
}
.sheet h2 {
  margin: 0 0 16px;
  font-size: 19px; font-weight: 700; letter-spacing: -.02em;
}
.sheet-actions {
  display: flex; gap: 10px; margin-top: 20px;
}
.sheet-actions .btn { flex: 1; }

@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { transform: translateY(14px); opacity: .4 } }

/* ── Toast ──────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-bottom) + 82px);
  transform: translateX(-50%);
  z-index: 80;
  padding: 11px 18px;
  border-radius: 22px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow);
  animation: rise .24s var(--ease);
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast[hidden] { display: none; }

/* ── Detalle de día ─────────────────────────────────────── */

.daylist { margin-top: 4px; }
.daylist li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.daylist { list-style: none; padding: 0; margin: 0; }
.daylist li:last-child { border-bottom: none; }
.daylist .mark { width: 20px; text-align: center; }
.daylist .mark.yes { color: var(--green); }
.daylist .mark.no  { color: var(--text-faint); }
.daylist .val { margin-left: auto; color: var(--text-dim); font-size: 13px; font-variant-numeric: tabular-nums; }

.quote {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--r-sm);
  font-size: 14px; line-height: 1.6; color: var(--text-dim);
  white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
