/* Grok chat — dry-run sidebar + mobile overlay
   Ethos dark · gold accents · clear separation from main app */

:root {
  --chat-w: 400px;
}
@media (min-width: 1400px) {
  :root { --chat-w: 420px; }
}
@media (max-width: 960px) {
  :root { --chat-w: 100vw; }
}


.grok-page-banner {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  background: linear-gradient(90deg, #5c1f18, #8a3428 40%, #5c1f18);
  color: #ffe8e2;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255, 180, 168, 0.25);
}
.grok-page-banner .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #ffb4a8;
  animation: pulse 1.8s ease infinite;
}

/* When chat is open, keep the red banner out of the chat column */
body.grok-chat-open .grok-page-banner {
  margin-right: var(--chat-w, 400px);
  transition: margin-right 0.28s var(--ease);
}
@media (max-width: 960px) {
  body.grok-chat-open .grok-page-banner { margin-right: 0; }
}

.chat-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--amber-soft);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.chat-toggle-btn:hover {
  border-color: rgba(232, 184, 109, 0.45);
  background: var(--card-hover);
}
.chat-toggle-btn.active {
  border-color: rgba(232, 184, 109, 0.55);
  background: var(--amber-dim);
  color: var(--amber);
}
.chat-toggle-btn svg { flex-shrink: 0; }

/* ── Desktop right sidebar ─────────────────────────────── */
.grok-chat {
  --chat-pad-x: 16px;
  --composer-btn: 44px;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--chat-w);
  min-width: 360px;
  max-width: 100vw;
  z-index: 100; /* above page banner so header stays usable */
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(26, 24, 22, 0.97) 0%, rgba(18, 17, 16, 0.99) 40%, #121110 100%);
  color: var(--text);
  /* Clear separator — gold-tinted border + depth shadow (no harsh white hairline) */
  border-left: 1px solid rgba(232, 184, 109, 0.22);
  box-shadow:
    -1px 0 0 rgba(0, 0, 0, 0.55),
    -16px 0 48px rgba(0, 0, 0, 0.45),
    -4px 0 24px rgba(0, 0, 0, 0.25);
  transform: translateX(100%);
  transition: transform 0.28s var(--ease);
  overflow: hidden;
}
.grok-chat.open { transform: translateX(0); }

body.grok-chat-open .app {
  margin-right: var(--chat-w, 400px);
  transition: margin-right 0.28s var(--ease);
}
@media (max-width: 960px) {
  body.grok-chat-open .app { margin-right: 0; }
}

/* ── Header ────────────────────────────────────────────── */
.grok-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px var(--chat-pad-x);
  border-bottom: 1px solid rgba(232, 184, 109, 0.14);
  background:
    linear-gradient(180deg, rgba(34, 31, 28, 0.95) 0%, rgba(26, 24, 22, 0.9) 100%);
  flex-shrink: 0;
  min-height: 56px;
}
.grok-chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 0;
}
.grok-chat-mark {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--amber-dim);
  border: 1px solid rgba(232, 184, 109, 0.35);
  color: var(--amber);
  flex-shrink: 0;
}
.grok-chat-title-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.grok-chat-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--cream);
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1.2;
}
.grok-chat-subtitle {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.grok-chat-header .spacer { flex: 1; min-width: 4px; }

.grok-model-select {
  max-width: 128px;
  min-width: 96px;
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(232, 184, 109, 0.2);
  background: var(--card);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) calc(50% - 2px),
    calc(100% - 10px) calc(50% - 2px);
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  padding-right: 24px;
}
.grok-model-select:hover,
.grok-model-select:focus {
  outline: none;
  border-color: rgba(232, 184, 109, 0.45);
  color: var(--cream);
}

.grok-chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(232, 220, 198, 0.12);
  background: var(--card);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.grok-chat-close:hover {
  background: var(--card-hover);
  border-color: rgba(232, 184, 109, 0.35);
  color: var(--cream);
}

/* ── Messages ──────────────────────────────────────────── */
.grok-chat-messages {
  flex: 1;
  min-height: 0; /* critical for flex scroll */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px var(--chat-pad-x) 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.grok-chat-messages::-webkit-scrollbar { width: 6px; }
.grok-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(232, 184, 109, 0.22);
  border-radius: 999px;
}

/* Empty state */
.grok-empty {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 28px 12px 36px;
  color: var(--text-secondary);
}
.grok-empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--amber-dim);
  border: 1px solid rgba(232, 184, 109, 0.28);
  color: var(--amber);
  margin-bottom: 4px;
}
.grok-empty h3 {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--cream);
  margin: 0;
}
.grok-empty p {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
  max-width: 260px;
  margin: 0;
}
.grok-empty-hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
}
.grok-empty-hints span {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(232, 184, 109, 0.18);
  background: rgba(232, 184, 109, 0.06);
  color: var(--amber-soft);
}

.grok-msg {
  max-width: 92%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.grok-msg.user {
  align-self: flex-end;
  background: var(--amber-dim);
  border: 1px solid rgba(232, 184, 109, 0.28);
  color: var(--cream);
  border-bottom-right-radius: 4px;
}
.grok-msg.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.grok-msg.system-note {
  align-self: center;
  max-width: 100%;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 4px 8px;
}
.grok-msg .atts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.grok-msg .att-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(0,0,0,0.25);
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.grok-msg .att-chip img {
  width: 28px; height: 28px; object-fit: cover; border-radius: 4px;
}

/* ── Composer ──────────────────────────────────────────── */
.grok-chat-composer {
  border-top: 1px solid rgba(232, 184, 109, 0.14);
  background:
    linear-gradient(180deg, rgba(26, 24, 22, 0.92) 0%, rgba(18, 17, 16, 0.98) 100%);
  padding: 12px var(--chat-pad-x) calc(14px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}

.grok-attach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 0;
  min-height: 0;
}
.grok-attach-row:not(:empty) { margin-bottom: 10px; }

.grok-attach-preview {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(232, 184, 109, 0.2);
  background: var(--card);
}
.grok-attach-preview img {
  width: 100%; height: 100%; object-fit: cover;
}
.grok-attach-preview .pdf-label {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  font-size: 0.65rem; font-weight: 700; color: var(--amber);
  text-align: center; padding: 4px;
}
.grok-attach-preview .rm {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  border: none; background: rgba(0,0,0,0.65); color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer;
}

.grok-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.grok-attach-btn,
.grok-send-btn {
  flex-shrink: 0;
  width: var(--composer-btn);
  height: var(--composer-btn);
  border-radius: 12px;
  border: 1px solid rgba(232, 220, 198, 0.12);
  background: var(--card);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.grok-attach-btn:hover {
  color: var(--amber);
  border-color: rgba(232, 184, 109, 0.4);
  background: var(--card-hover);
}
.grok-send-btn {
  background: linear-gradient(180deg, rgba(232, 184, 109, 0.32), rgba(232, 184, 109, 0.18));
  color: var(--cream);
  border-color: rgba(232, 184, 109, 0.45);
}
.grok-send-btn:hover {
  background: linear-gradient(180deg, rgba(232, 184, 109, 0.42), rgba(232, 184, 109, 0.26));
  color: #fff;
}
.grok-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.grok-composer-input {
  flex: 1;
  min-width: 0;
  min-height: var(--composer-btn);
  max-height: 140px;
  resize: none;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(232, 220, 198, 0.12);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-y: auto;
  /* Prevent placeholder/descenders from clipping */
  box-sizing: border-box;
}
.grok-composer-input::placeholder {
  color: var(--muted);
  opacity: 1;
  line-height: 1.45;
}
.grok-composer-input:focus {
  outline: none;
  border-color: rgba(232, 184, 109, 0.45);
  box-shadow: 0 0 0 3px rgba(232, 184, 109, 0.1);
}

.grok-chat-status {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 8px;
  min-height: 1.1em;
  padding: 0 2px;
}
.grok-chat-status.error { color: var(--expense); }

/* ── Mobile: full-screen overlay ───────────────────────── */
@media (max-width: 960px) {
  .grok-chat {
    width: 100vw;
    min-width: 0;
    --chat-pad-x: 14px;
    border-left: none;
    box-shadow: none;
    background: var(--bg);
  }
  .grok-chat-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }
  .grok-chat-close {
    background: var(--card);
    border-color: var(--border-strong);
  }
  .grok-model-select { max-width: 120px; }
  .grok-chat-composer {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .grok-chat-subtitle { display: none; }
}
