*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,.07), 0 20px 40px rgba(0,0,0,.1);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.state { min-height: 100dvh; }
.fullscreen-center { display: flex; align-items: center; justify-content: center; }

/* ── Spinner ─────────────────────────────────────────────── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Layout Login ────────────────────────────────────────── */
.login-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100dvh;
}

.login-brand {
  background: linear-gradient(145deg, #1e3a8a 0%, #2563eb 50%, #3b82f6 100%);
  padding: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.login-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(255,255,255,.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,.06) 0%, transparent 40%);
}

.brand-content {
  position: relative;
  z-index: 1;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.brand-copy h1 {
  color: white;
  font-size: clamp(1.75rem, 3vw, 2.5rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.03em;
}

.brand-copy p {
  color: rgba(255,255,255,.7);
  font-size: 1rem;
  line-height: 1.6;
  margin-top: 16px;
}

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

.brand-tag {
  background: rgba(255,255,255,.15);
  color: rgba(255,255,255,.9);
  font-size: .78rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.2);
  backdrop-filter: blur(4px);
}

/* ── Panel formulario ────────────────────────────────────── */
.login-form-panel {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
}

.login-form-wrap {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.login-form-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--text);
}

.login-form-header p {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: .92rem;
}

/* ── Campos ──────────────────────────────────────────────── */
form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: .83rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .01em;
}

.field input,
.input-wrap input {
  width: 100%;
  padding: 11px 14px;
  font-family: inherit;
  font-size: .92rem;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus,
.input-wrap input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  background: white;
}

.field input.error,
.input-wrap input.error {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  padding-right: 44px;
}

.toggle-pw {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color .15s;
}
.toggle-pw:hover { color: var(--text-muted); }

/* ── Error ───────────────────────────────────────────────── */
.form-error {
  font-size: .84rem;
  color: #ef4444;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-error::before {
  content: '';
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  background: #ef4444;
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 9v4m0 4h.01M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z'/%3E%3C/svg%3E");
  background-size: contain;
}

/* ── Botones ─────────────────────────────────────────────── */
.btn-primary {
  font-family: inherit;
  font-size: .92rem;
  font-weight: 600;
  color: white;
  background: var(--brand);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px;
  width: 100%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 1px 2px rgba(37,99,235,.3), 0 4px 12px rgba(37,99,235,.2);
  margin-top: 4px;
}
.btn-primary:hover { background: var(--brand-dark); box-shadow: 0 2px 4px rgba(37,99,235,.4), 0 8px 20px rgba(37,99,235,.25); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .65; cursor: not-allowed; }

.btn-secondary {
  font-family: inherit;
  font-size: .92rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px;
  width: 100%;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-secondary:hover { background: white; color: var(--text); }

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .65s linear infinite;
  flex-shrink: 0;
}

/* ── Sin acceso ──────────────────────────────────────────── */
.noaccess-icon {
  width: 60px;
  height: 60px;
  background: #fef3c7;
  color: #d97706;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: -8px;
}

#state-noaccess .login-form-wrap { gap: 16px; }
#state-noaccess h2 { font-size: 1.4rem; font-weight: 800; letter-spacing: -.02em; }
#state-noaccess p { color: var(--text-muted); font-size: .9rem; line-height: 1.6; }
#state-noaccess .btn-secondary { margin-top: 8px; }
#state-noaccess .login-brand { background: linear-gradient(145deg, #1e3a8a 0%, #2563eb 50%, #3b82f6 100%); }

/* ── Header ──────────────────────────────────────────────── */
.portal-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
  color: white;
  font-size: .78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

#user-name {
  font-size: .88rem;
  font-weight: 500;
  color: var(--text-muted);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-logout:hover { background: var(--bg); color: var(--text); border-color: #cbd5e1; }

/* ── Portal main ─────────────────────────────────────────── */
.portal-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.portal-welcome {
  margin-bottom: 36px;
}

.portal-welcome h2 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--text);
}

.portal-welcome p {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: .95rem;
}

/* ── Cards ───────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.platform-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: border-color .2s, box-shadow .2s, transform .2s;
  position: relative;
  overflow: hidden;
}

.platform-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-color);
  opacity: 0;
  transition: opacity .2s;
}

.platform-card:hover {
  border-color: color-mix(in srgb, var(--card-color) 35%, var(--border));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--card-color) 8%, transparent),
              var(--shadow);
  transform: translateY(-3px);
}

.platform-card:hover::before { opacity: 1; }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.card-icon {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  background: var(--card-color-light);
  color: var(--card-color);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-arrow {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  transition: background .2s, color .2s, transform .2s;
  flex-shrink: 0;
}

.platform-card:hover .card-arrow {
  background: var(--card-color);
  color: white;
  transform: translateX(2px);
}

.card-body h3 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.01em;
  margin-bottom: 6px;
}

.card-body p {
  font-size: .84rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .login-layout { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-form-panel { padding: 40px 24px; min-height: 100dvh; align-items: flex-start; padding-top: 64px; }
  .portal-header { padding: 0 16px; }
  #user-name { display: none; }
  .portal-main { padding: 32px 16px 60px; }
  .portal-welcome h2 { font-size: 1.4rem; }
}
