/* FamilyFit — hoja de estilos única, sin dependencias externas.
   Mobile-first, tema oscuro por defecto. Organizada por componente. */

:root {
  --bg: #0b1220;
  --bg-elevated: #131c2e;
  --card: #1a2338;
  --card-border: #263047;
  --text: #e7ecf5;
  --text-muted: #93a1bd;
  --primary: #22c55e;
  --primary-dark: #16a34a;
  --primary-ink: #04220f;
  --accent: #38bdf8;
  --warning: #f59e0b;
  --danger: #f87171;
  --danger-ink: #3a0a0a;
  --radius: 0.85rem;
  --radius-sm: 0.55rem;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.2);
  --focus-ring: 0 0 0 3px rgba(56, 189, 248, 0.35);
  --nav-height: 4.25rem;
  --sidebar-width: 15.5rem;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html { scroll-behavior: smooth; }
body { min-width: 20rem; }
button, input, select, textarea { font: inherit; }
img, svg { max-width: 100%; }

.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 100;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 800;
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  box-shadow: var(--focus-ring);
}

h1, h2, h3, h4 { margin: 0 0 0.5rem; line-height: 1.25; }
p { margin: 0 0 0.75rem; line-height: 1.55; color: var(--text); }

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.text-center { text-align: center; }

/* ---------- Layout: app shell ---------- */

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(var(--nav-height) + 1rem);
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--card-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text);
}

.brand .brand-dot { color: var(--primary); }

.app-main {
  padding: 1rem;
  max-width: 72rem;
  margin: 0 auto;
}

.app-main > h1,
.app-main > .row-between:first-child h1 { font-size: clamp(1.55rem, 5vw, 2.15rem); }
.page-toolbar { justify-content: flex-end; min-height: 2.9rem; margin-bottom: 0.5rem; }
.app-topbar-actions { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }

.mobile-menu { position: relative; }
.mobile-menu summary {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  list-style: none;
  font-size: 1.2rem;
}
.mobile-menu summary::-webkit-details-marker { display: none; }
.mobile-menu-panel {
  position: fixed;
  top: 4.2rem;
  right: 0.75rem;
  left: 0.75rem;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
  max-height: calc(100vh - 9rem);
  padding: 0.75rem;
  overflow-y: auto;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}
.mobile-menu-panel a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.9rem;
  padding: 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 650;
}
.mobile-menu-panel a:hover { background: var(--card); text-decoration: none; }
.mobile-menu-panel a.active { color: var(--primary); background: rgba(34, 197, 94, 0.14); }

/* ---------- Bottom nav (mobile) ---------- */

.nav-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  height: var(--nav-height);
  background: var(--bg-elevated);
  border-top: 1px solid var(--card-border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-bottom a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  text-decoration: none;
}

.nav-bottom a .icon { font-size: 1.3rem; line-height: 1; }
.nav-bottom a.active { color: var(--primary); }
.nav-bottom a.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 2rem;
  height: 0.2rem;
  border-radius: 0 0 999px 999px;
  background: var(--primary);
}
.nav-bottom a { position: relative; }

/* ---------- Sidebar (desktop) ---------- */

.sidebar {
  display: none;
}

@media (min-width: 992px) {
  .nav-bottom { display: none; }

  .app-shell { padding-bottom: 0; display: flex; }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    min-height: 100vh;
    padding: 1.25rem 1rem;
    background: var(--bg-elevated);
    border-right: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    gap: 0.25rem;
  }

  .sidebar .brand { padding: 0 0.5rem 1.25rem; }

  .sidebar a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.92rem;
  }

  .sidebar a:hover { background: var(--card); text-decoration: none; }
  .sidebar a.active { background: rgba(34, 197, 94, 0.14); color: var(--primary); }
  .sidebar .icon { font-size: 1.1rem; }

  .app-content { flex: 1; min-width: 0; }
  .app-topbar { display: none; }
  .app-main { padding: 1.75rem 2rem; max-width: 76rem; }
  .mobile-menu { display: none; }
}

.sidebar-logout { margin-top: auto; padding-top: 1rem; }

.topbar-only-desktop { display: none; }
@media (min-width: 992px) {
  .topbar-only-desktop { display: flex; }
}

/* ---------- Cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.card { transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease; }
a.card:hover { border-color: rgba(56, 189, 248, 0.55); box-shadow: var(--shadow-soft); transform: translateY(-2px); text-decoration: none; }

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}

@media (min-width: 640px) {
  .card-grid.cols-2 { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 992px) {
  .card-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
  .card-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}

.card-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.stat-value { font-size: 1.9rem; font-weight: 800; }
.stat-sub { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.15rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 2.75rem;
  text-decoration: none;
  transition: transform 120ms ease, background-color 160ms ease, opacity 160ms ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; opacity: 0.5; }
.btn.is-loading { cursor: wait; opacity: 0.72; }

.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--card-border); color: var(--text); }
.btn-secondary:hover { background: #313e5b; }

.btn-danger { background: var(--danger); color: var(--danger-ink); }

.btn-block { width: 100%; }
.btn-sm { min-height: 2.25rem; padding: 0.5rem 0.85rem; font-size: 0.85rem; }

.btn-group { display: flex; flex-wrap: wrap; gap: 0.6rem; }

/* ---------- Forms ---------- */

.field { margin-bottom: 1rem; }

label {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.field-hint { color: var(--text-muted); font-size: 0.78rem; margin-top: 0.3rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 0.85rem;
  min-height: 2.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

input::placeholder, textarea::placeholder { color: #71809e; opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: #3a4865; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.65; cursor: not-allowed; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }

textarea { min-height: 5rem; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-row input { width: auto; min-height: auto; }
.checkbox-row { min-height: 2.75rem; cursor: pointer; }
.checkbox-row input { width: 1.15rem; height: 1.15rem; accent-color: var(--primary); }

.field-error { color: var(--danger); font-size: 0.8rem; margin-top: 0.35rem; }
.field-label { display: block; font-weight: 700; font-size: 0.85rem; margin-bottom: 0.35rem; }

fieldset { border: none; padding: 0; margin: 0 0 1rem; }
legend { font-weight: 800; margin-bottom: 0.5rem; padding: 0; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 1rem;
}

@media (min-width: 640px) {
  .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
}

/* ---------- Alerts / flash ---------- */

.alert {
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.alert { animation: slide-in 220ms ease-out; }

.alert-success { background: rgba(34, 197, 94, 0.16); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.35); }
.alert-error { background: rgba(248, 113, 113, 0.14); color: #fca5a5; border: 1px solid rgba(248, 113, 113, 0.35); }
.alert-warning { background: rgba(245, 158, 11, 0.14); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.35); }
.alert-info { background: rgba(56, 189, 248, 0.12); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.3); }

/* ---------- Badges / progress ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--card-border);
  color: var(--text);
}

.badge-primary { background: rgba(34, 197, 94, 0.18); color: var(--primary); }
.badge-warning { background: rgba(245, 158, 11, 0.18); color: var(--warning); }

.progress {
  width: 100%;
  height: 0.6rem;
  border-radius: 999px;
  background: var(--card-border);
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}
.progress > span { transition: width 500ms ease-out; }

/* ---------- Empty states ---------- */

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 2.2rem; display: block; margin-bottom: 0.5rem; }

/* ---------- Lists ---------- */

.list { list-style: none; margin: 0; padding: 0; }

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--card-border);
}

.list-item:last-child { border-bottom: none; }

/* ---------- Avatar ---------- */

.avatar {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #04220f;
  flex-shrink: 0;
}

.avatar-lg { width: 4.5rem; height: 4.5rem; font-size: 1.4rem; }

/* ---------- Guest / onboarding layouts ---------- */

.centered-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card { width: 100%; max-width: 26rem; }
.auth-brand { justify-content: center; }

.onboarding-shell {
  min-height: 100vh;
  padding: 1.25rem;
  max-width: 34rem;
  margin: 0 auto;
}
.onboarding-brand { margin-bottom: 1rem; }

.onboarding-steps {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.onboarding-steps span {
  flex: 1;
  height: 0.35rem;
  border-radius: 999px;
  background: var(--card-border);
}

.onboarding-steps span.done { background: var(--primary); }

/* ---------- Charts ---------- */

.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { width: 100%; height: auto; display: block; }

/* ---------- Photo gallery ---------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

@media (min-width: 640px) {
  .photo-grid { grid-template-columns: repeat(3, 1fr); }
}

.photo-grid figure {
  margin: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-elevated);
  aspect-ratio: 3 / 4;
}

.photo-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-grid figcaption { padding: 0.35rem 0.5rem; font-size: 0.72rem; color: var(--text-muted); }

/* ---------- Data tables ---------- */

.table-wrap { width: 100%; overflow-x: auto; border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 0.7rem 0.65rem; text-align: left; white-space: nowrap; }
.data-table th { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tbody tr { border-top: 1px solid var(--card-border); }
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

/* ---------- Shared responsive helpers ---------- */

.member-selector { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.member-selector select { min-height: 2.55rem; padding-block: 0.5rem; max-width: 12rem; }
.full-row { grid-column: 1 / -1; }
.form-action { align-self: end; }
.page-heading { margin-bottom: 1rem; }
.page-heading h1 { margin: 0; }
.section-actions { margin-bottom: 1rem; }
.card-link { color: inherit; text-decoration: none; }
.dashboard-greeting { margin-bottom: 0.25rem; }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; }
.checkbox-label { font-weight: 400; }
.comparison-photo { width: 100%; border-radius: var(--radius-sm); }
.invitation-code { margin-bottom: 0.5rem; font-size: 1.4rem; font-weight: 800; letter-spacing: 0.1em; overflow-wrap: anywhere; }
.reward-points { font-size: 1.3rem; }
.responsive-inline-form { display: flex; align-items: center; gap: 0.65rem; }
.compact-input { max-width: 9rem; }
.indicator-section { margin-top: 1.5rem; }
.indicator-section > h2 { margin-bottom: 0.75rem; }
.indicator-card { box-shadow: var(--shadow-soft); }
.indicator-card .row-between { align-items: flex-start; }
.indicator-value { font-size: clamp(1.25rem, 4vw, 1.75rem); margin-top: 0.4rem; }
.indicator-value small { color: var(--text-muted); font-size: 0.75rem; font-weight: 600; }
.indicator-disclaimer { color: var(--warning); font-size: 0.75rem; margin-bottom: 0; }
.indicator-featured { border-color: rgba(34,197,94,.55); background: linear-gradient(145deg,rgba(34,197,94,.12),var(--card)); }
@media (min-width: 768px) { .form-grid.cols-3 { grid-template-columns: repeat(3,1fr); } }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-0.35rem); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 639px) {
  .centered-shell { align-items: flex-start; padding: 1rem; }
  .auth-card { margin-top: max(1rem, 6vh); }
  .card { padding: 1rem; }
  .btn-group { display: grid; grid-template-columns: 1fr 1fr; }
  .btn-group .btn { width: 100%; }
  .row-between { align-items: flex-start; }
  .page-heading { gap: 0.5rem; }
  .app-topbar .brand { font-size: 1rem; }
  .app-topbar .member-selector select { max-width: 9rem; }
  input[type="date"], input[type="file"] { min-width: 0; }
  .responsive-inline-form { align-items: stretch; flex-direction: column; }
  .responsive-inline-form .btn, .compact-input { width: 100%; max-width: none; }
}

@media (max-width: 380px) {
  .nav-bottom a { font-size: 0.62rem; }
  .nav-bottom a .icon { font-size: 1.15rem; }
  .btn-group { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media (prefers-contrast: more) {
  :root { --card-border: #64748b; --text-muted: #cbd5e1; }
  .btn, input, select, textarea, .card { border: 1px solid currentColor; }
}

/* ---------- Utility ---------- */

.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.row { display: flex; align-items: center; gap: 0.75rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.mt-1 { margin-top: 0.75rem; }
.mb-0 { margin-bottom: 0; }

/* ---------- PWA install/update ---------- */
.pwa-prompt, .pwa-update, .pwa-toast { position: fixed; z-index: 90; right: 1rem; bottom: calc(var(--nav-height) + 1rem); max-width: 27rem; border: 1px solid var(--card-border); border-radius: var(--radius); background: var(--bg-elevated); box-shadow: var(--shadow); }
.pwa-prompt { display: grid; grid-template-columns: auto 1fr; gap: .85rem; padding: 1.1rem; }
.pwa-prompt[hidden], .pwa-update[hidden], .pwa-toast[hidden] { display: none; }
.pwa-prompt h2 { padding-right: 1.5rem; font-size: 1.1rem; }
.pwa-prompt p, .pwa-ios-instructions { font-size: .86rem; color: var(--text-muted); }
.pwa-icon { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: .75rem; background: var(--primary); color: var(--primary-ink); font-size: 1.5rem; font-weight: 800; }
.pwa-close { position: absolute; top: .45rem; right: .55rem; border: 0; background: transparent; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; }
.pwa-ios-instructions { margin-top: .75rem; }
.pwa-ios-instructions ol { padding-left: 1.25rem; margin-bottom: 0; }
.pwa-update { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; padding: .8rem 1rem; }
.pwa-toast { padding: .85rem 1rem; color: #86efac; }
.pwa-install-manual { margin-top: .5rem; }
.pwa-installed .pwa-browser-only { display: none !important; }
@media (min-width: 992px) { .pwa-prompt, .pwa-update, .pwa-toast { bottom: 1rem; } }
@media (max-width: 639px) { .pwa-prompt, .pwa-update, .pwa-toast { left: .75rem; right: .75rem; max-width: none; } .pwa-prompt { grid-template-columns: 1fr; } .pwa-icon { display: none; } }
