/* ══════════════════════════════════════════════════════════════════════
   INTERNAL CHAT — dashboard chat for logged-in users.
   Org members get a room + DMs; solo users get the platform support line.

   Every colour comes from a variable so the panel repaints with the navbar
   theme toggle. Light is the default; [data-theme="dark"] overrides below.
   ══════════════════════════════════════════════════════════════════════ */

:root {
  --ic-surface:     rgba(255, 255, 255, 0.86);
  --ic-surface-2:   rgba(255, 255, 255, 0.96);
  --ic-rail:        rgba(15, 23, 42, 0.035);
  --ic-border:      rgba(15, 23, 42, 0.10);
  --ic-ink:         #1e293b;
  --ic-heading:     #0f172a;
  --ic-muted:       rgba(30, 41, 59, 0.60);
  --ic-hover:       rgba(15, 23, 42, 0.05);
  --ic-active:      rgba(124, 58, 237, 0.10);
  --ic-bubble-them: rgba(15, 23, 42, 0.06);
  --ic-input-bg:    rgba(255, 255, 255, 0.9);
  --ic-shadow:      0 20px 60px rgba(15, 23, 42, 0.18);
  --ic-accent:      #7c3aed;
  --ic-accent-2:    #4f46e5;
  --ic-on-accent:   #ffffff;
  --ic-blur:        blur(18px) saturate(140%);
}

[data-theme="dark"] {
  --ic-surface:     rgba(11, 18, 32, 0.92);
  --ic-surface-2:   rgba(18, 27, 45, 0.96);
  --ic-rail:        rgba(255, 255, 255, 0.04);
  --ic-border:      rgba(255, 255, 255, 0.12);
  --ic-ink:         #eef3f9;
  --ic-heading:     #f8fafc;
  --ic-muted:       rgba(226, 232, 240, 0.60);
  --ic-hover:       rgba(255, 255, 255, 0.07);
  --ic-active:      rgba(167, 139, 250, 0.18);
  --ic-bubble-them: rgba(255, 255, 255, 0.09);
  --ic-input-bg:    rgba(255, 255, 255, 0.07);
  --ic-shadow:      0 20px 60px rgba(0, 0, 0, 0.55);
  --ic-accent:      #a78bfa;
  --ic-accent-2:    #818cf8;
  --ic-on-accent:   #0b1220;
}

/* ── Launcher ─────────────────────────────────────────────────────────── */
.ic-launcher {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 1200;
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--ic-accent), var(--ic-accent-2));
  box-shadow: 0 12px 34px rgba(124, 58, 237, 0.45);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.ic-launcher:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 16px 42px rgba(124, 58, 237, 0.55); }
.ic-launcher svg { width: 26px; height: 26px; }

/* Unread pip */
.ic-launcher .ic-pip {
  position: absolute;
  top: 4px; right: 4px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font: 600 11px/18px system-ui, sans-serif;
  text-align: center;
  display: none;
}
.ic-launcher .ic-pip.show { display: block; }

/* Hide the launcher while the panel is open, so they never overlap. */
.ic-open .ic-launcher { display: none; }

/* ── Panel ────────────────────────────────────────────────────────────── */
.ic-panel {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 1201;
  display: none;
  flex-direction: column;
  width: 380px;
  height: min(580px, calc(100vh - 100px));
  overflow: hidden;
  color: var(--ic-ink);
  background: var(--ic-surface);
  border: 1px solid var(--ic-border);
  border-radius: 18px;
  box-shadow: var(--ic-shadow);
  -webkit-backdrop-filter: var(--ic-blur);
  backdrop-filter: var(--ic-blur);
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
}
.ic-panel.open { display: flex; animation: ic-rise 0.22s ease both; }

/* Org mode needs room for the conversation rail alongside the thread. */
.ic-panel.mode-org { width: 620px; }

@keyframes ic-rise {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ───────────────────────────────────────────────────────────── */
.ic-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ic-border);
  background: var(--ic-rail);
}
.ic-head-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ic-head-title strong {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ic-heading);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ic-head-title span { font-size: 0.75rem; color: var(--ic-muted); }

.ic-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: none; }

.ic-x {
  flex: none;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: none; border-radius: 8px;
  background: transparent;
  color: var(--ic-muted);
  font-size: 20px; line-height: 1;
  cursor: pointer;
}
.ic-x:hover { background: var(--ic-hover); color: var(--ic-ink); }

/* AI Ask — opens the AI assistant from inside the chat header (replaces the
   old standalone floating button). */
.ic-aiask {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 8px; border: 1px solid var(--ic-border);
  background: var(--ic-hover); color: var(--ic-ink); cursor: pointer;
  font-size: 0.76rem; font-weight: 600; font-family: inherit; line-height: 1;
  transition: border-color .15s, color .15s;
}
.ic-aiask i { font-size: 0.8rem; color: #7c3aed; }
.ic-aiask:hover { border-color: #7c3aed; color: #7c3aed; }
@media (max-width: 400px) { .ic-aiask span { display: none; } }

/* Starter questions shown in the thread when the AI conversation opens. */
.ic-ai-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0 2px; }
.ic-ai-chip {
  font-size: 0.74rem; padding: 6px 10px; border-radius: 999px; cursor: pointer;
  background: var(--ic-hover); border: 1px solid var(--ic-border);
  color: var(--ic-ink); font-family: inherit; line-height: 1;
  transition: border-color .15s, color .15s;
}
.ic-ai-chip:hover { border-color: #7c3aed; color: #7c3aed; }

/* ── Body: rail + thread ──────────────────────────────────────────────── */
.ic-body { display: flex; flex: 1; min-height: 0; }

.ic-rail {
  display: none;               /* only shown in org mode */
  flex-direction: column;
  width: 210px;
  flex: none;
  border-right: 1px solid var(--ic-border);
  background: var(--ic-rail);
  overflow-y: auto;
}
.ic-panel.mode-org .ic-rail { display: flex; }

.ic-rail-label {
  padding: 12px 14px 6px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ic-muted);
}

.ic-convo {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 14px;
  border: none;
  background: transparent;
  color: var(--ic-ink);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}
.ic-convo:hover  { background: var(--ic-hover); }
.ic-convo.active { background: var(--ic-active); font-weight: 600; }

.ic-avatar {
  width: 26px; height: 26px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  object-fit: cover;
  background: linear-gradient(135deg, var(--ic-accent), var(--ic-accent-2));
  color: #fff;
  font: 600 11px/1 system-ui, sans-serif;
  text-transform: uppercase;
}

.ic-convo-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ic-convo-role { font-size: 0.68rem; color: var(--ic-muted); font-weight: 400; }

.ic-thread-wrap { display: flex; flex-direction: column; flex: 1; min-width: 0; }

/* ── Messages ─────────────────────────────────────────────────────────── */
.ic-thread {
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ic-msg { display: flex; flex-direction: column; max-width: 78%; }
.ic-msg.mine { align-self: flex-end; align-items: flex-end; }

.ic-msg-who {
  margin-bottom: 3px;
  padding: 0 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ic-muted);
}

.ic-bubble {
  padding: 9px 13px;
  border-radius: 14px 14px 14px 4px;
  background: var(--ic-bubble-them);
  font-size: 0.87rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.ic-msg.mine .ic-bubble {
  border-radius: 14px 14px 4px 14px;
  background: linear-gradient(135deg, var(--ic-accent), var(--ic-accent-2));
  color: var(--ic-on-accent);
}
/* AI replies read as assistive, not as a teammate. */
.ic-msg.ai .ic-bubble { border: 1px dashed var(--ic-border); background: transparent; }

.ic-msg-at { margin-top: 3px; padding: 0 4px; font-size: 0.66rem; color: var(--ic-muted); }

.ic-empty  { margin: auto; padding: 20px; text-align: center; font-size: 0.83rem; color: var(--ic-muted); }
.ic-typing { padding: 0 16px 6px; font-size: 0.74rem; font-style: italic; color: var(--ic-muted); min-height: 18px; }

/* ── Composer ─────────────────────────────────────────────────────────── */
.ic-composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--ic-border);
  background: var(--ic-surface-2);
}
.ic-composer input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--ic-border);
  border-radius: 22px;
  background: var(--ic-input-bg);
  color: var(--ic-ink);
  font-size: 0.87rem;
  outline: none;
}
.ic-composer input::placeholder { color: var(--ic-muted); }
.ic-composer input:focus { border-color: var(--ic-accent); }

.ic-send {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--ic-accent), var(--ic-accent-2));
}
.ic-send:disabled { opacity: 0.45; cursor: not-allowed; }
.ic-send svg { width: 17px; height: 17px; }

/* ── Winning against the global dark-mode text rule ───────────────────────
   dashboard-theme.css declares `[data-theme="dark"] span { color: … !important }`
   for EVERY span on the page. This panel is built from spans, so without
   re-asserting here the avatar initials and the unread badge lose their white
   and turn grey-on-purple in dark mode. These use vars, so they stay correct
   in light too. Specificity alone can't win against !important — only
   !important can. */
.ic-panel .ic-avatar,
.ic-launcher .ic-pip            { color: #fff !important; }
.ic-panel .ic-convo-name        { color: var(--ic-ink) !important; }
.ic-panel .ic-convo-role,
.ic-panel .ic-head-title span   { color: var(--ic-muted) !important; }

/* ── Small screens: fill the viewport rather than float ───────────────── */
@media (max-width: 700px) {
  .ic-panel,
  .ic-panel.mode-org {
    right: 0; bottom: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }
  .ic-panel.mode-org .ic-rail { width: 150px; }
}
