/*
 * Oracle chat — visual layer (Fable-owned; behavior lives in oracle-chat.js).
 *
 * PRIMARY: the chat is EMBEDDED at the bottom of the floating control panel
 * (`.panel-chat` inside `.galaxy-panel` in index.html — ids oc-messages /
 * oc-input / oc-send). Styled to read as the panel's footer dock: same glass,
 * ORACLE-orange accent, compact type to fit the 272px panel.
 *
 * FALLBACK: if that markup is ever missing, oracle-chat.js self-mounts a
 * floating bubble (`.oc-fab` / `.oc-panel`). Those styles are kept at the
 * bottom, scoped so they never leak into the embedded look.
 *
 * Message classes applied at runtime (shared by both mounts):
 *   .oc-msg .oc-user .oc-oracle .oc-hint  — bubbles
 *   .oc-note                              — small meta line
 *   .oc-typing                            — three-dot indicator
 */

:root {
  --oc-accent: #d97757;
  --oc-accent-hi: #f0946f;
  --oc-accent-soft: rgba(217, 119, 87, 0.14);
  --oc-edge: rgba(255, 255, 255, 0.09);
  --oc-text: #e9e6f5;      /* --starlight */
  --oc-dim: #8f87b8;       /* --dust */
  --oc-faint: #5e5880;     /* --faint */
  --oc-bubble: rgba(255, 255, 255, 0.055);
}

/* ============ EMBEDDED CHAT — footer dock of the control panel ============ */

.panel-chat {
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.34));
  user-select: text;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px 7px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 2.6px;
  color: var(--oc-faint);
  user-select: none;
}
.chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--oc-accent);
  box-shadow: 0 0 9px rgba(217, 119, 87, 0.85);
  animation: oc-pulse 3.2s ease-in-out infinite;
}
@keyframes oc-pulse {
  0%, 100% { opacity: 0.65; box-shadow: 0 0 5px rgba(217, 119, 87, 0.5); }
  50%      { opacity: 1;    box-shadow: 0 0 11px rgba(217, 119, 87, 0.95); }
}

/* scrollable message log */
.chat-log {
  height: 176px;
  min-height: 90px;
  overflow-y: auto;
  padding: 2px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}
.chat-log::-webkit-scrollbar { width: 5px; }
.chat-log::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 3px; }

/* input row */
.chat-input-row {
  display: flex;
  gap: 7px;
  align-items: flex-end;
  padding: 9px 12px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.055);
}
.chat-input {
  flex: 1;
  min-width: 0;
  resize: none;
  min-height: 34px;
  max-height: 120px;
  padding: 8px 11px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--oc-text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--oc-edge);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  scrollbar-width: thin;
}
.chat-input::placeholder { color: var(--oc-faint); }
.chat-input:focus {
  border-color: rgba(217, 119, 87, 0.55);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.12);
}
.chat-send {
  flex: none;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--oc-accent-hi), var(--oc-accent) 70%);
  box-shadow: 0 2px 10px rgba(217, 119, 87, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.12s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.chat-send:hover { box-shadow: 0 3px 14px rgba(217, 119, 87, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.18); }
.chat-send:active { transform: scale(0.94); }
.chat-send:disabled { opacity: 0.35; cursor: default; transform: none; box-shadow: none; }

/* ============ MESSAGES (shared by embedded + fallback mounts) ============ */

.oc-msg {
  max-width: 88%;
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
.oc-msg.oc-user {
  align-self: flex-end;
  color: #fff;
  background: linear-gradient(160deg, var(--oc-accent-hi), var(--oc-accent) 75%);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(217, 119, 87, 0.25);
}
.oc-msg.oc-oracle {
  align-self: flex-start;
  color: var(--oc-text);
  background: var(--oc-bubble);
  border: 1px solid var(--oc-edge);
  border-bottom-left-radius: 4px;
}
.oc-msg.oc-hint {
  align-self: center;
  max-width: 96%;
  text-align: center;
  font-size: 11.5px;
  color: var(--oc-text);
  background: var(--oc-accent-soft);
  border: 1px solid rgba(217, 119, 87, 0.45);
}
.oc-msg code {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 11px;
}

.oc-note {
  align-self: flex-start;
  margin-top: -4px;
  padding: 0 4px;
  font-size: 10.5px;
  color: var(--oc-faint);
}

.oc-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  background: var(--oc-bubble);
  border: 1px solid var(--oc-edge);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.oc-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--oc-dim);
  animation: oc-blink 1.2s infinite;
}
.oc-typing span:nth-child(2) { animation-delay: 0.2s; }
.oc-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes oc-blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .chat-dot { animation: none; }
  .oc-typing span { animation: none; opacity: 0.6; }
}

/* ============ FLOATING FALLBACK (only if embedded markup is absent) ============ */

.oc-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 9000;
  background: radial-gradient(circle at 32% 28%, var(--oc-accent-hi), var(--oc-accent) 70%);
  box-shadow: 0 6px 22px rgba(217, 119, 87, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  font-size: 26px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.oc-fab:hover { transform: scale(1.06); box-shadow: 0 8px 28px rgba(217, 119, 87, 0.6); }
.oc-fab:active { transform: scale(0.97); }
.oc-fab.oc-hidden { display: none; }

.oc-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 44px));
  z-index: 9001;
  display: flex;
  flex-direction: column;
  background: rgba(18, 20, 28, 0.92);
  border: 1px solid var(--oc-edge);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--oc-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  transform-origin: bottom right;
  animation: oc-pop 0.16s ease-out;
}
@keyframes oc-pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } to { opacity: 1; transform: none; } }
.oc-panel.oc-hidden { display: none; }

.oc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--oc-edge);
}
.oc-header .oc-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--oc-accent); box-shadow: 0 0 10px var(--oc-accent);
}
.oc-header h2 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: 0.3px; }
.oc-header .oc-sub { font-size: 11px; color: var(--oc-dim); margin-left: 2px; }
.oc-close {
  margin-left: auto; background: none; border: none; color: var(--oc-dim);
  font-size: 20px; cursor: pointer; line-height: 1; padding: 2px 6px; border-radius: 8px;
}
.oc-close:hover { color: var(--oc-text); background: rgba(255,255,255,0.06); }

.oc-panel .oc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}
.oc-panel .oc-messages::-webkit-scrollbar { width: 6px; }
.oc-panel .oc-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

.oc-panel .oc-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--oc-edge); align-items: flex-end; }
.oc-panel .oc-input {
  flex: 1; resize: none; max-height: 120px; min-height: 40px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--oc-edge);
  border-radius: 12px; color: var(--oc-text); font-size: 13.5px; padding: 10px 12px;
  font-family: inherit; line-height: 1.4; outline: none;
}
.oc-panel .oc-input:focus { border-color: var(--oc-accent); }
.oc-panel .oc-input::placeholder { color: var(--oc-dim); }
.oc-panel .oc-send {
  width: 40px; height: 40px; flex: none; border-radius: 12px; border: none; cursor: pointer;
  background: var(--oc-accent); color: #fff; font-size: 17px; display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s ease;
}
.oc-panel .oc-send:hover { opacity: 0.9; }
.oc-panel .oc-send:disabled { opacity: 0.4; cursor: default; }
