.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(13,17,23,0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--canvas);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp .2s ease;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 28px 20px;
  border-bottom: 1px solid var(--divider);
  position: sticky;
  top: 0;
  background: var(--canvas);
  z-index: 1;
}
.modal-eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--chip-text);
  background: var(--chip-bg);
  border-radius: var(--r-pill);
  padding: 3px 10px;
  margin-bottom: 8px;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.3px;
  color: var(--ink);
  margin-bottom: 4px;
}
.modal-id {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-48);
}
.modal-close {
  flex-shrink: 0;
  background: var(--parchment);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-48);
  font-size: 14px;
  transition: background .15s, color .15s;
}
.modal-close:hover { background: var(--divider); color: var(--ink); }

.modal-body { padding: 24px 28px 32px; }
.modal-section { margin-bottom: 24px; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--ink-48);
  margin-bottom: 8px;
}
.modal-section-body {
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: -0.2px;
  color: var(--ink-80);
}
.modal-keywords { display: flex; flex-wrap: wrap; gap: 6px; }
.modal-keyword {
  font-size: 12px;
  color: var(--ink-80);
  background: var(--parchment);
  border: 1px solid var(--divider);
  border-radius: var(--r-pill);
  padding: 4px 12px;
}
.modal-key-sections { display: flex; flex-direction: column; gap: 16px; }
.key-section-item {
  background: var(--parchment);
  border-radius: var(--r-md);
  padding: 16px;
  border-left: 3px solid var(--accent);
}
.key-section-name {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.key-section-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-80);
}

/* ── AI Chat Panel ── */
.ai-panel {
  background: linear-gradient(135deg, rgba(212,83,10,0.04) 0%, rgba(26,34,48,0.04) 100%);
  border: 1px solid rgba(212,83,10,0.15);
  border-radius: var(--r-lg);
  padding: 20px;
  margin-top: 8px;
}
.ai-label-icon {
  color: var(--accent);
  margin-right: 6px;
  font-size: 13px;
}

/* Suggestion chips */
.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.suggestion-chip {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-family: var(--font-text);
  font-size: 13px;
  color: var(--ink-80);
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.suggestion-chip:hover {
  border-color: var(--accent);
  background: rgba(212,83,10,0.04);
  color: var(--ink);
}

/* Chat log */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}
.chat-bubble {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 92%;
}
.chat-bubble--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-bubble--user .bubble-text {
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-md) var(--r-md) 4px var(--r-md);
}
.chat-bubble--ai .bubble-text {
  background: var(--canvas);
  border: 1px solid var(--divider);
  color: var(--ink-80);
  border-radius: var(--r-md) var(--r-md) var(--r-md) 4px;
}
.bubble-text {
  font-size: 14px;
  line-height: 1.6;
  padding: 10px 14px;
  margin: 0;
}
.bubble-label {
  flex-shrink: 0;
  font-size: 14px;
  color: var(--accent);
  margin-top: 10px;
}

/* Typing dots */
.chat-bubble--loading .bubble-text { display: none; }
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--canvas);
  border: 1px solid var(--divider);
  padding: 12px 16px;
  border-radius: var(--r-md) var(--r-md) var(--r-md) 4px;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: .5; }
  40%           { transform: scale(1);   opacity: 1; }
}

.chat-error {
  font-size: 13px;
  color: #b91c1c;
  background: #fff5f5;
  border: 1px solid #fca5a5;
  border-radius: var(--r-sm);
  padding: 10px 14px;
}

/* Chat input */
.chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-input {
  flex: 1;
  font-family: var(--font-text);
  font-size: 14px;
  color: var(--ink);
  background: var(--canvas);
  border: 1.5px solid var(--hairline);
  border-radius: var(--r-pill);
  padding: 10px 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212,83,10,0.1);
}
.chat-input:disabled { opacity: 0.6; }
.chat-input::placeholder { color: var(--body-muted); }

.chat-send {
  background: var(--accent);
  color: #fff;
  font-family: var(--font-text);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--r-pill);
  padding: 10px 20px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
  flex-shrink: 0;
}
.chat-send:hover:not(:disabled) { background: var(--accent-hover); }
.chat-send:active:not(:disabled) { transform: scale(.95); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

@media (max-width: 640px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { border-radius: var(--r-md) var(--r-md) 0 0; max-height: 90vh; }
  .chat-form { flex-direction: column; align-items: stretch; }
  .chat-send { text-align: center; }
}
