/* ============================================================
   System-update-running – underhållsfronten
   Mörkt tema, animerad status, SV/EN
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

:root {
  --bg-0: #070b14;
  --bg-1: #0a1122;
  --card: rgba(255, 255, 255, 0.045);
  --border: rgba(255, 255, 255, 0.09);
  --text: #e8edf7;
  --muted: #93a0b8;
  --faint: #5d6a84;
  --amber: #ffb454;
  --green: #34d399;
  --blue: #60a5fa;
  --radius: 22px;
  --s-icon-border: rgba(255, 255, 255, 0.16);
  --meta-bg: rgba(10, 16, 30, 0.55);
  --bar-bg: rgba(255, 255, 255, 0.06);
  --pill-bg: rgba(255, 255, 255, 0.05);
  --pill-active-bg: rgba(255, 255, 255, 0.12);
  --item-bg: rgba(255, 255, 255, 0.03);
  --grid-line: rgba(255, 255, 255, 0.035);
  --ghost-hover-border: rgba(255, 255, 255, 0.22);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-0);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: grid;
  place-items: center;
  padding: 24px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- Bakgrund ---------- */

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 520px at 12% -10%, rgba(255, 170, 70, 0.10), transparent 60%),
    radial-gradient(820px 540px at 108% 112%, rgba(80, 140, 255, 0.12), transparent 60%),
    linear-gradient(180deg, #070b14, #0a1122 55%, #070b14);
}

.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 75% 62% at 50% 40%, black, transparent 78%);
  mask-image: radial-gradient(ellipse 75% 62% at 50% 40%, black, transparent 78%);
}

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

.wrap {
  width: 100%;
  max-width: 600px;
}

.card {
  position: relative;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 40px 26px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.fineprint {
  text-align: center;
  color: var(--faint);
  font-size: 11.5px;
  margin: 18px 0 0;
}

.noscript {
  margin-top: 14px;
  text-align: center;
  color: var(--amber);
  font-size: 13px;
}

/* ---------- Språkbytte ---------- */

.lang {
  position: absolute;
  top: 18px;
  right: 18px;
  display: flex;
  gap: 4px;
  background: var(--pill-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.lang button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.lang button.active {
  background: var(--pill-active-bg);
  color: var(--text);
}

.lang button:focus-visible,
.foot a:focus-visible,
.btn-primary:focus-visible,
.btn-ghost:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ---------- Statusorb ---------- */

.orb {
  width: 88px;
  height: 88px;
  margin: 4px auto 20px;
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
}

/* roterande ring */
.orb::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0turn, transparent, var(--amber) 1turn);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  animation: spin 1.6s linear infinite;
}

/* inre skiva + andningsljus */
.orb::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, rgba(255, 190, 110, 0.16), rgba(255, 170, 70, 0.05) 70%);
  border: 1px solid rgba(255, 180, 84, 0.28);
  animation: breathe 2.4s ease-in-out infinite;
}

.orb .icon {
  position: relative;
  z-index: 1;
  width: 30px;
  height: 30px;
  stroke: var(--amber);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.orb .icon-check { display: none; }

@keyframes spin { to { transform: rotate(1turn); } }

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 180, 84, 0.22); }
  50%      { box-shadow: 0 0 0 14px rgba(255, 180, 84, 0); }
}

/* ---------- Statusrad ---------- */

.status-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
  margin: 0 0 10px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  animation: dotpulse 1.6s ease-in-out infinite;
}

@keyframes dotpulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.8); }
}

.status-line.ok { color: var(--green); }
.status-line.ok .dot { background: var(--green); animation: none; }

h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.15;
  text-align: center;
  letter-spacing: -0.01em;
}

.lead {
  margin: 0 auto 26px;
  max-width: 44ch;
  text-align: center;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.55;
}

/* ---------- Förloppsrad ---------- */

.progress { margin-bottom: 22px; }

.progress-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13.5px;
}

.progress-top #stageNow {
  color: var(--text);
  font-weight: 600;
}

.pct {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 600;
}

.bar {
  height: 12px;
  border-radius: 999px;
  background: var(--bar-bg);
  border: 1px solid var(--bar-bg);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff9d4d, #ffc46b);
  position: relative;
  transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

.bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, 0.4) 50%, transparent 80%);
  animation: shimmer 1.9s linear infinite;
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* ---------- Etapper ---------- */

.stages {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: grid;
  gap: 10px;
}

.stages li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--faint);
}

.stages .s-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--s-icon-border);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.stages li.active { color: var(--text); }

.stages li.active .s-icon {
  border-color: var(--amber);
  animation: ring 1.8s ease-out infinite;
}

.stages li.active .s-icon::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  animation: dotpulse 1.6s ease-in-out infinite;
}

.stages li.done { color: var(--muted); }

.stages li.done .s-icon {
  border-color: rgba(52, 211, 153, 0.5);
  background: rgba(52, 211, 153, 0.12);
}

.stages li.done .s-icon::after {
  content: "";
  width: 8px;
  height: 5px;
  border-left: 2px solid var(--green);
  border-bottom: 2px solid var(--green);
  transform: rotate(-45deg) translate(1px, -1px);
}

@keyframes ring {
  0%   { box-shadow: 0 0 0 0 rgba(255, 180, 84, 0.28); }
  100% { box-shadow: 0 0 0 8px rgba(255, 180, 84, 0); }
}

/* ---------- Metadata ---------- */

.meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin: 0 0 22px;
}

.meta > div {
  background: var(--meta-bg);
  padding: 12px 16px;
}

.meta dt {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--faint);
  margin-bottom: 4px;
}

.meta dd {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  letter-spacing: 0.02em;
}

/* ---------- Sidfot ---------- */

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}

.foot a {
  color: var(--blue);
  text-decoration: none;
}

.foot a:hover { text-decoration: underline; }

.auto {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--faint);
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: dotpulse 1.8s ease-in-out infinite;
}

.auto.sim .pulse { background: var(--amber); }

/* ---------- "Klart"-tillstånd ---------- */

body[data-state="done"] .orb::before,
body[data-state="online"] .orb::before {
  animation: none;
  background: conic-gradient(from 0turn, rgba(52, 211, 153, 0.65), var(--green));
}

body[data-state="done"] .orb::after,
body[data-state="online"] .orb::after {
  background: radial-gradient(circle at 50% 35%, rgba(52, 211, 153, 0.18), rgba(52, 211, 153, 0.05) 70%);
  border-color: rgba(52, 211, 153, 0.35);
  animation: none;
}

body[data-state="done"] .icon-refresh,
body[data-state="online"] .icon-refresh { display: none; }

body[data-state="done"] .icon-check,
body[data-state="online"] .icon-check {
  display: block;
  stroke: var(--green);
}

body[data-state="done"] .status-line { color: var(--green); }
body[data-state="done"] .dot { background: var(--green); animation: none; }
body[data-state="done"] .bar-fill { background: linear-gradient(90deg, #2bbf8a, #52e6b0); }
body[data-state="done"] .bar-fill::after { display: none; }

/* ---------- Demo-panel (running.html) ---------- */

.demo-panel {
  background: var(--item-bg);
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 20px;
}

.demo-panel p {
  margin: 0 0 12px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
}

.btn-primary {
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffb454, #ff9d4d);
  color: #221503;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 157, 77, 0.25);
}

.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

/* ---------- Små skärmar ---------- */

@media (max-width: 520px) {
  .card { padding: 32px 22px 20px; }
  h1 { font-size: 25px; }
  .lead { font-size: 14px; }
  .meta dd { font-size: 13.5px; }
}

/* ---------- Minimerad animation ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Skärmläsarregion ---------- */

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

/* ---------- Fel-tillstånd ---------- */

.icon-x { display: none; }

body[data-state="error"] .orb::before {
  animation: none;
  background: conic-gradient(from 0turn, rgba(248, 113, 113, 0.6), #f87171);
}

body[data-state="error"] .orb::after {
  background: radial-gradient(circle at 50% 35%, rgba(248, 113, 113, 0.18), rgba(248, 113, 113, 0.05) 70%);
  border-color: rgba(248, 113, 113, 0.35);
  animation: none;
}

body[data-state="error"] .icon-refresh,
body[data-state="error"] .icon-check { display: none; }

body[data-state="error"] .icon-x {
  display: block;
  stroke: #f87171;
}

body[data-state="error"] .status-line { color: #f87171; }
body[data-state="error"] .dot { background: #f87171; animation: none; }
body[data-state="error"] .pulse { background: #f87171; animation: none; }

.error-reason {
  margin: 0 0 22px;
  padding: 12px 16px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.08);
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  color: #fca5a5;
  word-break: break-word;
}

.error-reason .r-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f87171;
  margin-bottom: 4px;
}

.stages li.failed { color: #f87171; }
.stages li.failed .s-icon { border-color: #f87171; }
.stages li.failed .s-icon::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f87171;
}

/* ---------- Knappar ---------- */

.btn-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.btn-ghost {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--ghost-hover-border);
}

.btn-ghost:disabled { opacity: 0.6; cursor: wait; }

/* ---------- Operatör (inloggning & avbrytning) ---------- */

.operator {
  margin: 0 0 22px;
  padding: 14px 16px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}

.linkish {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--blue);
  cursor: pointer;
}

.linkish:hover { text-decoration: underline; }
.linkish:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.operator form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
}

.operator input {
  flex: 1 1 140px;
  min-width: 0;
  background: var(--item-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
}

.operator input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.login-error {
  width: 100%;
  color: #f87171;
  font-size: 13px;
}

#abortWrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-danger {
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #f87171, #ef4444);
  color: #2b0a0a;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.25);
}

.btn-danger:hover { filter: brightness(1.06); }
.btn-danger:disabled { opacity: 0.6; cursor: wait; }
.btn-danger:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.e-badge.abort { color: var(--amber); background: rgba(255, 180, 84, 0.12); }

/* ---------- Uppdateringshistorik ---------- */

.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 10px;
}

.events {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.events li {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  background: var(--item-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
}

.events li.empty {
  justify-content: center;
  color: var(--faint);
}

.e-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.e-badge.ok { color: var(--green); background: rgba(52, 211, 153, 0.12); }
.e-badge.fail { color: #f87171; background: rgba(248, 113, 113, 0.12); }

.e-versions {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--text);
  font-weight: 600;
}

.e-when {
  margin-left: auto;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* ---------- Ljust tema (?theme=light) ---------- */

:root[data-theme="light"] {
  --bg-0: #eef1f7;
  --card: rgba(255, 255, 255, 0.85);
  --border: rgba(16, 24, 40, 0.12);
  --text: #101828;
  --muted: #475467;
  --faint: #98a2b3;
  --s-icon-border: rgba(16, 24, 40, 0.2);
  --meta-bg: rgba(255, 255, 255, 0.8);
  --bar-bg: rgba(16, 24, 40, 0.08);
  --pill-bg: rgba(16, 24, 40, 0.04);
  --pill-active-bg: rgba(16, 24, 40, 0.1);
  --item-bg: rgba(16, 24, 40, 0.03);
  --grid-line: rgba(16, 24, 40, 0.04);
  --ghost-hover-border: rgba(16, 24, 40, 0.3);
}

:root[data-theme="light"] .bg {
  background:
    radial-gradient(900px 520px at 12% -10%, rgba(255, 157, 60, 0.14), transparent 60%),
    radial-gradient(820px 540px at 108% 112%, rgba(80, 140, 255, 0.12), transparent 60%),
    linear-gradient(180deg, #f6f8fc, #eef1f7 55%, #e9edf5);
}

:root[data-theme="light"] .card {
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
