/* LLMcoach — MSN Messenger retro skin, layered on top of xp.css (MIT). */

:root {
  --msn-blue: #0e6cc4;
  --msn-green: #59b547;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  /* "Bliss"-inspired XP wallpaper gradient: sky to grass. */
  background: linear-gradient(
    to bottom,
    #4a90d9 0%,
    #6fb1e8 42%,
    #7fc66e 55%,
    #3f7d2e 100%
  );
  font-family: Tahoma, "Trebuchet MS", Arial, sans-serif;
  display: flex;
  align-items: center;
  /* Con el contenido más alto que el viewport, centrar deja la parte de ARRIBA
     fuera de alcance (no hay scroll hacia ella). `safe center` centra mientras
     cabe y cae a flex-start cuando no; quien no conoce `safe` ignora la línea
     y conserva el `center` de arriba. */
  align-items: safe center;
  justify-content: center;
  min-height: 100vh;
  /* `dvh` es el alto VISIBLE: en el móvil la barra del navegador aparece y
     desaparece, así que `100vh` (el alto con la barra colapsada) pide más
     ventana de la que se ve y la barra superior se va de la pantalla. */
  min-height: 100dvh;
  padding: 16px;
}

.hidden {
  display: none !important;
}

.screen {
  width: 100%;
  display: flex;
  justify-content: center;
}

.window {
  margin: 0;
  box-shadow: 2px 2px 12px rgba(0, 0, 0, 0.35);
}

/* ---------- Login ---------- */

.login-window {
  width: 380px;
  max-width: 100%;
}

.msn-header {
  padding: 18px 16px;
  background: linear-gradient(90deg, #0e6cc4 0%, #2aa3d8 55%, #7bc44e 100%);
  color: #fff;
}

.msn-logo {
  font-size: 28px;
  font-weight: bold;
  letter-spacing: 0.5px;
}

.msn-tagline {
  margin: 4px 0 0;
  font-size: 12px;
  opacity: 0.92;
}

.tabs {
  display: flex;
  background: #ece9d8;
  border-bottom: 1px solid #d4d0c8;
}

.tab {
  flex: 1;
  padding: 8px;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  font: inherit;
  cursor: pointer;
  color: #222;
}

.tab.active {
  background: #fff;
  border-color: #d4d0c8;
  position: relative;
  top: 1px;
}

.form {
  padding: 16px;
}

.form[hidden] {
  display: none;
}

.field-row {
  margin-bottom: 12px;
}

.field-row label {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
}

.field-row input {
  width: 100%;
}

.form-actions {
  text-align: right;
  margin-top: 10px;
}

.form-error {
  margin: 10px 0 0;
  padding: 8px;
  background: #fde7e7;
  border: 1px solid #c00;
  color: #a00000;
  font-size: 12px;
}

.form-status {
  margin: 8px 0 0;
  padding: 6px 8px;
  border: 1px solid #7f9db9;
  background: #eef3fd;
  color: #333;
  font-size: 12px;
}

.form-status.is-busy {
  color: #174a77;
}

.form-status.is-ready {
  border-color: #59b547;
  background: #edf9e9;
  color: #25651c;
}

.form-status.is-error {
  border-color: #c00;
  background: #fde7e7;
  color: #a00000;
}

/* ---------- Chat ---------- */

.chat-window {
  width: 820px;
  max-width: 100%;
}

.chat-body {
  display: flex;
  padding: 0;
  /* El suelo son 440 px, pero nunca más del 60 % del alto visible: en un
     teléfono en apaisado (390 px de alto y 844 de ancho, fuera del media query
     móvil) un cuerpo de 440 px no cabe y empujaba la barra de título fuera de
     la pantalla. El tope del 70 % queda siempre por encima del suelo. */
  min-height: min(440px, 60vh);
  min-height: min(440px, 60dvh);
  max-height: 70vh;
  max-height: 70dvh;
}

.contact-list {
  width: 170px;
  flex: 0 0 170px;
  background: #eef3fd;
  border-right: 1px solid #d4d0c8;
  padding: 8px;
  /* La columna de contactos es más alta que su hueco en pantallas bajas: sin
     scroll propio desbordaba el cuerpo, alargaba la página y con ella se
     perdía la barra de título de la ventana. */
  overflow-y: auto;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

.contact-item:hover {
  border-color: #d4d0c8;
  background: #fff;
}

.avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 4px;
  color: #fff;
  font-weight: bold;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-coach {
  background: linear-gradient(135deg, #2aa3d8, #59b547);
}

.avatar-me {
  background: #0e6cc4;
}

.avatar-garmin {
  background: #1f2a44;
}

.avatar-fatsecret {
  background: #e4791f;
}

.avatar-hevy {
  background: #b3323a;
}

.avatar-renpho {
  background: #1b9e77;
}

.avatar-intervals {
  background: #205295;
}

.avatar-news {
  background: #7a5fd0;
}

.avatar-stats {
  background: linear-gradient(135deg, #1f8a70, #59b547);
}

.contact-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.contact-name {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-status {
  font-size: 10px;
  color: #777;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-status.status-ok {
  color: #1d6b1d;
}

.contact-status.status-off {
  color: #999;
}

.contact-status.status-bad {
  color: #a00000;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Selector de conversaciones (varias chats con el entrenador). */
.conversation-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid #d4d0c8;
  background: #ece9d8;
}

.conv-label {
  font-size: 11px;
  color: #555;
}

.conversation-bar select {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 12px;
  padding: 2px 4px;
}

.conversation-bar button {
  font-size: 11px;
  padding: 2px 8px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant,
.message.system {
  align-self: flex-start;
  align-items: flex-start;
}

.who {
  font-size: 11px;
  color: #555;
  margin-bottom: 2px;
}

/* Datestamp discreto junto al nombre del remitente. */
.who .msg-time {
  font-size: 10px;
  color: #9aa0a6;
  margin-left: 6px;
  font-weight: normal;
}

.message.user .who {
  color: #0e6cc4;
}

.message.assistant .who {
  color: #2a7d2a;
}

.message.system .who {
  color: #a00000;
}

/* Línea de estado mientras el coach piensa / consulta una herramienta. */
.typing-status {
  color: #888;
  font-size: 11px;
  font-style: italic;
  margin-bottom: 4px;
}

.bubble {
  padding: 8px 12px;
  border: 1px solid #c8d6f5;
  background: #eef3fd;
  border-radius: 10px 10px 10px 2px;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Markdown renderizado dentro de los mensajes del coach */
.bubble p {
  margin: 4px 0;
}

.bubble .md-heading {
  font-weight: bold;
  margin: 6px 0 2px;
}

.bubble .md-list {
  margin: 4px 0;
  padding-left: 20px;
}

.bubble table.md-table {
  white-space: normal;
  border-collapse: collapse;
  margin: 6px 0;
  width: 100%;
}

.bubble .md-table th,
.bubble .md-table td {
  border: 1px solid #c8d6f5;
  padding: 4px 8px;
  font-size: 12px;
  text-align: left;
}

.bubble .md-table th {
  background: #e2ecfb;
}

.message.user .bubble {
  background: #e6f4e6;
  border-color: #b6d7b6;
  border-radius: 10px 10px 2px 10px;
}

.message.system .bubble {
  background: #fde7e7;
  border-color: #e0a0a0;
}

/* Gráficos (Chart.js) incrustados en el chat. */
.message.chart .bubble {
  background: #fbfcfe;
  border-color: #c8d6f5;
}

.message.chart .chart-bubble {
  width: 360px;
  max-width: 100%;
  height: 220px;
  padding: 8px;
  position: relative;
}

.message.chart .chart-title {
  font-size: 11px;
  font-weight: bold;
  color: #0e6cc4;
  margin-bottom: 6px;
}

.message.chart canvas {
  width: 100%;
  height: 175px;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid #d4d0c8;
  background: #ece9d8;
}

.chat-input textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: 13px;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font-size: 11px;
  color: #222;
  background: #ece9d8;
  border-top: 1px solid #fff;
  box-shadow: inset 0 1px 0 #fff, inset 0 -1px 0 #d4d0c8;
}

/* Progreso de sincronización en la barra de estado (estilo XP). */
.sync-progress {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
}

/* The author display:flex overrides the UA [hidden]{display:none}, so the
   hidden attribute needs an explicit rule to actually hide the bar. */
.sync-progress[hidden] {
  display: none;
}

.sync-progress-label {
  font-size: 10px;
  color: #333;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  position: relative;
  width: 110px;
  height: 14px;
  flex: 0 0 110px;
  border: 1px solid #7f9db9;
  background: #fff;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, #0a63c4 0 6px, #3b8ee8 6px 12px);
  transition: width 0.3s ease;
}

/* Barra indeterminada: el bloque barre el track mientras no hay % concreto. */
.progress-track.indeterminate .progress-fill {
  width: 40%;
  animation: sync-shimmer 1.1s linear infinite;
}

@keyframes sync-shimmer {
  from {
    transform: translateX(-110%);
  }
  to {
    transform: translateX(330%);
  }
}

.conn-status.is-busy {
  color: #174a77;
  font-style: italic;
}

@media (max-width: 600px) {
  .sync-progress-label {
    display: none;
  }

  .progress-track {
    width: 80px;
    flex-basis: 80px;
  }
}

/* Botón de menú móvil: sustituye a la lista lateral en pantallas pequeñas. */
.contact-menu-toggle {
  display: none;
  font-size: 14px;
  line-height: 1;
  padding: 2px 8px;
}

@media (max-width: 600px) {
  body {
    padding: 8px;
  }

  /* En el teléfono la ventana del chat ocupa el 90 % del alto VISIBLE (`dvh`):
     el 10 % que sobra deja aire para la barra del navegador, que crece y
     encoge al desplazarse, y así la barra de título nunca se va de la
     pantalla. Es `height`, no `max-height`, para que el chat aproveche el
     hueco en lugar de quedarse en el mínimo del cuerpo. */
  .chat-window {
    height: 90vh;
    height: 90dvh;
    display: flex;
    flex-direction: column;
  }

  /* El cuerpo se queda con el alto que no usan la barra de título y el borde,
     y el registro de mensajes hace su propio scroll: el cuadro de texto y la
     barra de estado quedan siempre dentro de la ventana. */
  .chat-body {
    flex: 1;
    min-height: 0;
    max-height: none;
    position: relative;
  }

  .contact-menu-toggle {
    display: inline-block;
    /* xp.css da min-width:75px a todos los botones; en móvil deja al selector
       de conversaciones en unos pocos píxeles. Se compacta en pantallas
       pequeñas para que el selector recupere el espacio. */
    min-width: 0;
  }

  .conversation-bar button {
    min-width: 0;
    padding: 2px 8px;
  }

  .conversation-bar select {
    min-width: 60px;
  }

  /* Ocultar la etiqueta "Chat:" para dejar sitio al menú en pantallas pequeñas. */
  .conv-label {
    display: none;
  }

  /* La lista de contactos pasa a ser un menú desplegable bajo la barra de
     conversación, en lugar de un panel lateral fijo que se perdía en móvil. */
  .contact-list {
    display: block;
    position: absolute;
    top: 36px;
    left: 6px;
    z-index: 20;
    width: 210px;
    max-height: calc(100% - 44px);
    overflow-y: auto;
    background: #eef3fd;
    border: 1px solid #d4d0c8;
    border-radius: 4px;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.25);
    padding: 6px;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.12s ease, visibility 0.12s ease;
  }

  .contact-list.open {
    visibility: visible;
    opacity: 1;
  }
}

/* ---------- Perfil / Conexiones ---------- */

.profile-window {
  width: 420px;
  max-width: 100%;
}

.profile-window .window-body {
  max-height: 78vh;
  max-height: 78dvh;
  overflow-y: auto;
}

.field-row textarea {
  width: 100%;
  resize: vertical;
  font: inherit;
  font-size: 13px;
}

.field-row select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 2px 4px;
}

.form-ok {
  margin: 10px 0 0;
  padding: 8px;
  background: #e6f4e6;
  border: 1px solid #59b547;
  color: #1d6b1d;
  font-size: 12px;
}

.conn-window {
  width: 420px;
  max-width: 100%;
}

.conn-status {
  margin: 12px 16px 0;
  padding: 8px;
  background: #eef3fd;
  border: 1px solid #c8d6f5;
  font-size: 12px;
}

.conn-note {
  margin: 0 0 8px;
  font-size: 12px;
  color: #333;
}

.conn-note a {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.news-content {
  max-height: 380px;
  overflow-y: auto;
  margin: 12px 16px;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid #d6dce5;
  font-size: 13px;
  line-height: 1.45;
}

.news-content .md-heading {
  font-weight: 700;
  color: #0e6cc4;
  margin: 10px 0 4px;
}

.news-content .md-heading:first-child {
  margin-top: 0;
  font-size: 16px;
}

.news-content .md-list {
  margin: 4px 0 10px;
  padding-left: 18px;
}

.news-content p {
  margin: 4px 0 10px;
}

/* ---------- Estadísticas (panel de indicadores) ---------- */

.stats-window {
  width: 760px;
  max-width: 100%;
}

.stats-window .window-body {
  padding: 0 0 12px;
}

.stats-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid #d4d0c8;
  background: #ece9d8;
}

.stats-label {
  font-size: 11px;
  color: #555;
}

.stats-toolbar select {
  font: inherit;
  font-size: 12px;
  padding: 2px 4px;
  max-width: 180px;
  min-width: 0;
}

.stats-days-custom {
  width: 80px;
  font: inherit;
  font-size: 12px;
  padding: 2px 4px;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
  max-height: 62vh;
  max-height: 62dvh;
  overflow-y: auto;
}

.stat-card {
  border: 1px solid #d4d0c8;
  background: #ffffff;
  padding: 8px 10px;
  min-width: 0;
}

.stat-card h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: bold;
  color: #0e6cc4;
}

.stat-canvas {
  position: relative;
  height: 170px;
  min-width: 0;
}

/* Selector de ejercicio, colocado bajo la tarjeta de progresión (solo afecta
   a ese gráfico). */
.stat-exercise-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
}

.stat-exercise-row select {
  font: inherit;
  font-size: 12px;
  padding: 1px 4px;
  min-width: 0;
  max-width: 100%;
}

/* Casillas de deportes bajo el gráfico de pasos: qué pasos se cuentan en el
   total del día. Solo se dibuja esta tarjeta, no la barra superior. */
.stat-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 8px;
  font-size: 11px;
}

.stat-filter-item {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.stat-empty {
  margin: 0;
  padding: 14px 10px;
  font-size: 12px;
  color: #888;
  font-style: italic;
}

@media (max-width: 600px) {
  /* minmax(0, 1fr): el mínimo automático de 1fr dejaría que el canvas de
     Chart.js (300px por defecto) desbordara el panel en pantallas pequeñas. */
  .stats-panel {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Prioridad de fuentes de datos ---------- */

.avatar-sources {
  background: #c2185b;
}

.sources-window {
  width: 620px;
  max-width: 100%;
}

.sources-window .window-body {
  padding: 0 0 12px;
}

.sources-window .conn-note {
  margin: 10px 12px 4px;
  line-height: 1.4;
}

.sources-panel {
  max-height: 56vh;
  max-height: 56dvh;
  overflow-y: auto;
  padding: 0 12px 12px;
}

.source-group h3 {
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: bold;
  color: #0e6cc4;
  border-bottom: 1px solid #d4d0c8;
  padding-bottom: 2px;
}

.source-field {
  margin: 10px 0;
  border: 1px solid #d6dce5;
  background: #ffffff;
}

.source-field-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #ece9d8;
}

.source-field-name {
  font-weight: bold;
  font-size: 12px;
}

.source-custom {
  font-size: 10px;
  color: #b3323a;
  border: 1px solid #b3323a;
  border-radius: 3px;
  padding: 0 4px;
}

.source-reset {
  margin-left: auto;
  font-size: 11px;
  min-width: 0;
  padding: 1px 6px;
}

.source-list {
  list-style: none;
  margin: 0;
  padding: 6px 8px 8px;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.source-item.is-top {
  background: #f0f7f0;
}

.source-rank {
  width: 14px;
  font-size: 11px;
  color: #888;
  text-align: right;
  flex: 0 0 14px;
}

.source-label {
  font-size: 12px;
  flex: 1;
  min-width: 0;
}

.source-top-badge {
  font-size: 10px;
  color: #1d6b1d;
  background: #e6f4e6;
  border: 1px solid #59b547;
  border-radius: 3px;
  padding: 0 4px;
  white-space: nowrap;
}

.source-controls {
  display: inline-flex;
  gap: 2px;
  flex: 0 0 auto;
}

.source-arrow {
  /* xp.css da min-width:75px a todos los botones; los compactos lo anulan. */
  min-width: 0;
  width: 22px;
  height: 20px;
  padding: 0;
  font-size: 11px;
  line-height: 1;
}

/* ---------- Administración ---------- */

.avatar-admin {
  background: #6b3fa0;
}

.admin-window {
  width: 720px;
  max-width: 100%;
}

.admin-window .window-body {
  padding: 0 0 12px;
}

.admin-window .conn-status {
  margin: 10px 12px 6px;
}

.admin-table-wrap {
  max-height: 34vh;
  max-height: 34dvh;
  overflow-y: auto;
  margin: 0 12px;
  border: 1px solid #d4d0c8;
  background: #ffffff;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid #e3e0d8;
  white-space: nowrap;
}

.admin-table th {
  background: #ece9d8;
  position: sticky;
  top: 0;
}

.admin-row {
  cursor: pointer;
}

.admin-row:hover {
  background: #eef3fd;
}

.admin-detail {
  margin: 10px 12px 0;
  padding: 10px 12px;
  border: 1px solid #d4d0c8;
  background: #ffffff;
  font-size: 12px;
  max-height: 32vh;
  max-height: 32dvh;
  overflow-y: auto;
}

.admin-detail h3,
.admin-detail h4 {
  margin: 0 0 6px;
  color: #0e6cc4;
}

.admin-detail p {
  margin: 2px 0;
}
