/* ============================================================
   Arenita — sistema de diseño (v1.1)
   Paleta: tinta casi-negra + hueso cálido + un solo acento ámbar.
   Layout inspirado en la dirección visual de arena.ai: barra lateral
   fija, hairlines finos en vez de bloques pesados, paneles A/B lado
   a lado sin divisor "VS" voluminoso.

   ============================================================ */

:root {
  --ink: #161310;
  --ink-raised: #25201c;
  --ink-sidebar: #161310;
  --bone: #EDEAE3;
  --bone-dim: #A9A9A0;
  --amber: #E8A33D;
  --amber-dim: #7A5A22;
  --line: #2c2a25;
  --danger: #C1503E;
  --good: #4E9F6E;
  --link: #6c9efa;

  --font-display: "Space Grotesk", sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  --sidebar-width: 200px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--bone);
  font-family: var(--font-display);
}

a {
  color: var(--link)
}

button {
  font-family: inherit;
  cursor: pointer;
}

input,
textarea {
  font-family: var(--font-display);
  background: var(--ink-raised);
  border: 1px solid var(--line);
  color: var(--bone);
  border-radius: 6px;
  padding: 0.65rem 0.8rem;
  width: 100%;
}

input:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.muted {
  color: var(--bone-dim);
}

.ftlist {
  line-height: 2em;
  color: var(--bone-dim);
}

.nodeco {
  text-decoration: none;
  color: inherit;
}

.noticebnr {
  background-color: var(--amber);
  color: var(--ink);
  padding: 1em;
  border-radius: 10px;
}

/* ---------------- Utilidades de accesibilidad ---------------- */
.is-hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--amber);
  color: var(--ink);
  padding: 0.6rem 1rem;
  z-index: 100;
  font-weight: 700;
  border-radius: 0 0 6px 0;
}

.skip-link:focus {
  left: 0;
}

/* ---------------- Scrollbars finos y translúcidos (globales) ---------------- */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(169, 169, 160, 0.35) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background-color: rgba(169, 169, 160, 0.3);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: rgba(232, 163, 61, 0.45);
}

/* ---------------- Layout general ---------------- */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------------- Barra lateral ---------------- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--ink-sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 0.9rem;
  gap: 0.9rem;
  transition: width 0.15s ease;
  overflow: hidden;
}

/* Colapsada (escritorio): NO desaparece — se reduce a una franja
   delgada con solo íconos, para que el botón de reabrir siga siendo
   alcanzable (bug de v1.1: el botón se iba fuera de pantalla junto
   con toda la barra). */
.sidebar.collapsed {
  width: 56px;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.sidebar.collapsed .label-text,
.sidebar.collapsed .sidebar-nav,
.sidebar.collapsed .label-text-small,
.sidebar.collapsed .sidebar-heading {
  display: none;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
}

.sidebar.collapsed .sidebar-primary-btn,
.sidebar.collapsed .label-text-small,
.sidebar.collapsed .sidebar-link {
  justify-content: center;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar .sidebar-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: row;
}

.sidebar.collapsed .sidebar-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: column;
  position: absolute;
  bottom: 14px;
  left: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  white-space: nowrap;
}

.brand-mark {
  color: var(--amber);
  font-size: 1.2rem;
}

.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--bone-dim);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  flex-shrink: 0;
}

.icon-btn:hover {
  border-color: var(--line);
  color: var(--bone);
}

.sidebar-primary-btn {
  background: var(--amber);
  color: var(--ink);
  border: none;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-weight: 700;
  text-align: left;
  display: flex;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-primary-btn:hover {
  filter: brightness(1.08);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
}

.sidebar-heading {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--bone-dim);
  margin: 0.4rem 0;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.history-item {
  background: none;
  border: none;
  color: var(--bone);
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  width: 100%;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item:hover,
.history-item:focus-visible {
  background: var(--ink-raised);
}

.history-empty {
  color: var(--bone-dim);
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
}

.sidebar-link {
  background: none;
  border: none;
  color: var(--bone-dim);
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link:hover {
  background: var(--ink-raised);
  color: var(--bone);
}

/* ---------------- Contenido principal ---------------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: none;
  /* solo visible en móvil, ver media query */
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  font-weight: 700;
}

.link-btn {
  background: none;
  border: none;
  color: var(--bone-dim);
  text-decoration: underline;
  font-size: 0.85rem;
}

.link-btn.small {
  font-size: 0.78rem;
}

/* ---------------- Homepage (hero + auth, split vertical) ---------------- */
.auth-screen {
  flex: 1;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  min-height: 0;
  overflow-y: auto;
}

.hero-pane {
  display: flex;
  align-items: center;
  padding: 3rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(232, 163, 61, 0.10), transparent 45%),
    var(--ink-sidebar);
  border-right: 1px solid var(--line);
}

.hero-content {
  max-width: 100%;
}

.hero-mark {
  font-size: 2.4rem;
  display: block;
  margin-bottom: 0.8rem;
}

.hero-content h1 {
  font-size: 1.9rem;
  line-height: 1.25;
  margin: 0 0 1rem;
}

.hero-lead {
  color: var(--bone-dim);
  line-height: 1.6;
  margin-bottom: 1.4rem;
}

.hero-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.hero-points li {
  padding-left: 1.4rem;
  position: relative;
  font-size: 0.9rem;
  color: var(--bone);
}

.hero-points li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--amber);
}

.auth-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--ink-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2rem;
}

.auth-card h2 {
  margin: 0 0 0.3rem;
  font-size: 1.4rem;
}

.auth-step {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.2rem;
}

.auth-step label {
  font-size: 0.8rem;
  color: var(--bone-dim);
}

.primary-btn {
  background: var(--amber);
  color: var(--ink);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.1rem;
  font-weight: 700;
  margin-top: 0.3rem;
}

.primary-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-message {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--danger);
  min-height: 1.1em;
}

.auth-message.success {
  color: var(--good);
}

/* ---------------- Chat / Arena ---------------- */
.chat-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px 10px;
  gap: 0.7rem;
  min-height: 0;
}

.arena {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.model-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.panel-actions {
  display: flex;
  gap: 0.2rem;
}

.panel-tag {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--amber);
  font-size: 0.78rem;
}

.panel-body {
  flex: 1;
  padding: 10px 10px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.55;
}

.panel-body p:first-child {
  margin-top: 0;
}

.empty-hint {
  color: var(--bone-dim);
  font-style: italic;
}

.msg-bubble {
  border-radius: 10px;
  padding: 0.15rem 0;
  margin-bottom: 1rem;
}

.msg-bubble.user {
  color: var(--bone-dim);
  font-size: 0.85rem;
  border-left: 2px solid var(--line);
  padding-left: 0.7rem;
}

.msg-bubble.assistant {
  color: var(--bone);
}

.msg-bubble pre {
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.7rem;
  overflow-x: auto;
}

.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.hairline-divider {
  width: 1px;
  background: var(--line);
}

.fallback-notices {
  font-size: 0.8rem;
  color: var(--amber);
  min-height: 0em;
}

/* ---------------- Indicador de progreso (sin streaming) ---------------- */
.thinking-indicator {
  text-align: center;
  font-size: 0.82rem;
  color: var(--bone-dim);
  font-family: var(--font-mono);
  min-height: 0em;
}

.thinking-indicator .dots::after {
  content: "";
  animation: thinking-dots 1.2s steps(4, end) infinite;
}

@keyframes thinking-dots {
  0% {
    content: "";
  }

  25% {
    content: ".";
  }

  50% {
    content: "..";
  }

  75% {
    content: "...";
  }

  100% {
    content: "";
  }
}

.privacy-notice {
  font-size: 0.72rem;
  color: var(--bone-dim);
  line-height: 1.5;
  border-top: 1px solid var(--line);
  padding-top: 0.6rem;
}

.privacy-notice a {
  color: var(--amber);
}

.privacy-notice.is-hidden {
  display: none;
}

/* ---------------- Módulo de voto (overlay) ---------------- */
.vote-overlay {
  position: relative;
  z-index: 5;
  background: var(--ink-raised);
  border: 1px solid var(--amber-dim);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: row;
  gap: 10px;
}

.vote-prompt {
  margin: 0;
  font-weight: 600;
  font-size: 0.9rem;
}

.vote-row-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.vote-btn {
  background: transparent;
  border: 2px solid var(--line);
  color: var(--amber);
  border-radius: 6px;
  padding: 0.5rem 0.7em;
  font-size: 0.8rem;
  margin: 10px 0;
}

.vote-btn:hover,
.vote-btn[aria-pressed="true"] {
  border-color: var(--amber);
  color: var(--amber);
}

.vote-btn.bad:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.vote-row-comment {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
}

.vote-row-comment textarea {
  flex: 1;
  resize: vertical;
  min-height: 2.4rem;
}

.char-counter {
  font-size: 0.72rem;
  color: var(--bone-dim);
  white-space: nowrap;
}

.char-counter.char-counter-limit {
  color: var(--danger);
}

.chat-input-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
}

.chat-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chat-input-wrap textarea {
  resize: vertical;
}

/*.chat-input-wrap .char-counter { align-self: flex-end; margin-top: 0.15rem; }*/
.chat-input-row .primary-btn {
  white-space: nowrap;
}

.chat-ress-wrap {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  min-width: 69px;
  max-width: 77px;
}

.chat-ress-wrap .char-counter {
  align-self: flex-end;
  margin-top: 0.15rem;
}

small.keybs {
  font-size: 0.8em;
  font-weight: 400;
  color: var(--bone-dim);
  margin-left: 0em;
}

/* ---------------- Modales ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  position: relative;
  background: var(--ink-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  width: 100%;
  max-width: 380px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.modal-close {
  position: absolute;
  top: 0.8rem;
  right: 0.9rem;
  background: none;
  border: none;
  color: var(--bone-dim);
  font-size: 1rem;
}

.modal-card h2 {
  margin: 0 0 0.4rem;
}

.avatar-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--amber), var(--amber-dim));
  margin-bottom: 0.4rem;
}

.score-badge {
  font-size: 0.85rem;
  color: var(--bone-dim);
}

.score-badge strong {
  color: var(--amber);
}

/* Modal "ampliar respuesta": ancho completo, con botón de cerrar
   grande y siempre en la esquina superior — importante en móvil,
   donde no siempre hay "afuera" visible para hacer clic. */
.modal-card-wide {
  max-width: 900px;
  width: 94vw;
  max-height: 90vh;
  padding: 12px;
}

.maximize-body {
  max-height: 70vh;
  font-size: 1rem;
}

@media (max-width: 600px) {
  .modal-card-wide {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .maximize-body {
    max-height: calc(100vh - 6rem);
  }

  .modal-close {
    top: 1rem;
    right: 1rem;
    font-size: 1.3rem;
    padding: 0.4rem 0.6rem;
  }
}

/* ---------------- Toasts ---------------- */
.toast-container {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: var(--ink-raised);
  border: 1px solid var(--line);
  color: var(--bone);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.15s ease-out;
}

.toast.toast-error {
  border-color: var(--danger);
  color: var(--danger);
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------------- Página de ranking ---------------- */
.ranking-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.ranking-header h1 {
  margin-bottom: 0.2rem;
}

.ranking-meta {
  color: var(--bone-dim);
  font-size: 0.85rem;
  margin-bottom: 1.2rem;
}

.ranking-note {
  font-size: 0.78rem;
  color: var(--bone-dim);
  background: var(--ink-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1.4rem;
}

table.ranking-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 2rem;
}

.ranking-table th,
.ranking-table td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.ranking-table th {
  color: var(--bone-dim);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.ranking-table td.rank-cell {
  font-family: var(--font-mono);
  color: var(--amber);
}

.ranking-table td.score-cell {
  font-family: var(--font-mono);
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.4rem;
}

.chart-card {
  background: var(--ink-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
}

.chart-card h2 {
  font-size: 0.95rem;
  margin: 0 0 0.8rem;
}

.chart-card canvas {
  max-height: 320px;
}

.heatmap-wrapper {
  overflow-x: auto;
}

table.heatmap-table {
  border-collapse: collapse;
  font-size: 0.7rem;
}

.heatmap-table th,
.heatmap-table td {
  padding: 0.35rem 0.5rem;
  text-align: center;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.heatmap-table th {
  color: var(--bone-dim);
  font-weight: 500;
}

.heatmap-table td.diag {
  background: var(--ink);
  color: var(--bone-dim);
}

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--bone-dim);
  text-decoration: none;
}

.back-link:hover {
  color: var(--amber);
}

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: var(--sidebar-width);
    margin-left: calc(-1 * var(--sidebar-width));
  }

  .sidebar.open {
    margin-left: 0;
  }

  /* En móvil el colapso NO se usa (el hamburger ya controla mostrar/ocultar
     por completo); se anula el modo "franja delgada" de escritorio. */
  .sidebar.collapsed {
    width: var(--sidebar-width);
  }

  .sidebar.collapsed .label-text,
  /* .sidebar.collapsed .label-text-small, */
  .sidebar.collapsed .sidebar-nav,
  .sidebar.collapsed .sidebar-heading {
    display: revert;
  }

  .topbar {
    display: flex;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .auth-screen {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
  }

  .hero-pane {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 2rem 1.5rem;
  }

  .hero-content h1 {
    font-size: 1.4rem;
  }
}

span .label-text-small {
  font-size: 0.618em;
  color: #939597;
}


@media (max-width: 720px) and (orientation: landscape) {
  .arena {
    grid-template-columns: 1fr;
    grid-auto-rows: 1fr;
  }

  .hairline-divider {
    width: auto;
    height: 1px;
  }

  .chat-screen {
    padding: 0.6rem 0.8rem;
  }

  .vote-row-buttons {
    flex-wrap: nowrap;
  }
}

@media (max-width: 480px) {
  .arena {
    grid-template-columns: 1fr auto 1fr;
    grid-auto-rows: 1fr;
  }

  .hairline-divider {
    width: auto;
    height: 1px;
  }

  .vote-overlay {
    display: flex;
    flex-direction: row;
  }

  .vote-btn {
    border: 2px solid var(--line);
    color: var(--bone);
    border-radius: 6px;
    padding: 0.5rem 0.7em;
    font-size: 0.8rem;
    margin: 10px 0;
  }

}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}