:root {
  --primary: #8E2F87;
  --primary-dark: #6B1F65;
  --primary-light: #B85DB0;
  --primary-subtle: #F3E6F2;
  --primary-muted: #D4A8D1;
  --accent: #EBB700;
  --accent-light: #FFF0B3;
  --accent-dark: #C49600;
  --teal: #199399;
  --teal-light: #E0F4F5;
  --teal-dark: #127478;
  --surface: #FFF7F2;
  --card: #FFFFFF;
  --surface-sunken: #F5EDE8;
  --text: #1F2937;
  --muted: #6B7280;
  --border: #E5D9D4;
  --border-strong: #8E2F87;
  --success: #1A7A5E;
  --error: #C0392B;
  --warning: #C49600;
  --card-radius: 16px;
  --button-radius: 28px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  font-family: 'Rethink Sans', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 24px;
}
.app.hidden { display: none; }

/* Pantalla previa: elegir usuario */
.picker-screen {
  min-height: 100vh;
  max-width: 420px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}
.picker-screen.hidden { display: none; }
.picker-mascot {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 4px var(--accent-light);
  margin-bottom: 18px;
}
.picker-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary-dark);
  margin: 0 0 28px;
}
.picker-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.picker-btn {
  width: 100%;
  border: none;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 16px;
  border-radius: var(--button-radius);
  cursor: pointer;
  border: 1.5px solid var(--border);
  transition: background .12s ease, color .12s ease, transform .1s ease;
}
.picker-btn:active { transform: scale(0.98); }
.picker-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Botón de usuario actual (reemplaza el dropdown) */
.user-current {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  padding: 4px 2px;
}
.user-current #currentUserName {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}
.user-current-swap {
  font-size: 10.5px;
  color: var(--muted);
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 8px;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mascot {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--accent-light);
}
.brand-name { font-weight: 800; font-size: 20px; color: var(--primary-dark); }
.user-select {
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 12px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
}

/* Toggle */
.toggle {
  display: flex;
  gap: 6px;
  margin: 12px 20px 4px;
  background: var(--surface-sunken);
  border-radius: var(--button-radius);
  padding: 4px;
}
.toggle-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-weight: 700;
  font-size: 13.5px;
  padding: 10px 6px;
  border-radius: 24px;
  cursor: pointer;
}
.toggle-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Views */
.views { flex: 1; padding: 16px 20px 0; }
.view { display: none; }
.view.active { display: block; animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* Actividades grid */
.activities-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.activity-btn {
  border: none;
  border-radius: var(--card-radius);
  padding: 22px 14px;
  background: var(--surface-sunken);
  color: var(--muted);
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .1s ease;
  min-height: 92px;
  justify-content: center;
  text-align: center;
}
.activity-btn:active { transform: scale(0.97); }
.activity-btn .emoji { font-size: 24px; }
.activity-btn.running {
  background: var(--cat-color, var(--primary));
  color: #fff;
}
.btn-add-activity {
  margin-top: 16px;
  width: 100%;
  border: 1.5px dashed var(--border-strong);
  background: transparent;
  color: var(--primary);
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 12px;
  border-radius: var(--button-radius);
  cursor: pointer;
}

/* Semanal */
.week-label { font-weight: 700; font-size: 13px; color: var(--muted); margin: 0 0 10px; text-align: center; }

.grid-scroll { overflow-x: auto; }
.week-grid {
  display: grid;
  grid-template-columns: 44px repeat(7, minmax(40px, 1fr));
  gap: 2px;
  min-width: 500px;
}
.week-grid .head {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  padding: 4px 0;
}
.week-grid .hour-label {
  font-size: 10px;
  color: var(--muted);
  text-align: right;
  padding-right: 4px;
  align-self: center;
}
.week-cell {
  background: var(--surface-sunken);
  border-radius: 6px;
  min-height: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  line-height: 1.1;
  padding: 1px;
  overflow: hidden;
}
.week-cell.filled { background: var(--cell-color, var(--teal)); }
.week-cell.today-col { outline: 1.5px solid var(--primary-light); outline-offset: -1.5px; }

/* Resumen */
.resumen-subtitle { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

.radar-card {
  background: var(--card);
  border-radius: var(--card-radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.radar-title { font-weight: 800; font-size: 14px; color: var(--text); margin: 0 0 4px; align-self: flex-start; }
.radar-wrap { width: 100%; max-width: 280px; }
.radar-wrap svg { width: 100%; height: auto; display: block; }
.radar-status { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; text-align: center; }
.resumen-cards { display: flex; flex-direction: column; gap: 12px; }
.resumen-card {
  background: var(--card);
  border-radius: var(--card-radius);
  padding: 16px;
  border: 1px solid var(--border);
}
.resumen-card.neglected { border-color: var(--warning); background: #FFF9E8; }
.resumen-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.resumen-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 15px;
}
.resumen-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--warning);
  background: var(--accent-light);
  padding: 3px 8px;
  border-radius: 10px;
}
.resumen-bar-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.resumen-bar-label { font-size: 11px; color: var(--muted); width: 58px; flex-shrink: 0; }
.resumen-bar-track {
  flex: 1;
  height: 10px;
  background: var(--surface-sunken);
  border-radius: 6px;
  overflow: hidden;
}
.resumen-bar-fill { height: 100%; border-radius: 6px; }
.resumen-bar-fill.planned { background: var(--primary-muted); }
.resumen-bar-fill.actual { background: var(--teal); }
.resumen-bar-fill.overlap { background: var(--accent); }
.resumen-bar-value { font-size: 11px; font-weight: 700; width: 44px; text-align: right; flex-shrink: 0; }
.resumen-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 20px; }

.resumen-activities {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.resumen-activity-sub-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.resumen-activity-sub .resumen-bar-label { width: 52px; font-size: 10px; }
.resumen-activity-sub .resumen-bar-track { height: 7px; }
.resumen-activity-sub .resumen-bar-value { width: 40px; font-size: 10px; }
.resumen-activity-sub .resumen-bar-row { margin-top: 4px; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(31,41,55,0.45);
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card);
  width: 100%;
  max-width: 520px;
  border-radius: 20px 20px 0 0;
  padding: 22px 20px 26px;
}
.modal h3 { margin: 0 0 14px; font-size: 17px; color: var(--primary-dark); }
.modal-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 12px 0 6px; }
.modal-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
}
.rango-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-top: 4px;
}
.rango-field { flex: 1; }
.rango-field .modal-label { margin: 0 0 6px; }
.rango-hasta {
  font-size: 12px;
  color: var(--muted);
  padding-bottom: 12px;
  flex-shrink: 0;
}
.modal-select {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 10px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
}

.categoria-picker, .bloque-actividad-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.categoria-chip, .actividad-chip {
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.categoria-chip.selected, .actividad-chip.selected {
  background: var(--cat-color, var(--primary));
  border-color: var(--cat-color, var(--primary));
  color: #fff;
}
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-primary, .btn-secondary {
  flex: 1;
  border: none;
  border-radius: var(--button-radius);
  padding: 13px;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface-sunken); color: var(--text); }
