/* =========================================================
   ETERNAWORLD · FASE 1
   Historial por hábito, calendario, días de gracia, "hoy no",
   modo simple y onboarding guiado.
   Usa los tokens de base.css (claro/oscuro): --panel, --line,
   --muted, --ok, --warning, --accent… No define colores fijos
   salvo los semánticos de los estados.
========================================================= */

/* ---------- Botón propio (los .secondary-button globales son 100% de ancho) ---------- */
.f1-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 12px;
    border: 1px solid rgba(177, 141, 255, 0.32);
    background: rgba(124, 60, 255, 0.10);
    color: var(--text);
    font: inherit;
    font-size: .88rem;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 120ms ease, filter 120ms ease;
}
.f1-btn:hover { filter: brightness(1.12); border-color: var(--accent-2, #c66dff); }
.f1-btn:focus-visible { outline: 3px solid rgba(169, 131, 255, 0.45); outline-offset: 2px; }
.f1-btn.block { display: flex; width: 100%; }
html[data-theme="light"] .f1-btn { color: #5b21b6; background: rgba(124, 60, 255, .07); border-color: rgba(124, 60, 255, .28); }

/* ---------- Panel: cabecera con acciones ---------- */
.header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}
.simple-mode-form { margin: 0; }

.panel-flash {
    margin: 0 0 16px;
    padding: 12px 16px;
    border-radius: var(--radius-md, 14px);
    border: 1px solid var(--line);
    font-weight: 700;
    font-size: .9rem;
}
.panel-flash.ok    { border-color: color-mix(in srgb, var(--ok) 55%, transparent);     background: color-mix(in srgb, var(--ok) 10%, transparent); }
.panel-flash.error { border-color: color-mix(in srgb, var(--danger) 55%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ---------- Racha: mejor racha y días de gracia ---------- */
.streak-best { display: block; margin-top: 6px; color: var(--muted); font-size: .76rem; font-weight: 700; }

.freeze-box { margin-top: 12px; display: grid; gap: 10px; }
.freeze-form {
    padding: 14px;
    border: 1px solid color-mix(in srgb, #5ec8ff 45%, transparent);
    border-radius: var(--radius-md, 14px);
    background: color-mix(in srgb, #5ec8ff 8%, transparent);
}
.freeze-form p { margin: 0 0 10px; font-size: .82rem; line-height: 1.5; color: var(--muted); }
.freeze-form strong { color: var(--text); display: block; margin-bottom: 2px; }


.week-day.frozen .week-dot {
    background: color-mix(in srgb, #5ec8ff 30%, transparent);
    border-color: #5ec8ff;
    color: var(--text);
}

/* ---------- Tarjeta de hábito: "no hoy" ---------- */
.habit-card.skipped { opacity: .88; }
.habit-card.skipped .habit-state { color: var(--warning); }
.habit-card.skipped .habit-toggle-native { border-style: dashed; }

.habit-actions { flex-wrap: wrap; }
.habit-skip-button,
.f1-link-button {
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    color: var(--muted);
    font: inherit;
    font-size: .8rem;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.habit-skip-button:hover,
.f1-link-button:hover { color: var(--text); }
.habit-skip-button[hidden] { display: none; }

/* ---------- Toast y diálogos ---------- */
.ew-toast {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: min(92vw, 460px);
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel-3, #1d2432);
    color: var(--text);
    box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
    font-size: .88rem;
    font-weight: 700;
}
.ew-toast[hidden] { display: none; }
.ew-toast.error { border-color: var(--danger); }
.ew-toast button {
    background: none;
    border: 0;
    color: var(--accent-2, #c66dff);
    font: inherit;
    font-weight: 900;
    cursor: pointer;
    padding: 4px 6px;
}
html[data-theme="light"] .ew-toast { background: #ffffff; box-shadow: 0 18px 50px rgba(15, 23, 42, .18); }
html[data-theme="light"] .ew-toast button { color: #5b21b6; }

.ew-dialog {
    width: min(92vw, 420px);
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel, #111620);
    color: var(--text);
}
.ew-dialog::backdrop { background: rgba(4, 6, 12, .62); }
.ew-dialog h3 { margin: 0 0 6px; font-size: 1.05rem; }
.ew-dialog p { margin: 0 0 14px; color: var(--muted); font-size: .84rem; line-height: 1.5; }
.ew-dialog-options { display: grid; gap: 8px; }
.ew-dialog-options button,
.ew-dialog-cancel {
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--panel-2, #171d29);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
}
.ew-dialog-options button:hover,
.ew-dialog-options button:focus-visible { border-color: var(--accent-2, #c66dff); outline: none; }
.ew-dialog-options button.current { border-color: var(--ok); }
.ew-dialog-cancel { margin-top: 10px; width: 100%; text-align: center; background: transparent; color: var(--muted); }
html[data-theme="light"] .ew-dialog { background: #ffffff; }
html[data-theme="light"] .ew-dialog-options button { background: #f4f6fb; }

/* ---------- Páginas nuevas (historial, calendario, onboarding) ---------- */
.f1-page {
    width: min(920px, calc(100% - 28px));
    margin: 0 auto;
    padding: 20px 0 64px;
    display: grid;
    gap: 18px;
}
.f1-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.f1-header img { height: 44px; width: auto; }
.f1-title h1 { margin: 4px 0 8px; font-size: clamp(1.6rem, 4vw, 2.3rem); line-height: 1.15; }
.f1-title .muted, .f1-help { color: var(--muted); line-height: 1.6; }
.f1-note { margin-top: 8px; color: var(--warning); font-weight: 700; }
.f1-card { padding: 22px; }
.f1-help { margin: 14px 0 0; font-size: .82rem; }
.f1-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.f1-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.f1-stat {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md, 14px);
    background: var(--panel, #111620);
    display: grid;
    gap: 2px;
}
.f1-stat small { color: var(--muted); font-weight: 700; font-size: .74rem; }
.f1-stat strong { font-size: 1.9rem; line-height: 1.1; }
.f1-stat span { color: var(--muted); font-size: .76rem; }
html[data-theme="light"] .f1-stat { background: #ffffff; }

/* Mapa de calor */
.f1-heat-wrap { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.f1-heat-days { display: grid; grid-template-rows: repeat(7, 18px); gap: 4px; font-size: .62rem; color: var(--muted); font-weight: 800; align-items: center; }
.f1-heat { display: grid; grid-auto-flow: column; gap: 4px; }
.f1-heat-col { display: grid; grid-template-rows: repeat(7, 18px); gap: 4px; }
.f1-heat-cell {
    display: inline-block;
    width: 18px;
    height: 18px;
    border-radius: 5px;
    background: var(--panel-3, #1d2432);
}
.f1-heat-cell.done    { background: var(--ok); }
.f1-heat-cell.skipped { background: color-mix(in srgb, var(--warning) 70%, transparent); }
.f1-heat-cell.partial { background: color-mix(in srgb, var(--ok) 38%, transparent); }
.f1-heat-cell.frozen  { background: color-mix(in srgb, #5ec8ff 60%, transparent); }
.f1-heat-cell.before, .f1-heat-cell.future { background: transparent; border: 1px dashed var(--line-soft, rgba(255,255,255,.07)); }
html[data-theme="light"] .f1-heat-cell { background: rgba(15, 23, 42, .09); }
html[data-theme="light"] .f1-heat-cell.done { background: var(--ok); }
html[data-theme="light"] .f1-heat-cell.skipped { background: color-mix(in srgb, var(--warning) 75%, transparent); }
html[data-theme="light"] .f1-heat-cell.partial { background: color-mix(in srgb, var(--ok) 40%, transparent); }
html[data-theme="light"] .f1-heat-cell.frozen { background: color-mix(in srgb, #5ec8ff 65%, transparent); }
html[data-theme="light"] .f1-heat-cell.before, html[data-theme="light"] .f1-heat-cell.future { background: transparent; }

.f1-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; color: var(--muted); font-size: .76rem; font-weight: 700; }
.f1-legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Calendario mensual */
.f1-cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 auto 14px; max-width: 620px; }
.f1-cal-nav .f1-btn { min-width: 46px; }
.f1-cal-nav h2 { margin: 0; text-transform: capitalize; font-size: 1.15rem; }
.f1-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; max-width: 620px; margin: 0 auto; }
.f1-cal-head { text-align: center; color: var(--muted); font-size: .72rem; font-weight: 900; padding-bottom: 2px; }
.f1-cal-cell {
    position: relative;
    aspect-ratio: 1 / 0.85;
    min-height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel, #111620);
    color: var(--text);
    font: inherit;
    padding: 0;
}
.f1-cal-cell .cal-num { position: absolute; top: 4px; left: 7px; font-size: .68rem; color: var(--muted); font-weight: 800; }
.f1-cal-cell .cal-mark { font-weight: 900; font-size: .95rem; }
.f1-cal-cell.is-done    { background: color-mix(in srgb, var(--ok) 22%, transparent); border-color: var(--ok); }
.f1-cal-cell.is-skipped { background: color-mix(in srgb, var(--warning) 16%, transparent); border-color: var(--warning); }
.f1-cal-cell.is-partial { background: color-mix(in srgb, var(--ok) 9%, transparent); }
.f1-cal-cell.is-frozen  { background: color-mix(in srgb, #5ec8ff 14%, transparent); border-color: #5ec8ff; }
.f1-cal-cell.is-today   { outline: 2px solid var(--accent-2, #c66dff); outline-offset: 1px; }
.f1-cal-cell.is-off     { opacity: .38; }
.f1-cal-cell.is-editable { cursor: pointer; }
.f1-cal-cell.is-editable:hover, .f1-cal-cell.is-editable:focus-visible { border-color: var(--accent-2, #c66dff); outline: none; }
.f1-cal-cell:disabled { opacity: .6; cursor: wait; }
html[data-theme="light"] .f1-cal-cell { background: #ffffff; }
html[data-theme="light"] .f1-cal-cell.is-done { background: color-mix(in srgb, var(--ok) 20%, #ffffff); }
html[data-theme="light"] .f1-cal-cell.is-skipped { background: color-mix(in srgb, var(--warning) 20%, #ffffff); }
html[data-theme="light"] .f1-cal-cell.is-frozen { background: color-mix(in srgb, #5ec8ff 20%, #ffffff); }

.f1-reasons, .f1-habit-links { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.f1-reasons li { display: flex; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; }
.f1-habit-links a {
    display: flex; justify-content: space-between; padding: 14px 16px;
    border: 1px solid var(--line); border-radius: 12px; color: var(--text); text-decoration: none; font-weight: 700;
}
.f1-habit-links a:hover { border-color: var(--accent-2, #c66dff); }

/* ---------- Onboarding guiado ---------- */
.f1-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.f1-chip {
    padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
    background: transparent; color: var(--muted); font: inherit; font-weight: 800; font-size: .82rem; cursor: pointer;
}
.f1-chip.active { color: var(--text); border-color: var(--accent-2, #c66dff); background: var(--accent-soft, rgba(157,0,255,.1)); }

.f1-starter-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.f1-starter {
    position: relative; display: flex; align-items: center; gap: 12px; padding: 14px;
    border: 1px solid var(--line); border-radius: 16px; background: var(--panel, #111620); cursor: pointer;
}
.f1-starter[hidden] { display: none; }
.f1-starter input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.f1-starter-icon { font-size: 1.6rem; }
.f1-starter-text { display: grid; gap: 2px; flex: 1; min-width: 0; }
.f1-starter-text strong { font-size: .92rem; line-height: 1.3; }
.f1-starter-text small { color: var(--muted); font-size: .76rem; line-height: 1.4; }
.f1-starter-check {
    width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
    border: 1px solid var(--line); color: transparent; font-weight: 900; font-size: .8rem;
}
.f1-starter:has(input:checked) { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--panel, #111620)); }
.f1-starter:has(input:checked) .f1-starter-check { background: var(--ok); border-color: var(--ok); color: #071f17; }
.f1-starter:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.f1-starter:has(input:focus-visible) { outline: 2px solid var(--accent-2, #c66dff); outline-offset: 2px; }
html[data-theme="light"] .f1-starter { background: #ffffff; }

.f1-starter-bar {
    position: sticky; bottom: 12px; margin-top: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel-2, #171d29);
    font-weight: 800; font-size: .88rem;
}
.f1-starter-bar .primary-link[disabled] { opacity: .45; pointer-events: none; }
html[data-theme="light"] .f1-starter-bar { background: #ffffff; }
.f1-skip-form { text-align: center; }

/* ---------- MODO SIMPLE ---------- */
/* Solo hábitos, rachas y calendario. No elimina datos: solo oculta. */
body.simple-mode :is(
    .ranking-card, .eterna-coach-card, .eterna-card, .plus-command-bar, .usage-card,
    .optional-checkin, .evolution-card, .plus-sidebar-badge, .eterna-plus-ambient,
    .streak-fire-background, .badge-unlock-card, .plus-title-pill
) { display: none !important; }

body.simple-mode .sidebar-action-group a[href*="tienda.php"],
body.simple-mode .sidebar-action-group a[href*="eterna-goals.php"] { display: none; }

body.simple-mode .dashboard-grid { grid-template-columns: 1fr; }
body.simple-mode .habit-card { border-radius: 14px; }


/* ---------- GUÍA DE FUNCIONES ---------- */
.f1-plan-banner { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
    padding: 16px 18px; margin-bottom: 16px; border-radius: 16px; border: 1px solid var(--border, rgba(255,255,255,.12));
    background: var(--panel, rgba(255,255,255,.04)); }
.f1-plan-banner p { margin: 4px 0 0; opacity: .8; font-size: .92rem; }
.f1-plan-banner.active { border-color: rgba(255, 200, 80, .55); background: rgba(255, 200, 80, .08); }
.f1-guide-section { margin-top: 26px; }
.f1-guide-head h2 { margin: 0 0 4px; font-size: 1.25rem; }
.f1-guide-head p { margin: 0 0 12px; }
.f1-guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.f1-feature { padding: 16px; border-radius: 16px; border: 1px solid var(--border, rgba(255,255,255,.12));
    background: var(--panel, rgba(255,255,255,.04)); display: flex; flex-direction: column; gap: 8px; }
.f1-feature[hidden], .f1-guide-section[hidden] { display: none; }
.f1-feature.is-plus { border-color: rgba(255, 200, 80, .5); box-shadow: 0 0 0 1px rgba(255, 200, 80, .12) inset; }
.f1-feature-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.f1-feature h3 { margin: 0; font-size: 1.02rem; line-height: 1.3; }
.f1-feature p { margin: 0; font-size: .93rem; line-height: 1.5; opacity: .88; }
.f1-feature-note { font-size: .86rem !important; opacity: .72 !important; }
.f1-feature-tags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; flex-shrink: 0; }
.f1-tag { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.f1-tag.plus { color: #3b2a00; background: linear-gradient(135deg, #ffd873, #ffb347); }
.f1-tag.quota { color: #ffd873; border: 1px solid rgba(255, 200, 80, .55); }
.f1-tag.new { color: #d9fff0; background: rgba(40, 190, 130, .35); }
.f1-feature-link { margin-top: auto; font-weight: 600; text-decoration: none; color: var(--accent-2, #c66dff); }
.f1-feature-link:hover { text-decoration: underline; }
.f1-feature-lock { opacity: .65; }
.f1-help { margin-top: 28px; text-align: center; }
html[data-theme="light"] .f1-tag.quota { color: #8a5a00; }
html[data-theme="light"] .f1-tag.new { color: #0b5a3c; background: rgba(40, 190, 130, .2); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
    .f1-stats { grid-template-columns: repeat(2, 1fr); }
    .f1-starter-grid { grid-template-columns: 1fr; }
    .f1-card { padding: 16px; }
    .f1-cal { gap: 4px; }
    .f1-cal-cell { min-height: 40px; border-radius: 10px; }
    .header-actions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
    .ew-toast, .f1-cal-cell, .f1-starter { transition: none; }
}
