/* Ciclo: maqueta visual movil. Negro con violeta como acento principal y rosa para el sangrado. */

:root {
  --bg: #0B0A10;
  --surface: #14121C;
  --surface2: #1D1A28;
  --ink: #F1ECF8;
  --ink2: #A59DB8;
  --line: #2A2538;
  --accent: #A58BFA;
  --on-accent: #140C28;
  --accent-soft: #2A2148;
  --rose: #F27BAA;
  --rose-soft: #3A1F33;
  --grad: linear-gradient(135deg, #A58BFA 0%, #F27BAA 100%);
  --glow: rgba(157, 124, 245, .16);
  --warn: #E3A857;
  --warn-soft: #33260F;
  --ok: #7CC4A0;
  --ok-soft: #1B2F26;
  --l1: #6B3A5C; --l1t: #F6E9F1;
  --l2: #A5497A; --l2t: #FFF1F7;
  --l3: #E0679A; --l3t: #260A18;
  --l4: #FF8FBA; --l4t: #260A18;
  --backdrop: rgba(0, 0, 0, .65);
  --serif: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
  --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F7F4FC;
  --surface: #FFFFFF;
  --surface2: #EFEAF8;
  --ink: #1B1428;
  --ink2: #62587A;
  --line: #E2DAF0;
  --accent: #6D45D6;
  --on-accent: #FFFFFF;
  --accent-soft: #E9E1FB;
  --rose: #CC4F85;
  --rose-soft: #FBE3EE;
  --grad: linear-gradient(135deg, #6D45D6 0%, #CC4F85 100%);
  --glow: rgba(109, 69, 214, .08);
  --warn: #8F5710;
  --warn-soft: #F9ECD6;
  --ok: #3F7D5F;
  --ok-soft: #DDEFE6;
  --l1: #F6C6DA; --l1t: #4A2434;
  --l2: #EC8FB4; --l2t: #3A1626;
  --l3: #CC4F85; --l3t: #FFFFFF;
  --l4: #9C2F5B; --l4t: #FFFFFF;
  --backdrop: rgba(30, 15, 40, .45);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  background-color: var(--bg);
  background-image: radial-gradient(120% 55% at 50% -8%, var(--glow), transparent 62%);
  background-repeat: no-repeat;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
svg { display: block; }

/* ---------- Estructura ---------- */
.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  padding-block: 8px 130px;
}
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 0 18px; }
.eyebrow { font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--ink2); font-weight: 500; }
h1 { font-family: var(--serif); font-weight: 400; font-size: 38px; line-height: 1.05; margin-top: 4px; text-wrap: balance; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.icon-btn svg { width: 22px; height: 22px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 20px; }
.q { font-size: 13px; font-weight: 600; letter-spacing: .02em; color: var(--ink2); margin: 22px 0 10px; }
.q:first-child { margin-top: 0; }
.hint { font-size: 13px; color: var(--ink2); }
[hidden] { display: none !important; }
.chip-btn { height: 40px; padding: 0 16px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px; flex: none; }
.list .row input[type="date"] { flex: 1; min-width: 0; }
.chip-back {
  align-self: flex-start; display: inline-flex; gap: 6px; align-items: center; height: 36px; padding: 0 14px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px; margin-bottom: 14px;
}

/* ---------- Avisos de implante ---------- */
.banner {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 14px 16px; border-radius: 20px; margin-bottom: 14px;
  background: var(--warn-soft); color: var(--warn);
}
.banner .b-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); flex: none; }
.banner .b-ic svg { width: 22px; height: 22px; }
.banner span:nth-child(2) { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.banner b { font-weight: 600; font-size: 15px; }
.banner small { font-size: 13px; opacity: .9; }
.banner > svg { width: 18px; height: 18px; flex: none; }

/* ---------- Formulario Hoy ---------- */
.flow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.flow button {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0 10px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink2);
  font-size: 11.5px; min-width: 0;
}
.flow button.on { border-color: var(--rose); background: var(--rose-soft); color: var(--ink); font-weight: 600; }
.flow svg { width: 26px; height: 26px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface2); border-radius: 16px; }
.seg button { height: 40px; border-radius: 12px; font-size: 14px; color: var(--ink2); min-width: 0; }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; color: var(--ink2);
}
.chips button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }
textarea, input[type="date"], input[type="time"], input[type="email"], input[type="text"], select {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface2); border: 1px solid transparent;
  border-radius: 14px; padding: 12px 14px; resize: none;
}
input[type="time"] { width: auto; }
.savebar {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); padding-top: 18px; margin-top: 8px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.btn {
  width: 100%; height: 54px; border-radius: 18px; background: var(--grad); color: var(--on-accent);
  font-weight: 600; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn[disabled] { background: var(--surface2); color: var(--ink2); cursor: default; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--warn); border: 1px solid var(--line); }
.btn svg { width: 20px; height: 20px; }
.saved-note { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; color: var(--ok); margin-bottom: 8px; font-weight: 500; }
.saved-note svg { width: 16px; height: 16px; }

.chips.rose button.on { background: var(--rose-soft); border-color: var(--rose); }
.q .opt { font-weight: 400; }
.hues { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.hues button {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0 10px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink2); font-size: 11.5px; min-width: 0;
}
.hues button.on { border-color: var(--rose); background: var(--rose-soft); color: var(--ink); font-weight: 600; }
.hues i { width: 26px; height: 26px; border-radius: 50%; display: block; box-shadow: 0 0 0 1.5px var(--line); }
.hdot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.day.hued::after { content: ''; position: absolute; bottom: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--hue); box-shadow: 0 0 0 1.5px var(--surface); }

/* ---------- Calendario ---------- */
.monthbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.monthbar h2 { font-family: var(--serif); font-weight: 400; font-size: 28px; }
.monthbar .icon-btn[disabled] { opacity: .35; cursor: default; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span { text-align: center; font-size: 12px; color: var(--ink2); padding-bottom: 8px; font-weight: 500; }
.grid { row-gap: 6px; }
.day {
  position: relative; width: 100%; max-width: 44px; aspect-ratio: 1; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center; font-size: 15px; font-variant-numeric: tabular-nums;
}
.day.logged::after { content: ''; position: absolute; bottom: 6px; width: 4px; height: 4px; border-radius: 50%; background: var(--ink2); opacity: .5; }
.day.l1 { background: var(--l1); color: var(--l1t); }
.day.l2 { background: var(--l2); color: var(--l2t); }
.day.l3 { background: var(--l3); color: var(--l3t); }
.day.l4 { background: var(--l4); color: var(--l4t); }
.day.today { box-shadow: inset 0 0 0 2px var(--accent); font-weight: 700; }
.day.sel { outline: 2px solid var(--ink); outline-offset: 2px; }
.day[disabled] { color: var(--ink2); opacity: .4; cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 18px; font-size: 12px; color: var(--ink2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.legend .dot { width: 5px; height: 5px; background: var(--ink2); opacity: .5; margin: 0 3.5px; }

/* ---------- Implante ---------- */
.preview-toggle { border: 1px dashed var(--line); border-radius: 18px; padding: 12px; margin-bottom: 14px; }
.preview-toggle p { font-size: 12px; color: var(--ink2); margin-bottom: 8px; }
.ring-card { text-align: center; padding: 26px 20px 22px; }
.ring { position: relative; width: 210px; height: 210px; margin: 0 auto 14px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .num { font-family: var(--serif); font-size: 64px; line-height: 1; font-variant-numeric: tabular-nums; }
.ring .lbl { font-size: 13px; color: var(--ink2); margin-top: 4px; }
.status { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.status.warn { background: var(--warn-soft); color: var(--warn); }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.ring-card .when { margin-top: 12px; color: var(--ink2); font-size: 14px; }
.note-box { margin-top: 16px; padding: 14px 16px; border-radius: 16px; background: var(--warn-soft); color: var(--warn); font-size: 14px; text-align: left; }
.list { display: flex; flex-direction: column; }
.list .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list .row:last-child { border-bottom: 0; padding-bottom: 0; }
.list .row:first-child { padding-top: 0; }
.row .t { display: flex; flex-direction: column; min-width: 0; }
.row .t b { font-weight: 600; font-size: 15px; }
.row .t small { color: var(--ink2); font-size: 13px; }
.row .v { color: var(--ink2); font-size: 14px; text-align: right; }
.h2 { font-family: var(--serif); font-weight: 400; font-size: 26px; margin: 8px 0 -2px; }
.ticks { display: flex; flex-wrap: wrap; gap: 8px; }
.ticks span { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px; background: var(--surface2); font-size: 13px; color: var(--ink2); }
.ticks svg { width: 14px; height: 14px; color: var(--ok); }

/* ---------- Resumen ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 14px 12px; min-width: 0; }
.stat b { display: block; font-family: var(--serif); font-weight: 400; font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; }
.stat small { display: block; margin-top: 6px; font-size: 12px; color: var(--ink2); line-height: 1.3; }
.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; margin-top: 14px; }
.heat i { aspect-ratio: 1; border-radius: 5px; background: var(--surface2); display: block; }
.heat i.none { background: transparent; border: 1px dashed var(--line); }
.heat i.empty { background: transparent; }
.heat i.l1 { background: var(--l1); } .heat i.l2 { background: var(--l2); }
.heat i.l3 { background: var(--l3); } .heat i.l4 { background: var(--l4); }
.heat-cap { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink2); margin-top: 10px; }
.bar { display: grid; grid-template-columns: 110px 1fr 28px; align-items: center; gap: 10px; font-size: 14px; padding: 6px 0; }
.bar .track { height: 8px; border-radius: 4px; background: var(--surface2); overflow: hidden; }
.bar .track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar em { font-style: normal; color: var(--ink2); text-align: right; font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 4px; background: var(--surface2); overflow: hidden; margin: 10px 0 6px; }
.meter i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }

/* ---------- Barra inferior ---------- */
.tabbar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 430px); z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px max(10px, env(safe-area-inset-left, 0px)) calc(8px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; font-size: 11.5px; color: var(--ink2); border-radius: 14px; }
.tabbar svg { width: 25px; height: 25px; }
.tabbar button.on { color: var(--accent); font-weight: 600; }

/* ---------- Capas: ajustes y hoja ---------- */
.layer {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: min(100%, 430px); height: 100%;
  background: var(--bg); z-index: 40; overflow-y: auto;
  padding: 8px max(20px, env(safe-area-inset-left, 0px)) 48px;
}
.layer[hidden] { display: none; }
.layer .back { display: flex; align-items: center; gap: 8px; height: 44px; font-weight: 600; margin-top: 8px; }
.layer .back svg { width: 20px; height: 20px; }
.sect { margin-top: 24px; }
.sect > h3 { font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--ink2); font-weight: 600; margin: 0 0 10px 4px; }
.sw { width: 52px; height: 32px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); position: relative; flex: none; transition: background .2s; }
.sw i { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--ink2); transition: transform .2s, background .2s; }
.sw[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.sw[aria-checked="true"] i { transform: translateX(20px); background: var(--on-accent); }
.lock { border-radius: 26px; padding: 16px; background: linear-gradient(165deg, #3a2a4a, #1d2742); display: flex; flex-direction: column; gap: 8px; }
.lock .clock { text-align: center; color: #fff; font-size: 13px; opacity: .8; padding: 2px 0 6px; }
.notif { display: flex; gap: 10px; padding: 12px; border-radius: 18px; background: rgba(255, 255, 255, .16); color: #fff; }
.notif .ico { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #7C5CE0, #E0679A); display: grid; place-items: center; flex: none; }
.notif .ico svg { width: 20px; height: 20px; }
.notif div { min-width: 0; }
.notif b { font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.notif b em { font-style: normal; font-weight: 400; opacity: .7; font-size: 12px; }
.notif p { font-size: 14px; opacity: .92; line-height: 1.35; }

.backdrop { position: fixed; inset: 0; background: var(--backdrop); z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s; }
.backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translate(-50%, 100%); width: min(100%, 430px); z-index: 60;
  background: var(--surface); border-radius: 28px 28px 0 0; transition: transform .25s;
  padding: 10px max(20px, env(safe-area-inset-left, 0px)) calc(22px + env(safe-area-inset-bottom, 0px));
  max-height: 92%; overflow-y: auto;
}
.sheet.open { transform: translate(-50%, 0); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { font-family: var(--serif); font-weight: 400; font-size: 30px; margin-bottom: 4px; }
.sheet .field { margin-top: 18px; }
.sheet .field > label { display: block; font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 8px; }
.sheet .result { margin-top: 18px; padding: 14px 16px; border-radius: 16px; background: var(--accent-soft); font-size: 15px; }
.sheet .btn { margin-top: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 12px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-size: 14px; z-index: 80;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 40px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 520px) {
  body { background: var(--surface2); }
  .app { background: var(--bg); box-shadow: 0 0 0 1px var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (max-width: 360px) {
  h1 { font-size: 34px; }
  .bar { grid-template-columns: 92px 1fr 24px; }
}
