:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-raised: #f6f7f9;
  --line: #e4e6eb;
  --line-strong: #d3d6dd;
  --ink: #15181e;
  --ink-soft: #3d434d;
  --muted: #6a717d;
  --accent: #1f5fd1;
  --accent-hover: #1a52b6;
  --accent-soft: rgba(31, 95, 209, .09);
  --green: #17804b;
  --amber: #a86a00;
  --red: #c63737;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { height: 100%; }
body { min-height: 100%; }

body {
  margin: 0;
  font: 15.5px/1.6 var(--sans);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }

::selection { background: rgba(31, 95, 209, .18); }

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

/* --- Header ---------------------------------------------------------------- */

.site-header { padding: 22px 24px 4px; }

.brand { display: flex; align-items: center; gap: 14px; max-width: 1320px; margin: 0 auto; color: inherit; text-decoration: none; }

.logo { width: 40px; height: 40px; }
.logo-pins { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; }
.logo-chip { fill: var(--panel); stroke: var(--ink); stroke-width: 2; }
.logo-core { fill: var(--accent); }

.wordmark { font: 700 21px/1 var(--sans); letter-spacing: .18em; color: var(--ink); }
.tagline {
  display: block; margin-top: 5px;
  font: 500 11px/1 var(--sans); letter-spacing: .2em; text-transform: uppercase; color: var(--muted);
}

/* --- Layout ---------------------------------------------------------------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 22px;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 24px 28px;
  min-height: 0;
}

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px 20px; gap: 16px; }
  .site-header { padding: 16px 16px 0; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
}

/* --- Chat ------------------------------------------------------------------ */

/* Chatten fyller fönstret: bara meddelandena skrollar, skrivfältet syns alltid. */
.chat {
  display: flex; flex-direction: column; overflow: hidden;
  align-self: start; position: sticky; top: 18px;
  height: calc(100dvh - 120px); min-height: 420px;
}
@media (max-width: 920px) {
  .chat { position: static; height: calc(100dvh - 110px); }
}

.messages { flex: 1; overflow-y: auto; padding: 28px 28px 8px; display: flex; flex-direction: column; gap: 18px; }
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.msg { display: flex; gap: 12px; max-width: 780px; animation: rise .35s ease-out both; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft);
  display: grid; place-items: center;
}
.avatar svg { width: 18px; height: 18px; }
.avatar svg path { fill: var(--accent); }

.bubble { padding: 12px 16px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.vela .bubble {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.msg.user .bubble {
  background: var(--accent);
  color: #fff;
  border-top-right-radius: 4px;
}
.msg.note .bubble { background: #fdf6e7; border: 1px solid #f1dcab; }

.bubble.md { white-space: normal; }
.bubble.md > :first-child { margin-top: 0; }
.bubble.md > :last-child { margin-bottom: 0; }
.bubble.md p { margin: 0 0 .7em; }
.bubble.md ul, .bubble.md ol { margin: 0 0 .7em; padding-left: 1.3em; }
.bubble.md li { margin: .2em 0; }
.bubble.md li::marker { color: var(--muted); }
.bubble.md strong { font-weight: 600; color: var(--ink); }
.bubble.md em { color: var(--ink-soft); }
.bubble.md .md-heading {
  margin: 1em 0 .4em; font: 600 13px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--accent);
}
.bubble.md hr { border: 0; height: 1px; margin: 1em 0; background: var(--line); }

.typing span {
  display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%;
  background: var(--muted); animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 28px 0; }
.suggestions[hidden] { display: none; }

.chip {
  border: 1px solid var(--line-strong); background: var(--panel); border-radius: 999px;
  padding: 8px 15px; font-size: 14px; color: var(--ink); cursor: pointer; text-align: left;
  transition: border-color .2s, background .2s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  margin: 16px 20px 20px; padding: 8px 8px 8px 18px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--panel);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; border: 0; background: transparent; resize: none; outline: none;
  padding: 7px 0; max-height: 160px;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  flex: none; width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: var(--accent); cursor: pointer; display: grid; place-items: center;
  transition: background .2s;
}
.send:hover { background: var(--accent-hover); }
.send svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.send:disabled { opacity: .4; cursor: default; }

/* --- Bygglista ------------------------------------------------------------- */

.build {
  align-self: start; position: sticky; top: 18px; padding: 20px 20px 22px;
  max-height: calc(100dvh - 120px); overflow-y: auto;
}
.build::-webkit-scrollbar { width: 8px; }
.build::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
@media (max-width: 920px) { .build { position: static; max-height: none; } }

.build-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.build h2 { font: 600 20px var(--sans); margin: 0; }

.link { border: 0; background: none; color: var(--muted); font-size: 13px; cursor: pointer; padding: 0; }
.link:hover { color: var(--accent); }

.slots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.slot {
  padding: 9px 10px; border-radius: 10px; border: 1px solid transparent;
  transition: background .2s, border-color .2s;
}
.slot:hover { background: var(--panel-raised); border-color: var(--line); }
.slot.filled { background: var(--panel-raised); border-color: var(--line); }

.slot-head { display: flex; align-items: center; gap: 10px; }
.slot-icon {
  flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--panel-raised); color: var(--muted);
}
.slot.filled .slot-icon { background: var(--accent-soft); color: var(--accent); }
.slot-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.slot-label { flex: 1; font: 500 12px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

.add {
  border: 1px solid var(--line-strong); background: var(--panel); border-radius: 8px; padding: 4px 11px;
  font-size: 13px; color: var(--accent); cursor: pointer; transition: background .2s, border-color .2s;
}
.add:hover { border-color: var(--accent); background: var(--accent-soft); }

.chosen { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 6px 0 0 40px; }
.buy-links { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.buy-link {
  font-size: 12.5px; color: var(--accent); text-decoration: none;
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 2px 8px; background: var(--panel);
}
.buy-link:hover { border-color: var(--accent); background: var(--accent-soft); }
.chosen-name { flex: 1; min-width: 0; font-size: 14.5px; }
.chosen-price { font-variant-numeric: tabular-nums; font-size: 13.5px; color: var(--muted); white-space: nowrap; }

.icon-btn {
  flex: none; width: 26px; height: 26px; border: 0; background: none; border-radius: 7px;
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: rgba(198, 55, 55, .08); color: var(--red); }
.icon-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* Totalpris och köpknapp ligger kvar längst ned i panelen när listan skrollar. */
.summary-bar {
  position: sticky; bottom: -22px; z-index: 1;
  margin: 14px -20px 0; padding: 14px 20px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
@media (max-width: 920px) { .summary-bar { position: static; } }
.summary:empty { display: none; }
.total { display: flex; justify-content: space-between; align-items: baseline; }
.total span { font: 500 12px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.total strong { font: 700 28px var(--sans); font-variant-numeric: tabular-nums; color: var(--ink); }
.price-note { margin: 2px 0 0; font-size: 12px; color: var(--muted); text-align: right; }
.ad-note { margin: 2px 0 0; font-size: 12px; color: var(--muted); text-align: right; }
.ad-note a { color: inherit; }
.ad-note a:hover { color: var(--accent); }

.buy {
  width: 100%; margin-top: 12px; padding: 12px 16px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; cursor: pointer;
  transition: background .2s;
}
.buy:hover { background: var(--accent-hover); }
.buy:disabled { background: var(--line-strong); color: var(--muted); cursor: default; }

.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.dot.green { background: var(--green); }
.dot.yellow { background: var(--amber); }
.dot.red { background: var(--red); }

.issues { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.issue { font-size: 13px; line-height: 1.5; padding-left: 14px; position: relative; color: var(--ink-soft); }
.issue::before { content: ""; position: absolute; left: 0; top: .55em; width: 6px; height: 6px; border-radius: 50%; }
.issue.error::before { background: var(--red); }
.issue.warning::before { background: var(--amber); }
.issue.unknown::before { background: var(--muted); }
.issue.info::before { background: var(--accent); }
.issue-kind {
  display: block; font: 600 10.5px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
}

.power {
  font-size: 13px; color: var(--muted); margin: 14px 0 0; padding: 10px 12px;
  border-radius: 10px; background: var(--panel-raised); border: 1px solid var(--line);
}

/* --- Väljare --------------------------------------------------------------- */

.picker {
  width: min(640px, calc(100vw - 32px));
  max-height: min(740px, calc(100vh - 48px));
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--panel); color: var(--ink);
  box-shadow: 0 20px 50px rgba(16, 24, 40, .18);
}
.picker[open] { display: flex; flex-direction: column; animation: rise .25s ease-out both; }
.picker::backdrop { background: rgba(16, 24, 40, .35); }

.picker-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 22px 0; margin: 0; }
.picker-head h3 { font: 600 21px var(--sans); margin: 0; }
.picker-head .icon-btn:hover { background: var(--panel-raised); color: var(--ink); }
.picker-hint { margin: 4px 22px 0; font-size: 13px; color: var(--muted); }

#picker-search {
  margin: 14px 22px 8px; padding: 11px 15px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--panel); outline: none; transition: border-color .2s, box-shadow .2s;
}
#picker-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.picker-list { list-style: none; margin: 0; padding: 4px 12px 16px; overflow-y: auto; }
.option {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center;
  text-align: left; border: 1px solid transparent; background: none; padding: 11px 12px; border-radius: 10px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.option:hover, .option:focus-visible { background: var(--accent-soft); border-color: var(--line-strong); outline: none; }
.option .dot { grid-row: span 2; }
.option-name { font-size: 15px; }
.option-price { font-size: 14px; color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.option-specs { grid-column: 2 / 4; font-size: 13px; color: var(--muted); }
.option-issue { grid-column: 2 / 4; font-size: 12px; color: var(--amber); }
.option-issue.error { color: var(--red); }

.buy-dialog { width: min(860px, calc(100vw - 32px)); }
.buy-stores {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px;
  padding: 16px 22px 22px; overflow-y: auto;
}
.store-card {
  display: flex; flex-direction: column;
  border: 2px solid var(--accent); border-radius: 14px; background: var(--panel); overflow: hidden;
  box-shadow: 0 6px 20px rgba(31, 95, 209, .12);
}
.store-card h4 {
  display: flex; align-items: center; justify-content: center; height: 72px; margin: 0; padding: 14px 18px;
  background: var(--accent-soft); border-bottom: 1px solid rgba(31, 95, 209, .2);
}
.store-logo { max-height: 40px; max-width: 70%; object-fit: contain; }
.store-name { font: 700 21px var(--sans); letter-spacing: .01em; color: var(--ink); }
.store-card ul { list-style: none; margin: 0; padding: 6px 8px; flex: 1; }
.store-card a {
  display: flex; justify-content: space-between; gap: 12px; padding: 10px; border-radius: 8px;
  color: var(--ink); text-decoration: none; font-size: 14px;
}
.store-card a:hover { background: var(--accent-soft); }
.store-card a:hover .store-part { color: var(--accent); }
.store-card a .store-part::after { content: " ↗"; color: var(--accent); }
.store-price { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.store-part.missing { display: block; padding: 10px; font-size: 14px; color: var(--muted); }
.store-total {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 18px 14px; border-top: 1px solid var(--line); background: var(--panel);
}
.store-total span { font: 500 12px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.store-total strong { font: 700 20px var(--sans); font-variant-numeric: tabular-nums; }

.empty { padding: 24px 10px; color: var(--muted); font-size: 14px; text-align: center; }
.excluded { padding: 8px 12px 0; font-size: 12px; color: var(--muted); }

/* --- Sidfot och informationssidor ------------------------------------------ */

.site-footer { padding: 0 24px 28px; }
.site-footer nav {
  display: flex; flex-wrap: wrap; gap: 6px 22px; max-width: 1320px; margin: 0 auto;
  font-size: 13px;
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

.page { width: 100%; max-width: 760px; margin: 0 auto; padding: 18px 24px 40px; }
.page article { padding: 32px 36px; }
.page h1 { font: 700 30px/1.25 var(--sans); margin: 0 0 10px; }
.page h2 { font: 600 19px/1.3 var(--sans); margin: 34px 0 8px; scroll-margin-top: 20px; }
.page p, .page li { color: var(--ink-soft); }
.page ul { padding-left: 1.3em; }
.page a { color: var(--accent); }
.page .lead { font-size: 17px; color: var(--ink); }
@media (max-width: 920px) {
  .page { padding: 12px 16px 28px; }
  .page article { padding: 22px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
