/* MaddWebsenger — tema oscuro, CSS grid, sin frameworks (plan §3.5) */

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

:root {
  --bg: #14161a;
  --bg-panel: #1c1f26;
  --bg-raised: #262a33;
  --border: #333844;
  --text: #d8dce4;
  --text-dim: #8a90a0;
  --accent: #4f8ef7;
  --green: #3fb26f;
  --orange: #e8963a;
  --red: #e05252;
  --mine: #24435f;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

button {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

input, select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

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

#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
#login-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 340px;
  text-align: center;
}
#login-box h1 { margin-bottom: 4px; }
#login-box .subtitle { color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form button { background: var(--accent); border: none; font-weight: 600; }
#login-error { color: var(--red); font-size: 13px; }

/* ---- App: status bar + layout 3 paneles ---- */

#app-view { display: flex; flex-direction: column; height: 100vh; }

#status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
#conn-status.connected { color: var(--green); }
#conn-status.connecting, #conn-status.reconnecting { color: var(--orange); }
#conn-status.disconnected { color: var(--red); }
#rtt { color: var(--text-dim); }
#current-user { margin-left: auto; color: var(--text-dim); }

#layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  flex: 1;
  min-height: 0;
}

/* ---- Sidebar ---- */

#sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
}
#sidebar h2 { font-size: 14px; color: var(--text-dim); margin-bottom: 10px; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sidebar-header h2 { margin-bottom: 0 !important; }
.sidebar-actions { display: flex; gap: 6px; }
.sidebar-actions button { background: var(--bg-raised); color: var(--text); border: 1px solid var(--border); border-radius: 50%; width: 26px; height: 26px; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.sidebar-actions button:hover { border-color: var(--accent); }
#conv-list { list-style: none; }
#conv-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
}
#conv-list li:hover { background: var(--bg-raised); }
#conv-list li.active { background: var(--mine); }
.conv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.conv-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-raised);
}
.conv-icon svg {
  display: block;
}
.conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-meta { font-size: 11px; color: var(--text-dim); }
.conv-phone { font-size: 10px; color: var(--text-dim); display: block; margin-top: 1px; opacity: 0.7; width: 100%; }
.conv-unread { background: rgba(79, 142, 247, 0.08); }
.conv-unread-title { font-weight: 700; color: #fff; }
.conv-unread-dot {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 5px;
  margin-left: auto;
}

/* ---- Chat ---- */
#chat-subtitle { font-size: 12px; color: var(--text-dim); display: block; opacity: 0.7; }

#chat { display: flex; flex-direction: column; min-height: 0; }
#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--bg-raised);
  align-self: flex-start;
  position: relative;
}
.msg.mine { background: var(--mine); align-self: flex-end; }
.msg.deleted .msg-body { color: var(--text-dim); font-style: italic; }
.msg-sender { font-size: 11px; color: var(--accent); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.msg-meta { font-size: 10px; color: var(--text-dim); text-align: right; margin-top: 4px; }
.icon-delivered { color: var(--text-dim); }
.icon-read { color: var(--accent); }
.msg-actions { display: none; gap: 4px; margin-top: 6px; }
.msg:hover .msg-actions { display: flex; }
.msg-actions button { font-size: 11px; padding: 2px 8px; }

/* ---- Burbuja multimedia (spec §4.3) ---- */
.msg-img {
  display: block;
  max-width: 320px;
  max-height: 320px;
  border-radius: 8px;
  cursor: pointer;
}
.msg-video, .msg-audio {
  display: block;
  max-width: 320px;
  border-radius: 8px;
}
.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  min-width: 180px;
}
.msg-file-icon { font-size: 22px; flex-shrink: 0; }
.msg-file-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.msg-file-info a {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}
.msg-file-info a:hover { text-decoration: underline; }
.msg-file-size { font-size: 11px; color: var(--text-dim); }
.msg-caption { margin-top: 6px; white-space: pre-wrap; word-break: break-word; }

#send-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
#send-input { flex: 1; }
#send-form button { background: var(--accent); border: none; font-weight: 600; }
#send-form #btn-attach { background: var(--bg-raised); border: 1px solid var(--border); font-weight: 400; padding: 6px 10px; }

/* ---- Panel de grupo ---- */

#group-panel {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  max-height: 40vh;
  overflow-y: auto;
}
#group-panel h3 { font-size: 14px; margin-bottom: 8px; }
.group-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.group-actions button { font-size: 12px; }
.member-list { list-style: none; }
.member-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.member-list li span { flex: 1; }
.member-list select, .member-list button { font-size: 11px; padding: 2px 6px; }

/* ---- Event Inspector (sidebar derecho) ---- */

#layout.has-inspector {
  grid-template-columns: 240px 1fr 320px;
}

#inspector-panel {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}
#inspector-panel.hidden { display: none; }
#inspector-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  flex-shrink: 0;
}
#inspector-controls input { flex: 1; font-size: 11px; padding: 2px 6px; min-width: 60px; }
#inspector-controls button { font-size: 12px; padding: 2px 6px; }
#btn-pause.paused { border-color: var(--orange); color: var(--orange); }
#btn-inspector-close { margin-left: auto; }

#btn-inspector-toggle {
  background: transparent;
  border: none;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--text-dim);
  opacity: 0.5;
}
#btn-inspector-toggle:hover { opacity: 1; color: var(--text); background: var(--bg-raised); }
#btn-inspector-toggle.active { opacity: 1; color: var(--accent); }

#inspector-log {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 11px;
}
#inspector-log li {
  border-left: 3px solid var(--text-dim);
  margin-bottom: 4px;
  background: var(--bg-raised);
  border-radius: 0 6px 6px 0;
}
.ev-head {
  padding: 5px 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.ev-copy { font-size: 10px; padding: 0 6px; opacity: 0; }
#inspector-log li:hover .ev-copy { opacity: 1; }
.ev-json { padding: 6px 8px; border-top: 1px solid var(--border); overflow-x: auto; }

/* color por familia de evento (plan: inspector §3.5) */
.ev-message { border-left-color: var(--accent); }
.ev-group { border-left-color: var(--green); }
.ev-member { border-left-color: var(--orange); }
.ev-error { border-left-color: var(--red); }
.ev-heartbeat { border-left-color: var(--border); opacity: 0.55; }
.dir-out .ev-head { color: var(--text-dim); }

/* ---- Toasts ---- */

#toasts {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  animation: toastIn 0.3s ease;
  pointer-events: auto;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast.error { border-color: var(--red); }
.toast.warn { border-color: var(--orange); }
.toast.success { border-color: var(--green); }

/* ---- Modal ---- */

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
#modal-overlay.hidden { display: none; }
#modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 380px;
  max-width: 90vw;
}
#modal-box h3 { margin-bottom: 8px; }
#modal-body { color: var(--text-dim); margin-bottom: 16px; font-size: 14px; line-height: 1.5; }
#modal-input { width: 100%; margin-bottom: 16px; }
#modal-input.hidden { display: none; }
#modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
#modal-cancel { background: var(--bg-raised); }
#modal-confirm { background: var(--accent); border-color: var(--accent); font-weight: 600; }

