/* ═══════════════════════════════════════════════════════
   COMETA v3 · hoja de estilos
   Paleta: índigo profundo + ámbar (cometa) + azul hielo (Slack)
   Tipos:  Bricolage Grotesque (marca) · Instrument Sans (UI)
   ═══════════════════════════════════════════════════════ */
:root {
  --bg:        #15122b;
  --bg-deep:   #100e22;
  --panel:     #1e1a3a;
  --panel-2:   #272148;
  --line:      #352e5e;
  --text:      #f1edfc;
  --text-dim:  #a99fd1;
  --amber:     #ffb454;
  --amber-soft:#ffb45426;
  --ice:       #a8d8ff;
  --ice-soft:  #a8d8ff1f;
  --danger:    #ff7a8a;
  --ok:        #6fe3a1;
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --font-ui: "Instrument Sans", system-ui, sans-serif;
  --font-brand: "Bricolage Grotesque", var(--font-ui);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; }
::selection { background: var(--amber); color: #2a1a00; }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 9px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

/* ─────────── Acceso ─────────── */
.auth { min-height: 100dvh; display: grid; place-items: center; position: relative; overflow: hidden; padding: 24px 16px; }
.auth-sky { position: absolute; inset: 0; pointer-events: none; }
.comet-trail {
  position: absolute; top: -12%; right: -22%;
  width: 135%; height: 46%;
  transform: rotate(-16deg);
  background: linear-gradient(90deg, transparent 0%, #a8d8ff12 30%, #a8d8ff33 62%, #ffb45488 88%, #ffd08c 100%);
  filter: blur(26px); border-radius: 999px;
}
.comet-head {
  position: absolute; top: 9.5%; right: 6%;
  width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle at 38% 38%, #fff6e3, var(--amber) 55%, transparent 75%);
  box-shadow: 0 0 60px 22px #ffb45466, 0 0 140px 60px #ffb45422;
}
.stars {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1.4px 1.4px at 12% 68%, #cfc4ff99 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 28% 22%, #cfc4ff77 50%, transparent 51%),
    radial-gradient(1.6px 1.6px at 47% 81%, #a8d8ff88 50%, transparent 51%),
    radial-gradient(1.1px 1.1px at 63% 34%, #cfc4ff66 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 81% 72%, #cfc4ff88 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 91% 18%, #a8d8ff77 50%, transparent 51%),
    radial-gradient(1.3px 1.3px at 6% 12%, #cfc4ff66 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 72% 9%, #cfc4ff55 50%, transparent 51%);
}
.auth-card {
  position: relative; width: min(380px, 100%);
  background: #1e1a3ad9; border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 34px 30px 26px;
  backdrop-filter: blur(10px);
}
.brand { font-family: var(--font-brand); font-weight: 800; font-size: 1.05rem; color: var(--amber); margin: 0 0 14px; }
.auth-card h1 { font-family: var(--font-brand); font-weight: 700; font-size: 1.7rem; line-height: 1.15; margin: 0 0 6px; }
.auth-sub { color: var(--text-dim); margin: 0 0 22px; }
.auth-card label { display: block; margin-bottom: 14px; }
.auth-card label span, .dlg label span {
  display: block; font-size: .86rem; font-weight: 600; color: var(--text-dim); margin-bottom: 5px;
}
.auth-card input, .dlg input, .dlg select {
  width: 100%; padding: 11px 13px;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--text); outline: none;
}
.auth-card input:focus, .dlg input:focus, .dlg select:focus, textarea:focus { border-color: var(--amber); }
.form-error { color: var(--danger); font-size: .88rem; min-height: 1.2em; margin: 2px 0 10px; }

.btn-primary {
  width: 100%; padding: 12px 18px; border: none;
  border-radius: var(--r-sm); background: var(--amber);
  color: #2a1a00; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { padding: 11px 16px; border: 1px solid var(--line); border-radius: var(--r-sm); background: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-wide { width: 100%; }
.link { display: block; margin: 16px auto 0; background: none; border: none; color: var(--ice); text-decoration: underline; text-underline-offset: 3px; }
.link-dim { color: var(--text-dim); margin: 0; display: inline; font-size: .85rem; }

/* ─────────── Estructura ─────────── */
.app { height: 100dvh; display: flex; }
.left { display: flex; flex: none; }

/* ─── Barra de organizaciones ─── */
.org-rail {
  width: 68px; flex: none;
  background: var(--bg-deep);
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0 14px; gap: 10px;
  border-right: 1px solid #0a081d;
}
.org-brand {
  font-size: 1.3rem; width: 42px; height: 42px;
  display: grid; place-items: center;
  color: var(--amber);
  filter: drop-shadow(0 0 10px #ffb45455);
  margin-bottom: 2px;
}
.org-rail ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; flex: 1; overflow-y: auto; width: 100%; align-items: center; }
.org-btn {
  width: 44px; height: 44px; flex: none;
  border: none; padding: 0;
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-brand); font-weight: 700; font-size: 1.05rem;
  display: grid; place-items: center;
  overflow: hidden;
  position: relative;
  transition: border-radius .15s ease;
}
.org-btn img { width: 100%; height: 100%; object-fit: cover; }
.org-btn:hover { border-radius: 10px; }
.org-btn.active { outline: 2px solid var(--amber); outline-offset: 3px; border-radius: 10px; }
.org-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 99px; background: var(--amber); color: #2a1a00;
  font-size: .68rem; font-weight: 700; font-family: var(--font-ui);
  display: grid; place-items: center;
  border: 2px solid var(--bg-deep);
}
.org-add {
  width: 44px; height: 44px; flex: none;
  border: 1px dashed var(--line); border-radius: 14px;
  background: none; color: var(--text-dim); font-size: 1.3rem;
}
.org-add:hover { color: var(--amber); border-color: var(--amber); }

/* ─── Barra de canales ─── */
.rail {
  width: 250px; flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-width: 0;
}
.rail-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 15px 14px 12px;
  border-bottom: 1px solid var(--line);
  background: radial-gradient(130px 42px at 94% 0%, #ffb45414, transparent 70%), var(--panel);
}
.org-title {
  font-family: var(--font-brand); font-weight: 700; font-size: 1.08rem;
  margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail-scroll { flex: 1; overflow-y: auto; padding: 12px 8px 16px; }
.rail-group { margin-bottom: 20px; }
.rail-group-head { display: flex; align-items: center; justify-content: space-between; padding: 0 10px 4px; }
.rail-group-head h2 { font-size: .82rem; font-weight: 600; color: var(--text-dim); margin: 0; }
.rail-group ul { list-style: none; margin: 0; padding: 0; }
.rail-item {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: none; background: none;
  border-radius: var(--r-sm); color: var(--text-dim);
  text-align: left; min-width: 0;
}
.rail-item:hover { background: var(--panel-2); color: var(--text); }
.rail-item.active { background: var(--amber-soft); color: var(--text); }
.rail-item.has-unread { color: var(--text); font-weight: 600; }
.rail-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-pill {
  min-width: 20px; padding: 1px 6px;
  border-radius: 99px; background: var(--amber); color: #2a1a00;
  font-size: .72rem; font-weight: 700; text-align: center;
}
.hash { opacity: .6; }
.bridge-mark { color: var(--ice); font-size: .8rem; }
.ia-dot { color: var(--amber); }
.rail-group-slack .rail-item.active { background: var(--ice-soft); }
.slack-ws-btn {
  width: 100%; display: flex; align-items: center; gap: 7px;
  padding: 7px 10px; border: none; background: none;
  border-radius: var(--r-sm);
  color: var(--ice); font-weight: 600; text-align: left;
}
.slack-ws-btn:hover { background: var(--ice-soft); }
.slack-ws-btn .chev { font-size: .75rem; width: 12px; flex: none; opacity: .8; }
.slack-ws-btn .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-count { font-size: .72rem; color: var(--text-dim); font-weight: 400; }
.slack-sub {
  margin: 6px 0 2px; padding: 0 10px 0 28px;
  font-size: .74rem; font-weight: 600; letter-spacing: .02em;
  color: var(--text-dim);
}
.slack-convo { padding-left: 28px; }
.mini-ava {
  width: 20px; height: 20px; flex: none;
  border-radius: 6px; object-fit: cover;
  display: grid; place-items: center;
}
.mini-ava-ph {
  background: var(--ice);
  color: #15122b; font-size: .6rem; font-weight: 700;
  border-radius: 50%;
}
.avatar-img { object-fit: cover; padding: 0; border: 1px solid var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px #6fe3a177; }
.dot-me { background: var(--ok); }
.rail-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.me-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: none; background: none; color: var(--text-dim); font-size: 1rem; padding: 4px 8px; border-radius: var(--r-sm); line-height: 1; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ─── Sala ─── */
.room { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.room-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.room-title { flex: 1; min-width: 0; }
.room-title h1 { font-family: var(--font-brand); font-weight: 700; font-size: 1.15rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-title p { margin: 0; font-size: .84rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: .76rem; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--ice); color: var(--ice); white-space: nowrap; background: none; }
.badge-refresh { border-color: var(--line); color: var(--text-dim); }
.badge-refresh:hover { color: var(--text); }

.feed { flex: 1; overflow-y: auto; padding: 18px 20px 6px; display: flex; flex-direction: column; gap: 2px; }
.day-sep {
  align-self: center; font-size: .78rem; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--line);
  padding: 2px 12px; border-radius: 999px; margin: 14px 0 8px;
}
.msg { display: flex; gap: 11px; padding: 5px 8px; border-radius: var(--r-sm); position: relative; }
.msg:hover { background: #ffffff06; }
.msg.compact { padding-top: 1px; }
.avatar {
  width: 34px; height: 34px; flex: none;
  border-radius: 10px; display: grid; place-items: center;
  font-weight: 700; font-size: .9rem; color: #15122b;
}
.avatar.slack { background: var(--ice); border-radius: 50%; }
.avatar.ia { background: linear-gradient(135deg, var(--amber), #ff8a5c); border-radius: 50%; color: #2a1a00; }
.msg.compact .avatar { visibility: hidden; height: 0; }
.msg-main { min-width: 0; flex: 1; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 600; }
.msg-time { font-size: .76rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.msg-edited { font-size: .72rem; color: var(--text-dim); font-style: italic; }
.msg-slack-tag { font-size: .72rem; color: var(--ice); border: 1px solid var(--ice-soft); background: var(--ice-soft); padding: 0 6px; border-radius: 999px; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.feed-empty { margin: auto; text-align: center; color: var(--text-dim); max-width: 340px; }
.feed-empty strong { color: var(--text); font-family: var(--font-brand); }

/* adjuntos dentro del mensaje */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.att-img {
  max-width: min(340px, 100%); max-height: 260px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  cursor: zoom-in; display: block; object-fit: cover;
}
.att-file {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--panel);
  color: var(--ice); text-decoration: none; font-size: .9rem; max-width: 100%;
}
.att-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file:hover { border-color: var(--ice); }

/* acciones al pasar el ratón */
.msg-actions {
  position: absolute; top: -14px; right: 10px;
  display: none; gap: 2px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 99px; padding: 3px 6px;
  box-shadow: 0 6px 18px #00000055;
}
.msg:hover .msg-actions { display: flex; }
.msg-actions button { border: none; background: none; font-size: .95rem; padding: 2px 5px; border-radius: 6px; line-height: 1; }
.msg-actions button:hover { background: var(--panel); }
.emoji-pop {
  position: absolute; top: -52px; right: 10px; z-index: 5;
  display: flex; gap: 2px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 6px 8px;
  box-shadow: 0 10px 28px #00000077;
}
.emoji-pop button { border: none; background: none; font-size: 1.15rem; padding: 3px 5px; border-radius: 8px; }
.emoji-pop button:hover { background: var(--panel); transform: scale(1.12); }

/* reacciones */
.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.reaction {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 1px 9px;
  font-size: .85rem; display: inline-flex; gap: 5px; align-items: center;
}
.reaction .n { font-size: .76rem; color: var(--text-dim); font-weight: 600; }
.reaction:hover { border-color: var(--amber); }
.reaction.mine { background: var(--amber-soft); border-color: var(--amber); }
.reaction.mine .n { color: var(--amber); }

.typing { min-height: 20px; margin: 0; padding: 0 24px; font-size: .8rem; color: var(--text-dim); font-style: italic; }

/* menciones */
.mention {
  color: var(--ice);
  background: var(--ice-soft);
  border-radius: 6px;
  padding: 0 4px;
  font-weight: 600;
}
.mention.me {
  color: #2a1a00;
  background: var(--amber);
}
.mention-pop {
  position: absolute;
  bottom: calc(100% + 6px); left: 68px;
  min-width: 240px; max-width: 320px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 14px 40px #00000088;
  padding: 5px;
  z-index: 20;
  display: flex; flex-direction: column;
}
.composer { position: relative; }
.mention-pop button {
  display: flex; align-items: center; gap: 9px;
  width: 100%; border: none; background: none;
  padding: 7px 9px; border-radius: var(--r-sm); text-align: left;
}
.mention-pop button:hover, .mention-pop button.sel { background: var(--amber-soft); }
.mp-ava {
  width: 26px; height: 26px; flex: none;
  border-radius: 8px; background: var(--panel);
  display: grid; place-items: center;
  font-size: .72rem; font-weight: 700;
}
.mp-ava.slack { background: var(--ice); color: #15122b; border-radius: 50%; }
.mp-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-sub { font-size: .76rem; color: var(--text-dim); }

/* adjuntos pendientes de enviar */
.pending { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px; }
.pending:not(:empty) { padding-bottom: 6px; }
.pend-chip {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--panel); padding: 5px 9px; font-size: .85rem; color: var(--text-dim);
}
.pend-chip img { width: 30px; height: 30px; object-fit: cover; border-radius: 6px; }
.pend-chip button { border: none; background: none; color: var(--danger); font-size: .95rem; padding: 0 2px; }

.composer { display: flex; gap: 10px; align-items: flex-end; padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); }
.composer textarea {
  flex: 1; resize: none; max-height: 160px;
  padding: 11px 14px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text); outline: none;
}
.btn-send {
  width: 42px; height: 42px; flex: none; border: none; border-radius: 50%;
  background: var(--amber); color: #2a1a00; font-size: 1.15rem; font-weight: 700;
}
.btn-send:disabled { background: var(--line); color: var(--text-dim); cursor: default; }
.btn-attach {
  width: 42px; height: 42px; flex: none;
  border: 1px solid var(--line); border-radius: 50%;
  background: none; color: var(--text-dim); font-size: 1.2rem; line-height: 1;
}
.btn-attach:hover { color: var(--amber); border-color: var(--amber); }
.room.dragover .feed { outline: 2px dashed var(--amber); outline-offset: -10px; border-radius: var(--r-lg); }

/* visor de imágenes */
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: #0a081de6; backdrop-filter: blur(4px);
  display: grid; place-items: center; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: var(--r-md); box-shadow: 0 20px 80px #000; }

/* ─── Diálogos ─── */
dialog {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--panel); color: var(--text);
  padding: 0; width: min(430px, calc(100vw - 32px));
}
dialog::backdrop { background: #0a081dcc; backdrop-filter: blur(3px); }
.dlg { padding: 24px; }
dialog.wide { width: min(580px, calc(100vw - 32px)); }
.dlg h2 { font-family: var(--font-brand); font-weight: 700; margin: 0 0 14px; font-size: 1.25rem; }
.dlg h3 { font-size: .95rem; margin: 0 0 6px; }
.dlg label { display: block; margin-bottom: 12px; }
.dlg-help { color: var(--text-dim); font-size: .88rem; margin: 0 0 14px; }
.dlg-help code { color: var(--ice); }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.dlg-actions .btn-primary { width: auto; }
.org-sep { text-align: center; color: var(--text-dim); margin: 14px 0; font-size: .85rem; }
.btn-slack {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 18px;
  border: none; border-radius: var(--r-sm);
  background: var(--ice); color: #0d2238;
  font-weight: 700; font-size: 1rem;
  margin-bottom: 4px;
}
.btn-slack:hover { filter: brightness(1.06); }
.slack-logo { font-weight: 800; letter-spacing: -2px; transform: rotate(45deg); display: inline-block; }
#form-org-create .btn-primary { margin-top: 2px; }

.pick-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; }
.pick-list button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border: none; background: none;
  border-radius: var(--r-sm); text-align: left;
}
.pick-list button:hover { background: var(--panel-2); }

.set-block { margin-bottom: 20px; }
.invite-row { display: flex; align-items: center; gap: 10px; margin: 6px 0 10px; }
.invite-row code {
  flex: 1; background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 9px 12px;
  letter-spacing: .12em; color: var(--amber); font-weight: 700;
}
.org-admin-row { display: flex; gap: 8px; align-items: center; margin: 6px 0 10px; flex-wrap: wrap; }
.org-admin-row input { flex: 1; min-width: 150px; }
.org-logo-lbl {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px dashed var(--line); border-radius: var(--r-sm);
  padding: 8px 12px; cursor: pointer; color: var(--text-dim); font-size: .9rem;
  margin: 0;
}
.org-logo-lbl:hover { border-color: var(--amber); color: var(--amber); }
.org-logo-preview { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.bridge-list { list-style: none; margin: 0 0 12px; padding: 0; }
.bridge-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: 1px solid var(--line);
  border-radius: var(--r-sm); margin-bottom: 6px; font-size: .9rem;
}
.bridge-list .grow { flex: 1; }
.bridge-list .del { border: none; background: none; color: var(--danger); }
.bridge-form { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.bridge-form .btn-primary { grid-column: 1 / -1; width: auto; justify-self: end; }
.bridge-arrow { color: var(--ice); }

/* ─── Móvil ─── */
.only-mobile { display: none; }
@media (max-width: 760px) {
  .left {
    position: fixed; inset: 0 22% 0 0; z-index: 30;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 14px 0 40px #00000066;
  }
  .left.open { transform: none; }
  .rail { width: auto; flex: 1; }
  .only-mobile { display: inline-block; }
  .bridge-form { grid-template-columns: 1fr; }
  .bridge-arrow { display: none; }
  .att-img { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
