:root {
  --bg: #0d0f14;
  --surface: #151821;
  --border: #262b38;
  --text: #dfe3ee;
  --muted: #7c8296;
  --accent: #8ab4ff;
  --danger: #f2788c;

  /* Violet means "written by AI" everywhere in the panel */
  --ai: #c39bff;

  /* The interface is sans-serif; the text you read and write is serif */
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, Cambria, serif;
}

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-family: var(--sans);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

canvas { display: block; width: 100%; height: 100%; cursor: grab; }
canvas.dragging { cursor: grabbing; }
canvas.delete-mode { cursor: crosshair; }
.mode-hint {
  position: fixed; left: calc(50% - 180px); top: 20px;
  transform: translateX(-50%);
  padding: 8px 14px;
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 10px;
  font-size: 0.85rem;
  pointer-events: none;
}
.toast.has-action { pointer-events: auto; }
.toast-undo {
  margin-left: 12px; padding: 3px 12px;
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 999px;
  font-size: 0.82rem; font-weight: 600;
}
.toast-undo:hover { background: var(--accent); color: var(--bg); filter: none; }

/* ---------- Panel frame ---------- */
.panel {
  position: fixed;
  top: 16px; right: 16px; bottom: 16px;
  width: 360px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background: var(--panel-bg, rgba(21, 24, 33, 0.96));
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 16px 12px;
}
.brand h1 { margin: 0; font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; }
.stats { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; }

.brand { flex: 0 0 auto; }
.ai-bar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 1; min-width: 0; }
.ai-bar select { flex: 1; max-width: 210px; padding: 5px 8px; font-size: 0.8rem; border-radius: 8px; }
.status-dot {
  width: 8px; height: 8px; flex: 0 0 8px;
  border-radius: 50%; background: #75d6a1;
  box-shadow: 0 0 10px rgba(117, 214, 161, 0.55);
}
.status-dot.off { background: var(--muted); box-shadow: none; }

.add-row { display: flex; gap: 8px; padding: 0 16px 14px; }

/* ---------- Form controls ---------- */
input, textarea, select {
  min-width: 0;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
}
.add-row input, .inline-form input { flex: 1; }
.stack input { width: 100%; box-sizing: border-box; }

button {
  padding: 10px 14px;
  background: var(--accent);
  color: var(--on-accent, #0d0f14);
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button:disabled, input:disabled, select:disabled { opacity: 0.55; cursor: progress; }

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}
button.ghost:hover { background: var(--accent-soft); filter: none; }
button.small { padding: 6px 11px; font-size: 0.78rem; }
button.wide { width: 100%; }

input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; padding: 0 8px; border-bottom: 1px solid var(--border); }
button.tab {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 4px;
  margin-bottom: -1px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 0.82rem;
  font-weight: 500;
}
button.tab:hover { color: var(--text); filter: none; }
button.tab.active { color: var(--text); border-bottom-color: var(--accent); }
button.tab svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

.tab-body {
  flex: 1; min-height: 0;
  padding: 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ---------- Anteckning ---------- */
.empty { color: var(--muted); font-size: 0.9rem; line-height: 1.55; }
.empty p { margin: 0 0 10px; }
.empty .empty-title { color: var(--text); font-size: 1rem; font-weight: 600; }

.note-head { display: flex; align-items: center; gap: 10px; }
.note-dot {
  width: 12px; height: 12px; flex: 0 0 12px;
  border-radius: 50%;
  background: var(--node, var(--accent));
  box-shadow: 0 0 12px var(--node, var(--accent));
}
#note-title {
  flex: 1; margin: 0;
  font: 600 1.3rem/1.25 var(--serif);
  overflow-wrap: anywhere;
}

.color-picker { display: flex; gap: 8px; margin: 12px 0 14px; }
button.swatch {
  width: 22px; height: 22px; padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  opacity: 0.75;
}
button.swatch:hover { opacity: 1; filter: none; }
button.swatch.active { border-color: var(--text); opacity: 1; }

.note-text {
  display: block; width: 100%; box-sizing: border-box;
  height: 200px; resize: vertical;
  padding: 12px 14px;
  font: 1rem/1.65 var(--serif);
}

.block { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.block h3 { margin: 0 0 10px; font-size: 0.88rem; font-weight: 600; }
.ai-block h3::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px; margin-right: 8px;
  border-radius: 50%;
  background: var(--ai);
}

.inline-form { display: flex; gap: 8px; }

.quick-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
button.chip-btn {
  padding: 6px 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}
button.chip-btn:hover { border-color: var(--ai); color: var(--ai); background: transparent; filter: none; }

/* The AI's answer: violet edge = written by AI */
.ai-answer {
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(195, 155, 255, 0.06);
  border-left: 3px solid var(--ai);
  border-radius: 0 10px 10px 0;
}
.ai-meta { margin: 0 0 6px; color: var(--muted); font-size: 0.78rem; }
.ai-text { font: 0.98rem/1.65 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-text.streaming::after {
  content: "";
  display: inline-block;
  width: 7px; height: 1em; margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--ai);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
.ai-answer-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-answer-actions:has(button:not([hidden])) { margin-top: 10px; }

.section-label { margin: 14px 0 6px; color: var(--muted); font-size: 0.78rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 110px; overflow-y: auto; }

/* A connection: [ dot name x ] as one pill. Name opens the note, x removes the link. */
.chip-group {
  display: inline-flex; align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.chip-group:hover { border-color: var(--accent); }
button.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 4px 5px 10px;
  background: transparent;
  color: var(--text);
  border: none;
  font-size: 0.78rem;
  font-weight: 500;
}
button.chip::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--dot, var(--accent));
}
button.chip-x {
  padding: 5px 9px 5px 3px;
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1;
}
button.chip:hover { filter: none; }
button.chip-x:hover { color: var(--danger); filter: none; }

button.danger-link {
  display: block;
  margin-top: 22px; padding: 6px 0;
  background: transparent;
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 500;
}
button.danger-link:hover { text-decoration: underline; filter: none; }

/* ---------- Skapa ---------- */
.lead { margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { color: var(--muted); font-size: 0.82rem; }

.drop-zone {
  padding: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-zone p { margin: 0 0 8px; }
.drop-preview img {
  display: block;
  max-width: 100%; max-height: 170px;
  margin: 0 auto 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.stack label.check { display: flex; align-items: flex-start; gap: 8px; line-height: 1.4; }
.stack label.check input { width: auto; margin-top: 2px; accent-color: var(--accent); }
#ai-text, #ai-instruction { width: 100%; box-sizing: border-box; resize: vertical; min-height: 84px; line-height: 1.45; }

.status-text { margin: 12px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.5; white-space: pre-line; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- Sök ---------- */
.assistant-results { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.search-result {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 9px;
}
.search-result-title { min-width: 0; overflow-wrap: anywhere; font-size: 0.86rem; font-weight: 600; }
.search-result button { flex: 0 0 auto; padding: 6px 10px; font-size: 0.75rem; }

/* ---------- Mer ---------- */
.plain-h { margin: 0 0 6px; font-size: 0.95rem; font-weight: 600; }
.plain-h:not(:first-child) { margin-top: 26px; }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 0.88rem; line-height: 1.6; }
.tips li { margin-bottom: 6px; }

/* ---------- Message at the bottom of the screen ---------- */
.toast {
  position: fixed;
  left: calc(50% - 180px); bottom: 28px;
  transform: translateX(-50%);
  max-width: min(420px, 80vw);
  padding: 10px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 10px;
  font-size: 0.88rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .ai-text.streaming::after { animation: none; }
  .drop-zone { transition: none; }
}

@media (max-width: 600px) {
  .panel {
    top: auto; left: 10px; right: 10px; bottom: 10px;
    width: auto; max-height: 62vh;
  }
  .toast { left: 50%; bottom: calc(62vh + 24px); }
  .mode-hint { left: 50%; }
}

/* ---------- Utseende ---------- */
.look-group { display: flex; flex-direction: column; gap: 7px; margin: 12px 0 0; }
.look-label { color: var(--muted); font-size: 0.82rem; }
.look-group .color-picker { margin: 2px 0 0; }
.look-group .hint { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; line-height: 1.45; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1; padding: 7px 6px;
  background: transparent; color: var(--text);
  border: none; border-radius: 0;
  font-size: 0.82rem; font-weight: 500;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover:not(.active) { background: var(--accent-soft); filter: none; }
.seg button.active { background: var(--accent); color: var(--on-accent); }

/* ---------- Dubbelkoll av AI:ns svar ---------- */
.ai-check { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.check-text { font-size: 0.9rem; line-height: 1.5; }
.check-text p { margin: 0 0 6px; }
.check-row { display: flex; gap: 8px; align-items: baseline; overflow-wrap: anywhere; }
.check-mark {
  flex: none; width: 1.3em; height: 1.3em;
  display: inline-grid; place-items: center;
  border-radius: 50%; font-size: 0.78rem; font-weight: 700;
}
.check-ok .check-mark { background: rgba(80, 190, 130, 0.22); color: #3fae77; }
.check-unsure .check-mark { background: rgba(240, 180, 60, 0.25); color: #c58a12; }
.check-wrong .check-mark { background: rgba(240, 90, 110, 0.25); color: var(--danger); }
.check-wrong { color: var(--danger); }
.check-conclusion { margin-top: 10px !important; padding-top: 8px; border-top: 1px solid var(--border); font-weight: 600; }
