:root {
  --utp-red: #B50D30;
  --utp-red-hover: #960A27;
  --utp-red-light: #FDF2F4;
  --utp-red-border: #F87171;
  --slate-900: #0F172A;
  --slate-800: #1E293B;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748B;
  --slate-400: #94A3B8;
  --slate-300: #CBD5E1;
  --slate-200: #E2E8F0;
  --slate-100: #F1F5F9;
  --slate-50: #F8FAFC;
  --white: #FFFFFF;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--slate-50);
  color: var(--slate-800);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ENCABEZADO INSTITUCIONAL */
.site-header {
  background-color: var(--slate-900);
  color: var(--white);
  border-bottom: 3px solid var(--utp-red);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  height: 34px;
  width: auto;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--white);
}

.brand-campus {
  font-size: 0.78rem;
  color: var(--slate-400);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-reader {
  background-color: rgba(255, 255, 255, 0.12);
  color: var(--slate-200);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.badge-editor {
  background-color: var(--utp-red);
  color: var(--white);
}

/* CONTENEDOR PRINCIPAL */
.main-container {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

/* PANTALLA DE ACCESO (LOGIN) */
.login-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
  width: 100%;
}

.login-wrapper {
  width: 100%;
  max-width: 980px;
  min-height: 560px;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background-color: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: fadeIn 0.4s ease-out;
}

/* COLUMNA IZQUIERDA: EXCLUSIVAMENTE LA FOTO DE LA UTP */
.login-photo-side {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 560px;
  background-color: var(--slate-900);
  overflow: hidden;
}

.login-utp-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* COLUMNA DERECHA: EXCLUSIVAMENTE EL FORMULARIO DE ACCESO */
.login-form-side {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px 42px;
  background-color: var(--white);
}

.login-brand {
  margin-bottom: 22px;
}

.login-brand-logo {
  height: 44px;
  width: auto;
  display: block;
}

.card-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--slate-900);
  letter-spacing: -0.02em;
}

.card-header p {
  font-size: 0.88rem;
  color: var(--slate-500);
  margin-top: 4px;
}
  color: var(--slate-500);
  margin-top: 4px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--slate-700);
}

input[type="text"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--slate-800);
  background-color: var(--white);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: none;
  border-color: var(--utp-red);
  box-shadow: 0 0 0 3px rgba(181, 13, 48, 0.18);
}

/* CAMPO DE CONTRASEÑA CON BOTÓN DE VISIBILIDAD */
.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field input {
  padding-right: 44px;
}

.toggle-password-btn {
  position: absolute;
  right: 6px;
  background: transparent;
  border: none;
  padding: 8px;
  color: var(--slate-500);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.toggle-password-btn:hover {
  color: var(--slate-900);
}

.icon {
  width: 20px;
  height: 20px;
  display: block;
}

/* BOTONES */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  font-family: inherit;
}

.btn-primary {
  background-color: var(--utp-red);
  color: var(--white);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--utp-red-hover);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--slate-300);
  color: var(--slate-700);
}

.site-header .btn-outline {
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--white);
}

.site-header .btn-outline:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  background-color: var(--slate-300) !important;
  color: var(--slate-600) !important;
  cursor: not-allowed;
  opacity: 0.8;
}

/* SPINNER */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  border-top-color: var(--white);
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* ALERTAS Y MENSAJES ACCESIBLES */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-danger {
  background-color: #FEF2F2;
  border: 1px solid #FECACA;
  color: #991B1B;
}

.alert-warning {
  background-color: #FFFBEB;
  border: 1px solid #FDE68A;
  color: #92400E;
}

.alert-success {
  background-color: #F0FDF4;
  border: 1px solid #BBF7D0;
  color: #166534;
}

/* ESPACIO DE TRABAJO (WORKSPACE) */
.workspace-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.3s ease-out;
}

.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.workspace-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--slate-900);
  letter-spacing: -0.02em;
}

.workspace-subtitle {
  font-size: 0.9rem;
  color: var(--slate-500);
}

.filters-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.search-box {
  position: relative;
  flex: 3;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--slate-400);
  pointer-events: none;
}

.search-box input {
  padding-left: 38px;
}

.filters-bar select {
  flex: 1;
  min-width: 180px;
}

.workspace-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  align-items: start;
}

/* LISTA LATERAL DE ARTÍCULOS */
.articles-nav {
  background-color: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - 240px);
  overflow-y: auto;
}

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

.article-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  width: 100%;
  font-family: inherit;
}

.article-btn:hover {
  background-color: var(--slate-100);
}

.article-btn.active {
  background-color: var(--utp-red-light);
  border-color: rgba(181, 13, 48, 0.3);
}

.article-btn-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--slate-900);
  line-height: 1.35;
}

.article-btn.active .article-btn-title {
  color: var(--utp-red);
}

.article-btn-meta {
  font-size: 0.75rem;
  color: var(--slate-500);
}

/* DETALLE DEL ARTÍCULO */
.article-detail {
  background-color: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  box-shadow: var(--shadow-sm);
  min-height: 480px;
}

.detail-header {
  border-bottom: 1px solid var(--slate-200);
  padding-bottom: 20px;
  margin-bottom: 24px;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--slate-500);
  margin-bottom: 8px;
}

.detail-meta-tag {
  background-color: var(--slate-100);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  color: var(--slate-700);
}

.detail-title {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--slate-900);
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--slate-200);
}

.btn-danger {
  background-color: #DC2626;
  color: var(--white);
}

.btn-danger:hover {
  background-color: #B91C1C;
}

.empty-state {
  text-align: center;
  color: var(--slate-500);
  padding: 60px 20px;
  font-size: 1rem;
}

/* RENDERIZADOR DE MARKDOWN */
.markdown-body {
  font-size: 0.98rem;
  line-height: 1.7;
  color: var(--slate-800);
  overflow-wrap: anywhere;
}

.markdown-body p {
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 700;
  color: var(--slate-900);
  margin-top: 28px;
  margin-bottom: 12px;
  line-height: 1.3;
}

.markdown-body h1 { font-size: 1.5rem; }
.markdown-body h2 { font-size: 1.3rem; border-bottom: 1px solid var(--slate-200); padding-bottom: 6px; }
.markdown-body h3 { font-size: 1.15rem; }

.markdown-body ul,
.markdown-body ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.markdown-body li {
  margin-bottom: 6px;
}

.markdown-body li.indented {
  margin-left: 20px;
}

.markdown-body input[type="checkbox"] {
  margin-right: 8px;
  vertical-align: middle;
}

.markdown-body pre {
  background-color: var(--slate-900);
  color: #E2E8F0;
  padding: 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 20px;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background-color: var(--slate-100);
  color: var(--utp-red);
  padding: 2px 6px;
  border-radius: 4px;
}

.markdown-body pre code {
  background-color: transparent;
  color: inherit;
  padding: 0;
}

.markdown-body blockquote {
  border-left: 4px solid var(--utp-red);
  padding: 8px 16px;
  background-color: var(--slate-50);
  color: var(--slate-700);
  margin-bottom: 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.markdown-body a {
  color: var(--utp-red);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 500;
}

.markdown-body a:hover {
  color: var(--utp-red-hover);
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 24px;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--slate-200);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background-color: var(--slate-100);
  font-weight: 700;
  color: var(--slate-800);
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 16px 0;
  border: 1px solid var(--slate-200);
  box-shadow: var(--shadow-sm);
  display: block;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--slate-200);
  margin: 28px 0;
}

/* MODAL DE EDICIÓN */
.editor-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(800px, 94vw);
  max-height: 92vh;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  margin: auto;
}

.editor-dialog::backdrop {
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
}

.editor-form {
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  max-height: 90vh;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--slate-200);
  padding-bottom: 14px;
}

.dialog-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--slate-900);
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--slate-400);
  cursor: pointer;
}

.close-btn:hover {
  color: var(--slate-800);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--slate-500);
  margin-top: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--slate-200);
  padding-top: 16px;
}

/* ANIMACIONES */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* RESPONSIVE DESIGN (MÓVIL Y TABLET) */
@media (max-width: 860px) {
  .login-wrapper {
    grid-template-columns: 1fr;
    max-width: 460px;
    margin: 0 auto;
    min-height: auto;
  }

  .login-photo-side {
    height: 220px;
    min-height: 220px;
  }

  .login-form-side {
    padding: 32px 24px;
  }

  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .filters-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .brand-campus {
    display: none;
  }
}

@media (max-width: 480px) {
  .main-container {
    padding: 16px 12px;
  }

  .article-detail {
    padding: 24px 18px;
  }

  .detail-title {
    font-size: 1.4rem;
  }
}

/* PREFERS-REDUCED-MOTION */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
