/* ── Atlas SideChat ───────────────────────────────────────────────────
   External CSS for the Atlas companion panel.
   Uses shared CSS variables from the host theme.
   No hardcoded colors, sizes, or fonts.
   Supports: language (dir-aware), accessibility (focus, contrast, motion),
             responsive (mobile), theme inheritance.
   ──────────────────────────────────────────────────────────────────── */

/* ── Panel shell ─────────────────────────────────────────────────────── */

.atlas-sidechat {
  position: fixed;
  top: var(--gx-sidepanel-top, 88px);
  right: 14px;
  bottom: auto;
  left: auto;
  height: var(--gx-sidepanel-height, calc(var(--gx-host-vh, 100dvh) - 104px));
  width: var(--gx-sidepanel-width, min(460px, 92vw));
  max-width: 92vw;
  background: var(--gx-panel);
  border: 1px solid var(--gx-border);
  border-radius: 18px;
  box-shadow: 0 18px 42px rgba(15,23,42,0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  font-family: inherit;
  color: var(--gx-ink);
}
.atlas-sidechat[data-layout='shell'] {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  left: auto;
  height: min(62dvh, calc(var(--gx-host-vh, 100dvh) - 132px));
  width: 100%;
  max-width: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  z-index: auto;
  transform: none;
}
.atlas-sidechat[data-layout='shell'][hidden] {
  display: flex;
}
.atlas-sidechat--open {
  transform: translateX(0);
}

/* RTL support */
[dir="rtl"] .atlas-sidechat {
  right: auto;
  left: 14px;
  transform: translateX(-100%);
}
[dir="rtl"] .atlas-sidechat--open {
  transform: translateX(0);
}
[dir="rtl"] .atlas-sidechat[data-layout='shell'] {
  transform: none;
}

/* ── Header ──────────────────────────────────────────────────────────── */

.atlas-sidechat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--gx-accent, #0b3a68);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.atlas-sidechat-badge {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--gx-panel);
  border: 1px solid var(--gx-border);
  overflow: hidden;
  flex-shrink: 0;
}
.atlas-sidechat-badge-icon {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}
.atlas-sidechat-title {
  flex: 1;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
}
.atlas-sidechat-close {
  appearance: none;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #fff;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.atlas-sidechat-close:hover,
.atlas-sidechat-close:focus-visible {
  background: rgba(255,255,255,0.12);
  outline: 2px solid rgba(255,255,255,0.45);
  outline-offset: 2px;
}

/* ── Message log ─────────────────────────────────────────────────────── */

.atlas-sidechat-log {
  flex: 1;
  min-height: 0;       /* prevents flex item from outgrowing the container */
  overflow-y: auto;
  padding: 12px 14px;
}
.atlas-sidechat-caption {
  padding: 0 16px 10px;
  font-size: var(--gx-font-size-xs, 12px);
  color: var(--gx-muted);
}
.atlas-sidechat-caption[hidden] {
  display: none;
}
.atlas-msg {
  margin-bottom: 10px;
  font-size: var(--gx-font-size-base, 14px);
  line-height: var(--gx-line-height-base, 1.5);
  padding: 8px 12px;
  border-radius: 8px;
}
.atlas-msg--atlas {
  background: var(--gx-panel2);
  color: var(--gx-ink);
}
.atlas-msg--user {
  background: var(--gx-accent);
  color: var(--gx-btn-ink, #ffffff);
  text-align: right;
}
[dir="rtl"] .atlas-msg--user {
  text-align: left;
}
.atlas-msg-label {
  font-weight: 600;
  font-size: var(--gx-font-size-xs, 12px);
  margin-bottom: 2px;
  display: block;
}

/* ── Suggestions ─────────────────────────────────────────────────────── */

.atlas-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.atlas-suggestion-btn {
  appearance: none;
  background: var(--gx-panel);
  border: 1px solid var(--gx-border);
  border-radius: 16px;
  padding: 4px 12px;
  font-size: var(--gx-font-size-xs, 12px);
  cursor: pointer;
  color: var(--gx-accent);
  font-weight: 600;
  font-family: inherit;
  transition: background 0.15s;
}
.atlas-suggestion-btn:hover,
.atlas-suggestion-btn:focus-visible {
  background: var(--gx-panel2);
  outline: 2px solid var(--gx-accent);
  outline-offset: 2px;
}

/* ── Input row ───────────────────────────────────────────────────────── */

.atlas-sidechat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--gx-border);
  background: var(--gx-panel);
  flex-shrink: 0;
}
.atlas-sidechat-input {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--gx-border);
  font-size: var(--gx-font-size-base, 14px);
  font-family: inherit;
  color: var(--gx-ink);
  background: var(--gx-bg);
}
.atlas-sidechat-input:focus {
  outline: none;
  border-color: var(--gx-accent);
  box-shadow: 0 0 0 2px var(--gx-focus-ring, rgba(26, 115, 232, 0.25));
}
.atlas-sidechat-send {
  appearance: none;
  min-width: var(--gx-control-height-sm, 34px);
  height: var(--gx-control-height-sm, 34px);
  border-radius: 8px;
  border: none;
  background: var(--gx-accent);
  color: var(--gx-btn-ink, #ffffff);
  font-size: 1em;
  cursor: pointer;
  flex-shrink: 0;
}
.atlas-sidechat-send:hover {
  opacity: 0.9;
}
.atlas-sidechat-send:focus-visible {
  outline: 2px solid var(--gx-accent);
  outline-offset: 2px;
}

/* ── Accessibility: reduced motion ───────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .atlas-sidechat {
    transition: none;
  }
}

/* ── Accessibility: high contrast ────────────────────────────────────── */

@media (forced-colors: active) {
  .atlas-msg--atlas,
  .atlas-msg--user {
    border: 1px solid ButtonText;
  }
  .atlas-suggestion-btn {
    border: 1px solid ButtonText;
  }
}

/* ── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .atlas-sidechat[data-layout='shell'] {
    min-height: 52dvh;
    height: min(68dvh, calc(var(--gx-host-vh, 100dvh) - 116px));
  }
  .atlas-sidechat {
    top: 74px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-width: none;
    height: auto;
    max-height: calc(var(--gx-host-vh, 100dvh) - 86px);
  }
  .atlas-sidechat[data-layout='shell'] {
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    height: min(52dvh, 420px);
    max-height: min(52dvh, 420px);
  }
}
