:root {
  --color-primary: #E31E2D;
  --color-primary-dark: #B4141F;
  --color-primary-light: #FDEBEC;
  --color-bg: #FFFFFF;
  --color-card: #F5F6F8;
  --color-card-alt: #FFFFFF;
  --color-border: #EDEEF1;
  --color-text: #24262B;
  --color-text-secondary: #8A8F98;
  --color-success: #1FA971;
  --color-success-light: #E7F8F1;
  --color-warning: #E8A100;
  --color-secondary: #2B3A55;
  --color-secondary-light: #E9ECF2;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow-card: 0 2px 14px rgba(20, 20, 30, 0.06);
  --shadow-fab: 0 8px 20px rgba(227, 30, 45, 0.30);
  --nav-height: 68px;
  --header-height: 56px;
  font-size: 16px;
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--color-bg);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

/* ---------- Header ---------- */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--color-border);
}

.app-header .logo-mark { height: 26px; }
.app-header h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}
.app-header .back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--color-primary);
  font-weight: 600;
  font-size: 15px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
}
.icon-btn:active { background: var(--color-card); color: var(--color-primary); }

/* ---------- Main content ---------- */
.app-content {
  flex: 1;
  padding: 20px 20px calc(var(--nav-height) + 28px);
}

.app-content.no-nav {
  padding-bottom: 28px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-height);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: stretch;
  z-index: 20;
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--color-text-secondary);
  font-size: 11px;
  font-weight: 600;
  transition: color 0.15s ease;
}

.bottom-nav a svg { width: 24px; height: 24px; transition: transform 0.15s ease; }
.bottom-nav a.active { color: var(--color-primary); }
.bottom-nav a.active svg { transform: translateY(-1px); }
.bottom-nav a:active svg { transform: scale(0.88); }

/* ---------- Cards ---------- */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.card + .card { margin-top: 14px; }

.card-white {
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.stat-card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
}

.stat-card .stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  margin-bottom: 12px;
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-label {
  margin-top: 6px;
  font-size: 13px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.stat-card.primary {
  background: var(--color-primary);
  color: #fff;
}
.stat-card.primary .stat-icon {
  background: rgba(255,255,255,0.18);
  color: #fff;
}
.stat-card.primary .stat-label { color: rgba(255,255,255,0.85); }

/* ---------- Quick actions ---------- */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.quick-action {
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.quick-action:active { transform: scale(0.95); box-shadow: var(--shadow-card); }
.quick-action .icon-circle { transition: transform 0.15s ease; }
.quick-action:active .icon-circle { transform: scale(1.08); }

.quick-action .icon-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 20px;
  border-radius: var(--radius-pill);
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-fab);
}
.btn-primary:active { background: var(--color-primary-dark); }

.btn-secondary {
  background: var(--color-card);
  color: var(--color-text);
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--color-primary);
  color: var(--color-primary);
}

.btn-sm {
  width: auto;
  padding: 9px 16px;
  font-size: 13.5px;
}

.btn-block-group { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field input[type="email"],
.field select,
.field textarea {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--color-border);
  background: var(--color-card-alt);
  font-size: 15px;
  color: var(--color-text);
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.errorlist { color: var(--color-primary); font-size: 12.5px; margin: 4px 0 0; padding: 0; list-style: none; }

/* ---------- Section headers ---------- */
.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 24px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title .add-link {
  font-size: 13px;
  color: var(--color-primary);
  font-weight: 600;
}

.greeting-row { display: flex; align-items: center; gap: 14px; margin: 4px 0 20px; }
.avatar-circle {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 700;
}
.greeting { font-size: 22px; font-weight: 700; margin: 0; }
.greeting span { display: block; font-size: 14px; font-weight: 500; color: var(--color-text-secondary); margin-bottom: 2px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 28px;
  animation: fade-in-up 0.4s ease;
}
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo img { height: 48px; }
.login-title { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { text-align: center; color: var(--color-text-secondary); font-size: 14px; margin-bottom: 32px; }

/* ---------- Line item rows (ventas/presupuestos formset) ---------- */
.line-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  background: var(--color-card-alt);
  position: relative;
}
.line-item .remove-line {
  position: absolute;
  top: 10px;
  right: 10px;
  color: var(--color-text-secondary);
  font-size: 18px;
  cursor: pointer;
  background: none;
  border: none;
}

/* ---------- Confirmation ---------- */
.confirm-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 28px;
  text-align: center;
}
.confirm-icon {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--color-success-light);
  color: var(--color-success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}
.confirm-icon svg { width: 44px; height: 44px; }
.confirm-title { font-size: 21px; font-weight: 700; margin-bottom: 8px; }
.confirm-subtitle { color: var(--color-text-secondary); font-size: 14.5px; margin-bottom: 28px; }
.confirm-points { display: flex; gap: 12px; width: 100%; margin-bottom: 32px; }

/* ---------- Course cards ---------- */
.course-card {
  display: flex;
  gap: 14px;
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 12px;
  align-items: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.course-card:active { transform: scale(0.98); box-shadow: var(--shadow-card); border-color: transparent; }
.course-card img, .course-card .thumb-fallback {
  width: 68px;
  height: 68px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--color-primary-light);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
}
.course-card .course-info { flex: 1; min-width: 0; }
.course-card .course-title { font-weight: 600; font-size: 14.5px; margin-bottom: 4px; }
.course-card .course-meta { display: flex; gap: 10px; font-size: 12px; color: var(--color-text-secondary); }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
}
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-pending { background: var(--color-primary-light); color: var(--color-primary); }
.badge-progress { background: #FFF4D9; color: var(--color-warning); }

/* ---------- Video player ---------- */
.video-wrap {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  aspect-ratio: 16/9;
  margin-bottom: 16px;
}
.video-wrap iframe, .video-wrap video { width: 100%; height: 100%; border: none; }

.video-progress-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-border);
  overflow: hidden;
  margin-top: 10px;
}
.video-progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-pill);
  transition: width 0.2s ease;
}
.video-progress-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  font-weight: 600;
  margin-top: 6px;
}

/* ---------- Quiz ---------- */
.quiz-question { font-size: 16px; font-weight: 700; margin: 20px 0 14px; }
.quiz-option {
  display: block;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  font-size: 14.5px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.quiz-option input { margin-right: 10px; }
.quiz-option.selected { border-color: var(--color-primary); background: var(--color-primary-light); font-weight: 600; }

#quiz-section { animation: fade-in 0.3s ease; }
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Rewards catalog ---------- */
.reward-card {
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 14px;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.reward-card img { transition: transform 0.3s ease; }
.reward-card:hover img { transform: scale(1.04); }
.reward-card:hover { box-shadow: var(--shadow-card); }
.reward-card img, .reward-card .thumb-fallback {
  width: 100%;
  height: 120px;
  object-fit: cover;
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
}
.reward-card .reward-body { padding: 14px; }
.reward-card .reward-name { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.reward-card .reward-points { color: var(--color-primary); font-weight: 700; font-size: 13.5px; margin-bottom: 12px; }

/* ---------- History ---------- */
.history-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border);
}
.history-item:last-child { border-bottom: none; }
.history-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-card);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  flex-shrink: 0;
}
.history-body { flex: 1; }
.history-title { font-weight: 600; font-size: 14px; }
.history-date { font-size: 12px; color: var(--color-text-secondary); margin-top: 2px; }
.history-points { font-weight: 700; font-size: 14px; white-space: nowrap; }
.history-points.positive { color: var(--color-success); }
.history-points.negative { color: var(--color-primary); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-secondary);
  font-size: 14px;
}
.empty-state .empty-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-card);
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.messages { margin-bottom: 14px; }
.messages li {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 8px;
  font-weight: 600;
}

/* ---------- Dashboard responsable ---------- */
.team-stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.team-stat-row .stat-card { padding: 14px 10px; }
.team-stat-row .stat-value { font-size: 21px; }
.team-stat-row .stat-label { font-size: 11.5px; }

.bar-chart { display: flex; flex-direction: column; gap: 16px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label {
  width: 84px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  flex: 1;
  background: var(--color-border);
  border-radius: var(--radius-pill);
  height: 14px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width 0.4s ease;
}
.bar-fill.c0 { background: var(--color-primary); }
.bar-fill.c1 { background: var(--color-secondary); }
.bar-value { width: 42px; text-align: right; font-size: 13px; font-weight: 700; flex-shrink: 0; }

.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 110px;
  padding-top: 10px;
}
.trend-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}
.trend-bar {
  width: 100%;
  max-width: 28px;
  background: var(--color-primary);
  border-radius: 6px 6px 2px 2px;
  min-height: 3px;
  transition: height 0.4s ease;
  position: relative;
}
.trend-bar-value {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}
.trend-label {
  margin-top: 8px;
  font-size: 10.5px;
  color: var(--color-text-secondary);
  font-weight: 600;
}

.worker-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--color-card-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.worker-card:active { transform: scale(0.98); box-shadow: var(--shadow-card); }
.worker-card .avatar-circle { width: 44px; height: 44px; font-size: 16px; flex-shrink: 0; background: var(--color-secondary); }
.worker-card .worker-info { flex: 1; min-width: 0; }
.worker-card .worker-name { font-weight: 700; font-size: 14.5px; }
.worker-card .worker-meta { font-size: 12.5px; color: var(--color-text-secondary); margin-top: 2px; }
.worker-card .worker-points { text-align: right; flex-shrink: 0; }
.worker-card .worker-points .value { font-weight: 700; font-size: 17px; color: var(--color-primary); }
.worker-card .worker-points .label { font-size: 10.5px; color: var(--color-text-secondary); }
.worker-card .chevron { color: var(--color-text-secondary); flex-shrink: 0; }

.event-owner-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-secondary);
  background: var(--color-secondary-light);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin-bottom: 3px;
}
