/* Saile. Designtokens från Andwhys styleguide (andwhy.se/pressmaterial/style-guide): Poppins, en mörk bas
   (blue #13262f) med aquamarin, gult och rosa som accenter. "Bold and high-contrast." */

:root, [data-theme="dark"] {
  --brand-ink:    #13262F;   /* --blue */
  --brand-pink:   #E36397;
  --brand-yellow: #FFE401;
  --brand-mint:   #70F8BA;   /* --aquamarine */
  --brand-gray:   #6C685F;
  --brand-white:  #F5F5F5;   /* --whitetext */

  --bg:      #0b181f;
  --bg-1:    #13262F;
  --bg-2:    #1c323c;
  --bg-3:    #264452;
  --line:    #1f3a46;
  --line-2:  #2e5260;
  --fg:      #f5f5f5;
  --fg-mute: #a8b7bd;
  --fg-dim:  #74878f;

  --accent:      var(--brand-mint);
  --accent-soft: color-mix(in oklab, var(--brand-mint) 18%, transparent);
  --accent-ink:  var(--brand-ink);
  --attn:        var(--brand-yellow);
  --attn-soft:   color-mix(in oklab, var(--brand-yellow) 18%, transparent);
  --warn:        var(--brand-pink);
  --warn-soft:   color-mix(in oklab, var(--brand-pink) 18%, transparent);
  --err:         #ff7b7b;
  --err-soft:    color-mix(in oklab, #ff7b7b 18%, transparent);

  /* Brush-markeringen (<mark>): gul på ljust, aquamarin på mörkt, som på andwhy.se. */
  --mark:     var(--brand-mint);
  --mark-ink: var(--brand-ink);

  /* Knappar och inputs: knappens kant (alt-knappen) och inputens underkant följer textfärgen. */
  --btn-line: var(--brand-white);

  --radius-sm: 8px;
  --radius:    1rem;
  --radius-lg: 1rem;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
}

[data-theme="light"] {
  --bg:      #ffffff;
  --bg-1:    #ffffff;
  --bg-2:    #f5f5f5;
  --bg-3:    #e8e8e8;
  --line:    #e0e0e0;
  --line-2:  #c9c9c9;
  --fg:      #13262F;
  --fg-mute: #4f5f65;
  --fg-dim:  #6C685F;
  --mark:     var(--brand-yellow);
  --mark-ink: var(--brand-ink);
  --btn-line: var(--brand-ink);
  --shadow-sm: 0 1px 2px rgba(19,38,47,0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'Poppins', -apple-system, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.1; }
/* FocusOnNavigate flyttar fokus till h1 vid varje navigering (för skärmläsare); ingen synlig ram behövs. */
h1:focus, h1:focus-visible { outline: none; }
h1 { font-size: 24px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.01em; }
h2 { font-size: 15px; font-weight: 700; }
h3 { font-size: 12px; font-weight: 700; color: var(--brand-gray); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; }

/* Brush-markering som på andwhy.se: transparent mark med en lätt roterad färgplatta bakom. */
mark { position: relative; z-index: 1; padding: 0 0.35em; color: var(--mark-ink); background: transparent; white-space: nowrap; }
mark::before { content: ""; position: absolute; left: 0; right: 0; top: 0.1em; bottom: 0.1em; background: var(--mark); transform: rotate(-0.75deg); z-index: -1; }
mark:nth-of-type(even)::before { transform: rotate(0.75deg); }
p { margin: 0 0 8px; }
.muted { color: var(--fg-mute); }
.dim { color: var(--fg-dim); }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.spacer { flex: 1; }
.hint { color: var(--fg-dim); font-size: 12px; }

/* ====== Skal ====== */
.app-shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
/* Navigeringen är alltid brand-blå med vit text, som headern på andwhy.se, oavsett tema. */
.left-nav {
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 16px; background: var(--brand-ink); color: var(--brand-white);
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px; }
.brand-mark { width: 34px; height: 34px; }
/* Symbolen är bläckfärgad; på mörk bakgrund inverteras den till vit, som logotyperna i theme-dark på andwhy.se. */
.left-nav .brand-mark, [data-theme="dark"] .brand-mark { filter: brightness(0) invert(1); }
.brand-name { font-weight: 700; font-size: 16px; text-transform: uppercase; letter-spacing: 0.02em; }
.brand-sub { font-size: 11px; color: rgba(245,245,245,0.6); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: block; padding: 8px 12px; border-left: 3px solid transparent;
  color: rgba(245,245,245,0.75); font-weight: 600;
}
.nav-item:hover { text-decoration: none; color: var(--brand-white); background: rgba(255,255,255,0.06); }
.nav-item.active { border-left-color: var(--brand-mint); color: var(--brand-white); }
.theme-toggle {
  font: inherit; font-weight: 600; color: var(--brand-white); background: none; border: 2px solid rgba(245,245,245,0.5);
  border-radius: 2rem; padding: 6px 14px; cursor: pointer; text-align: left;
}
.theme-toggle:hover { background: var(--brand-white); color: var(--brand-ink); border-color: var(--brand-white); }
[data-theme="dark"] .tt-show-in-light { display: none; }
[data-theme="light"] .tt-show-in-dark { display: none; }

.app-main { padding: 28px 36px 60px; min-width: 0; }
.page { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; margin-left: auto; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* ====== Kort ====== */
.card { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-body { padding: 16px 18px; }
.card-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--bg-2); border-radius: 0 0 var(--radius) var(--radius); }
.card-foot .input { flex: 1; }
.card-head h2 { text-transform: uppercase; letter-spacing: 0.04em; font-size: 13px; }

/* ====== Knappar ====== */
/* Styleguiden: primär = aquamarin med blå text, hover = blå med vit text. Alt = transparent med 2px kant. */
.btn {
  font: inherit; font-weight: 700; font-size: 13px; cursor: pointer; line-height: 1.3; white-space: nowrap;
  border: 2px solid var(--btn-line); background: transparent; color: var(--fg);
  padding: 6px 16px; border-radius: 2rem; transition: background-color 120ms, color 120ms, border-color 120ms;
}
.btn:hover { background: var(--btn-line); color: var(--bg-1); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover { background: transparent; color: var(--fg); }
.btn-primary { background: var(--brand-mint); color: var(--brand-ink); border-color: var(--brand-mint); }
.btn-primary:hover { background: var(--brand-ink); color: var(--brand-white); border-color: var(--brand-ink); }
[data-theme="dark"] .btn-primary:hover { background: var(--brand-white); color: var(--brand-ink); border-color: var(--brand-white); }
.btn-primary:disabled:hover { background: var(--brand-mint); color: var(--brand-ink); }
.btn-ghost { border-color: transparent; color: var(--fg-mute); font-weight: 600; }
.btn-ghost:hover { background: var(--bg-2); color: var(--fg); }
.btn-danger { color: var(--brand-pink); border-color: transparent; font-weight: 600; }
.btn-danger:hover { background: var(--brand-pink); color: var(--brand-white); }
.btn-sm { padding: 3px 10px; font-size: 12px; }

/* ====== Formulär ====== */
/* Styleguiden: inputs har bara en 2px underkantslinje, textarea en streckad ram med rundade hörn. */
.input, .select {
  font: inherit; color: var(--fg); background: transparent; border: 0; border-bottom: 2px solid var(--btn-line);
  border-radius: 0; padding: 6px 2px; width: 100%;
}
.select { padding-right: 24px; }
.textarea {
  font: inherit; color: var(--fg); background: transparent; border: 2px dashed var(--btn-line);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 72px; resize: vertical;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--brand-mint); }
[data-theme="light"] .input:focus, [data-theme="light"] .textarea:focus, [data-theme="light"] .select:focus { border-color: var(--brand-pink); }
.input::placeholder, .textarea::placeholder { color: var(--fg-dim); }
.input:-webkit-autofill { -webkit-box-shadow: 0 0 0 1000px var(--bg-1) inset; -webkit-text-fill-color: var(--fg); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > label { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand-gray); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ====== Redigerbara rader ====== */
.rows { display: flex; flex-direction: column; gap: 10px; }
.row-edit { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; background: var(--bg); display: flex; flex-direction: column; gap: 8px; }
.row-edit .field { margin-bottom: 0; }
.row-tools { display: flex; justify-content: flex-end; gap: 6px; }
.add-row { margin-top: 10px; }

/* ====== Listor och tabeller ====== */
.kv { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.kv dt { color: var(--fg-mute); font-size: 13px; }
.kv dd { margin: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 500; color: var(--fg-mute); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.list { margin: 0; padding-left: 18px; }
.list li { margin-bottom: 4px; }
.empty { color: var(--fg-dim); font-style: italic; }
.section-gap { margin-top: 14px; }

/* ====== Badges ====== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--bg-3); color: var(--fg-mute); }
.badge-accent { background: var(--accent-soft); color: var(--fg); }
.badge-attn { background: var(--attn-soft); color: var(--fg); }
.badge-warn { background: var(--warn-soft); color: var(--fg); }

/* ====== Meddelanden ====== */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; }
.alert-err { background: var(--err-soft); color: var(--fg); border: 1px solid color-mix(in oklab, var(--err) 40%, transparent); }
.alert-ok { background: var(--accent-soft); color: var(--fg); }
.alert-info { background: var(--bg-2); color: var(--fg-mute); border: 1px solid var(--line); }

/* ====== Versionshistorik ====== */
.version-list { display: flex; flex-direction: column; gap: 6px; }
.version {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg);
}
.version:hover { background: var(--bg-2); }
.version.selected { border-color: var(--accent); background: var(--accent-soft); }
.version .v-head { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.version .v-meta { font-size: 12px; color: var(--fg-dim); }

pre.prompt-text {
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; margin: 0; padding: 14px 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
}

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 20px; background: var(--attn); color: var(--brand-ink); z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 12px; top: 8px; }

/* ====== Modal ====== */
.modal-layer {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; overflow-y: auto;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(11, 24, 31, 0.55); }
.modal {
  position: relative;
  background: var(--bg-1); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
  width: 100%; max-width: 640px; max-height: 88vh;
  display: flex; flex-direction: column;
}
.modal-lg { max-width: 900px; }
.modal-sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--bg-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.modal-foot .input { flex: 1; }

/* ====== Idélista ====== */
.idea-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.idea-card { display: flex; flex-direction: column; gap: 8px; padding: 16px 18px; background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius); }
.idea-card:hover { border-color: var(--line-2); text-decoration: none; }
.idea-card .title { font-weight: 600; font-size: 15px; }
.idea-card .meta { font-size: 12px; color: var(--fg-dim); display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .select, .toolbar .input { width: auto; }

/* ====== Verdikt och poäng ====== */
.verdict-go { border-left: 4px solid var(--accent); }
.verdict-investigate { border-left: 4px solid var(--attn); }
.verdict-decline { border-left: 4px solid var(--warn); }
.verdict-big { font-size: 20px; font-weight: 700; }
.score-bar { display: inline-block; width: 90px; height: 8px; background: var(--bg-3); border-radius: 4px; vertical-align: middle; overflow: hidden; }
.score-bar > i { display: block; height: 100%; background: var(--accent); }
.steps { display: flex; flex-direction: column; gap: 6px; }
.step-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.step-row .meta { font-size: 12px; color: var(--fg-dim); }
.step-dot { width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; background: var(--bg-3); color: var(--fg-mute); }
.step-dot.running { background: var(--attn-soft); color: var(--fg); animation: pulse 1.2s infinite; }
.step-dot.completed { background: var(--accent-soft); color: var(--fg); }
.step-dot.failed { background: var(--err-soft); color: var(--fg); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
details.io { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 10px; margin-top: 6px; }
details.io summary { cursor: pointer; font-size: 12px; color: var(--fg-mute); }

/* ====== Rapport (markdown) ====== */
.report { line-height: 1.6; }
.report h2 { font-size: 16px; margin: 22px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.report h3 { font-size: 13px; margin: 14px 0 6px; text-transform: none; letter-spacing: 0; color: var(--fg); }
.report table { border-collapse: collapse; font-size: 13px; margin: 8px 0; width: 100%; }
.report th, .report td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.report a { color: var(--accent); text-decoration: underline; }
[data-theme="light"] .report a { color: #0b6b4f; }
.report ul, .report ol { padding-left: 22px; }
.report blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--line-2); color: var(--fg-mute); }
.warning-inline { background: var(--attn-soft); border-radius: var(--radius-sm); padding: 6px 10px; font-size: 12px; margin: 6px 0; }

.radio-list { display: flex; flex-direction: column; gap: 6px; }
.radio-list label { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.radio-list label:hover { background: var(--bg-2); }
.question { padding: 12px 0; border-bottom: 1px solid var(--line); }
.question:last-child { border-bottom: none; }
.question .q-text { font-weight: 600; margin-bottom: 4px; }
.question .q-why { font-size: 12px; color: var(--fg-dim); margin-bottom: 8px; }

/* ====== Hopfällbara kort ====== */
.card-head.clickable { cursor: pointer; user-select: none; }
.card-head.clickable:hover { background: var(--bg-2); }
.card.collapsed .card-head { border-bottom: none; border-radius: var(--radius); }
.chevron { width: 14px; color: var(--fg-dim); font-size: 12px; }
.card-summary { font-size: 13px; color: var(--fg-mute); }
.card-actions { display: flex; gap: 6px; align-items: center; }

/* ====== Körningsväljare och flikar ====== */
.run-switcher { display: flex; flex-direction: column; gap: 8px; }
.run-switcher-head { display: flex; align-items: baseline; gap: 12px; }
.run-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.run-tab {
  font: inherit; color: var(--fg-mute); cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 3px; min-width: 190px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-1);
}
.run-tab:hover { background: var(--bg-2); }
.run-tab.active { border-color: var(--accent); background: var(--accent-soft); color: var(--fg); }
.run-tab-title { font-weight: 600; }
.run-tab-meta { font-size: 12px; color: var(--fg-dim); display: flex; gap: 6px; align-items: center; }
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); }
.tab {
  font: inherit; font-weight: 500; color: var(--fg-mute); cursor: pointer; background: none; border: 0;
  padding: 10px 16px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }

/* ====== Inloggad användare ====== */
.user-box { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid rgba(245,245,245,0.2); border-radius: var(--radius-sm); }
.user-name { font-size: 12px; color: rgba(245,245,245,0.8); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box .btn-ghost { color: rgba(245,245,245,0.75); align-self: flex-start; }
.user-box .btn-ghost:hover { background: rgba(255,255,255,0.1); color: var(--brand-white); }

/* ====== Modellkort: fast storlek ====== */
.model-card { height: 380px; overflow: hidden; }
.model-card.inactive { opacity: 0.7; }
.model-card .kv dd { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-notes { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.model-tools { margin-top: auto; flex-wrap: wrap; }

/* ====== Toasts ====== */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 950; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px 10px 14px;
  background: var(--bg-1); color: var(--fg); border: 1px solid var(--line-2); border-left-width: 4px;
  border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0,0,0,0.35); font-size: 13px;
  animation: toast-in 160ms ease-out;
}
.toast-info { border-left-color: var(--fg-dim); }
.toast-success { border-left-color: var(--accent); }
.toast-error { border-left-color: var(--warn); }
.toast-text { flex: 1; word-break: break-word; }
.toast-close { font: inherit; background: none; border: 0; color: var(--fg-dim); cursor: pointer; padding: 0 2px; }
.toast-close:hover { color: var(--fg); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ====== Långa länkar i tabeller ====== */
.table td { word-break: break-word; overflow-wrap: anywhere; }
.feed-cell { max-width: 0; width: 45%; }
.feed-url { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--fg-dim); }
.feed-url:hover { color: var(--fg); }

/* ---- Inloggning och konto (Features/Account) ---- */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; }
.auth-brand .brand-sub { color: var(--fg-dim); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { margin-top: 0; }
.auth-form { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; }
.auth-btn { width: 100%; justify-content: center; min-height: 40px; }
.auth-divider { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: var(--fg-dim); font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth-foot { margin-top: 16px; text-align: center; font-size: 13px; }
.field-error { display: block; color: var(--err); font-size: 12px; }
.code-input { text-align: center; font-size: 24px; letter-spacing: 0.3em; font-family: 'JetBrains Mono', ui-monospace, monospace; }
.session-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.session-row:last-child { border-bottom: none; }
.user-box a.user-name { text-decoration: none; }
.user-box a.user-name:hover { color: var(--brand-white); text-decoration: underline; }
