:root, [data-theme="dark"] {
  --chat-font-size: 13.5px;
  --bg-app: #0f172a;
  --bg-sidebar: #111827;
  --bg-panel: #1e293b;
  --bg-hover: #334155;
  --bg-input: #0b1120;
  --border: #334155;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
}

[data-theme="light"] {
  --bg-app: #f8fafc;
  --bg-sidebar: #f1f5f9;
  --bg-panel: #ffffff;
  --bg-hover: #e2e8f0;
  --bg-input: #ffffff;
  --border: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
}

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  overflow: hidden;
  font-size: 14px;
  position: fixed;
  inset: 0;
}

.hidden {
  display: none !important;
}

/* Overlay de Conexión */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 24, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.connect-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 620px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-header h1 {
  font-size: 20px;
  margin-bottom: 4px;
}

.brand-header p {
  color: var(--text-muted);
  font-size: 13px;
}

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

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

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--accent);
}

.connect-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-main);
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
  padding: 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}

/* Layout Principal */
.app-shell {
  display: grid;
  grid-template-columns: 250px 1fr 230px;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

.sidebar-left {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.network-banner {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.conn-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot.connected { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot.connecting { background: var(--warning); }
.dot.disconnected { background: var(--danger); }

.my-profile-bar {
  padding: 10px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.my-profile-bar small {
  color: var(--accent);
  margin-left: 6px;
  font-family: monospace;
}

.icon-btn, .btn-mini {
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.icon-btn:hover, .btn-mini:hover {
  border-color: var(--accent);
}

.nav-section {
  padding: 12px 10px 4px;
}

.nav-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.buffer-list {
  list-style: none;
}

.buffer-item {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  color: var(--text-muted);
}

.buffer-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.buffer-item.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.unread-badge {
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
}

/* Centro del Chat */
.chat-main {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--bg-app);
}

.chat-header {
  padding: 10px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  min-height: 54px;
  position: relative;
  z-index: 600;
}

.header-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.title-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-line h2 {
  font-size: 16px;
}

.badge-modes {
  font-family: monospace;
  font-size: 12px;
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

.topic-bar {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.messages-viewport {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 18px;
}

.msg-line {
  padding: 3px 6px;
  border-radius: 4px;
  line-height: 1.45;
  word-break: break-word;
  font-size: var(--chat-font-size, 13.5px);
}

.msg-line:hover {
  background: rgba(148, 163, 184, 0.06);
}

.msg-time {
  color: var(--text-muted);
  font-family: monospace;
  font-size: 0.88em;
  margin-right: 8px;
}

.msg-sender {
  font-weight: 700;
  margin-right: 6px;
  cursor: pointer;
}

.msg-account-tag {
  font-size: 10px;
  background: rgba(34, 197, 94, 0.16);
  color: #4ade80;
  padding: 1px 4px;
  border-radius: 3px;
  margin-right: 5px;
}

.msg-system { color: #60a5fa; }
.msg-notice { color: #fbbf24; }
.msg-action { color: #c084fc; font-style: italic; }
.msg-event  { color: var(--text-muted); font-size: 0.92em; }
.msg-error  { color: #f87171; font-weight: 600; }
.msg-line.msg-mention {
  background: rgba(245, 158, 11, 0.12);
  border-left: 3px solid #f59e0b;
  padding-left: 5px;
}

/* Compositor */
.chat-composer {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 8px 14px 12px;
  flex-shrink: 0;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.fmt-btn {
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 12px;
  cursor: pointer;
}

.font-size-btn {
  font-weight: 700;
  letter-spacing: 0.3px;
  min-width: 28px;
  text-align: center;
}

.c-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 2px;
}

.toolbar-hint {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--text-muted);
}

.composer-row {
  display: flex;
  gap: 8px;
}

#message-input {
  flex: 1;
}

.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0 18px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

/* Lista de Nicks Derecha */
.sidebar-right {
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.nicklist-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nicklist-filter {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.nicklist-filter input {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
}

.nicklist-ul {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 6px;
}

.nick-item {
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.nick-item:hover {
  background: var(--bg-hover);
}

.role-badge {
  font-family: monospace;
  font-weight: 700;
  width: 16px;
  text-align: center;
  border-radius: 3px;
  font-size: 11px;
}

.role-owner { color: #f43f5e; }
.role-admin { color: #a855f7; }
.role-op    { color: #22c55e; }
.role-halfop{ color: #06b6d4; }
.role-voice { color: #eab308; }

/* Modales */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 16px;
}

.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 740px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
}

.modal-small {
  max-width: 440px;
}

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

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.modal-toolbar {
  padding: 10px 18px;
  display: flex;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.modal-toolbar input {
  flex: 1;
}

.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.mobile-toggle {
  display: none;
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid rgba(59, 130, 246, 0.5);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.mobile-toggle:hover,
.mobile-toggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.mobile-bottom-toggles {
  display: none;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.mobile-toggle-bottom {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.mobile-toggle-bottom:hover,
.mobile-toggle-bottom.active {
  background: var(--accent);
  color: #fff;
}

.mobile-only-close {
  display: none;
}

.mobile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 700;
}

/* Vista de Radio Integrada */
.radio-viewport,
.community-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.radio-container,
.community-container {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.radio-panel-card,
.community-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
}

.radio-panel-card h3,
.community-card h3 {
  font-size: 17px;
  margin-bottom: 6px;
}

.radio-panel-card p,
.community-card p {
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.radio-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, var(--bg-panel) 0%, rgba(15, 23, 42, 0.92) 100%);
  border: 1px solid rgba(59, 130, 246, 0.28);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] .radio-card {
  background: linear-gradient(145deg, #ffffff 0%, #f1f5f9 100%);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

.radio-card.is-playing {
  border-color: rgba(59, 130, 246, 0.65);
  box-shadow: 0 12px 36px rgba(59, 130, 246, 0.18);
}

.radio-top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

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

.radio-disc {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(139, 92, 246, 0.22));
  border: 1px solid rgba(99, 102, 241, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.radio-card.is-playing .radio-disc {
  box-shadow: 0 0 18px rgba(59, 130, 246, 0.45);
  animation: radioPulseDisc 2.2s ease-in-out infinite;
}

@keyframes radioPulseDisc {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.radio-icon {
  font-size: 26px;
}

.radio-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.radio-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-muted);
  border: 1px solid var(--border);
  letter-spacing: 0.03em;
}

.radio-badge.live-active {
  background: rgba(239, 68, 68, 0.16);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.45);
}

.radio-badge.live-idle {
  background: rgba(34, 197, 94, 0.14);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.38);
}

.radio-badge.live-offline {
  background: rgba(148, 163, 184, 0.12);
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.28);
}

.radio-badge.dj-badge {
  background: rgba(139, 92, 246, 0.15);
  color: #c4b5fd;
  border-color: rgba(139, 92, 246, 0.4);
}

.radio-badge.dj-badge strong {
  color: #f8fafc;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.radio-badge.live-active .live-dot {
  box-shadow: 0 0 8px #ef4444;
  animation: liveBlink 1.2s infinite;
}

@keyframes liveBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Pantalla Central: Canción / Artista + Analizador de Espectro (EQ) */
.radio-visualizer-deck {
  background: rgba(11, 17, 32, 0.72);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 96px;
}

[data-theme="light"] .radio-visualizer-deck {
  background: #0f172a;
  color: #f8fafc;
}

.radio-now-playing {
  flex: 1;
  min-width: 0;
}

.now-playing-label {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #38bdf8;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.song-title {
  font-size: 17px;
  font-weight: 800;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
  transition: color 0.3s ease, transform 0.25s ease;
}

.song-title.song-flash {
  color: #38bdf8;
}

.song-artist {
  font-size: 13.5px;
  font-weight: 500;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Barras del Analizador de Espectro / Equalizador */
.radio-eq-wrapper {
  width: 240px;
  height: 58px;
  display: flex;
  align-items: flex-end;
  flex-shrink: 0;
}

.radio-eq-bars {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 3px;
}

.eq-bar {
  flex: 1;
  height: 10%;
  min-height: 4px;
  border-radius: 3px 3px 1px 1px;
  background: linear-gradient(to top, #3b82f6 0%, #8b5cf6 55%, #ec4899 90%, #f43f5e 100%);
  opacity: 0.38;
  transition: height 95ms ease-out, opacity 0.25s ease;
  will-change: height;
}

.radio-card.is-playing .eq-bar {
  opacity: 0.95;
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.35);
}

/* Barra de Controles del Reproductor */
.radio-controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-radio-play {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn-radio-play:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.radio-card.is-playing .btn-radio-play {
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  box-shadow: 0 4px 14px rgba(236, 72, 153, 0.35);
}

.btn-radio-icon {
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn-radio-icon:hover {
  border-color: var(--accent);
}

.radio-volume-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 4px 12px 4px 6px;
  border-radius: 8px;
}

.radio-volume-group .btn-radio-icon {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
}

.radio-volume-slider {
  width: 110px;
  accent-color: var(--accent);
  cursor: pointer;
}

.radio-vol-label {
  font-size: 12px;
  font-family: monospace;
  color: var(--text-muted);
  min-width: 34px;
  text-align: right;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar-left, .sidebar-right {
    position: fixed;
    top: 0;
    bottom: 0;
    height: 100%;
    max-height: 100dvh;
    z-index: 750;
    width: min(280px, 84vw);
    display: none;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
  }
  .sidebar-left.open {
    left: 0;
    display: flex !important;
  }
  .sidebar-right.open {
    right: 0;
    display: flex !important;
  }
  .mobile-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
  }
  .mobile-bottom-toggles {
    display: inline-flex;
  }
  .mobile-only-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .toolbar-hint {
    display: none;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .chat-header {
    padding: 8px 10px;
    min-height: 48px;
    gap: 8px;
  }
  .title-line h2 {
    font-size: 14.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .btn-text-desktop {
    display: none;
  }
  .messages-viewport {
    padding: 10px 12px;
  }
  .chat-composer {
    padding: 6px 10px 10px;
  }
  #message-input {
    font-size: 16px; /* Evita zoom automático en iOS/Android al enfocar */
    padding: 8px 10px;
  }
  .radio-visualizer-deck {
    flex-direction: column;
    align-items: stretch;
  }
  .radio-eq-wrapper {
    width: 100%;
    height: 46px;
  }
  .radio-volume-group {
    margin-left: 0;
    flex: 1;
  }
}

@media (max-width: 400px) {
  .mobile-toggle .toggle-label {
    display: none;
  }
}

/* ==========================================================================
   Menú Contextual de Usuario (Click Derecho PC / Tap y Long-Press Móvil)
   ========================================================================== */

.user-context-backdrop {
  position: fixed;
  inset: 0;
  z-index: 855;
  background: transparent;
}

@media (max-width: 960px) {
  .user-context-backdrop {
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
}

.user-context-menu {
  position: fixed;
  z-index: 860;
  min-width: 240px;
  max-width: 320px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45), 0 2px 10px rgba(0, 0, 0, 0.25);
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  animation: ctxFadeIn 0.12s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes ctxFadeIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.user-context-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.16);
  border-bottom: 1px solid var(--border);
}

.user-context-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.user-context-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.user-context-nick {
  font-weight: 700;
  font-size: 14.5px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-context-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-context-actions {
  list-style: none;
  margin: 0;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ctx-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-main);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}

.ctx-item:hover,
.ctx-item:focus {
  background: var(--bg-hover);
}

.ctx-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.ctx-item.ctx-danger {
  color: var(--danger);
}

.ctx-item.ctx-danger:hover,
.ctx-item.ctx-danger:focus {
  background: rgba(239, 68, 68, 0.14);
  color: #f87171;
}

.ctx-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

.user-context-mobile-cancel {
  display: none;
}

@media (max-width: 960px) {
  .user-context-menu {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 18px 18px 0 0 !important;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    animation: ctxSlideUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .user-context-menu::before {
    content: '';
    display: block;
    width: 42px;
    height: 4px;
    border-radius: 2px;
    background: var(--text-muted);
    opacity: 0.4;
    margin: 0 auto 10px;
  }

  @keyframes ctxSlideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  .user-context-mobile-cancel {
    display: block;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }

  .btn-ctx-cancel {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    background: var(--bg-hover);
    color: var(--text-main);
    border: none;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
  }

  .ctx-item {
    padding: 12px 14px;
    font-size: 14.5px;
  }
}

/* ==========================================================================
   Modal Perfil de Usuario
   ========================================================================== */

.modal-profile {
  max-width: 540px;
}

.profile-body {
  padding: 18px 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  max-height: calc(82vh - 65px);
}

.profile-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.16);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.profile-avatar-wrap {
  position: relative;
  width: 58px;
  height: 58px;
  flex-shrink: 0;
}

.profile-avatar-edit-btn {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #3b82f6;
  color: #fff;
  border: 2px solid var(--card);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s, background-color 0.15s;
  z-index: 2;
}

.profile-avatar-edit-btn:hover {
  transform: scale(1.15);
  background: #2563eb;
}

.my-profile-bar {
  transition: background-color 0.15s;
  border-radius: 8px;
}

.my-profile-bar:hover {
  background: rgba(255, 255, 255, 0.06);
}

.profile-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  position: relative;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.profile-limited-alert {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  color: #fef3c7;
  font-size: 13px;
  line-height: 1.45;
}

.profile-limited-alert .limited-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.profile-limited-alert .limited-link {
  color: #38bdf8;
  font-weight: 600;
  text-decoration: underline;
  margin-left: 6px;
}
.profile-limited-alert .limited-link:hover {
  color: #60a5fa;
}

.profile-main-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.profile-nick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.profile-nick {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}

.profile-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge-online {
  background: rgba(34, 197, 94, 0.18);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.badge-away {
  background: rgba(245, 158, 11, 0.18);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.badge-secure {
  background: rgba(59, 130, 246, 0.18);
  color: var(--accent);
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.profile-role-line {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.profile-gecos {
  font-size: 12.5px;
  color: var(--text-muted);
}

.profile-loading {
  font-size: 12px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(59, 130, 246, 0.12);
  border-radius: 6px;
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.profile-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 520px) {
  .profile-grid {
    grid-template-columns: 1fr;
  }
}

.profile-field {
  background: rgba(0, 0, 0, 0.12);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.profile-field-full {
  grid-column: 1 / -1;
}

.pf-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.pf-value {
  font-size: 13.5px;
  color: var(--text-main);
  word-break: break-all;
}

.pf-channels-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.pf-chan-tag {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg-hover);
  color: var(--accent);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.pf-chan-tag:hover {
  background: var(--accent);
  color: #fff;
}

.profile-actions-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.btn-profile-action {
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease, opacity 0.15s ease;
}

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

.btn-profile-action.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-profile-action.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-profile-action.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-profile-action.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-profile-action.btn-icon-only {
  padding: 9px 12px;
  margin-left: auto;
  font-size: 15px;
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.nick-ignored-badge {
  font-size: 11px;
  margin-left: 4px;
  opacity: 0.85;
  vertical-align: middle;
}

/* =========================================================
   GALERÍA DE FOTOS DE PERFIL
   ========================================================= */
.profile-gallery-section {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 4px;
  animation: fadeIn 0.15s ease-in-out;
}

.gallery-section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gallery-section-bar h4 {
  font-size: 14px;
  color: var(--text-main);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gallery-bar-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.profile-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 12px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
}

.gallery-card {
  position: relative;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, border-color 0.15s;
}

.gallery-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.gallery-card.is-current {
  border-color: #22c55e;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.25);
}

.gallery-img-wrap {
  width: 100%;
  height: 95px;
  position: relative;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  overflow: hidden;
}

.gallery-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.gallery-img-wrap:hover img {
  transform: scale(1.08);
}

.gallery-badge-active {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(34, 197, 94, 0.9);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

.gallery-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px;
  background: rgba(15, 23, 42, 0.85);
  border-top: 1px solid var(--border);
  gap: 4px;
}

.btn-gallery-action {
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-gallery-set {
  background: #3b82f6;
  color: #fff;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-gallery-set:hover {
  background: #2563eb;
}

.btn-gallery-del {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  padding: 4px 7px;
}
.btn-gallery-del:hover {
  background: rgba(239, 68, 68, 0.4);
  color: #fff;
}

.gallery-empty-hint {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 20px 10px;
}
