/* ===========================================================================
   styles.css — Chat privado (móvil primero)
   =========================================================================== */

:root {
  --bg: #0b141a;
  --panel: #111b21;
  --header: #202c33;
  --bubble-mine: #005c4b;
  --bubble-theirs: #202c33;
  --text: #e9edef;
  --text-dim: #8696a0;
  --accent: #00a884;
  --error: #f15c6d;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* Cada "pantalla" ocupa el viewport completo */
.screen {
  height: 100dvh;
  width: 100%;
}

[hidden] {
  display: none !important;
}

/* ===================== LOGIN ===================== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border-radius: 16px;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.login-title {
  font-size: 1.5rem;
  text-align: center;
}

.login-subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.password-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #2a3942;
  border-radius: 10px;
  background: #0b141a;
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.password-input:focus {
  border-color: var(--accent);
}

.primary-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #04130d;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.error-text {
  color: var(--error);
  text-align: center;
  font-size: 0.9rem;
}

/* ===================== CHAT ===================== */
#chat-screen {
  display: flex;
  flex-direction: column;
}

.chat-header {
  flex: 0 0 auto;
  height: 60px;
  background: var(--header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  font-size: 1.4rem;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: #2a3942;
  border-radius: 50%;
}

.header-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.other-name {
  font-weight: 600;
  font-size: 1.05rem;
}

/* Línea de estado bajo el nombre (escribiendo / en línea / desconectado) */
.status-indicator {
  font-size: 0.78rem;
}

.status-indicator.typing {
  color: var(--accent);
  font-style: italic;
}

.status-indicator.online {
  color: #53bdeb;
}

.status-indicator.offline {
  color: var(--text-dim);
}

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

.logout-icon {
  font-size: 0.95rem;
}

.logout-btn {
  background: transparent;
  border: 1px solid #2a3942;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.logout-btn:hover {
  background: #2a3942;
}

/* Lista de mensajes */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Fondo sutil tipo chat */
  background-image: linear-gradient(rgba(11, 20, 26, 0.96), rgba(11, 20, 26, 0.96));
}

.msg-row {
  display: flex;
  max-width: 100%;
}

.msg-row.mine {
  justify-content: flex-end;
}

.msg-row.theirs {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 8px 10px 6px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-row.mine .bubble {
  background: var(--bubble-mine);
  border-bottom-right-radius: 3px;
}

.msg-row.theirs .bubble {
  background: var(--bubble-theirs);
  border-bottom-left-radius: 3px;
}

.bubble .text {
  font-size: 0.98rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

.bubble .media {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  margin-bottom: 4px;
}

.bubble .time {
  display: block;
  text-align: right;
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Barra de progreso de subida */
.upload-bar {
  flex: 0 0 auto;
  position: relative;
  height: 26px;
  background: var(--header);
  display: flex;
  align-items: center;
  padding: 0 12px;
}

.upload-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: var(--accent);
  opacity: 0.35;
  transition: width 0.15s ease;
}

.upload-label {
  position: relative;
  font-size: 0.8rem;
  color: var(--text);
}

/* Error general del chat */
.chat-error {
  flex: 0 0 auto;
  background: rgba(241, 92, 109, 0.15);
  color: var(--error);
  text-align: center;
  font-size: 0.85rem;
  padding: 8px 12px;
}

/* Vista previa del adjunto seleccionado */
.attach-preview {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--header);
  padding: 8px 12px;
  border-top: 1px solid #2a3942;
}

.attach-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
}

.attach-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.attach-name {
  font-size: 0.85rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-hint {
  font-size: 0.72rem;
  color: var(--accent);
}

.attach-remove {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: #2a3942;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

/* Barra de composición */
.composer {
  flex: 0 0 auto;
  background: var(--header);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

.attach-btn {
  font-size: 1.3rem;
  cursor: pointer;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  user-select: none;
}

.attach-btn:hover {
  background: #2a3942;
}

.text-input {
  flex: 1 1 auto;
  padding: 12px 16px;
  border: none;
  border-radius: 22px;
  background: #2a3942;
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.send-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #04130d;
  font-size: 1.2rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Resalta el botón de enviar cuando hay algo listo (texto o adjunto). */
.send-btn.ready {
  animation: send-pulse 1.4s ease-in-out infinite;
}

@keyframes send-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(0, 168, 132, 0.55);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(0, 168, 132, 0);
    transform: scale(1.08);
  }
}

/* ===================== MODAL: HISTORIAL DE LOGINS ===================== */
.history-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.history-card {
  background: var(--header);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #2a3942;
}

.history-title {
  font-size: 1rem;
  font-weight: 600;
}

.history-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #2a3942;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.history-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: #111b21;
  border: 1px solid #2a3942;
  border-radius: 10px;
  padding: 10px 12px;
}

.history-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.history-owner {
  font-weight: 700;
  font-size: 0.85rem;
  padding: 2px 8px;
  border-radius: 10px;
}

.history-owner.owner-a {
  background: rgba(0, 168, 132, 0.18);
  color: var(--accent);
}

.history-owner.owner-b {
  background: rgba(83, 189, 235, 0.18);
  color: #53bdeb;
}

.history-when {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.history-row {
  font-size: 0.85rem;
  color: var(--text);
  margin-top: 2px;
}

.history-row.history-dim {
  color: var(--text-dim);
  font-size: 0.78rem;
}

.history-map {
  color: #53bdeb;
}

.history-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 24px 0;
  font-size: 0.9rem;
}

/* ===================== PANEL DE ADMINISTRACIÓN ===================== */
.admin-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #111b21;
  border: 1px solid #2a3942;
  border-radius: 10px;
  padding: 12px;
}

.admin-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.admin-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.admin-status {
  font-size: 0.8rem;
  font-weight: 600;
}

.admin-status.on {
  color: var(--accent);
}

.admin-status.off {
  color: var(--error);
}

.admin-toggle {
  flex: 0 0 auto;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.admin-toggle.disable {
  background: rgba(241, 92, 109, 0.18);
  color: var(--error);
}

.admin-toggle.enable {
  background: rgba(0, 168, 132, 0.2);
  color: var(--accent);
}

.admin-note {
  flex: 0 0 auto;
  padding: 10px 14px;
  font-size: 0.78rem;
  color: var(--text-dim);
  border-top: 1px solid #2a3942;
}

/* ===================== ESCRITORIO ===================== */
@media (min-width: 768px) {
  #chat-screen {
    max-width: 720px;
    margin: 0 auto;
    border-left: 1px solid #2a3942;
    border-right: 1px solid #2a3942;
  }
}
