/* ==========================================================================
   LineGuard AI — AI narrative layer + chat assistant (session 3)
   Brand-restrained: DM Sans for prose, DM Mono for figures, one blue accent.
   ========================================================================== */

/* ---- Shared AI fragments ------------------------------------------------- */

.ai-mark {
  font-family: var(--athera-display);
  color: var(--athera-blue);
  font-weight: 400;
  line-height: 1;
}

.figure { font-family: var(--athera-mono); color: var(--athera-charcoal); font-size: 0.94em; }

.ai-fallback-note {
  font-family: var(--athera-sans);
  font-size: 12px;
  color: var(--athera-grey);
  font-style: italic;
  margin: 0 0 8px;
}

/* Loading shimmer */
.ai-shimmer { display: flex; flex-direction: column; gap: 8px; }
.ai-shimmer .shimmer-line {
  height: 10px; border-radius: 3px;
  background: linear-gradient(90deg, var(--athera-surface) 25%, var(--athera-mist) 37%, var(--athera-surface) 63%);
  background-size: 400% 100%;
  animation: ai-shimmer 1.4s ease infinite;
}
@keyframes ai-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ---- Dashboard: planning narrative panel --------------------------------- */

.ai-panel .label .ai-mark { font-size: 14px; margin-right: 2px; vertical-align: -1px; }
.ai-narrative p {
  font-family: var(--athera-sans);
  font-size: 13.5px; line-height: 1.66;
  color: var(--athera-charcoal-light);
  margin: 0 0 10px;
}
.ai-narrative p:last-child { margin-bottom: 0; }

/* ---- Dashboard: explain this alert --------------------------------------- */

.btn-sm { font-size: 11px; padding: 7px 14px; }
.explain-btn .ai-mark { font-size: 13px; margin-right: 4px; vertical-align: -1px; }

.explain-block { margin-top: var(--sp-2); }
.explain-out { margin-top: var(--sp-2); }
.explain-text {
  border-left: 2px solid var(--athera-blue);
  padding: 2px 0 2px var(--sp-2);
}
.explain-text p {
  font-family: var(--athera-sans);
  font-size: 13.5px; line-height: 1.66; color: var(--athera-charcoal);
  margin: 0;
}
.explain-caveats {
  list-style: none; margin: 10px 0 0; padding: 0;
}
.explain-caveats li {
  font-family: var(--athera-sans); font-size: 12.5px; line-height: 1.5;
  color: var(--athera-grey); padding-left: 16px; position: relative; margin-bottom: 4px;
}
.explain-caveats li::before {
  content: "!"; position: absolute; left: 0; top: 0;
  font-family: var(--athera-display); color: var(--athera-amber); font-weight: 500;
}

/* ---- Brief: AI narration slots ------------------------------------------- */

.ai-narration:empty { display: none; }
.ai-narration { margin: 0 0 var(--sp-2); }
.ai-narration-text {
  font-family: var(--athera-sans);
  font-size: 14px; line-height: 1.7; color: var(--athera-charcoal);
  margin: 0;
}

/* ==========================================================================
   Chat assistant
   ========================================================================== */

.chat-launcher {
  position: fixed; right: 28px; bottom: 28px; z-index: 60;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 18px;
  background: var(--athera-navy); color: #fff;
  border: 1px solid var(--athera-line-dark);
  border-radius: 40px;
  font-family: var(--athera-sans); font-size: 13px; font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.18);
  transition: background 0.2s ease, opacity 0.2s ease;
}
.chat-launcher:hover { background: var(--athera-navy-mid); }
.chat-launcher .ai-mark { color: var(--athera-blue); font-size: 16px; }
.chat-launcher.route-hidden { display: none; }

.chat-panel {
  position: fixed; right: 28px; bottom: 28px; z-index: 61;
  width: 400px; max-width: calc(100vw - 32px);
  height: 600px; max-height: calc(100vh - 48px);
  display: none; flex-direction: column;
  background: var(--athera-white);
  border: 1px solid var(--athera-line);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
  overflow: hidden;
}
.chat-panel.open { display: flex; animation: chat-in 0.22s ease; }
@keyframes chat-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  background: var(--athera-navy);
  border-bottom: 1px solid var(--athera-line-dark);
}
.chat-head .label { color: #fff; display: flex; align-items: center; gap: 6px; }
.chat-head .label .ai-mark { color: var(--athera-blue); font-size: 15px; }
.chat-scope {
  display: block; margin-top: 4px;
  font-family: var(--athera-mono); font-size: 10px; letter-spacing: 0.04em;
  color: var(--athera-blue-light);
}
.chat-close {
  background: transparent; border: none; color: rgba(255,255,255,0.7);
  font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.chat-close:hover { color: #fff; }

.chat-notice {
  margin: 0; padding: 8px var(--sp-3);
  background: var(--athera-surface);
  border-bottom: 1px solid var(--athera-line-light);
  font-family: var(--athera-sans); font-size: 11px; line-height: 1.4;
  color: var(--athera-grey);
}

.chat-log {
  flex: 1; overflow-y: auto;
  padding: var(--sp-3);
  display: flex; flex-direction: column; gap: var(--sp-2);
}

.chat-msg { display: flex; gap: 8px; max-width: 100%; }
.chat-msg .bubble {
  font-family: var(--athera-sans); font-size: 13.5px; line-height: 1.6;
  padding: 10px 14px; border-radius: 12px;
}
.chat-msg .bubble p { margin: 0 0 8px; }
.chat-msg .bubble p:last-child { margin-bottom: 0; }

.chat-user { justify-content: flex-end; }
.chat-user .bubble {
  background: var(--athera-navy); color: #fff;
  border-bottom-right-radius: 3px; max-width: 80%;
}

.chat-assistant { justify-content: flex-start; }
.chat-assistant .bubble {
  background: var(--athera-surface); color: var(--athera-charcoal);
  border-bottom-left-radius: 3px; max-width: 86%;
}
.chat-avatar {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  background: var(--athera-navy);
  display: inline-flex; align-items: center; justify-content: center;
}
.chat-avatar .ai-mark { color: var(--athera-blue); font-size: 14px; }
.chat-assistant .bubble .figure { color: var(--athera-blue-deep); }
.chat-assistant .bubble .ai-fallback-note { display: block; }

/* typing indicator */
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--athera-grey-light);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-starters {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0 var(--sp-3) var(--sp-2);
}
.chat-chip {
  font-family: var(--athera-sans); font-size: 12px; line-height: 1.3;
  text-align: left;
  padding: 8px 12px;
  background: var(--athera-white);
  border: 1px solid var(--athera-line);
  border-radius: 16px;
  color: var(--athera-charcoal-light);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}
.chat-chip:hover { border-color: var(--athera-blue); color: var(--athera-blue-deep); }

.chat-input {
  display: flex; gap: 8px; align-items: center;
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--athera-line);
  background: var(--athera-white);
}
.chat-input input {
  flex: 1;
  font-family: var(--athera-sans); font-size: 13.5px;
  padding: 10px 14px;
  border: 1px solid var(--athera-line);
  border-radius: 20px;
  color: var(--athera-charcoal);
  background: var(--athera-off-white);
  outline: none;
  transition: border-color 0.2s ease;
}
.chat-input input:focus { border-color: var(--athera-blue); }
.chat-send { white-space: nowrap; }

@media (max-width: 480px) {
  .chat-panel { right: 8px; bottom: 8px; height: calc(100vh - 16px); }
  .chat-launcher { right: 12px; bottom: 12px; }
}
