/* ============================================================
   PORTAL CORPORATIVO — ROCA / DETIA DEGESCH GROUP
   Estilo corporativo: rojo ROCA + azul acento + fondo oscuro
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Barlow:wght@600;700;800&display=swap');

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --red:        #CC1F1F;
  --red-dark:   #a01818;
  --red-light:  #e63030;
  --blue:       #1E6FBF;
  --blue-light: #3b8fe0;
  --blue-dark:  #155a9c;

  --bg:         #0f1218;
  --bg-2:       #161b24;
  --bg-3:       #1e2533;
  --bg-card:    #1a2030;
  --bg-hover:   #212840;

  --border:     rgba(255,255,255,0.07);
  --border-2:   rgba(255,255,255,0.12);

  --text:       #f0f2f5;
  --text-2:     #9aa5b8;
  --text-3:     #5e6e87;

  --sidebar-w:  260px;
  --topbar-h:   60px;
  --radius:     10px;
  --radius-lg:  16px;

  --shadow:     0 4px 24px rgba(0,0,0,0.35);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.5);

  --font-body:  'DM Sans', sans-serif;
  --font-display: 'Barlow', sans-serif;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }

/* ── Screens ───────────────────────────────────────────────── */
.screen {
  display: none;
  min-height: 100dvh;
}
.screen.active { display: flex; }

/* ══════════════════════════════════════════════════════════════
   LOGIN SCREEN
══════════════════════════════════════════════════════════════ */
#loginScreen {
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* Grid de fondo */
.login-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
}

/* Glow rojo ROCA */
.login-glow {
  position: absolute;
  top: -200px;
  left: 50%;
  transform: translateX(-50%);
  width: 700px;
  height: 500px;
  background: radial-gradient(ellipse at center, rgba(204,31,31,0.2) 0%, transparent 65%);
  pointer-events: none;
}

/* Línea roja en la parte superior */
#loginScreen::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--red), var(--blue));
  z-index: 10;
}

.login-card {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 48px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(204,31,31,0.1);
  text-align: center;
  animation: fadeUp 0.5s ease both;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
}

/* Logo mark cuadros Microsoft-style coloreados en rojo/azul ROCA */
.logo-mark svg rect:nth-child(1) { fill: var(--red); }
.logo-mark svg rect:nth-child(2) { fill: var(--red-light); }
.logo-mark svg rect:nth-child(3) { fill: var(--blue); }
.logo-mark svg rect:nth-child(4) { fill: var(--blue-light); }

.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  color: var(--text);
}

.login-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  color: var(--text);
}

.login-subtitle {
  color: var(--text-2);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 32px;
}

.btn-microsoft {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: var(--red);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(204,31,31,0.35);
  letter-spacing: 0.01em;
}

.btn-microsoft:hover {
  background: var(--red-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(204,31,31,0.45);
}
.btn-microsoft:active { transform: translateY(0); }

.login-note {
  margin-top: 20px;
  font-size: 0.78rem;
  color: var(--text-3);
}

/* ══════════════════════════════════════════════════════════════
   LOADING SCREEN
══════════════════════════════════════════════════════════════ */
#loadingScreen {
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: var(--bg);
}

.loading-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.loading-spinner {
  position: relative;
  width: 60px;
  height: 60px;
}

.spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}
.spinner-ring:nth-child(1) {
  border-top-color: var(--red);
  animation: spin 1s linear infinite;
}
.spinner-ring:nth-child(2) {
  inset: 8px;
  border-top-color: var(--blue);
  animation: spin 0.8s linear infinite reverse;
}
.spinner-ring:nth-child(3) {
  inset: 16px;
  border-top-color: rgba(255,255,255,0.3);
  animation: spin 1.2s linear infinite;
}

.loading-msg {
  color: var(--text-2);
  font-size: 0.9rem;
  letter-spacing: 0.03em;
}

/* ══════════════════════════════════════════════════════════════
   APP SCREEN
══════════════════════════════════════════════════════════════ */
#appScreen {
  flex-direction: row;
  min-height: 100dvh;
}

/* ── SIDEBAR ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}

/* Línea roja en el sidebar */
.sidebar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--red), var(--blue));
}

.sidebar.open { transform: translateX(0); }

/* En desktop, siempre visible */
@media (min-width: 1024px) {
  .sidebar {
    transform: translateX(0);
    position: sticky;
    top: 0;
    height: 100dvh;
    flex-shrink: 0;
  }
  .sidebar-close { display: none !important; }
  .sidebar-overlay { display: none !important; }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 190;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.logo-mark.small { width: 28px; height: 28px; }
.logo-mark.small svg { width: 28px; height: 28px; }

.sidebar-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.sidebar-close:hover { background: var(--bg-3); color: var(--text); }
.sidebar-close svg { width: 18px; height: 18px; }

/* Usuario en sidebar */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.user-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid var(--border-2);
}
.user-avatar.small { width: 32px; height: 32px; }

.avatar-inner {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  letter-spacing: 0.05em;
}

.user-info { overflow: hidden; flex: 1; min-width: 0; }
.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-email {
  font-size: 0.73rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-3) transparent;
}

.nav-separator {
  padding: 12px 8px 6px;
}
.nav-separator span {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
  user-select: none;
}
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active {
  background: rgba(204,31,31,0.12);
  color: #fff;
  font-weight: 600;
}
.nav-item.active .nav-icon { filter: none; }

.nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-count {
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg-3);
  color: var(--text-3);
  padding: 1px 6px;
  border-radius: 20px;
  flex-shrink: 0;
}
.nav-item.active .nav-count {
  background: rgba(204,31,31,0.2);
  color: var(--red-light);
}

.nav-empty {
  font-size: 0.8rem;
  color: var(--text-3);
  padding: 8px 12px;
  font-style: italic;
}

.sidebar-footer {
  padding: 12px 12px 20px;
  border-top: 1px solid var(--border);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-3);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.btn-logout:hover { background: rgba(220,38,38,0.1); color: #f87171; }
.btn-logout svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── MAIN CONTENT ──────────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;

  /* En móvil ocupa todo */
  margin-left: 0;
}

@media (min-width: 1024px) {
  .main-content { /* sidebar is sticky, no margin needed */ }
}

/* ── TOPBAR ────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Línea roja topbar */
.topbar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--red), var(--blue));
}

.menu-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.menu-btn:hover { background: var(--bg-3); color: var(--text); }
.menu-btn svg { width: 20px; height: 20px; }

@media (min-width: 1024px) {
  .menu-btn { display: none; }
}

.topbar-title { flex: 1; min-width: 0; }
.topbar-title h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.topbar-user span {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-2);
  display: none;
}
@media (min-width: 640px) {
  .topbar-user span { display: block; }
}

/* ── VIEWS ─────────────────────────────────────────────────── */
.view { display: none; flex: 1; padding: 24px 20px; }
.view.active { display: block; }

@media (min-width: 768px) {
  .view { padding: 32px 32px; }
}

/* ── WELCOME BANNER ────────────────────────────────────────── */
.welcome-banner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 28px;
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  position: relative;
}

/* Línea roja izquierda */
.welcome-banner::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--red), var(--blue));
}

.welcome-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--red-light);
  margin-bottom: 6px;
}

.welcome-text h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  line-height: 1.2;
}

.welcome-text p {
  font-size: 0.875rem;
  color: var(--text-2);
}

.welcome-text strong { color: var(--text); }

.welcome-visual {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  display: none;
}
@media (min-width: 480px) { .welcome-visual { display: block; } }

.welcome-orb {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--red), var(--blue), var(--red));
  opacity: 0.15;
  animation: spin 8s linear infinite;
}

/* ── CATEGORIES GRID ───────────────────────────────────────── */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.category-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  width: 100%;
  color: var(--text);
  position: relative;
  overflow: hidden;
  opacity: 0;
}

.category-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--cat-color, var(--red));
  transform: scaleX(0);
  transition: transform 0.25s ease;
  transform-origin: left;
}

.category-card:hover {
  border-color: var(--border-2);
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}
.category-card:hover::after { transform: scaleX(1); }

.cat-icon {
  font-size: 1.6rem;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-3);
  border-radius: 10px;
  flex-shrink: 0;
}

.cat-info { flex: 1; min-width: 0; }
.cat-name {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin-bottom: 2px;
}
.cat-count { font-size: 0.75rem; color: var(--text-2); }

.cat-badge {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── MODULES VIEW ──────────────────────────────────────────── */
.modules-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.modules-header-icon {
  font-size: 2rem;
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex-shrink: 0;
}

.modules-header h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.modules-header p { font-size: 0.85rem; color: var(--text-2); margin-top: 2px; }

.modules-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.module-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  transition: border-color 0.2s, background 0.2s, transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  color: var(--text);
  position: relative;
  overflow: hidden;
  opacity: 0;
}

.module-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--red);
  transform: scaleY(0);
  transition: transform 0.2s ease;
  transform-origin: bottom;
}

.module-card:hover {
  border-color: var(--border-2);
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.module-card:hover::before { transform: scaleY(1); }

.module-icon {
  font-size: 1.4rem;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-3);
  border-radius: 10px;
  flex-shrink: 0;
}

.module-info { flex: 1; min-width: 0; }
.module-name {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 3px;
  letter-spacing: 0.01em;
}
.module-desc {
  font-size: 0.78rem;
  color: var(--text-2);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.module-arrow {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  color: var(--text-3);
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s, transform 0.2s;
}
.module-card:hover .module-arrow {
  color: var(--red-light);
  background: rgba(204,31,31,0.1);
  transform: translate(2px, -2px);
}
.module-arrow svg { width: 16px; height: 16px; }

/* ── EMPTY STATE ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  grid-column: 1 / -1;
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.empty-state p { color: var(--text-2); font-size: 0.875rem; line-height: 1.6; }

/* ── ANIMATIONS ────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

.card-enter {
  animation: fadeUp 0.4s ease both;
}

/* ── SCROLLBAR ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* ── MOBILE ADJUSTMENTS ────────────────────────────────────── */
@media (max-width: 480px) {
  .login-card { padding: 36px 24px; margin: 16px; }
  .welcome-banner { padding: 20px 20px 20px 24px; }
  .welcome-text h1 { font-size: 1.3rem; }
  .modules-list { grid-template-columns: 1fr; }
}
