/* Biblioteca — tokens portados de tailwind.config.js + paleta Tailwind de la app Expo. */

@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('Poppins Regular'), local('Poppins-Regular');
}

:root {
  /* Escala tipográfica exacta del tailwind.config.js */
  --text-xs: 12.8px;   --lh-xs: 18px;
  --text-sm: 15px;     --lh-sm: 21px;
  --text-base: 17.1px; --lh-base: 25px;
  --text-lg: 19.3px;   --lh-lg: 27px;
  --text-xl: 21.4px;   --lh-xl: 29px;
  --text-2xl: 25.7px;  --lh-2xl: 33px;
  --text-3xl: 32.1px;  --lh-3xl: 38px;

  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;

  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;

  --indigo-50:  #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-400: #818cf8;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;

  --green-50:  #f0fdf4;
  --green-100: #dcfce7;
  --green-400: #4ade80;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;

  --red-100: #fee2e2;
  --red-400: #f87171;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;

  --amber-100: #fef3c7;
  --amber-500: #f59e0b;
  --amber-700: #b45309;

  --violet-100: #ede9fe;
  --purple-100: #f3e8ff;
  --purple-600: #9333ea;
  --purple-700: #7c3aed;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, .28);

  --tabbar-h: 64px;
  --header-h: 56px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: Poppins, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: var(--text-base);
  line-height: var(--lh-base);
  color: var(--slate-800);
  background: var(--slate-50);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* La app es mobile-only: la centramos con un ancho de teléfono. */
.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--slate-50);
  /* Espacio para que la tab bar fija nunca tape el último botón. */
  padding-bottom: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom, 0px));
}

.app.no-tabs { padding-bottom: 24px; }

/* ── Header ─────────────────────────────────────────────── */

.header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-h);
  padding: 8px 16px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-200);
}

.header__title {
  flex: 1;
  margin: 0;
  font-size: var(--text-lg);
  line-height: var(--lh-lg);
  font-weight: 600;
  color: var(--slate-800);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header__back,
.header__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--slate-600);
  font-size: var(--text-lg);
  text-decoration: none;
  cursor: pointer;
}

.header__action:active,
.header__back:active { background: var(--slate-200); }

.header__actions { display: flex; gap: 4px; }

/* ── Tab bar ────────────────────────────────────────────── */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #fff;
  border-top: 1px solid var(--slate-200);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 30;
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--tabbar-h);
  text-decoration: none;
  color: var(--slate-400);
  font-size: 11px;
  font-weight: 500;
}

.tabbar a.is-active { color: var(--blue-500); }
.tabbar .tabbar__icon { font-size: 22px; line-height: 1; }

/* ── Layout ─────────────────────────────────────────────── */

.screen { padding: 16px; }
.screen--tight { padding-top: 8px; }

.stack-2 > * + * { margin-top: 8px; }
.stack-3 > * + * { margin-top: 12px; }
.stack-4 > * + * { margin-top: 16px; }

.row { display: flex; align-items: center; gap: 12px; }
.row--top { align-items: flex-start; }
.row--between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.spacer-6 { height: 24px; }
.spacer-8 { height: 32px; }

/* ── Tipografía ─────────────────────────────────────────── */

.t-xs   { font-size: var(--text-xs);   line-height: var(--lh-xs); }
.t-sm   { font-size: var(--text-sm);   line-height: var(--lh-sm); }
.t-base { font-size: var(--text-base); line-height: var(--lh-base); }
.t-lg   { font-size: var(--text-lg);   line-height: var(--lh-lg); }
.t-xl   { font-size: var(--text-xl);   line-height: var(--lh-xl); }
.t-2xl  { font-size: var(--text-2xl);  line-height: var(--lh-2xl); }
.t-3xl  { font-size: var(--text-3xl);  line-height: var(--lh-3xl); }

.semibold { font-weight: 600; }
.bold     { font-weight: 700; }

.c-slate-400 { color: var(--slate-400); }
.c-slate-500 { color: var(--slate-500); }
.c-slate-600 { color: var(--slate-600); }
.c-slate-700 { color: var(--slate-700); }
.c-slate-800 { color: var(--slate-800); }
.c-blue-500  { color: var(--blue-500); }
.c-red-500   { color: var(--red-500); }
.c-green-600 { color: var(--green-600); }

.clamp-1, .clamp-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.clamp-1 { -webkit-line-clamp: 1; }
.clamp-2 { -webkit-line-clamp: 2; }

.page-title {
  margin: 0;
  font-size: var(--text-2xl);
  line-height: var(--lh-2xl);
  font-weight: 700;
  color: var(--slate-800);
}

.page-title--lg {
  font-size: var(--text-3xl);
  line-height: var(--lh-3xl);
}

/* ── Card ───────────────────────────────────────────────── */

.card {
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.card--flush { padding: 0; overflow: hidden; }
.card--tap { display: block; text-decoration: none; color: inherit; }
.card--tap:active { background: var(--slate-50); }

/* ── Badge ──────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--text-xs);
  line-height: 18px;
  font-weight: 500;
  white-space: nowrap;
}

.badge--slate  { background: var(--slate-100);  color: var(--slate-600); }
.badge--blue   { background: var(--blue-100);   color: var(--blue-700); }
.badge--green  { background: var(--green-100);  color: var(--green-700); }
.badge--red    { background: var(--red-100);    color: var(--red-700); }
.badge--amber  { background: var(--amber-100);  color: var(--amber-700); }
.badge--indigo { background: var(--indigo-100); color: var(--indigo-700); }
.badge--ai     { background: var(--purple-100); color: var(--purple-700); }

/* ── Botones ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn--primary   { background: var(--blue-600);   color: #fff; }
.btn--primary:active   { background: var(--blue-700); }
.btn--secondary { background: var(--slate-200);  color: var(--slate-700); }
.btn--secondary:active { background: var(--slate-300); }
.btn--danger    { background: var(--red-600);    color: #fff; }
.btn--danger:active    { background: var(--red-700); }
.btn--ghost     { background: transparent; color: var(--slate-600); border: 1px solid var(--slate-300); }
.btn--ghost:active     { background: var(--slate-50); }
.btn--ai        { background: var(--purple-600); color: #fff; }
.btn--ai:active        { background: var(--purple-700); }

.btn[disabled] { opacity: .5; pointer-events: none; }
.btn--auto { width: auto; }

.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--blue-600);
  color: #fff;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.link-danger {
  display: block;
  width: 100%;
  padding: 12px;
  border: 0;
  background: none;
  color: var(--red-500);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 500;
  text-align: center;
  cursor: pointer;
}

/* ── Chips de filtro ────────────────────────────────────── */

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  padding: 6px 12px;
  border: 1px solid var(--slate-200);
  border-radius: 999px;
  background: #fff;
  color: var(--slate-600);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.chip.is-active {
  background: var(--blue-600);
  border-color: var(--blue-600);
  color: #fff;
}

/* ── Formularios ────────────────────────────────────────── */

.field { margin-bottom: 16px; }

.field__label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 500;
  color: var(--slate-700);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  background: #fff;
  font-family: inherit;
  font-size: var(--text-base);
  line-height: var(--lh-base);
  color: var(--slate-800);
  appearance: none;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
}

.input::placeholder,
.textarea::placeholder { color: var(--slate-400); }

.input--error { border-color: var(--red-400); }

.textarea { min-height: 120px; resize: vertical; }

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.6' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
  padding-right: 36px;
}

.field__error {
  margin: 4px 0 0;
  font-size: var(--text-xs);
  color: var(--red-500);
}

.field__hint {
  margin: 4px 0 0;
  font-size: var(--text-xs);
  line-height: var(--lh-xs);
  color: var(--slate-400);
}

/* Atajos de fecha del DateInput original */
.date-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.date-quick button {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--slate-100);
  color: var(--slate-700);
  font-family: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.date-quick button:active { background: var(--slate-200); }

/* ── Progress bar ───────────────────────────────────────── */

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

.progress--thin { height: 4px; }
.progress--thick { height: 12px; background: var(--slate-200); }

.progress__fill { height: 100%; border-radius: 999px; }

.fill--green  { background: var(--green-500); }
.fill--red    { background: var(--red-500); }
.fill--blue   { background: var(--blue-500); }
.fill--indigo { background: var(--indigo-500); }
.fill--slate  { background: var(--slate-400); }
.fill--amber  { background: var(--amber-500); }

/* ── Bloques de métrica ─────────────────────────────────── */

.metric { margin-bottom: 16px; }

.metric__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.metric__label  { font-size: var(--text-sm); font-weight: 500; color: var(--slate-600); }
.metric__value  { font-size: var(--text-sm); font-weight: 600; color: var(--slate-800); }
.metric__detail { margin: 4px 0 0; font-size: var(--text-xs); color: var(--slate-400); }

/* Tiles de números grandes del dashboard */
.tiles { display: flex; gap: 12px; }

.tile {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
}

.tile--indigo { background: var(--indigo-50); }
.tile--slate  { background: var(--slate-50); }
.tile--green  { background: var(--green-50); }

.tile__value {
  font-size: var(--text-2xl);
  line-height: var(--lh-2xl);
  font-weight: 700;
}

.tile__value small { font-size: var(--text-base); font-weight: 400; }

.tile__label { margin-top: 2px; font-size: var(--text-xs); line-height: var(--lh-xs); }

.tile--indigo .tile__value { color: var(--indigo-700); }
.tile--indigo .tile__value small { color: var(--indigo-400); }
.tile--indigo .tile__label { color: var(--indigo-500); }

.tile--slate .tile__value { color: var(--slate-700); }
.tile--slate .tile__value small { color: var(--slate-400); }
.tile--slate .tile__label { color: var(--slate-500); }

.tile--green .tile__value { color: var(--green-700); }
.tile--green .tile__value small { color: var(--green-400); }
.tile--green .tile__label { color: var(--green-600); }

.tile--wide { display: flex; align-items: center; justify-content: space-between; }

.tile__diff { font-size: var(--text-sm); font-weight: 700; }
.diff--up   { color: var(--green-600); }
.diff--down { color: var(--red-500); }

/* ── Portadas ───────────────────────────────────────────── */

.cover {
  flex-shrink: 0;
  border-radius: 6px;
  background: var(--slate-100);
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--slate-400);
}

.cover--sm { width: 40px;  height: 56px;  font-size: 16px; }
.cover--md { width: 64px;  height: 88px;  font-size: 24px; }
.cover--lg { width: 120px; height: 168px; font-size: 40px; }

.cover-course {
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--violet-100);
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-course--sm   { width: 80px;  height: 45px;  font-size: 18px; }
.cover-course--md   { width: 160px; height: 90px;  font-size: 28px; }
.cover-course--full { width: 100%;  height: 200px; font-size: 48px; border-radius: 0; }

/* ── Picker de foto ─────────────────────────────────────── */

.photo-picker { position: relative; display: inline-block; }

.photo-picker input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.photo-picker__box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 96px;
  height: 128px;
  border: 2px dashed var(--slate-300);
  border-radius: 12px;
  color: var(--slate-400);
  font-size: var(--text-xs);
  line-height: var(--lh-xs);
  text-align: center;
}

.photo-picker--wide .photo-picker__box { width: 100%; height: 176px; }

.photo-picker__preview {
  width: 96px;
  height: 128px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--slate-200);
  display: block;
}

.photo-picker--wide .photo-picker__preview { width: 100%; height: 180px; }

.photo-picker__edit {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  font-size: 11px;
  pointer-events: none;
}

/* ── Búsqueda ───────────────────────────────────────────── */

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  background: #fff;
}

.search input {
  flex: 1;
  padding: 10px 0;
  border: 0;
  background: none;
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--slate-800);
  outline: none;
  min-width: 0;
}

.search input::placeholder { color: var(--slate-400); }

.search__clear { color: var(--slate-400); text-decoration: none; font-size: 16px; }

/* ── Estado vacío ───────────────────────────────────────── */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 32px;
  text-align: center;
}

.empty__icon { font-size: 48px; opacity: .45; }

.empty__title {
  margin: 16px 0 0;
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--slate-400);
}

.empty__subtitle {
  margin: 4px 0 0;
  font-size: var(--text-sm);
  color: var(--slate-400);
}

/* ── Flash ──────────────────────────────────────────────── */

.flash {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
}

.flash--success { background: var(--green-100); color: var(--green-700); }
.flash--error   { background: var(--red-100);   color: var(--red-700); }
.flash--info    { background: var(--blue-100);  color: var(--blue-700); }

/* ── Login ──────────────────────────────────────────────── */

.login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--slate-50);
}

.login__card {
  width: 100%;
  max-width: 380px;
  padding: 24px;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

.login__logo { font-size: 44px; text-align: center; }

.login__title {
  margin: 8px 0 4px;
  font-size: var(--text-xl);
  font-weight: 700;
  text-align: center;
  color: var(--slate-800);
}

.login__subtitle {
  margin: 0 0 24px;
  font-size: var(--text-sm);
  text-align: center;
  color: var(--slate-500);
}

/* ── Spinner ────────────────────────────────────────────── */

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.spinner--purple {
  border-color: rgba(124, 58, 237, .3);
  border-top-color: var(--purple-700);
}

@keyframes spin { to { transform: rotate(360deg); } }

.is-hidden { display: none !important; }

/* ── Modal de confirmación ──────────────────────────────── */

dialog.confirm {
  width: calc(100% - 48px);
  max-width: 380px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}

dialog.confirm::backdrop { background: rgba(0, 0, 0, .4); }

.confirm__body { padding: 24px; }

.confirm__title {
  margin: 0 0 8px;
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--slate-800);
}

.confirm__message {
  margin: 0 0 24px;
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  color: var(--slate-600);
}

.confirm__actions { display: flex; gap: 12px; }
.confirm__actions .btn { flex: 1; }

/* ── Estados de carga ───────────────────────────────────── */

.btn.is-loading {
  opacity: .92;
  pointer-events: none;
}

.btn .spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
  flex-shrink: 0;
}

.btn--secondary .spinner,
.btn--ghost .spinner {
  border-color: rgba(71, 85, 105, .3);
  border-top-color: var(--slate-600);
}

.btn--sm {
  width: auto;
  padding: 8px 14px;
  font-size: var(--text-sm);
}

/* Mientras se envía, el formulario no acepta más toques. */
form.is-submitting {
  pointer-events: none;
}
form.is-submitting .btn.is-loading {
  pointer-events: none;
}

/* Barra de progreso al navegar */
.route-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--blue-500), var(--indigo-500));
  z-index: 100;
  opacity: 0;
  transition: width .5s ease, opacity .2s ease;
  pointer-events: none;
}

.route-progress.is-active {
  width: 85%;
  opacity: 1;
  transition: width 8s cubic-bezier(.1, .8, .2, 1), opacity .15s ease;
}

/* La tarjeta que tocaste se hunde apenas, para dar respuesta inmediata */
a.is-navigating {
  opacity: .65;
  transform: scale(.995);
}

/* ── Pulido visual ──────────────────────────────────────── */

/* El header se despega del fondo al hacer scroll */
.header {
  backdrop-filter: saturate(180%) blur(8px);
  background: rgba(248, 250, 252, .88);
}

/* Feedback táctil en las tarjetas */
.card--tap {
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
  -webkit-tap-highlight-color: transparent;
}

.card--tap:active {
  transform: scale(.985);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}

.btn,
.btn-pill,
.chip {
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}

.btn:active:not([disabled]),
.btn-pill:active { transform: scale(.97); }

/* Barras de progreso con una transición al entrar */
.progress__fill {
  transition: width .6s cubic-bezier(.22, .8, .3, 1);
}

/* La tab bar activa marca también con una línea arriba */
.tabbar a {
  position: relative;
  transition: color .15s ease;
}

.tabbar a.is-active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--blue-500);
}

.tabbar a:active { background: var(--slate-50); }

/* La tab bar flota sobre el contenido: que se note el corte */
.tabbar {
  box-shadow: 0 -1px 3px rgba(15, 23, 42, .06);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(180%) blur(10px);
}

/* Estados vacíos con algo más de aire */
.empty__icon {
  filter: saturate(.4);
}

/* Los formularios largos terminan bien arriba de la tab bar */
form.screen > .btn:last-of-type,
form.screen > .spacer-8 {
  margin-bottom: 0;
}

/* Flash como cinta flotante, no empuja el contenido */
.flash {
  animation: flash-in .25s ease-out;
}

@keyframes flash-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Respeta a quien prefiere menos movimiento */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* El flash se puede tocar para cerrarlo */
.flash { cursor: pointer; }
