/* ══════════════════════════════════════════════════════════════
   CANAL SONORA CHAT — CSS
   Responsive: desktop 3 cols / tablet 2 cols / mobile 1 col
══════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens dark ── */
:root {
  --cs-blue:     #1a1f8f;
  --cs-blue-dk:  #12156b;
  --cs-gold:     #f5c400;
  --cs-red:      #e8401c;

  --bg-deep:     #0d0e1a;
  --bg-sidebar:  #11133a;
  --bg-main:     #14163f;
  --bg-surface:  #191c4a;
  --bg-hover:    #1e2255;
  --bg-active:   #232860;
  --border:      #252862;
  --text:        #eceef8;
  --text-muted:  #6b72a8;
  --text-dim:    #9ba3cc;
  --online:      #3dd68c;

  --font:  'Barlow', sans-serif;
  --cond:  'Barlow Condensed', sans-serif;
  --mono:  'JetBrains Mono', monospace;

  --sidebar-w:  248px;
  --users-w:    215px;
  --topbar-h:   48px;
}

/* ── Tokens light ── */
[data-theme="light"] {
  --bg-deep:    #dde0f5;
  --bg-sidebar: #ffffff;
  --bg-main:    #f0f2fc;
  --bg-surface: #ffffff;
  --bg-hover:   #e8eaf8;
  --bg-active:  #d8dcf5;
  --border:     #c8cce8;
  --text:       #0d0e2a;
  --text-muted: #7880b0;
  --text-dim:   #3d4470;
}

html, body { height: 100%; overflow: hidden; font-family: var(--font); background: var(--bg-deep); color: var(--text); }

.page  { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.hidden { display: none !important; }
.desk-only { display: flex; }
.mob-only  { display: none; }

/* ══════════════════════════════════════════
   LOGIN
══════════════════════════════════════════ */
.login-card {
  width: 100%; max-width: 360px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,.3);
  margin: 16px;
}
.login-logo { display: flex; justify-content: center; }
.login-logo img { height: 48px; width: auto; object-fit: contain; }
.login-sub { font-size: 13px; color: var(--text-muted); text-align: center; }

.alert { background: rgba(232,64,28,.15); color: var(--cs-red); border: 1px solid rgba(232,64,28,.3); border-radius: 10px; padding: 10px 14px; font-size: 13px; font-weight: 500; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11px; font-weight: 700; letter-spacing: .5px; color: var(--text-muted); text-transform: uppercase; font-family: var(--cond); }
.field input {
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--bg-main); outline: none;
  transition: border-color .15s, background .15s;
}
.field input:focus { border-color: var(--cs-gold); background: var(--bg-surface); }

.btn-primary {
  padding: 13px; background: var(--cs-blue); color: white;
  border: none; border-radius: 10px;
  font-family: var(--font); font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background .15s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary:hover { background: var(--cs-gold); color: #0d0e1a; }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════
   LAYOUT
══════════════════════════════════════════ */
.mobile-topbar {
  display: none;
  height: var(--topbar-h);
  background: linear-gradient(135deg, var(--cs-blue-dk), var(--cs-blue));
  border-bottom: 2px solid var(--cs-gold);
  align-items: center; justify-content: space-between;
  padding: 0 12px; flex-shrink: 0; gap: 8px;
}
.mob-logo img { height: 28px; width: auto; }
.mob-btn {
  width: 36px; height: 36px; background: none; border: none;
  color: white; cursor: pointer; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.mob-btn:hover { background: rgba(255,255,255,.15); }
.mob-btn svg { width: 20px; height: 20px; fill: currentColor; }

.chat-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex; flex-direction: column; flex-shrink: 0;
  border-right: 1px solid var(--border);
  transition: background .3s, border-color .3s;
  z-index: 100;
}
.server-header {
  background: linear-gradient(135deg, var(--cs-blue-dk) 0%, var(--cs-blue) 100%);
  border-bottom: 3px solid var(--cs-gold);
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.server-logo img { height: 36px; width: auto; object-fit: contain; }
.sidebar-close {
  background: none; border: none; color: rgba(255,255,255,.7);
  font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
  transition: background .15s;
}
.sidebar-close:hover { background: rgba(255,255,255,.15); color: white; }

.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 99; display: none;
}
.sidebar-overlay.visible { display: block; }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 6px 0; }
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 4px;
}
.section-label {
  font-size: 10px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text-muted); font-family: var(--cond);
}
.section-add {
  width: 20px; height: 20px; background: none; border: none;
  color: var(--text-muted); cursor: pointer; border-radius: 5px;
  font-size: 18px; display: flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s; line-height: 1;
}
.section-add:hover { color: var(--text); background: var(--bg-hover); }

.channel-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px 5px 12px; margin: 1px 8px;
  border-radius: 7px; cursor: pointer;
  color: var(--text-muted); font-size: 13.5px; font-weight: 500;
  transition: background .12s, color .12s; position: relative;
  user-select: none;
}
.channel-item:hover { background: var(--bg-hover); color: var(--text-dim); }
.channel-item.active { background: var(--bg-active); color: var(--text); }
.channel-item.active::before {
  content: ''; position: absolute; left: -8px; top: 50%;
  transform: translateY(-50%); width: 3px; height: 55%;
  background: var(--cs-gold); border-radius: 0 3px 3px 0;
}
.ch-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }
.ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-badge { background: var(--cs-red); color: white; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 99px; flex-shrink: 0; }

.dm-item {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 8px 5px 12px; margin: 1px 8px;
  border-radius: 7px; cursor: pointer;
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  transition: background .12s, color .12s;
}
.dm-item:hover { background: var(--bg-hover); color: var(--text-dim); }
.dm-item.active { background: var(--bg-active); color: var(--text); }

.dm-av {
  width: 28px; height: 28px; border-radius: 50%;
  font-size: 10px; font-weight: 700; color: white;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; position: relative;
}
.dm-dot { position: absolute; bottom: -1px; right: -1px; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--bg-sidebar); }
.dm-dot.on  { background: var(--online); }
.dm-dot.off { background: var(--text-muted); }

.user-bar {
  padding: 9px 12px; border-top: 1px solid var(--border);
  background: var(--bg-deep);
  display: flex; align-items: center; gap: 9px; flex-shrink: 0;
  transition: background .3s;
}
.my-av {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--cs-blue); border: 2px solid var(--cs-gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: white;
  position: relative; flex-shrink: 0;
}
.my-dot { position: absolute; bottom: -2px; right: -2px; width: 11px; height: 11px; background: var(--online); border-radius: 50%; border: 2px solid var(--bg-deep); }
.my-info { flex: 1; min-width: 0; }
.my-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.my-tag  { font-size: 10px; color: var(--text-muted); font-family: var(--mono); }
.ub-actions { display: flex; gap: 3px; }
.ub-btn {
  width: 28px; height: 28px; background: none; border: none;
  color: var(--text-muted); cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s; font-size: 15px;
}
.ub-btn:hover { background: var(--bg-hover); color: var(--text); }
.ub-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ══════════════════════════════════════════
   MAIN
══════════════════════════════════════════ */
.main { flex: 1; display: flex; flex-direction: column; background: var(--bg-main); overflow: hidden; transition: background .3s; min-width: 0; }

.chat-header {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  background: var(--bg-main); transition: background .3s, border-color .3s;
  min-height: 48px;
}
.ch-hdr-icon { font-size: 17px; color: var(--text-muted); flex-shrink: 0; }
.ch-hdr-name { font-size: 15px; font-weight: 800; font-family: var(--cond); letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-hdr-sep  { color: var(--border); flex-shrink: 0; }
.ch-hdr-desc { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ch-hdr-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.live-pill {
  display: flex; align-items: center; gap: 5px;
  background: rgba(232,64,28,.15); border: 1px solid rgba(232,64,28,.3);
  color: var(--cs-red); font-size: 10px; font-weight: 800;
  letter-spacing: .5px; text-transform: uppercase;
  padding: 3px 9px; border-radius: 99px; font-family: var(--cond);
  white-space: nowrap;
}
.live-dot { width: 6px; height: 6px; background: var(--cs-red); border-radius: 50%; animation: pulse 1.5s ease-in-out infinite; flex-shrink: 0; }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.3;transform:scale(.75)} }

.online-count { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.online-dot { width: 7px; height: 7px; background: var(--online); border-radius: 50%; flex-shrink: 0; }

.hdr-btn {
  width: 30px; height: 30px; background: none; border: none;
  color: var(--text-muted); cursor: pointer; border-radius: 7px;
  align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.hdr-btn:hover { background: var(--bg-hover); color: var(--text); }
.hdr-btn svg { width: 17px; height: 17px; fill: currentColor; }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 1px; }
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.msg-placeholder { text-align: center; color: var(--text-muted); font-size: 14px; margin: auto; }

.day-div {
  display: flex; align-items: center; gap: 10px;
  font-size: 10px; color: var(--text-muted); font-weight: 800;
  letter-spacing: .5px; margin: 10px 0 6px;
  font-family: var(--cond); text-transform: uppercase;
}
.day-div::before, .day-div::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.msg-group {
  display: flex; gap: 11px; padding: 3px 6px; border-radius: 8px;
  transition: background .1s;
  animation: fadeUp .18s ease;
}
.msg-group:hover { background: var(--bg-surface); }
.msg-group.cont .msg-av  { visibility: hidden; }
.msg-group.cont .msg-hdr { display: none; }
.msg-group.cont { padding-top: 1px; }

@keyframes fadeUp { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:translateY(0)} }

.msg-av {
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 11px; font-weight: 800; color: white;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
}
.msg-body { flex: 1; min-width: 0; }
.msg-hdr  { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; flex-wrap: wrap; }
.msg-author { font-size: 14px; font-weight: 800; cursor: pointer; font-family: var(--cond); letter-spacing: .2px; }
.msg-author:hover { text-decoration: underline; }
.msg-ts { font-size: 10px; color: var(--text-muted); font-family: var(--mono); }
.msg-text { font-size: 13.5px; line-height: 1.55; color: var(--text-dim); word-break: break-word; }

.sys-msg { text-align: center; font-size: 11px; color: var(--text-muted); padding: 3px 0; font-style: italic; }

.typing-bar { padding: 3px 18px 8px; font-size: 12px; color: var(--text-muted); font-style: italic; min-height: 26px; flex-shrink: 0; }

/* Composer */
.composer { padding: 0 12px 12px; flex-shrink: 0; position: relative; }
.composer-box {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 10px; display: flex; align-items: flex-end;
  transition: border-color .2s, box-shadow .2s, background .3s;
}
.composer-box:focus-within { border-color: var(--cs-gold); box-shadow: 0 0 0 2px rgba(245,196,0,.1); }

.c-emoji { font-size: 17px; background: none; border: none; cursor: pointer; padding: 12px 6px 12px 12px; opacity: .6; transition: opacity .15s; flex-shrink: 0; }
.c-emoji:hover { opacity: 1; }

.c-input {
  flex: 1; background: transparent; border: none; outline: none;
  font-family: var(--font); font-size: 14px; color: var(--text);
  padding: 12px 6px; resize: none; max-height: 120px; line-height: 1.5;
}
.c-input::placeholder { color: var(--text-muted); }

.c-send {
  width: 36px; height: 36px; background: var(--cs-blue);
  border: none; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  margin: 0 6px 6px; flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.c-send:hover { background: var(--cs-gold); }
.c-send:active { transform: scale(.93); }
.c-send svg { width: 16px; height: 16px; fill: white; }

/* Emoji picker */
.emoji-picker {
  position: absolute; bottom: 62px; left: 12px;
  background: var(--bg-sidebar); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px;
  display: grid; grid-template-columns: repeat(8,1fr); gap: 4px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 50;
  animation: fadeUp .15s ease;
}
.emoji-picker button { background: none; border: none; font-size: 20px; cursor: pointer; border-radius: 7px; padding: 5px; transition: background .1s; }
.emoji-picker button:hover { background: var(--bg-hover); }

/* ══════════════════════════════════════════
   USERS PANEL
══════════════════════════════════════════ */
.users-panel {
  width: var(--users-w); background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  overflow-y: auto; padding: 12px 0;
  transition: background .3s, border-color .3s;
}
.users-panel::-webkit-scrollbar { width: 4px; }
.users-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.up-label { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); padding: 8px 14px 4px; font-family: var(--cond); }
.up-item {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 10px; border-radius: 7px; margin: 1px 6px;
  cursor: pointer; transition: background .12s;
}
.up-item:hover { background: var(--bg-hover); }
.up-av {
  width: 30px; height: 30px; border-radius: 50%;
  font-size: 10px; font-weight: 800; color: white;
  display: flex; align-items: center; justify-content: center;
  position: relative; flex-shrink: 0;
}
.up-dot { position: absolute; bottom: -1px; right: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--bg-sidebar); transition: border-color .3s; }
.up-dot.on  { background: var(--online); }
.up-dot.off { background: var(--text-muted); }
.up-name { font-size: 13px; font-weight: 500; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item:hover .up-name { color: var(--text); }
.up-item.me .up-name { color: var(--cs-gold); font-weight: 700; }

/* ══════════════════════════════════════════
   MODAL
══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal {
  background: var(--bg-sidebar); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  animation: fadeUp .2s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 16px; font-weight: 800; font-family: var(--cond);
}
.modal-header button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; border-radius: 6px; padding: 4px 8px; transition: background .15s; }
.modal-header button:hover { background: var(--bg-hover); color: var(--text); }

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */

/* Tablet: ocultar panel de usuarios */
@media (max-width: 900px) {
  .users-panel { display: none; }
  .users-panel.visible { display: flex; position: fixed; right: 0; top: 0; bottom: 0; z-index: 150; box-shadow: -4px 0 20px rgba(0,0,0,.3); }
  .desk-only { display: none !important; }
}

/* Mobile: sidebar deslizante */
@media (max-width: 640px) {
  :root { --topbar-h: 48px; }

  .mobile-topbar { display: flex; }

  .chat-layout {
    flex-direction: column;
    height: calc(100% - var(--topbar-h));
  }

  .sidebar {
    position: fixed; left: -100%; top: var(--topbar-h); bottom: 0;
    width: 280px; transition: left .25s ease, background .3s;
    z-index: 100;
  }
  .sidebar.open { left: 0; }

  .mob-only { display: flex !important; }
  .desk-only { display: none !important; }

  .server-header { display: none; }

  .main { height: 100%; }

  .emoji-picker { grid-template-columns: repeat(6,1fr); left: 8px; right: 8px; }
}

/* Safe area para iPhones con notch */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .user-bar  { padding-bottom: calc(9px  + env(safe-area-inset-bottom)); }
}

/* ══ MOBILE FIX ══════════════════════════════════════════════ */
@media (max-width: 640px) {
  .mobile-topbar { display: flex; }

  .page#chatPage { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; }

  .chat-layout {
    flex-direction: row !important;
    height: calc(100% - 48px);
    width: 100%;
    position: relative;
    overflow: hidden;
  }

  /* Sidebar completamente fuera del flujo */
  .sidebar {
    position: fixed !important;
    left: -300px !important;
    top: 48px; bottom: 0;
    width: 280px;
    transition: left .25s ease, background .3s;
    z-index: 100;
  }
  .sidebar.open { left: 0 !important; }

  /* Main ocupa TODO el ancho disponible */
  .main {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 !important;
    min-width: 0 !important;
  }

  .users-panel { display: none !important; }

  .server-header { display: none; }
  .desk-only { display: none !important; }
  .mob-only  { display: flex !important; }

  .emoji-picker { grid-template-columns: repeat(6,1fr); left: 8px; right: 8px; }
}

/* ══ FULL WIDTH FIX ══════════════════════════════════════════ */
html, body {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* Chat page ocupa todo — sin centrado ni márgenes */
.page#chatPage {
  align-items: stretch !important;
  justify-content: flex-start !important;
  flex-direction: column !important;
  padding: 0 !important;
  margin: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
}

.chat-layout {
  width: 100% !important;
  max-width: 100% !important;
  flex: 1 !important;
  overflow: hidden;
}

.main {
  flex: 1 !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

/* ══ DM BADGE FIX ════════════════════════════════════════════ */
.dm-item {
  display: flex !important;
  align-items: center !important;
  gap: 9px !important;
  overflow: hidden;
}

.dm-item .ch-name {
  flex: 1 !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.dm-item .ch-badge {
  flex-shrink: 0 !important;
  margin-left: auto;
}
