/* =====================================================================
   HABIT TRACKER · ESTILOS
   Paleta pastel: rosa, celeste, lavanda, blanco y grises suaves.
   Los colores principales son variables (--primary, etc.) para que cada
   persona pueda personalizarlos desde Configuración.
   ===================================================================== */

:root {
  /* Paleta base */
  --rosa: #F9C6D3;
  --rosa-suave: #FDE7EE;
  --celeste: #BFE3F5;
  --celeste-suave: #E6F4FB;
  --lavanda: #D9CCF2;
  --lavanda-suave: #F1ECFB;
  --verde: #C8EBD5;
  --amarillo: #FCE8B2;
  --durazno: #FCE1B8;

  /* Roles (personalizables) */
  --primary: #E48AAA;          /* botones y acentos */
  --primary-strong: #CF6F92;
  --primary-soft: var(--rosa-suave);
  --secondary: #7FBFE0;
  --secondary-soft: var(--celeste-suave);
  --accent: #B9A6E6;

  --bg: #FBF8FA;
  --surface: #FFFFFF;
  --surface-2: #F7F4F8;
  --border: #EEE8EF;
  --text: #4A4458;
  --text-soft: #7D768A;
  --text-faint: #A9A3B4;
  --danger: #D9637C;
  --danger-soft: #FCE4E9;
  --success: #5DB585;
  --success-soft: #E3F5EA;
  --warning: #D9A441;
  --warning-soft: #FBF1DC;

  --radius-sm: 10px;
  --radius: 18px;
  --radius-lg: 26px;
  --shadow-sm: 0 1px 2px rgba(74, 68, 88, .05), 0 2px 8px rgba(74, 68, 88, .04);
  --shadow: 0 2px 6px rgba(74, 68, 88, .05), 0 12px 32px rgba(74, 68, 88, .07);
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --sidebar-w: 248px;
  --bottom-nav-h: 68px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
img, svg { max-width: 100%; }
a { color: var(--primary-strong); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0 0 .4em; color: var(--text); }
h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
small, .small { font-size: .85rem; }
.muted { color: var(--text-soft); }
:focus-visible { outline: 3px solid var(--secondary); outline-offset: 2px; border-radius: 6px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 46px; padding: .7em 1.3em;
  border: 1.5px solid transparent; border-radius: 999px;
  font: inherit; font-weight: 700; cursor: pointer;
  transition: transform .15s var(--ease), background .2s, box-shadow .2s, opacity .2s;
  text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn-primary:hover:not(:disabled) { background: var(--primary-strong); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.95); }
.btn-google { background: #fff; color: var(--text); border-color: var(--border); }
.btn-google:hover:not(:disabled) { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-small { min-height: 38px; padding: .45em 1em; font-size: .9rem; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.6); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn-ghost.is-busy::after, .btn-google.is-busy::after { border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.link-btn {
  display: block; margin: 1rem auto 0; background: none; border: 0; padding: .4em;
  color: var(--primary-strong); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.icon-btn {
  background: none; border: 0; cursor: pointer; font-size: 1.1rem; padding: .3em .5em; border-radius: 8px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Formularios ---------- */
.field { display: block; margin: 0 0 1rem; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { display: block; font-weight: 700; font-size: .92rem; margin-bottom: .35rem; color: var(--text); padding: 0; }
.field small { font-weight: 400; color: var(--text-soft); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 48px; padding: .7em 1em;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
  transition: border-color .2s, box-shadow .2s;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
input:disabled { background: var(--surface-2); color: var(--text-soft); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 3rem; }
.password-wrap .icon-btn { position: absolute; right: .35rem; top: 50%; transform: translateY(-50%); }

/* ---------- Tarjetas y avisos ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: clamp(1.1rem, 3vw, 1.6rem); box-shadow: var(--shadow-sm);
}
.card-title { font-size: 1.15rem; margin-bottom: .9rem; }
.card-danger { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.notice { border-radius: var(--radius-sm); padding: .8em 1em; margin-bottom: 1rem; font-weight: 600; font-size: .95rem; }
.notice-info { background: var(--secondary-soft); color: #3D6F8A; }
.notice-success { background: var(--success-soft); color: #2F7A52; }
.notice-error { background: var(--danger-soft); color: #A33D55; }
.notice-warning { background: var(--warning-soft); color: #8A6620; }
.big-emoji { font-size: 3rem; text-align: center; margin-bottom: .3rem; }
.empty-state { text-align: center; padding: 2.5rem 1.5rem; }
.stack { display: grid; gap: 1.2rem; align-content: start; }
.grid-2 { display: grid; gap: 1.2rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; } }

/* ---------- Avisos flotantes ---------- */
#toasts {
  position: fixed; z-index: 1000; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-h) + 16px + env(safe-area-inset-bottom));
  display: grid; gap: .5rem; width: min(92vw, 420px); pointer-events: none;
}
@media (min-width: 900px) { #toasts { bottom: 24px; } }
.toast {
  background: var(--text); color: #fff; padding: .8em 1.1em; border-radius: 14px;
  box-shadow: var(--shadow); font-weight: 600; font-size: .95rem;
  opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s var(--ease);
}
.toast.show { opacity: 1; transform: none; }
.toast-success { background: #4E9C72; }
.toast-error { background: #C9536D; }
.toast-warning { background: #B9872B; }

/* ---------- Ventana modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 900; background: rgba(74, 68, 88, .35);
  display: grid; place-items: center; padding: 1rem; animation: fade .2s;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); padding: 1.6rem;
  width: min(100%, 440px); box-shadow: var(--shadow); animation: pop .25s var(--ease);
}
.modal-message { color: var(--text-soft); }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* =====================================================================
   PANTALLA DE BIENVENIDA
   ===================================================================== */
.welcome-page { min-height: 100vh; overflow-x: hidden; position: relative; }
.blob { position: fixed; border-radius: 50%; filter: blur(60px); opacity: .55; z-index: 0; pointer-events: none; }
.blob-1 { width: 420px; height: 420px; background: var(--rosa); top: -120px; left: -120px; }
.blob-2 { width: 380px; height: 380px; background: var(--celeste); bottom: -140px; right: -100px; }
.blob-3 { width: 260px; height: 260px; background: var(--lavanda); top: 40%; left: 45%; }
.welcome {
  position: relative; z-index: 1; min-height: 100vh; max-width: 1100px; margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 4rem) 1.2rem; display: grid; gap: 2rem; align-items: center;
}
@media (min-width: 900px) { .welcome { grid-template-columns: 1.1fr .9fr; gap: 3.5rem; } }
.eyebrow { font-weight: 800; letter-spacing: .04em; color: var(--primary-strong); margin-bottom: .6rem; }
.welcome-hero h1 { font-size: clamp(2.1rem, 5vw, 3.3rem); }
.welcome-hero h1 em { font-style: italic; color: var(--primary-strong); }
.lead { font-size: 1.12rem; color: var(--text-soft); max-width: 34em; }
.feature-list { list-style: none; padding: 0; margin: 1.4rem 0 0; display: grid; gap: .55rem; }
.feature-list li {
  display: flex; align-items: center; gap: .7rem; font-weight: 600;
  background: rgba(255,255,255,.65); border: 1px solid rgba(255,255,255,.9); border-radius: 14px; padding: .55em .9em;
  backdrop-filter: blur(6px); width: fit-content;
}
@media (max-width: 899px) { .feature-list { display: none; } .welcome-hero { text-align: center; } .lead { margin: 0 auto; } }
.auth-card { box-shadow: var(--shadow); border-color: rgba(255,255,255,.9); backdrop-filter: blur(10px); background: rgba(255,255,255,.88); }
.auth-card h2 { margin-bottom: 1rem; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 999px; padding: 4px; margin-bottom: 1.4rem; }
.auth-tab {
  border: 0; background: transparent; padding: .65em; border-radius: 999px; font: inherit; font-weight: 700;
  color: var(--text-soft); cursor: pointer; transition: background .2s, color .2s;
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.divider { display: flex; align-items: center; gap: .8rem; margin: 1.2rem 0; color: var(--text-faint); font-size: .9rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.resend-box { margin-top: 1rem; text-align: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: .9rem; }
.resend-box p { margin-bottom: .5rem; font-size: .95rem; }
.fine-print { margin: 1.2rem 0 0; text-align: center; color: var(--text-faint); font-size: .82rem; }
.noscript { text-align: center; padding: 2rem; }

/* =====================================================================
   APLICACIÓN
   ===================================================================== */
.boot { min-height: 100vh; display: grid; place-content: center; text-align: center; gap: 1rem; padding: 2rem; }
.boot-flower { font-size: 3rem; animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.12) rotate(8deg); } }

.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 50;
  background: var(--surface); border-right: 1px solid var(--border);
  display: none; flex-direction: column; padding: 1.4rem 1rem;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 0 .5rem 1.4rem; }
.brand-icon { font-size: 1.6rem; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav { display: grid; gap: .2rem; }
.side-nav a {
  display: flex; align-items: center; gap: .75rem; padding: .7em .9em; border-radius: 14px;
  color: var(--text-soft); text-decoration: none; font-weight: 700; transition: background .2s, color .2s;
}
.side-nav a span { font-size: 1.15rem; width: 1.5rem; text-align: center; }
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--primary-soft); color: var(--primary-strong); }
.sidebar-footer { margin-top: auto; display: grid; gap: .7rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: .6rem; font-weight: 700; padding: 0 .4rem; overflow: hidden; }
.user-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: .55rem;
  padding: calc(.7rem + env(safe-area-inset-top)) 1rem .7rem;
  background: rgba(251, 248, 250, .9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar .brand-name { flex: 1; font-size: 1.05rem; }

.content {
  padding: 1.2rem 1rem calc(var(--bottom-nav-h) + 2rem + env(safe-area-inset-bottom));
  max-width: 1080px; margin: 0 auto;
}
.page { animation: fade .25s; }
.page-header { margin-bottom: 1.3rem; }
.page-header h1 { margin-bottom: .15em; }

.bottom-nav {
  position: fixed; inset: auto 0 0 0; z-index: 60; height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,.95); backdrop-filter: blur(10px); border-top: 1px solid var(--border);
}
.bottom-nav a, .bottom-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; font: inherit; color: var(--text-soft); text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav span { font-size: 1.3rem; line-height: 1; padding: .25em .8em; border-radius: 999px; transition: background .2s; }
.bottom-nav small { font-size: .72rem; font-weight: 700; }
.bottom-nav a.active { color: var(--primary-strong); }
.bottom-nav a.active span { background: var(--primary-soft); }

.sheet-overlay { position: fixed; inset: 0; z-index: 80; background: rgba(74,68,88,.3); display: flex; align-items: flex-end; animation: fade .2s; }
.sheet {
  width: 100%; background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: .6rem 1rem calc(1rem + env(safe-area-inset-bottom)); display: grid; gap: .25rem; animation: slideup .25s var(--ease);
}
.sheet-handle { width: 42px; height: 5px; border-radius: 99px; background: var(--border); margin: 0 auto .6rem; }
.sheet a, .sheet button {
  display: flex; align-items: center; gap: .8rem; padding: .95em 1em; border-radius: 14px; border: 0; background: none;
  font: inherit; font-weight: 700; color: var(--text); text-decoration: none; text-align: left; cursor: pointer;
}
.sheet a.active { background: var(--primary-soft); color: var(--primary-strong); }
.sheet .sheet-logout { color: var(--danger); }
@keyframes slideup { from { transform: translateY(100%); } }

@media (min-width: 900px) {
  .sidebar { display: flex; }
  .topbar, .bottom-nav, .sheet-overlay { display: none !important; }
  .content { margin-left: var(--sidebar-w); padding: 2.2rem 2.4rem 3rem; max-width: calc(1080px + var(--sidebar-w)); }
}

/* ---------- Indicador de conexión / guardado ---------- */
.sync-status { display: flex; align-items: center; gap: .5rem; font-size: .85rem; font-weight: 700; color: var(--text-soft); padding: 0 .4rem; }
.sync-status i { width: 9px; height: 9px; border-radius: 50%; background: var(--success); flex: none; transition: background .2s; }
.sync-status[data-state=saving] i { background: var(--warning); animation: pulse 1s infinite; }
.sync-status[data-state=offline] i, .sync-status[data-state=error] i { background: var(--danger); }
.sync-status.compact .sync-label { display: none; }
.sync-status.compact[data-state=offline] .sync-label, .sync-status.compact[data-state=error] .sync-label { display: inline; color: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Perfil ---------- */
.avatar-preview {
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; font-size: 2.6rem; margin: 0 auto 1rem;
  background: linear-gradient(135deg, var(--rosa-suave), var(--celeste-suave)); border: 3px solid #fff; box-shadow: var(--shadow-sm);
}
.emoji-picker { display: flex; flex-wrap: wrap; gap: .35rem; }
.emoji-option {
  width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  font-size: 1.35rem; cursor: pointer; transition: transform .15s, border-color .15s, background .15s;
}
.emoji-option:hover { transform: translateY(-2px); }
.emoji-option.selected { border-color: var(--primary); background: var(--primary-soft); }

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