/* Elevens AI-panel (student_assistant.js): knap nederst til højre og et panel i højre side.
   Samme mørke, flade udtryk som lærerens assistent og "Markér og spørg": ingen skygger, ingen kanter. */
:root {
  --sa-width: 380px;
  --sa-bg: #1a1a18;
  --sa-raised: #2a2926;
  --sa-line: #3a3934;
  --sa-text: #f9f7f4;
  --sa-muted: #a8a59c;
  --sa-error: #f0a58f;
}

/* style.css' pageFadeIn efterlader transform på html/body, som gør position: fixed relativ til siden */
html,
body { animation-name: saPageFade; }
@keyframes saPageFade { from { opacity: 0; } to { opacity: 1; } }

.sa-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 11px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--sa-bg);
  color: var(--sa-text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 140ms ease, opacity 160ms ease;
}
.sa-launcher:hover { background: var(--sa-raised); }
.sa-launcher[hidden] { display: none; }
body.sa-open .sa-launcher { opacity: 0; pointer-events: none; }

.sa-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  width: var(--sa-width);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  background: var(--sa-bg);
  color: var(--sa-text);
  font-family: var(--font);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 220ms;
}
body.sa-open .sa-panel { transform: none; visibility: visible; transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1); }
/* Brede skærme: siden rykker til side, så panelet ikke dækker indholdet */
@media (min-width: 1180px) {
  body.sa-open { padding-right: var(--sa-width); }
}

.sa-title { margin: 4px 0 0; font-size: 15px; font-weight: 600; line-height: 1.3; color: var(--sa-text); }
.sa-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; padding: 18px 18px 14px; border-bottom: 1px solid var(--sa-line); }
.sa-kicker { margin: 0; font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.12em; color: var(--sa-muted); }
.sa-where { margin: 4px 0 0; font-size: 15px; font-weight: 600; line-height: 1.3; color: var(--sa-text); }
.sa-head__tools { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.sa-link { padding: 4px 6px; border: 0; border-radius: 4px; background: none; font: inherit; font-size: 13px; color: var(--sa-muted); cursor: pointer; }
.sa-link:hover { color: var(--sa-text); background: var(--sa-raised); }
.sa-close { width: 28px; height: 28px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--sa-muted); font-size: 14px; line-height: 1; cursor: pointer; }
.sa-close:hover { color: var(--sa-text); background: var(--sa-raised); }

.sa-log { list-style: none; margin: 0; padding: 16px 18px; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: 14px; }
.sa-empty { font-size: 15px; line-height: 1.5; color: var(--sa-muted); }
.sa-msg { font-size: 15px; line-height: 1.55; color: var(--sa-text); }
.sa-msg--user { justify-self: end; max-width: 88%; padding: 9px 12px; border-radius: 6px; background: var(--sa-raised); white-space: pre-wrap; font-size: 14px; }
.sa-msg--ai > :first-child { margin-top: 0; }
.sa-msg--ai > :last-child { margin-bottom: 0; }
.sa-msg--ai p { margin: 0 0 8px; }
.sa-msg--ai ul, .sa-msg--ai ol { margin: 6px 0; padding-left: 18px; }
.sa-msg--ai li::marker { color: var(--sa-muted); }
.sa-msg--ai strong { font-weight: 600; }
.sa-msg--ai a { color: var(--sa-text); }
.sa-msg--busy { color: var(--sa-muted); animation: sa-pulse 1.2s ease-in-out infinite; }
.sa-msg--error { padding: 9px 12px; border-radius: 6px; background: var(--sa-raised); color: var(--sa-error); font-size: 14px; }
.sa-msg--error .sa-link { color: var(--sa-text); text-decoration: underline; }

/* Citat af det markerede i elevens besked */
.sa-quote { display: block; margin: 0 0 6px; padding-left: 8px; border-left: 2px solid var(--sa-muted); color: var(--sa-muted); font-size: 13px; }

/* Det markerede, som næste spørgsmål handler om */
.sa-selection { margin: 0 18px; padding: 12px; border-radius: 6px; background: var(--sa-raised); }
.sa-selection__head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sa-selection__head .sa-close { width: 24px; height: 24px; }
.sa-selection__text { margin: 6px 0 10px; font-size: 14px; line-height: 1.45; color: var(--sa-text); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.sa-selection__warn { margin: 0; font-size: 13px; color: var(--sa-error); }
.sa-selection__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sa-selection .sa-chip { background: var(--sa-bg); }
.sa-selection .sa-chip:hover { background: var(--sa-line); }

/* Kilder og feedback fra opgavehjælpen (ai_sources.js, ai_feedback.js) i panelets farver */
.sa-msg--ai :is(.ai-sources, .ai-feedback) { color: var(--sa-muted); font-size: 12px; }
.sa-msg--ai :is(.ai-sources, .ai-feedback) button { color: var(--sa-muted); background: transparent; border-color: var(--sa-line); }

.sa-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 18px 0; border-top: 1px solid var(--sa-line); }
.sa-chips[hidden] { display: none; }
.sa-chip { padding: 6px 10px; border: 0; border-radius: 999px; background: var(--sa-raised); color: var(--sa-text); font: inherit; font-size: 13px; cursor: pointer; }
.sa-chip:hover { background: var(--sa-line); }

.sa-form { display: flex; gap: 4px; align-items: end; margin: 10px 18px 16px; padding: 4px; border-radius: 6px; background: var(--sa-raised); }
.sa-form:focus-within { box-shadow: inset 0 0 0 1px var(--sa-muted); }
.sa-form textarea { flex: 1; min-width: 0; min-height: 40px; max-height: 160px; resize: none; padding: 8px; border: 0; background: transparent; color: var(--sa-text); font: inherit; font-size: 14px; line-height: 1.4; }
.sa-form textarea::placeholder { color: var(--sa-muted); }
.sa-form textarea:focus { outline: none; }
.sa-send { padding: 9px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--sa-text); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.sa-send:hover { background: var(--sa-line); }

.sa-launcher:focus-visible,
.sa-panel button:focus-visible {
  outline: 2px solid var(--sa-text);
  outline-offset: 2px;
}

/* Mørkt tema: vendes som "Markér og spørg" (theme.css), så panelet ikke går i ét med den mørke side */
:root[data-theme="dark"] :is(.sa-launcher, .sa-panel) {
  --sa-bg: #f9f7f4;
  --sa-raised: #ecebe7;
  --sa-line: #dcd9d3;
  --sa-text: #1a1a18;
  --sa-muted: #6b6b66;
  --sa-error: #a33a22;
  color-scheme: light;
}
:root[data-theme="dark"] .sa-panel textarea {
  background-color: transparent;
  color: var(--sa-text);
  border-color: transparent;
}

@keyframes sa-pulse { 50% { opacity: 0.45; } }

@media (max-width: 639px) {
  .sa-panel { width: 100%; padding-bottom: env(safe-area-inset-bottom); }
  .sa-launcher { right: 16px; bottom: 16px; }
  /* Over bundmenuen på mobil */
  body:has(.sidebar-nav) .sa-launcher { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .sa-panel, .sa-launcher { transition: none; }
  .sa-msg--busy { animation: none; }
}
