:root {
  color-scheme: light;
  --accent: #991b1b;
  --accent-dark: #7f1d1d;
  --ink: #1e2430;
  --muted: #72798a;
  --line: #e2e8f0;
  --surface: #ffffff;
  --soft: #fff5f5;
  --bubble: #f8fafc;
  --shadow: 0 16px 50px rgba(127, 29, 29, .18);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: #fdf2f2; color: var(--ink); overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell {
  display: grid;
  grid-template-rows: 66px auto 1fr;
  grid-template-columns: 350px 1fr;
  height: 100%;
  background: var(--surface);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 18px;
  color: white;
  background: linear-gradient(115deg, #6b1111 0%, #991b1b 55%, #7f1d1d 100%);
  box-shadow: 0 2px 14px rgba(107, 17, 17, .35);
  z-index: 999999 !important;
  position: relative;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand div { display: grid; line-height: 1.15; }
.brand small { color: #fca5a5; }
.topbar-nav { display: flex; align-items: center; gap: 8px; }

.ghost-button, .icon-button {
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: 9px;
  background: transparent;
  color: inherit;
  padding: 8px 12px;
  text-decoration: none;
}
.icon-button { min-width: 38px; padding-inline: 9px; font-size: 1.15rem; }
.ghost-button:hover, .icon-button:hover { background: rgba(255, 255, 255, .13); }
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ffcc4d;
  color: #332500;
  font-size: .75rem;
  font-weight: 700;
}

.conversation-panel {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: #fbfbfd;
  overflow: hidden;
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 12px;
}
.panel-title h2 { margin: 2px 0 0; font-size: 1.2rem; }
.panel-title small { color: var(--accent); }
.panel-title .icon-button { color: var(--accent); border-color: #fca5a5; }
.btn-new-chat-action {
  background: var(--accent) !important;
  color: white !important;
  border-color: var(--accent) !important;
  font-weight: bold;
  font-size: 1.1rem !important;
  min-width: 40px !important;
  height: 40px !important;
  border-radius: 10px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: 0 2px 8px rgba(153, 27, 27, 0.25);
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn-new-chat-action:hover {
  background: var(--accent-dark) !important;
  transform: scale(1.05);
}
.mobile-fab-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  bottom: calc(32px + env(safe-area-inset-bottom, 12px));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: linear-gradient(135deg, #991b1b, #7f1d1d);
  color: white;
  font-size: 1.5rem;
  border: none;
  box-shadow: 0 6px 20px rgba(153, 27, 27, 0.45);
  z-index: 900;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.mobile-fab-new-chat:hover, .mobile-fab-new-chat:active {
  transform: scale(1.08);
  box-shadow: 0 8px 24px rgba(153, 27, 27, 0.6);
}
.search {
  width: calc(100% - 32px);
  margin: 0 16px 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: white;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #fee2e2; }
.conversation-list { height: calc(100% - 112px); overflow: auto; }
.conversation {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-top: 1px solid #f8fafc;
  text-align: left;
  background: transparent;
  color: inherit;
}
.conversation:hover { background: #fff1f1; }
.conversation.active { background: #fee2e2; }
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7f1d1d, #991b1b);
  color: white;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
  overflow: hidden;
}
.conversation-copy { min-width: 0; }
.conversation-copy strong, .conversation-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-copy span { margin-top: 5px; color: var(--muted); font-size: .84rem; }
.conversation-meta {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
  justify-content: space-between !important;
  height: 100% !important;
  min-height: 40px !important;
  gap: 4px;
}
.conversation-meta time { color: var(--muted); font-size: .72rem; }
.unread {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 22px !important;
  height: 22px !important;
  padding: 0 7px !important;
  border-radius: 11px !important;
  background: #dc2626 !important;
  color: white !important;
  font-size: 0.76rem !important;
  font-weight: 800 !important;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.45) !important;
  margin-top: 2px !important;
}

.chat-panel {
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 10% 10%, rgba(153, 27, 27, .045), transparent 24%),
    #fafafa;
}
.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  height: 100%;
  color: var(--muted);
  text-align: center;
}
.empty-state h2 { margin: 14px 0 0; color: var(--ink); }
.empty-state p { margin: 6px 0; }
.active-chat { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; position: relative; }
.chat-header {
  display: flex;
  align-items: center;
  padding: 0 22px;
  min-height: 64px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.chat-header h2 { margin: 0; font-size: 1.12rem; }
.chat-header small { color: var(--muted); }

.composer-top {
  position: relative;
  z-index: 1000 !important;
  border-top: none !important;
  border-bottom: 1px solid var(--line) !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
  background: white;
  flex-shrink: 0;
}

.attachment-menu-popover {
  position: fixed;
  background: white;
  border-radius: 16px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(0, 0, 0, 0.12);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 999999 !important;
  min-width: 220px;
  animation: popoverFadeIn 0.15s ease-out;
}

dialog:not([open]) {
  display: none !important;
}
@keyframes popoverFadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: #1e293b;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s ease;
}
.attach-menu-item:hover {
  background: #f1f5f9;
}
.attach-menu-icon {
  width: 34px;
  height: 34px;
  border-radius: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
  flex-shrink: 0;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 22px clamp(16px, 5vw, 72px);
}
.message {
  position: relative;
  align-self: flex-start;
  max-width: min(72%, 700px);
  padding: 10px 12px 7px;
  border-radius: 4px 15px 15px 15px;
  background: white;
  box-shadow: 0 2px 10px rgba(35, 37, 45, .07);
}
.message.mine {
  align-self: flex-end;
  border-radius: 15px 4px 15px 15px;
  background: #fecaca;
}
.message.internal { border: 1px dashed #d07e00; background: #fff4dd; }
.message.system {
  align-self: center;
  max-width: 88%;
  border-radius: 12px;
  background: #ebebf2;
  color: #656b78;
  font-size: .84rem;
  text-align: center;
}
.forwarded-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-style: italic;
  color: #64748b;
  margin-bottom: 3px;
  font-weight: 500;
}
.message.mine .forwarded-label {
  color: #991b1b;
}
.msg-actions {
  display: none;
  position: absolute;
  top: 4px;
  right: 8px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  padding: 2px 4px;
  z-index: 5;
}
.message:hover .msg-actions {
  display: flex;
  align-items: center;
}
.msg-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 3px 6px;
  color: #4b5563;
  border-radius: 4px;
  transition: background 0.15s;
}
.msg-action-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #111827;
}
.sender { display: block; color: var(--accent-dark); font-size: .76rem; font-weight: 700; }
.message p { margin: 3px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message p a { color: #b91c1c; text-decoration: underline; word-break: break-all; font-weight: 500; }
.message.mine p a { color: #7f1d1d; text-decoration: underline; }
.message p a:hover { text-decoration: none; opacity: 0.85; }
.chat-img-attachment {
  max-width: min(100%, 160px);
  max-height: 120px;
  border-radius: 8px;
  margin-top: 5px;
  cursor: pointer;
  display: block;
  object-fit: cover;
  transition: transform 0.15s ease, filter 0.15s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.chat-img-attachment:hover {
  transform: scale(1.02);
  filter: brightness(0.96);
}
.chat-file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-top: 6px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 330px;
}
.message.mine .chat-file-card {
  background: rgba(255, 255, 255, 0.5);
  border-color: rgba(153, 27, 27, 0.25);
}
.file-card-icon {
  font-size: 2rem;
  line-height: 1;
}
.file-card-details {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.file-card-name {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.file-card-size {
  font-size: 0.74rem;
  color: var(--muted);
}
.file-card-download {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--accent);
  color: white !important;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none !important;
  transition: background 0.15s ease;
  white-space: nowrap;
}
.file-card-download:hover {
  background: var(--accent-dark);
}
.file-preview-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f4f4f8;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.file-preview-icon { font-size: 1.4rem; }
.file-preview-name { font-size: 0.85rem; font-weight: 600; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.image-preview-bar {
  position: relative;
  width: 100%;
  padding: 8px 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  box-sizing: border-box;
  margin-bottom: 4px;
  flex-shrink: 0;
}
.preview-card {
  position: relative;
  display: inline-block;
}
.preview-card img {
  height: 64px;
  max-width: 100px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.remove-image-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ef4444 !important;
  color: white !important;
  border: none !important;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0 !important;
}
.active-chat { position: relative; }
.drag-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(127, 29, 29, 0.88);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  pointer-events: none;
  animation: fadeIn 0.15s ease-out;
}
.drag-drop-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 30px 45px;
  border: 2px dashed rgba(255, 255, 255, 0.8);
  border-radius: 20px;
  text-align: center;
  background: rgba(0, 0, 0, 0.1);
}
.lightbox-modal {
  padding: 0;
  border: none;
  border-radius: 16px;
  background: transparent;
  max-width: 90vw;
  max-height: 90vh;
  outline: none;
  overflow: visible;
}
.lightbox-modal::backdrop {
  background: rgba(10, 10, 20, 0.82);
  backdrop-filter: blur(8px);
}
.lightbox-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-content img {
  max-width: 88vw;
  max-height: 85vh;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}
.lightbox-close {
  position: absolute;
  top: -16px;
  right: -16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: white;
  color: #333;
  border: none;
  font-size: 22px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
  z-index: 10;
  transition: transform 0.15s ease;
}
.lightbox-close:hover { transform: scale(1.1); }
.message footer { display: flex; justify-content: flex-end; color: var(--muted); font-size: .68rem; }
.composer {
  position: relative;
  flex-shrink: 0;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 18px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: white;
  z-index: 10;
}
.composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  position: relative;
}
.composer textarea {
  flex: 1;
  max-height: 130px;
  resize: none;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); }
.emoji-btn {
  background: transparent !important;
  border: 1px solid var(--line) !important;
  color: var(--ink) !important;
  font-size: 1.35rem;
  padding: 8px 11px !important;
  border-radius: 11px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.emoji-btn:hover {
  background: #f4f4f8 !important;
  transform: scale(1.08);
}
.emoji-picker-container {
  position: fixed;
  bottom: auto;
  width: 340px;
  max-width: calc(100vw - 20px);
  height: 320px;
  max-height: 340px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 35px rgba(20, 20, 40, 0.25);
  display: flex;
  flex-direction: column;
  z-index: 9999999 !important;
  overflow: hidden;
  animation: pickerPop 0.18s ease-out;
}
.composer-top .emoji-picker-container {
  bottom: auto;
}
@keyframes pickerPop {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.emoji-picker-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: #fafafa;
}
.emoji-picker-header input {
  flex: 1;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.85rem;
  outline: none;
}
.emoji-picker-header input:focus {
  border-color: var(--accent);
}
.emoji-tabs {
  display: flex;
  justify-content: space-around;
  border-bottom: 1px solid var(--line);
  background: #f4f4f8;
  padding: 4px;
}
.emoji-tab {
  background: transparent !important;
  border: none !important;
  padding: 6px 10px !important;
  font-size: 1.15rem;
  cursor: pointer;
  border-radius: 8px !important;
  opacity: 0.6;
  transition: opacity 0.15s, background 0.15s;
}
.emoji-tab:hover, .emoji-tab.active {
  opacity: 1;
  background: rgba(91, 54, 214, 0.1) !important;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 10px;
  overflow-y: auto;
  max-height: 230px;
}
.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s ease, background 0.1s ease;
}
.emoji-item:hover {
  background: #fee2e2;
  transform: scale(1.22);
}
.composer button, .login-card button {
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: white;
  padding: 10px 18px;
  font-weight: 700;
}
.composer button:hover, .login-card button:hover { background: var(--accent-dark); }

.login-view {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 20px;
  background: linear-gradient(145deg, #450a0a 0%, #7f1d1d 50%, #991b1b 100%);
}
.login-card {
  display: grid;
  gap: 13px;
  width: min(100%, 400px);
  padding: 30px;
  border-radius: 22px;
  background: white;
  box-shadow: var(--shadow);
}
.login-card img { margin: auto; }
.login-card h1, .login-card p { margin: 0; text-align: center; }
.login-card p, .login-card small { color: var(--muted); }
.login-card label { display: grid; gap: 5px; color: #555c6a; font-size: .86rem; }
.login-card input {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
}

dialog {
  width: min(92vw, 620px);
  max-height: 82vh;
  border: 0;
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(30, 10, 10, .60); backdrop-filter: blur(3px); }
dialog > header { display: flex; justify-content: space-between; align-items: start; }
dialog h2 { margin: 2px 0 16px; }
dialog small { color: var(--accent); }
dialog .icon-button { color: var(--ink); border-color: var(--line); }
dialog .ghost-button { color: var(--accent); border-color: #fca5a5; }
.approval {
  margin: 10px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.approval h3 { margin: 0 0 6px; }
.approval p { margin: 0 0 10px; color: var(--muted); }
.approval-actions { display: flex; gap: 8px; }
.approve, .deny { border: 0; border-radius: 8px; padding: 8px 12px; color: white; }
.approve { background: #158253; }
.deny { background: #bd3a48; }
.security-note { color: var(--muted); font-size: .78rem; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 99999;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 18px;
  border-radius: 12px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 0.92rem;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: opacity 0.3s ease;
}

@media (max-width: 760px) {
  .topbar { padding-inline: 12px; }
  .brand div { display: none; }
  .topbar nav .ghost-button { padding: 7px; font-size: .75rem; }
  .topbar nav a { display: none; }
  .message { max-width: 86%; }
  .message-list { padding-inline: 12px; }
  .composer { padding-inline: 10px; }
}

.sync-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #fef3c7;
  color: #92400e;
  border-bottom: 1px solid #fde68a;
  font-size: 0.85rem;
  font-weight: 500;
}
.sync-status-bar strong {
  font-weight: 700;
}
.msg-status {
  margin-left: 5px;
  font-size: 0.85rem;
  display: inline-block;
}
.msg-status.pending {
  color: #d97706;
}
.msg-status.sent {
  color: #9ca3af;
}
.msg-status.read {
  color: #2563eb;
  font-weight: bold;
}

/* Zona Superior de Mensajes HTML en Grupos */
/* Zona Superior de Mensajes HTML en Grupos (Compacta sin aire excesivo) */
.group-announcement-banner {
  background: linear-gradient(135deg, #f0fdf4 0%, #e0f2fe 100%);
  border-bottom: 2px solid #38bdf8;
  padding: 5px 12px;
  box-shadow: inset 0 -2px 6px rgba(0, 0, 0, 0.03);
  position: relative;
  z-index: 10;
}
.announcement-html-body {
  font-size: 0.88rem;
  color: #1e293b;
  line-height: 1.35;
}
.announcement-html-body h1, .announcement-html-body h2, .announcement-html-body h3 {
  margin: 1px 0 3px;
  color: #0f172a;
  font-size: 0.95rem;
}
.announcement-html-body p {
  margin: 0;
}
.announcement-html-body p + p {
  margin-top: 3px;
}
.announcement-html-body a {
  color: #0284c7;
  text-decoration: underline;
  font-weight: 600;
}

/* Panel Admin & Modales */
.admin-panel-modal::backdrop {
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
}
.admin-tabs .active-admin-tab {
  color: #ca8a04 !important;
  border-bottom: 2px solid #ca8a04 !important;
}
.badge-role {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-block;
}
.badge-superadmin { background: #fef08a; color: #854d0e; }
.badge-support { background: #e0f2fe; color: #0369a1; }
.badge-active { background: #dcfce7; color: #15803d; }
.badge-inactive { background: #fee2e2; color: #b91c1c; }

@keyframes bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-10px); }
}

.mobile-menu-btn {
  display: none !important;
}

/* Banner Anuncio General Superior (SuperAdmin) */
/* Banner Anuncio General Superior (SuperAdmin) */
.system-announcement-banner {
  grid-column: 1 / -1;
  width: 100%;
  box-sizing: border-box;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border-bottom: 2px solid #f59e0b;
  padding: 5px 12px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.12);
  z-index: 10;
}
.system-announcement-body p {
  margin: 0;
}
.system-announcement-body p + p {
  margin-top: 3px;
}
.system-announcement-badge {
  background: #d97706;
  color: white;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 0.8px;
  display: inline-block;
}
.system-announcement-body {
  width: 100%;
  font-size: 0.94rem;
  color: #78350f;
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
  html,
  body {
    width: 100%;
    height: calc(var(--vh, 1vh) * 100);
    margin: 0;
    padding: 0;
    overflow: hidden !important;
    overscroll-behavior: none !important;
    touch-action: pan-x pan-y;
  }

  body {
    position: fixed;
    inset: 0;
  }

  .login-view {
    padding: 16px 12px;
    align-items: flex-start;
    overflow-y: auto;
  }

  .login-card {
    width: 100%;
    max-width: 100%;
    padding: 22px 16px;
    border-radius: 18px;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    width: 100%;
    height: calc(var(--vh, 1vh) * 100);
    max-height: calc(var(--vh, 1vh) * 100);
    overflow: hidden !important;
    overscroll-behavior: none !important;
  }

  .topbar {
    position: relative;
    padding: 8px 12px;
    height: auto;
    min-height: 52px;
    width: 100vw;
    max-width: 100vw;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    overflow: visible;
  }

  .brand {
    gap: 6px;
    min-width: 0;
    flex-shrink: 0;
  }

  .brand img {
    width: 28px;
    height: 28px;
  }

  .brand strong {
    font-size: 0.95rem;
  }

  .brand small {
    font-size: 0.7rem;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    font-size: 1.25rem;
    background: rgba(255, 255, 255, 0.18) !important;
    border: 1px solid rgba(255, 255, 255, 0.35) !important;
    color: white !important;
    border-radius: 9px;
    cursor: pointer;
    flex-shrink: 0;
  }

  .topbar-nav {
    display: none !important;
    position: absolute;
    top: calc(100% + 4px);
    right: 10px;
    width: 250px;
    background: #7f1d1d;
    border: 1px solid #b91c1c;
    border-radius: 14px;
    padding: 10px;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.55);
    z-index: 9999999 !important;
  }

  .topbar-nav.mobile-open {
    display: flex !important;
  }

  .topbar-nav.mobile-open .ghost-button,
  .topbar-nav.mobile-open .icon-button {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    padding: 10px 12px;
    font-size: 0.88rem;
    border-radius: 10px;
  }

  /* Responsive System Announcement Banner */
  .system-announcement-banner {
    width: 100vw;
    max-width: 100vw;
    box-sizing: border-box;
    overflow: hidden;
    padding: 10px 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .system-announcement-content {
    max-width: 100%;
    overflow: hidden;
  }

  /* Responsive Panel Toggling */
  .topbar {
    flex-shrink: 0;
  }

  .system-announcement-banner {
    flex-shrink: 0;
  }

  .conversation-panel {
    width: 100vw;
    max-width: 100vw;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-right: none;
    overflow: hidden;
    position: relative;
  }

  .mobile-fab-new-chat {
    display: none !important;
  }

  .conversation-list {
    padding-bottom: 24px !important;
  }

  .conversation {
    display: grid !important;
    grid-template-columns: 44px 1fr auto !important;
    width: 100% !important;
    padding: 13px 16px !important;
    gap: 12px !important;
    align-items: center !important;
    border-bottom: 1px solid rgba(0,0,0,0.05) !important;
  }

  .conversation-copy {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    min-width: 0 !important;
  }

  .conversation-copy strong {
    font-size: 1rem !important;
    font-weight: 700 !important;
    color: var(--ink) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .conversation-copy span {
    font-size: 0.85rem !important;
    color: var(--muted) !important;
    margin-top: 3px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .conversation-meta time {
    display: block !important;
    font-size: 0.74rem !important;
    color: var(--muted) !important;
  }

  .chat-panel {
    width: 100%;
    max-width: 100%;
    flex: 1 1 0% !important;
    min-height: 0 !important;
    height: 0 !important;
    max-height: 100% !important;
    display: none;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  .app-shell.mobile-chat-open .conversation-panel {
    display: none !important;
  }

  .app-shell.mobile-chat-open .chat-panel {
    display: flex !important;
  }

  /* Active Chat Container Fixes */
  .active-chat {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0% !important;
    min-height: 0 !important;
    height: 0 !important;
    max-height: 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    position: relative !important;
  }

.mobile-back-btn:not(.hidden) {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  #group-header-desktop-actions {
    display: none !important;
  }
  #btn-group-options-mobile {
    display: inline-flex !important;
  }
}

@media (min-width: 769px) {
  #btn-group-options-mobile {
    display: none !important;
  }
  #group-header-desktop-actions {
    display: flex !important;
  }
}

  .mobile-back-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .chat-header {
    padding: 8px 10px;
    height: auto;
    min-height: 52px;
    width: 100vw;
    max-width: 100vw;
    box-sizing: border-box;
    flex-shrink: 0;
  }

  .chat-header h2 {
    font-size: 0.98rem;
    max-width: 100%;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .message-list {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    height: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 12px 10px !important;
    gap: 8px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  .message {
    max-width: 84%;
    font-size: 0.92rem;
    box-sizing: border-box;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .message.mine {
    align-self: flex-end;
    margin-left: auto;
  }

  /* Composer (Input Box) Fixes */
  .composer {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom)) !important;
    gap: 6px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    overflow: visible !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    position: relative !important;
    background: var(--surface) !important;
    z-index: 10 !important;
  }

  .composer textarea {
    flex: 1;
    min-width: 0;
    font-size: 16px; /* Prevents auto-zoom on iOS & Android Chrome */
    padding: 8px 10px;
    max-height: 100px;
  }

  .composer button[type="submit"] {
    padding: 8px 12px;
    font-size: 0.85rem;
    flex-shrink: 0;
  }

  .emoji-btn {
    padding: 5px 7px !important;
    font-size: 1.1rem;
    flex-shrink: 0;
  }

  /* Responsive Modal Dialogs */
  dialog {
    max-width: 94vw !important;
    width: 94vw !important;
    padding: 18px 14px !important;
    margin: auto !important;
    border-radius: 16px !important;
  }

  dialog form {
    max-width: 100% !important;
  }

  .admin-panel-modal {
    max-width: 96vw !important;
    width: 96vw !important;
    max-height: 90vh !important;
    overflow-y: auto;
  }
}

/* Modal de Editor HTML de Anuncios y Avisos (Amplio y Responsive) */
.html-editor-modal {
  max-width: 900px !important;
  width: 90vw !important;
  max-height: 88vh !important;
  padding: 24px !important;
  border-radius: 20px !important;
  box-shadow: 0 25px 50px rgba(0,0,0,0.35) !important;
}

.html-editor-modal form {
  display: flex !important;
  flex-direction: column !important;
  gap: 14px !important;
}

.html-editor-modal .rich-editor-canvas {
  min-height: 240px !important;
  height: 38vh !important;
  max-height: 50vh !important;
  overflow-y: auto !important;
  padding: 14px !important;
  border-radius: 12px !important;
  border: 1px solid var(--line) !important;
  background: white !important;
  color: #0f172a !important;
}

.html-editor-modal textarea {
  min-height: 220px !important;
  height: 35vh !important;
  max-height: 48vh !important;
  font-family: monospace !important;
  padding: 12px !important;
  border-radius: 10px !important;
  border: 1px solid var(--line) !important;
  resize: vertical !important;
  background: #f8fafc !important;
  color: #0f172a !important;
}

@media (max-width: 768px) {
  .html-editor-modal {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 92vh !important;
    padding: 16px 12px !important;
  }
  .html-editor-modal .rich-editor-canvas {
    min-height: 180px !important;
    height: 30vh !important;
  }
  .html-editor-modal textarea {
    min-height: 160px !important;
    height: 28vh !important;
  }
}

/* Estilos de imágenes centradas y limitadas a 400px en editor enriquecido y mensajes */
.rich-editor-canvas img,
.chat-msg-body img,
.message-text img,
.chat-img-attachment {
  max-width: min(400px, 100%);
  max-height: 400px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  margin: 8px auto;
  display: block;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
}

.rich-editor-canvas img:hover,
.chat-msg-body img:hover,
.message-text img:hover,
.chat-img-attachment:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

/* --- Tema Oscuro (Dark Mode) --- */
[data-theme="dark"] {
  color-scheme: dark;
  --accent: #dc2626;
  --accent-dark: #ef4444;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --surface: #0f172a;
  --soft: #1e293b;
  --bubble: #1e293b;
  --shadow: 0 16px 50px rgba(0, 0, 0, .6);
}

[data-theme="dark"] body {
  background: #020617;
  color: var(--ink);
}

[data-theme="dark"] .app-shell {
  background: #0f172a;
}

[data-theme="dark"] .topbar {
  background: linear-gradient(115deg, #450a0a 0%, #7f1d1d 55%, #991b1b 100%);
  box-shadow: 0 2px 14px rgba(0, 0, 0, .6);
}

[data-theme="dark"] .conversation-panel {
  background: #0f172a;
  border-right-color: #334155;
}

[data-theme="dark"] .search {
  background: #1e293b;
  color: #f8fafc;
  border-color: #334155;
}

[data-theme="dark"] .conversation {
  border-top-color: #1e293b;
}

[data-theme="dark"] .conversation:hover {
  background: #1e293b;
}

[data-theme="dark"] .conversation.active {
  background: #334155;
}

[data-theme="dark"] .chat-panel {
  background: #090d16;
}

[data-theme="dark"] .chat-header {
  background: #0f172a;
  border-bottom-color: #334155;
}

[data-theme="dark"] .composer {
  background: #0f172a;
  border-top-color: #334155;
}

[data-theme="dark"] .composer textarea {
  background: #1e293b;
  color: #f8fafc;
  border-color: #334155;
}

[data-theme="dark"] .composer textarea::placeholder {
  color: #64748b;
}

[data-theme="dark"] .emoji-btn {
  background: #1e293b !important;
  color: #f8fafc !important;
}

[data-theme="dark"] .emoji-picker-container {
  background: #0f172a;
  border-color: #334155;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .emoji-picker-header {
  background: #1e293b;
  border-bottom-color: #334155;
}

[data-theme="dark"] .emoji-picker-header input {
  background: #0f172a;
  color: #f8fafc;
  border-color: #334155;
}

[data-theme="dark"] .emoji-tab {
  color: #94a3b8;
}

[data-theme="dark"] .emoji-tab.active {
  background: #334155;
  color: #f8fafc;
}

[data-theme="dark"] .emoji-item:hover {
  background: #334155;
}

/* Globos de mensajes en Modo Oscuro con Alto Contraste */
[data-theme="dark"] .message {
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #334155;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .message.mine {
  background: linear-gradient(135deg, #7f1d1d 0%, #991b1b 100%);
  color: #ffffff;
  border: 1px solid #b91c1c;
  box-shadow: 0 4px 14px rgba(153, 27, 27, 0.35);
}

[data-theme="dark"] .message p a {
  color: #60a5fa;
}

[data-theme="dark"] .message.mine p a {
  color: #fca5a5;
}

[data-theme="dark"] .message.mine .forwarded-label {
  color: #fca5a5;
}

[data-theme="dark"] .message.internal {
  background: #2e1d05;
  color: #fde68a;
  border-color: #78350f;
}

[data-theme="dark"] .message.system {
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
}

[data-theme="dark"] .sender {
  color: #fca5a5 !important;
}

[data-theme="dark"] .meta {
  color: #94a3b8 !important;
}

[data-theme="dark"] .message.mine .meta {
  color: #fca5a5 !important;
}

[data-theme="dark"] .msg-actions {
  background: #1e293b;
  border-color: #334155;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .msg-action-btn {
  color: #cbd5e1;
}

[data-theme="dark"] .msg-action-btn:hover {
  background: #334155;
  color: #ffffff;
}

[data-theme="dark"] .chat-file-card {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
}

[data-theme="dark"] .login-card {
  background: #0f172a;
  border-color: #334155;
  color: #f8fafc;
}

[data-theme="dark"] dialog {
  background: #0f172a !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
}

[data-theme="dark"] dialog header {
  border-bottom-color: #334155;
}

[data-theme="dark"] dialog input,
[data-theme="dark"] dialog select,
[data-theme="dark"] dialog textarea {
  background: #1e293b;
  color: #f8fafc;
  border-color: #334155;
}

[data-theme="dark"] .toast {
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid #334155;
}

/* Editor HTML Enriquecido en Modo Oscuro */
[data-theme="dark"] .html-editor-modal .rich-editor-canvas {
  background: #0f172a !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
}

[data-theme="dark"] .html-editor-modal textarea {
  background: #020617 !important;
  color: #f8fafc !important;
  border-color: #334155 !important;
}

[data-theme="dark"] .rich-toolbar-group {
  background: transparent !important;
}

[data-theme="dark"] .rich-tool-btn {
  background: #1e293b !important;
  border-color: #334155 !important;
  color: #f8fafc !important;
}

[data-theme="dark"] .rich-tool-btn:hover {
  background: #334155 !important;
  border-color: #475569 !important;
}

/* Banners de Anuncios en Modo Oscuro */
[data-theme="dark"] .group-announcement-banner {
  background: linear-gradient(135deg, #064e3b 0%, #0f172a 100%) !important;
  border-bottom-color: #059669 !important;
  color: #f8fafc !important;
}

[data-theme="dark"] .announcement-html-body {
  color: #f8fafc !important;
}

[data-theme="dark"] .announcement-html-body h1,
[data-theme="dark"] .announcement-html-body h2,
[data-theme="dark"] .announcement-html-body h3 {
  color: #ffffff !important;
}

[data-theme="dark"] .system-announcement-banner {
  background: linear-gradient(135deg, #78350f 0%, #0f172a 100%) !important;
  border-bottom-color: #d97706 !important;
  color: #f8fafc !important;
}

/* Dialog Reproductor de Video Flotante (YouTube / TikTok) 🎬▶️ */
.video-player-dialog {
  padding: 0 !important;
  border-radius: 20px !important;
  max-width: 800px !important;
  width: 90vw !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  background: #090d16 !important;
  color: white !important;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6) !important;
  overflow: hidden !important;
}

.video-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
}

.video-dialog-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
}

.video-player-container {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* Aspect Ratio 16:9 */
  height: 0;
  background: #000;
}

.video-player-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Tarjeta Vista Previa de Video en Mensajes */
.video-preview-card {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.04);
  max-width: 280px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

[data-theme="dark"] .video-preview-card {
  background: rgba(255, 255, 255, 0.06);
  border-color: #334155;
}

.video-preview-card:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.video-preview-thumb-wrapper {
  position: relative;
  width: 100%;
  height: 140px;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-preview-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.88;
}

.video-play-btn-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.25);
  transition: background 0.15s;
}

.video-preview-card:hover .video-play-btn-overlay {
  background: rgba(0, 0, 0, 0.1);
}

.video-play-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(220, 38, 38, 0.9);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.video-preview-info {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
}

[data-theme="dark"] .video-preview-info {
  color: #f8fafc;
}

/* Marca y Créditos de Pie de Página (MyBusinessPOS & AngelSQL) */
.brand-credits-footer {
  font-size: 0.74rem;
  color: #64748b;
  text-align: center;
  line-height: 1.45;
  padding: 8px 12px;
}

.brand-credits-footer a {
  color: #0284c7;
  font-weight: 700;
  text-decoration: underline;
  transition: color 0.15s ease;
}

.brand-credits-footer a:hover {
  color: #0369a1;
  text-decoration: none;
}

.login-brand-footer {
  margin-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 12px;
  width: 100%;
}

.sidebar-brand-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
  padding: 10px 14px;
}

.empty-chat-brand-footer {
  margin-top: 16px;
}

[data-theme="dark"] .brand-credits-footer {
  color: #94a3b8;
}

[data-theme="dark"] .brand-credits-footer a {
  color: #38bdf8;
}

[data-theme="dark"] .brand-credits-footer a:hover {
  color: #7dd3fc;
}

[data-theme="dark"] .sidebar-brand-footer {
  border-top-color: #334155;
}

