/* ===== Variables de color =====
   El tema se elige con el atributo data-theme en <html> ("dark" o "light").
   Cambia aquí los colores para re-tematizar toda la página. */

:root {
  --radius: 16px;
}

/* --- Tema oscuro (por defecto) --- */
:root,
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --on-accent: #001018;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  --danger: #f87171;
  --danger-soft: #fca5a5;
  --ok: #86efac;
  color-scheme: dark;
}

/* --- Tema claro --- */
[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #e9eef5;
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --on-accent: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --danger: #dc2626;
  --danger-soft: #b91c1c;
  --ok: #15803d;
  color-scheme: light;
}

/* ===== Reset básico ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* El atributo hidden siempre oculta, aunque el elemento tenga display propio */
[hidden] {
  display: none !important;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ===== Encabezado ===== */
.hero {
  position: relative;
  text-align: center;
  padding: 1.25rem 1.5rem 2rem;
}

/* Barra superior: idioma (izquierda) y tema (derecha) */
.top-bar {
  width: 100%;
  margin: 0 auto 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.idioma-compact {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.idioma-compact label {
  font-weight: 600;
  cursor: pointer;
}

.idioma-compact-icon {
  font-size: 1rem;
  line-height: 1;
}

.idioma-select-compact {
  padding: 0.3rem 0.5rem;
  border-radius: 9px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

.idioma-select-compact:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ===== Sesión en la barra superior ===== */
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.auth-user {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-strong);
}

.auth-btn {
  background: none;
  border: 1px solid var(--surface-2);
  color: var(--text-muted);
  border-radius: 9px;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.auth-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.auth-btn--primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent);
  font-weight: 600;
}

.auth-btn--primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.auth-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Botón de tema claro/oscuro */
.theme-toggle {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background 0.2s ease;
}

.theme-toggle:hover {
  transform: scale(1.08);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hero h1 {
  font-size: clamp(2rem, 6vw, 3.5rem);
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 1.1rem;
}

/* ===== Contenedor principal ===== */
.container {
  width: min(800px, 90%);
  margin: 0 auto 3rem;
  display: grid;
  gap: 1.5rem;
  flex: 1;
}

/* ===== Estructura con barra lateral ===== */
.app-shell {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  display: grid;
  grid-template-columns: 250px minmax(0, 820px);
  gap: 1.5rem;
  justify-content: center;
  align-items: start;
  flex: 1;
}

.app-shell .container {
  width: 100%;
  max-width: none;
  margin: 0;
}

.app-sidebar {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-2) transparent;
  overscroll-behavior: contain;
}

.app-sidebar::-webkit-scrollbar {
  width: 8px;
}

.app-sidebar::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: 999px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.sidebar-brand {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-strong);
}

.sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}

.sidebar-section + .sidebar-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--surface-2);
}

.sidebar-title {
  margin-bottom: 0.45rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-nav {
  display: grid;
  gap: 0.2rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 9px;
  background: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
}

.sidebar-link:hover {
  background: var(--surface-2);
}

.sidebar-link.is-active {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  color: var(--accent-strong);
  font-weight: 600;
}

.sidebar-count {
  flex-shrink: 0;
  min-width: 1.7rem;
  padding: 0.02rem 0.4rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.72rem;
  text-align: center;
}

.sidebar-link.is-active .sidebar-count {
  color: var(--accent-strong);
}

.sidebar-filter-group {
  margin-bottom: 0.25rem;
}

.sidebar-filter-group summary {
  padding: 0.3rem 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.sidebar-filter-group summary:hover {
  color: var(--accent);
}

.sidebar-filter-list {
  display: grid;
  gap: 0.08rem;
  padding: 0.1rem 0 0.25rem;
}

.sidebar-filter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  min-width: 0;
  padding: 0.28rem 0.5rem;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
}

.sidebar-filter-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-filter-item.is-active {
  background: var(--surface-2);
  color: var(--accent-strong);
  font-weight: 600;
}

.sidebar-filter-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-clear {
  margin-top: 0.35rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
}

.sidebar-category-list {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.sidebar-category-group {
  border-radius: 8px;
  min-width: 0;
}

.sidebar-category-summary {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.6rem;
  width: 100%;
  min-width: 0;
  padding: 0.3rem 0.5rem;
  border-radius: 7px;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.sidebar-category-summary .sidebar-count {
  margin-left: auto;
}

.sidebar-category-summary > span:first-of-type {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-category-summary::-webkit-details-marker {
  display: none;
}

.sidebar-category-summary::before {
  content: "▸";
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.sidebar-category-group[open] > .sidebar-category-summary::before {
  content: "▾";
}

.sidebar-category-summary:hover {
  background: var(--surface-2);
}

.sidebar-category-children {
  display: grid;
  gap: 0.08rem;
  min-width: 0;
  margin-left: 0.55rem;
  padding-left: 0.55rem;
  border-left: 1px solid var(--surface-2);
}

.sidebar-category-item {
  min-width: 0;
  padding-left: 0.5rem;
}

.sidebar-stats {
  display: grid;
  gap: 0.4rem;
}

.sidebar-stats > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.84rem;
}

.sidebar-stats dt {
  color: var(--text-muted);
}

.sidebar-stats dd {
  font-weight: 600;
}

.sidebar-admin-actions {
  display: grid;
  gap: 0.35rem;
}

.sidebar-action {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
  text-align: left;
  cursor: pointer;
}

.sidebar-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar-action--danger {
  color: var(--danger);
}

.sidebar-toggle {
  display: none;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--surface-2);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.sidebar-link:focus-visible,
.sidebar-filter-group summary:focus-visible,
.sidebar-category-summary:focus-visible,
.sidebar-filter-item:focus-visible,
.sidebar-clear:focus-visible,
.sidebar-action:focus-visible,
.sidebar-close:focus-visible,
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 225px minmax(0, 800px);
    gap: 1.25rem;
    padding: 0 1.25rem 2.5rem;
  }
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
    width: min(800px, 100%);
    padding: 0 1rem 2.5rem;
  }

  .app-shell .container {
    margin: 0 auto;
  }

  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(320px, 86vw);
    height: 100dvh;
    max-height: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
  }

  body.sidebar-open .app-sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.25s ease, visibility 0s;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, 0.45);
  }

  .sidebar-close,
  .sidebar-toggle {
    display: inline-flex;
  }
}

/* ===== Tarjetas ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin-bottom: 0.75rem;
  font-size: 1.35rem;
}

/* ===== Botones ===== */
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: none;
  border-radius: 12px;
  font-size: 1.5rem;
  width: 3rem;
  height: 3rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease;
}

.btn:hover {
  background: var(--accent-strong);
  color: var(--on-accent);
}

.btn:active {
  transform: scale(0.92);
}

.btn-reset {
  display: block;
  margin: 0 auto;
  font-size: 0.95rem;
  width: auto;
  height: auto;
  padding: 0.6rem 1.5rem;
}

/* ===== Selector de idioma (ya no se usa la tarjeta grande) ===== */

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Problemas LaTeX ===== */
.almacen-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  margin-top: 0.75rem;
  border-left: 3px solid var(--text-muted);
}

.almacen-info--servidor {
  color: var(--ok);
  border-left-color: var(--ok);
}

/* ===== Aviso de solo lectura ===== */
.login-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--surface-2);
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.92rem;
}

.btn-login-inline {
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: 9px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-login-inline:hover {
  background: var(--accent);
}

/* ===== Ventana de inicio de sesión ===== */
.auth-dialog {
  margin: auto;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
}

.auth-dialog::backdrop {
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(2px);
}

.users-dialog {
  margin: auto;
  width: min(920px, 94vw);
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.users-dialog::backdrop {
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(2px);
}

.users-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--surface-2);
}

.users-dialog-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.users-close {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}

.users-note {
  margin: 0;
  padding: 0.65rem 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.users-status {
  min-height: 1.5rem;
  margin: 0;
  padding: 0.5rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.users-table-wrap {
  max-height: 60vh;
  overflow: auto;
  padding: 0 1.25rem 1.25rem;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.users-table th,
.users-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--surface-2);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.users-table th {
  color: var(--text-muted);
  font-weight: 600;
}

.users-table tbody tr:hover {
  background: var(--surface-2);
}

.user-role-admin {
  color: var(--accent);
  font-weight: 600;
}

/* ===== Vista previa de la imagen de un problema ===== */
.image-dialog {
  margin: auto;
  width: min(1100px, 96vw);
  max-height: 92vh;
  padding: 0;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
}

.image-dialog::backdrop {
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(2px);
}

.image-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--surface-2);
}

.image-dialog-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.image-dialog-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--surface-2);
}

.image-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.image-tab:hover {
  color: var(--text);
}

.image-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.image-tab:disabled {
  opacity: 0.6;
  cursor: default;
}

.image-dialog-body {
  display: flex;
  justify-content: center;
  padding: 1rem;
  background: #ffffff;
}

.image-dialog-body img {
  display: block;
  max-width: 100%;
  max-height: 65vh;
  width: auto;
  height: auto;
}

.image-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--surface-2);
}

.image-dialog-actions .btn-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-radius: 9px;
}

.image-dialog-actions .btn-link:hover {
  color: var(--on-accent);
  background: var(--accent-strong);
}

.image-download {
  background: var(--accent-strong);
  color: var(--on-accent);
  border: none;
  border-radius: 10px;
  padding: 0.5rem 1.1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.image-download:hover {
  background: var(--accent);
}

.image-download:disabled {
  opacity: 0.6;
  cursor: default;
}

@media (max-width: 520px) {
  .image-dialog-body {
    padding: 0.5rem;
  }

  .image-dialog-actions {
    justify-content: stretch;
  }

  .image-dialog-actions button {
    flex: 1 1 auto;
  }
}

.auth-form {
  display: grid;
  gap: 0.5rem;
  padding: 1.5rem;
}

.auth-form h2 {
  font-size: 1.3rem;
  margin-bottom: 0.25rem;
}

.auth-intro {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.auth-form label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

#auth-confirm-wrap,
#auth-name-wrap {
  display: grid;
  gap: 0.5rem;
}

.auth-form input {
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.auth-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.auth-form input[readonly] {
  opacity: 0.75;
  cursor: not-allowed;
}

.auth-error {
  margin-top: 0.5rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid var(--danger);
  color: var(--danger-soft);
  font-size: 0.88rem;
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
}

.auth-actions .btn-reset {
  margin: 0;
}

.auth-actions .btn-link {
  color: var(--text-muted);
}

.auth-actions .btn-link:hover {
  color: var(--text);
}

.problem-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 1rem 0 1.5rem;
}

.problem-form label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ===== Formulario: idioma, tema y nivel en una misma fila ===== */
.problem-form-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.problem-form-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.problem-form textarea,
.problem-form input,
.problem-form select {
  width: 100%;
  box-sizing: border-box;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

.problem-form textarea {
  min-height: 90px;
}

.problem-form textarea {
  min-height: 130px;
}

.problem-form textarea:focus,
.problem-form input:focus,
.problem-form select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.problem-image-field {
  grid-column: 1 / -1;
}

.problem-image-field input[type="file"] {
  padding: 0.5rem;
  cursor: pointer;
}

.problem-image-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.problem-image-preview img {
  max-width: 240px;
  max-height: 160px;
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  background: #fff;
  object-fit: contain;
}

.problem-image-status {
  min-height: 1.1rem;
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.problem-image-hint {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.problem-figure {
  margin: 0.75rem 0 0.25rem;
  text-align: center;
}

.problem-figure a {
  display: inline-block;
  max-width: 100%;
}

.problem-figure img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  margin: 0 auto;
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  background: #fff;
  object-fit: contain;
}

.problem-figure figcaption {
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.solution-images {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.solution-image-link {
  display: block;
}

.solution-images img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  background: #fff;
}

.problem-provenance {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-top: 0.6rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.problem-provenance-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.problem-provenance-contest {
  color: var(--accent-strong);
  font-weight: 600;
}

.problem-provenance a {
  color: var(--accent);
  text-decoration: none;
}

.problem-provenance a:hover {
  text-decoration: underline;
}

.problem-provenance-field {
  grid-column: 1 / -1;
}

.problem-provenance-field > label {
  margin-bottom: 0.4rem;
}

.problem-provenance-field .problem-form-fields {
  width: 100%;
}

.print-provenance {
  margin: 0.35rem 0 0;
  color: #444;
  font-size: 0.85rem;
}

.problem-form .btn-reset {
  margin: 0.9rem 0 0;
  align-self: flex-start;
  font-size: 1rem;
  background: var(--accent-strong);
  color: var(--on-accent);
}

.problem-form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.9rem;
}

.problem-form-actions .btn-reset {
  margin: 0;
}

.problem-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
}

.search-wrapper {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-input {
  width: 100%;
  padding: 0.6rem 0.9rem;
  padding-right: 2.25rem; /* espacio para el botón de limpiar */
  border-radius: 12px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

.clear-search {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}

.clear-search:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text);
}

[data-theme="dark"] .clear-search:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-search {
  border: none;
  border-radius: 12px;
  padding: 0.6rem 1.1rem;
  background: var(--accent-strong);
  color: var(--on-accent);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.btn-search:hover {
  filter: brightness(1.1);
}

.btn-search:active {
  transform: translateY(1px);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.problem-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--surface-2);
  margin-bottom: 1rem;
}

.problem-toolbar-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.problem-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.page-size {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.page-size .filter-select {
  padding: 0.3rem 0.5rem;
}

.filter-select {
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.filter-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.problem-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

.problem-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--surface-2);
}

.problem-footer .rating {
  margin: 0;
}

.problem-footer .problem-actions {
  margin-top: 0;
}

.problem-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: underline;
}

.btn-link:hover {
  color: var(--danger-soft);
}

.btn-link.btn-danger {
  color: var(--danger);
}

.problem-list {
  display: grid;
  gap: 1rem;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.pagination[hidden] {
  display: none;
}

.pagination-numbers {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.pagination-btn,
.page-number {
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 9px;
  padding: 0.4rem 0.65rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.page-number {
  min-width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pagination-btn:hover:not(:disabled),
.page-number:hover:not(.is-current) {
  border-color: var(--accent);
}

.pagination-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.page-number.is-current {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent);
  font-weight: 600;
  cursor: default;
}

.pagination-ellipsis {
  color: var(--text-muted);
  padding: 0 0.2rem;
}

.print-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  margin-top: 1.1rem;
}

.pdf-solutions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
}

.pdf-solutions input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent-strong);
  cursor: pointer;
}

.btn-pdf {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.95rem;
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-pdf:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-pdf:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn-pdf-icon {
  width: 1.2rem;
  height: 1.2rem;
  flex-shrink: 0;
}

.print-area {
  display: none;
}

.problem-item {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--accent);
}

.problem-item .problem-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.problem-item .problem-language-tag,
.problem-item .problem-category-tag,
.problem-item .problem-topic-tag,
.problem-item .problem-level-tag,
.problem-item .problem-author-tag {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.problem-item .problem-author-tag {
  background: rgba(148, 163, 184, 0.2);
  color: var(--text-muted);
}

.problem-item .problem-topic-tag {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
}

.problem-item .problem-category-tag {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
}

.problem-item .problem-level-tag {
  background: rgba(167, 139, 250, 0.2);
  color: #a78bfa;
}

.problem-item .problem-difficulty-tag {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(148, 163, 184, 0.2);
  color: var(--text-muted);
}

.problem-item .problem-difficulty-tag.difficulty-muy_facil {
  background: rgba(74, 222, 128, 0.18);
  color: #4ade80;
}

.problem-item .problem-difficulty-tag.difficulty-facil {
  background: rgba(134, 239, 172, 0.16);
  color: #86efac;
}

.problem-item .problem-difficulty-tag.difficulty-medio {
  background: rgba(251, 191, 36, 0.18);
  color: #fbbf24;
}

.problem-item .problem-difficulty-tag.difficulty-dificil {
  background: rgba(251, 146, 60, 0.18);
  color: #fb923c;
}

.problem-item .problem-difficulty-tag.difficulty-muy_dificil {
  background: rgba(248, 113, 113, 0.18);
  color: #f87171;
}

.print-difficulty {
  margin: 0.35rem 0 0;
  color: #444;
  font-size: 0.85rem;
}

/* Etiqueta con el idioma en que está escrito el problema */
.problem-item .problem-language-tag {
  background: rgba(134, 239, 172, 0.2);
  color: var(--ok);
}

.problem-date-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.problem-date-tag time {
  font: inherit;
}

/* En tema claro, los textos de las etiquetas necesitan más contraste. */
[data-theme="light"] .problem-item .problem-category-tag {
  color: #92400e;
}

[data-theme="light"] .problem-item .problem-level-tag {
  color: #6d28d9;
}

[data-theme="light"] .problem-item .problem-language-tag {
  color: #166534;
}

[data-theme="light"] .problem-item .problem-topic-tag {
  color: #075985;
}

[data-theme="light"] .problem-item .problem-difficulty-tag.difficulty-muy_facil {
  color: #166534;
}

[data-theme="light"] .problem-item .problem-difficulty-tag.difficulty-facil {
  color: #14532d;
}

[data-theme="light"] .problem-item .problem-difficulty-tag.difficulty-medio {
  color: #92400e;
}

[data-theme="light"] .problem-item .problem-difficulty-tag.difficulty-dificil {
  color: #9a3412;
}

[data-theme="light"] .problem-item .problem-difficulty-tag.difficulty-muy_dificil {
  color: #b91c1c;
}

[data-theme="light"] .sidebar-action--danger {
  color: #b91c1c;
}

/* Valoración con estrellas */
.rating {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.15rem 0 0.5rem;
}

.solution-head .rating {
  margin: 0;
}

.rating-stars {
  display: inline-flex;
  gap: 0.15rem;
}

.rating-star {
  background: none;
  border: none;
  min-width: 24px;
  min-height: 24px;
  padding: 0.1rem 0.15rem;
  font-size: 1.25rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  position: relative;
}

.rating-star.is-full {
  color: #fbbf24;
}

.rating-star.is-half {
  color: #64748b;
}

.rating-star.is-half::after {
  content: "★";
  position: absolute;
  left: 0.15rem;
  top: 0.1rem;
  width: 50%;
  overflow: hidden;
  color: #fbbf24;
  pointer-events: none;
}

/* Al pasar el ratón se iluminan las estrellas hasta la elegida */
.rating:not(.rating--readonly) .rating-stars:hover .rating-star {
  color: #fbbf24;
}

.rating:not(.rating--readonly) .rating-stars:hover .rating-star:hover ~ .rating-star {
  color: #64748b;
}

.rating:not(.rating--readonly) .rating-stars:hover .rating-star:hover ~ .rating-star::after {
  color: #64748b;
}

.rating-star:disabled {
  cursor: default;
}

.rating--readonly .rating-star {
  cursor: default;
}

.rating-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.problem-item .problem-statement {
  margin-bottom: 0.5rem;
}

.problem-item .problem-solution {
  border-top: 1px dashed var(--surface-2);
  padding-top: 0.5rem;
  color: var(--text-muted);
}

.problem-item .solution-label {
  font-weight: 600;
  color: var(--accent);
}

.btn-toggle-solution {
  display: inline-block;
  margin: 0.25rem 0 0.5rem;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--surface-2);
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-size: 0.8rem;
}

.btn-toggle-solution:hover {
  color: var(--on-accent);
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.problem-item .problem-actions {
  margin-top: 0.6rem;
  text-align: right;
}

.problem-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 1.5rem;
  font-style: italic;
}

/* ===== Lista de consejos ===== */
.tips {
  padding-left: 1.25rem;
  color: var(--text-muted);
}

.tips li {
  margin-bottom: 0.4rem;
}

code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-size: 0.9em;
  color: var(--accent);
}

/* ===== Pie de página ===== */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--surface-2);
}

/* ===== Avisos de LaTeX mal escrito ===== */

/* Caja roja con la explicación del error */
.latex-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  margin: 0.6rem 0 0.75rem;
  color: var(--danger);
  font-size: 0.85rem;
  line-height: 1.35;
}

.latex-error strong {
  display: block;
  margin-bottom: 0.25rem;
}

.latex-error ul {
  margin: 0;
  padding-left: 1.1rem;
}

.latex-error li {
  margin: 0.15rem 0;
  word-break: break-word;
}

/* Formulario: el aviso va dentro del propio formulario */
#latex-error-form {
  margin-top: 0.75rem;
}

/* Tarjeta con error: borde izquierdo rojo */
.problem-item--error {
  border-left-color: var(--danger);
}

/* ===== Soluciones m�ltiples ===== */
.solutions-extra {
  display: grid;
  gap: 0.75rem;
}

.solution-field {
  display: grid;
  gap: 0.4rem;
}

.solution-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.btn-add-solution {
  align-self: flex-start;
  margin-top: 0.35rem;
}

.problem-item .problem-solution {
  display: grid;
  gap: 0.5rem;
}

.problem-item .solution-item + .solution-item {
  margin-top: 0.35rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--surface-2);
}

.solution-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.2rem;
}

.solution-author {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.solution-item--pending {
  border-left: 3px solid #f59e0b;
  padding-left: 0.6rem;
}

.pending-solutions {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--surface-2);
}

.pending-title {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #f59e0b;
}

.solution-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.solution-proposal {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.6rem;
  padding: 0.6rem;
  border: 1px dashed var(--surface-2);
  border-radius: 8px;
}

/* ===== Impresión / PDF de la página actual ===== */
@media print {
  @page {
    margin: 16mm;
  }

  body {
    display: block !important;
    background: #fff !important;
    color: #000 !important;
  }

  body > *:not(.print-area) {
    display: none !important;
  }

  body > .print-area {
    display: block !important;
    color: #000;
    background: #fff;
  }

  .print-header {
    margin-bottom: 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #999;
  }

  .print-header h1 {
    margin: 0 0 0.25rem;
    color: #000;
    font-size: 1.6rem;
  }

  .print-meta {
    margin: 0;
    color: #333;
    font-size: 0.9rem;
  }

  .print-problem {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1.1rem;
    break-inside: auto;
    page-break-inside: auto;
  }

  .print-content {
    flex: 1;
    min-width: 0;
  }

  .print-statement,
  .print-solution {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .print-solution {
    margin-top: 0.5rem;
    padding-top: 0.4rem;
    border-top: 1px dashed #aaa;
  }

  .print-solution-label {
    color: #000;
    font-size: 0.85rem;
    font-weight: 700;
  }

  .print-solution-text {
    color: #000;
    font-size: 10.5pt;
    line-height: 1.45;
  }

  .print-number {
    flex-shrink: 0;
    min-width: 1.8rem;
    color: #000;
    font-weight: 700;
  }

  .print-statement {
    color: #000;
    font-size: 11pt;
    line-height: 1.5;
  }

  .print-statement mjx-container {
    color: #000;
  }
}

/* ===== Contraste de texto en tema claro ===== */
[data-theme="light"] .btn-link {
  color: #b91c1c;
}

[data-theme="light"] .btn-link:hover {
  color: #991b1b;
}

[data-theme="light"] code,
[data-theme="light"] .sidebar-clear,
[data-theme="light"] .btn-toggle-solution,
[data-theme="light"] .problem-item .solution-label {
  color: #0369a1;
}

[data-theme="light"] .btn-toggle-solution:hover {
  color: #075985;
}

[data-theme="light"] .image-dialog-actions .btn-link,
[data-theme="light"] .image-dialog-actions .btn-link:hover {
  color: var(--accent-strong);
}

[data-theme="light"] .almacen-info--servidor {
  color: #166534;
}

@media print {
  .problem-figure {
    break-inside: avoid;
  }

  .problem-figure img {
    max-height: 10cm;
  }

  .problem-figure figcaption {
    color: #444;
  }
}
@media print {
  .solution-images img {
    max-height: 12cm;
    break-inside: avoid;
  }
}
