/* ─────────────────────────────────────────────────────────────────────────
 * ai-chat.css — Task #83
 * Styling for AI Chat-panelet der lever inde i AI Analyse-sidepanelet.
 * Layout: chat fylder de nederste 60 % af #ai-panel; batch-analyse 40 % over.
 * Mørkt tema matcher MCS (#0f172a / #1a1a2e / #a78bfa).
 * ───────────────────────────────────────────────────────────────────────── */

#ai-chat-container {
  display: flex;
  flex-direction: column;
  flex: 1 1 60%;
  min-height: 280px;
  max-height: 60%;
  border-top: 1px solid #334155;
  background: #0a0a14;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e2e8f0;
  overflow: hidden;
}

#ai-chat-container .mcs-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #0f172a;
  border-bottom: 1px solid #334155;
  font-size: 13px;
  font-weight: 700;
  color: #a78bfa;
  letter-spacing: .3px;
  flex-shrink: 0;
}

#ai-chat-container .mcs-chat-header .mcs-chat-niche {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  text-transform: uppercase;
}

#ai-chat-container .mcs-chat-tabs .mcs-chat-clear,
#ai-chat-container .mcs-chat-tabs .mcs-chat-library {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid rgba(148, 163, 184, .3);
  color: #94a3b8;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  margin-left: 4px;
}

#ai-chat-container .mcs-chat-tabs .mcs-chat-clear:hover {
  background: rgba(239, 68, 68, .12);
  border-color: rgba(239, 68, 68, .5);
  color: #fca5a5;
}

#ai-chat-container .mcs-chat-tabs .mcs-chat-library:hover {
  background: rgba(124, 58, 237, .15);
  border-color: rgba(124, 58, 237, .5);
  color: #c4b5fd;
}

/* ── Prompt-bibliotek modal ────────────────────────────────────────── */
.mcs-chat-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(3px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  animation: mcs-modal-fade .15s ease-out;
}

@keyframes mcs-modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.mcs-chat-modal {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}

.mcs-chat-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid #334155;
  background: linear-gradient(135deg, rgba(124, 58, 237, .15), rgba(109, 40, 217, .1));
  font-size: 16px;
  font-weight: 700;
  color: #c4b5fd;
}

.mcs-chat-modal-close {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, .3);
  color: #94a3b8;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}

.mcs-chat-modal-close:hover {
  background: rgba(239, 68, 68, .12);
  border-color: rgba(239, 68, 68, .5);
  color: #fca5a5;
}

.mcs-chat-modal-subtitle {
  padding: 10px 20px;
  font-size: 12px;
  color: #94a3b8;
  border-bottom: 1px solid #1e293b;
  background: #0a0a14;
}

.mcs-chat-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

.mcs-chat-modal-body::-webkit-scrollbar {
  width: 8px;
}
.mcs-chat-modal-body::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}

.mcs-chat-lib-cat {
  margin-bottom: 18px;
}

.mcs-chat-lib-cat:last-child {
  margin-bottom: 0;
}

.mcs-chat-lib-cat-header {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 6px 0 6px 12px;
  margin-bottom: 8px;
  border-left: 3px solid;
}

.mcs-chat-lib-prompts {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mcs-chat-lib-prompt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all .12s;
  width: 100%;
}

.mcs-chat-lib-prompt:hover {
  background: #2a3a52;
  border-color: #475569;
  transform: translateX(2px);
}

.mcs-chat-lib-prompt:focus {
  outline: none;
  border-color: #7c3aed;
  background: rgba(124, 58, 237, .15);
}

.mcs-chat-lib-prompt-label {
  flex: 1;
}

.mcs-chat-lib-prompt-arrow {
  color: #475569;
  font-size: 14px;
  margin-left: 12px;
  transition: color .12s, transform .12s;
}

.mcs-chat-lib-prompt:hover .mcs-chat-lib-prompt-arrow {
  color: #c4b5fd;
  transform: translateX(3px);
}

@media (max-width: 600px) {
  .mcs-chat-modal-overlay { padding: 0; }
  .mcs-chat-modal {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    height: 100vh;
  }
}

#ai-chat-container .mcs-chat-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: #0f172a;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

#ai-chat-container .mcs-chat-tab {
  flex: 1;
  background: transparent;
  border: 1px solid #334155;
  color: #94a3b8;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

#ai-chat-container .mcs-chat-tab:hover {
  border-color: #475569;
  color: #cbd5e1;
}

#ai-chat-container .mcs-chat-tab.active {
  background: linear-gradient(135deg, #4c1d95, #6d28d9);
  border-color: #7c3aed;
  color: #fff;
}

#ai-chat-container .mcs-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: #0a0a14;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
  max-height: 88px;
  overflow-y: auto;
}

#ai-chat-container .mcs-chat-chip {
  background: rgba(124, 58, 237, .12);
  border: 1px solid rgba(124, 58, 237, .35);
  color: #c4b5fd;
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}

#ai-chat-container .mcs-chat-chip:hover {
  background: rgba(124, 58, 237, .25);
  color: #fff;
}

#ai-chat-container .mcs-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

#ai-chat-container .mcs-chat-messages::-webkit-scrollbar { width: 6px; }
#ai-chat-container .mcs-chat-messages::-webkit-scrollbar-thumb {
  background: #334155; border-radius: 3px;
}

#ai-chat-container .mcs-chat-bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

#ai-chat-container .mcs-chat-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #4c1d95, #6d28d9);
  color: #fff;
  border-bottom-right-radius: 2px;
}

#ai-chat-container .mcs-chat-bubble.assistant {
  align-self: flex-start;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-bottom-left-radius: 2px;
  /* Block-elementer (h2, ul, p) styrer egne linjeskift — undgå pre-wrap-dubletter */
  white-space: normal;
}

#ai-chat-container .mcs-chat-bubble.error {
  align-self: stretch;
  background: rgba(239, 68, 68, .1);
  border: 1px solid rgba(239, 68, 68, .4);
  color: #fca5a5;
}

#ai-chat-container .mcs-chat-bubble.assistant a.mcs-chat-link {
  color: #c4b5fd;
  text-decoration: underline;
  text-decoration-color: rgba(196, 181, 253, .5);
  text-underline-offset: 2px;
  font-weight: 500;
  transition: color .15s, text-decoration-color .15s;
}

#ai-chat-container .mcs-chat-bubble.assistant a.mcs-chat-link:hover {
  color: #ddd6fe;
  text-decoration-color: #a78bfa;
}

#ai-chat-container .mcs-chat-bubble.assistant strong {
  color: #fff;
  font-weight: 700;
}

#ai-chat-container .mcs-chat-bubble.assistant em {
  font-style: italic;
  color: #e2e8f0;
}

#ai-chat-container .mcs-chat-bubble.assistant code {
  background: rgba(124, 58, 237, .18);
  border: 1px solid rgba(124, 58, 237, .3);
  color: #ddd6fe;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-h1,
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-h2,
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-h3,
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-h4 {
  color: #fff;
  font-weight: 700;
  line-height: 1.3;
  margin: 10px 0 4px 0;
  padding-bottom: 2px;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-h1 {
  font-size: 16px;
  border-bottom: 1px solid rgba(124, 58, 237, .4);
  padding-bottom: 4px;
}
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-h2 {
  font-size: 14.5px;
  color: #c4b5fd;
}
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-h3 {
  font-size: 13.5px;
  color: #a78bfa;
}
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-h4 {
  font-size: 12.5px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .3px;
}

/* Første heading skal ikke have margin-top */
#ai-chat-container .mcs-chat-bubble.assistant > .mcs-md-h1:first-child,
#ai-chat-container .mcs-chat-bubble.assistant > .mcs-md-h2:first-child,
#ai-chat-container .mcs-chat-bubble.assistant > .mcs-md-h3:first-child,
#ai-chat-container .mcs-chat-bubble.assistant > .mcs-md-h4:first-child {
  margin-top: 0;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-p {
  margin: 4px 0;
  line-height: 1.5;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-ul,
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-ol {
  margin: 4px 0 6px 0;
  padding-left: 22px;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-ul li,
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-ol li {
  margin: 2px 0;
  line-height: 1.45;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-ul {
  list-style-type: disc;
}
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-ol {
  list-style-type: decimal;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-bq {
  border-left: 2px solid rgba(148, 163, 184, .35);
  background: transparent;
  margin: 4px 0;
  padding: 2px 0 2px 12px;
  color: #94a3b8;
  font-style: italic;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-hr {
  border: 0;
  border-top: 1px solid #334155;
  margin: 8px 0;
}

/* ── Tabel ──────────────────────────────────────────────────────────── */
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table-wrap {
  margin: 8px -4px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table-wrap::-webkit-scrollbar {
  height: 6px;
}
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table-wrap::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table {
  border-collapse: collapse;
  font-size: 11.5px;
  line-height: 1.35;
  min-width: 100%;
  background: #0f172a;
  border-radius: 6px;
  overflow: hidden;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table thead {
  background: linear-gradient(135deg, rgba(124, 58, 237, .25), rgba(109, 40, 217, .15));
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table th {
  padding: 6px 10px;
  font-weight: 700;
  color: #c4b5fd;
  border-bottom: 1px solid #334155;
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table td {
  padding: 5px 10px;
  border-bottom: 1px solid rgba(51, 65, 85, .5);
  color: #e2e8f0;
  vertical-align: top;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table tbody tr:last-child td {
  border-bottom: 0;
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table tbody tr:nth-child(even) {
  background: rgba(30, 41, 59, .4);
}

#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table tbody tr:hover {
  background: rgba(124, 58, 237, .08);
}

/* Links inde i tabel — lidt kompakt */
#ai-chat-container .mcs-chat-bubble.assistant .mcs-md-table a.mcs-chat-link {
  font-size: inherit;
}

#ai-chat-container .mcs-chat-tool {
  align-self: flex-start;
  font-size: 11px;
  color: #94a3b8;
  font-style: italic;
  padding: 2px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#ai-chat-container .mcs-chat-tool::before {
  content: '';
  width: 8px; height: 8px;
  border: 2px solid #7c3aed;
  border-top-color: transparent;
  border-radius: 50%;
  animation: mcs-chat-spin .8s linear infinite;
  display: inline-block;
}

@keyframes mcs-chat-spin {
  to { transform: rotate(360deg); }
}

#ai-chat-container .mcs-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  padding-left: 4px;
}

#ai-chat-container .mcs-chat-suggestion {
  background: transparent;
  border: 1px dashed rgba(124, 58, 237, .4);
  color: #c4b5fd;
  border-radius: 10px;
  padding: 3px 8px;
  font-size: 10.5px;
  cursor: pointer;
  transition: all .15s;
}

#ai-chat-container .mcs-chat-suggestion:hover {
  background: rgba(124, 58, 237, .15);
  border-style: solid;
}

#ai-chat-container .mcs-chat-input-wrap {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: #0f172a;
  border-top: 1px solid #334155;
  flex-shrink: 0;
}

#ai-chat-container .mcs-chat-input {
  flex: 1;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 8px 10px;
  color: #e2e8f0;
  font-size: 12.5px;
  font-family: inherit;
  resize: vertical;
  min-height: 96px;   /* 5 linjer default */
  max-height: 240px;  /* op til ~12 linjer hvis brugeren trækker */
  line-height: 1.5;
}

#ai-chat-container .mcs-chat-input:focus {
  outline: none;
  border-color: #7c3aed;
}

#ai-chat-container .mcs-chat-send {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}

#ai-chat-container .mcs-chat-send:disabled {
  opacity: .5;
  cursor: not-allowed;
}

#ai-chat-container .mcs-chat-empty {
  color: #475569;
  font-size: 11px;
  text-align: center;
  padding: 20px 12px;
  font-style: italic;
}

/* AI Analyse-panelet skal blive flex-column så vi kan splitte 40/60 */
#ai-panel.mcs-chat-host > div:nth-child(2) {
  /* eksisterende batch-analyse-section bliver 40% øverst */
  flex: 0 0 40% !important;
  min-height: 200px !important;
}
