/* ==========================================================
   ASK PDEC - Chat Panel Styles
   Uses existing CSS variables from styles.css
   ========================================================== */

/* --- Nav Button --- */
.nav-chat-btn {
  background: var(--teal);
  color: var(--white);
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
  font-family: inherit;
  text-decoration: none;
  line-height: inherit;
}
.nav-chat-btn:hover {
  background: #0b5a46;
}

/* --- Chat Panel --- */
.chat-panel {
  position: fixed;
  top: 64px;
  right: 0;
  width: 420px;
  max-height: calc(100vh - 64px);
  background: var(--white);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 900;
  transform: translateX(110%);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.2s ease;
}
.chat-panel.open {
  transform: translateX(0);
  opacity: 1;
}

/* --- Panel Header --- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--dark);
}
.chat-header-persona {
  font-size: 11px;
  color: var(--medium);
  font-weight: 500;
}
.chat-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-back-btn,
.chat-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--medium);
  padding: 4px;
  font-size: 18px;
  line-height: 1;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
  font-family: inherit;
}
.chat-back-btn:hover,
.chat-close-btn:hover {
  color: var(--dark);
  background: var(--bg);
}

/* --- Persona Selector --- */
.chat-persona-section {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}
.chat-persona-intro {
  font-size: 13px;
  color: var(--medium);
  margin-bottom: 12px;
  line-height: 1.5;
}
.chat-persona-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.chat-persona-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  text-align: left;
  font-family: inherit;
}
.chat-persona-card:hover {
  border-color: var(--teal);
  box-shadow: 0 0 0 1px var(--teal);
}
.chat-persona-card-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--dark);
  margin-bottom: 2px;
}
.chat-persona-card-hint {
  font-size: 11px;
  color: var(--medium);
  line-height: 1.4;
}

/* --- Messages Area --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* --- Message Bubbles --- */
.chat-msg {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
  word-wrap: break-word;
}
.chat-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--white);
  border-bottom-right-radius: 3px;
}
.chat-msg-assistant {
  align-self: flex-start;
  background: var(--bg);
  color: var(--dark);
  border-bottom-left-radius: 3px;
}
.chat-msg-assistant p { margin: 0 0 8px; }
.chat-msg-assistant p:last-child { margin-bottom: 0; }
.chat-msg-assistant h4 { font-size: 13px; font-weight: 700; color: var(--accent); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: 0.3px; }
.chat-msg-assistant h4:first-child { margin-top: 0; }
.chat-msg-assistant h5 { font-size: 13px; font-weight: 600; color: var(--dark); margin: 8px 0 2px; }
.chat-msg-assistant h5:first-child { margin-top: 0; }
.chat-msg-assistant ul, .chat-msg-assistant ol { margin: 4px 0 8px; padding-left: 18px; }
.chat-msg-assistant li { margin-bottom: 4px; }
.chat-msg-assistant strong { font-weight: 600; }
.chat-inline-cite {
  background: rgba(27, 94, 140, 0.08);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition);
}
.chat-inline-cite:hover { background: rgba(27, 94, 140, 0.18); }
.chat-inline-cite-plain { cursor: default; color: var(--medium); background: rgba(0,0,0,0.04); }
.chat-msg-welcome {
  align-self: flex-start;
  background: rgba(15, 110, 86, 0.06);
  color: var(--dark);
  border: 1px solid rgba(15, 110, 86, 0.12);
  border-bottom-left-radius: 3px;
}
.chat-msg-error {
  align-self: flex-start;
  background: rgba(216, 90, 48, 0.08);
  color: var(--coral);
  border: 1px solid rgba(216, 90, 48, 0.15);
  font-size: 12px;
}

/* --- Citations --- */
.chat-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.chat-citation-tag {
  display: inline-block;
  background: rgba(27, 94, 140, 0.08);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: background var(--transition);
}
.chat-citation-tag:hover {
  background: rgba(27, 94, 140, 0.18);
}

/* --- Follow-up Suggestions --- */
.chat-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-followup-btn {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  font-family: inherit;
  text-align: left;
  line-height: 1.4;
}
.chat-followup-btn:hover {
  border-color: var(--accent);
  background: var(--bg);
}

/* --- Input Form --- */
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--white);
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--dark);
  outline: none;
  transition: border-color var(--transition);
  resize: none;
  min-height: 38px;
  max-height: 80px;
}
.chat-input:focus {
  border-color: var(--accent);
}
.chat-input::placeholder {
  color: var(--medium);
}
.chat-send-btn {
  background: var(--accent);
  color: var(--white);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
  font-family: inherit;
}
.chat-send-btn:hover:not(:disabled) {
  background: var(--accent-dark);
}
.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Loading Dots --- */
.chat-loading {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  align-self: flex-start;
}
.chat-loading-dot {
  width: 6px;
  height: 6px;
  background: var(--medium);
  border-radius: 50%;
  animation: chatBounce 1.2s infinite ease-in-out;
}
.chat-loading-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-loading-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* --- Mobile --- */
@media (max-width: 768px) {
  .chat-panel {
    width: 100vw;
    max-width: 100%;
    left: 0;
    right: 0;
    border-left: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    top: 64px;
    max-height: calc(100vh - 64px);
    box-sizing: border-box;
  }

  .chat-persona-grid {
    grid-template-columns: 1fr;
  }

  .nav-chat-btn {
    width: 100%;
    justify-content: center;
    margin-top: 4px;
  }
}

/* --- Extra small screens --- */
@media (max-width: 480px) {
  .chat-msg { font-size: 12px; padding: 8px 12px; }
  .chat-followup-btn { font-size: 11px; padding: 4px 10px; }
  .chat-followups { padding: 6px 12px; }
  .chat-form { padding: 10px 12px; }
  .chat-input { font-size: 14px; } /* prevent iOS zoom on focus */
  .chat-persona-section { padding: 12px; }
  .chat-persona-card { padding: 10px; }
}

/* --- Backdrop (mobile) --- */
.chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: 64px;
  background: rgba(0, 0, 0, 0.2);
  z-index: 899;
}
.chat-backdrop.active {
  display: block;
}
@media (min-width: 769px) {
  .chat-backdrop { display: none !important; }
}
