/* Trygghetslarm – gränssnitt. Mobil först, fungerar även på dator. Ljust och mörkt läge följer telefonens inställning. */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-subtle: #f6f8fa;
  --border: #d1d9e0;
  --border-muted: #d1d9e0b3;
  --fg: #1f2328;
  --fg-muted: #59636e;
  --accent: #0969da;
  --accent-subtle: #ddf4ff;
  --accent-border: #54aeff66;
  --success: #1a7f37;
  --success-emphasis: #1f883d;
  --success-subtle: #dafbe1;
  --success-border: #4ac26b66;
  --attention: #9a6700;
  --attention-emphasis: #9a6700;
  --attention-subtle: #fff8c5;
  --attention-border: #d4a72c66;
  --danger: #d1242f;
  --danger-emphasis: #cf222e;
  --danger-subtle: #ffebe9;
  --danger-border: #ff818266;
  --neutral-emphasis: #59636e;
  --neutral-muted: #818b981f;
  --header-bg: #24292f;
  --header-fg: #ffffff;
  --header-fg-muted: #ffffffb3;
  --btn-bg: #f6f8fa;
  --btn-hover: #eff2f5;
  --nav-active: #fd8c73;
  --shadow: 0 8px 24px rgba(140, 149, 159, 0.2);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* Mörkt läge: följer telefonen/datorn om man inte har valt Ljust eller Mörkt i kontomenyn
   (data-theme på <html>, sparat i en cookie). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-subtle: #151b23;
    --border: #3d444d;
    --border-muted: #3d444db3;
    --fg: #f0f6fc;
    --fg-muted: #9198a1;
    --accent: #4493f8;
    --accent-subtle: #388bfd1a;
    --accent-border: #388bfd66;
    --success: #3fb950;
    --success-emphasis: #238636;
    --success-subtle: #2ea04326;
    --success-border: #2ea04366;
    --attention: #d29922;
    --attention-emphasis: #9e6a03;
    --attention-subtle: #bb800926;
    --attention-border: #bb800966;
    --danger: #f85149;
    --danger-emphasis: #da3633;
    --danger-subtle: #f851491a;
    --danger-border: #f8514966;
    --neutral-emphasis: #656c76;
    --neutral-muted: #656c7633;
    --header-bg: #010409;
    --btn-bg: #212830;
    --btn-hover: #262c36;
    --shadow: 0 8px 24px #010409;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-subtle: #151b23;
  --border: #3d444d;
  --border-muted: #3d444db3;
  --fg: #f0f6fc;
  --fg-muted: #9198a1;
  --accent: #4493f8;
  --accent-subtle: #388bfd1a;
  --accent-border: #388bfd66;
  --success: #3fb950;
  --success-emphasis: #238636;
  --success-subtle: #2ea04326;
  --success-border: #2ea04366;
  --attention: #d29922;
  --attention-emphasis: #9e6a03;
  --attention-subtle: #bb800926;
  --attention-border: #bb800966;
  --danger: #f85149;
  --danger-emphasis: #da3633;
  --danger-subtle: #f851491a;
  --danger-border: #f8514966;
  --neutral-emphasis: #656c76;
  --neutral-muted: #656c7633;
  --header-bg: #010409;
  --btn-bg: #212830;
  --btn-hover: #262c36;
  --shadow: 0 8px 24px #010409;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0 0 8px; }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
code { padding: 2px 5px; border-radius: 6px; background: var(--neutral-muted); }
.muted { color: var(--fg-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

.container { max-width: 1012px; margin: 0 auto; padding: 16px; }
.stack > * + * { margin-top: 16px; }

/* ---------- Sidhuvud ---------- */

.AppHeader { background: var(--header-bg); color: var(--header-fg); }
.AppHeader-inner {
  max-width: 1012px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 4px; min-height: 56px;
}
.AppHeader-brand {
  display: flex; align-items: center; gap: 8px; margin-right: auto;
  color: var(--header-fg); font-weight: 600; font-size: 16px;
}
.AppHeader-brand:hover { text-decoration: none; color: var(--header-fg-muted); }
.AppHeader-link {
  color: var(--header-fg-muted); font-weight: 600; font-size: 14px;
  padding: 8px 10px; border-radius: 6px;
}
.AppHeader-link:hover { color: var(--header-fg); text-decoration: none; background: #ffffff1f; }
.AppHeader-link.selected { color: var(--header-fg); }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: #ffffff26; color: var(--header-fg); font-weight: 600; font-size: 14px;
  border: 1px solid #ffffff33;
}

.dropdown { position: relative; margin-left: 4px; }
.dropdown > summary { list-style: none; cursor: pointer; display: flex; padding: 4px; border-radius: 50%; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 220px;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px;
}
.dropdown-header { padding: 6px 8px 10px; border-bottom: 1px solid var(--border-muted); margin-bottom: 8px; font-size: 13px; }
.dropdown-item {
  display: block; width: 100%; text-align: left; padding: 8px; border: 0; border-radius: 6px;
  background: none; color: var(--fg); font: inherit; font-size: 14px; cursor: pointer;
}
.dropdown-item:hover { background: var(--neutral-muted); text-decoration: none; }
.dropdown-section { padding: 8px 8px 10px; border-bottom: 1px solid var(--border-muted); margin-bottom: 8px; }
.dropdown-label { display: block; margin-bottom: 6px; color: var(--fg-muted); font-size: 12px; font-weight: 600; }
.theme-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-subtle); }
.theme-switch button {
  padding: 6px 4px; border: 0; border-radius: 6px; background: none; color: var(--fg);
  font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.theme-switch button:hover { background: var(--neutral-muted); }
.theme-switch button[aria-pressed="true"] { background: var(--bg); box-shadow: 0 0 0 1px var(--border); font-weight: 600; }

/* ---------- Flikar ---------- */

.UnderlineNav {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  margin: 0 -16px; padding: 0 16px;
}
.UnderlineNav::-webkit-scrollbar { display: none; }
.UnderlineNav-item {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 10px 10px; color: var(--fg); font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.UnderlineNav-item:hover { text-decoration: none; border-bottom-color: var(--border); }
.UnderlineNav-item.selected { font-weight: 600; border-bottom-color: var(--nav-active); }

.Counter {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 2em;
  background: var(--neutral-muted); font-size: 12px; font-weight: 500; line-height: 18px; text-align: center;
}
.Counter--danger { background: var(--danger-emphasis); color: #fff; }

/* ---------- Boxar ---------- */

.Box { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.Box > * + * { border-top: 1px solid var(--border); }
.Box-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--bg-subtle); border-radius: 6px 6px 0 0;
}
.Box-title { font-size: 14px; font-weight: 600; }
.Box-body { padding: 16px; }
.Box-row { display: block; padding: 12px 16px; color: var(--fg); }
a.Box-row:hover { background: var(--bg-subtle); text-decoration: none; }
.Box-row:last-child { border-radius: 0 0 6px 6px; }
.Box-footer { padding: 12px 16px; background: var(--bg-subtle); border-radius: 0 0 6px 6px; }
.Box--danger { border-color: var(--danger-border); }
.Box--danger > .Box-header { background: var(--danger-subtle); color: var(--danger); border-color: var(--danger-border); }

.row { display: flex; align-items: center; gap: 12px; }
.row-main { flex: 1; min-width: 0; }
.row-title { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; }
.row-meta { display: flex; flex-wrap: wrap; gap: 0 14px; margin-top: 2px; color: var(--fg-muted); font-size: 13px; }
.chevron { flex: none; color: var(--fg-muted); }

/* ---------- Etiketter och status ---------- */

.Label {
  display: inline-block; padding: 0 7px; border: 1px solid var(--border); border-radius: 2em;
  font-size: 12px; font-weight: 500; line-height: 18px; white-space: nowrap; color: var(--fg-muted);
}
.Label--success { color: var(--success); border-color: var(--success-border); }
.Label--danger { color: var(--danger); border-color: var(--danger-border); }
.Label--attention { color: var(--attention); border-color: var(--attention-border); }
.Label--accent { color: var(--accent); border-color: var(--accent-border); }

.State {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 2em;
  color: #fff; font-size: 14px; font-weight: 500; line-height: 20px; white-space: nowrap;
  background: var(--neutral-emphasis);
}
.State--ok { background: var(--success-emphasis); }
.State--alarm { background: var(--danger-emphasis); }
.State--paused { background: var(--attention-emphasis); }

.Hero { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; padding: 16px; }
.Hero-text { flex: 1; min-width: 200px; }
.Hero-text p { margin: 4px 0 0; color: var(--fg-muted); }

.Progress { height: 6px; margin-top: 8px; border-radius: 6px; background: var(--neutral-muted); overflow: hidden; }
.Progress > span { display: block; height: 100%; border-radius: 6px; background: var(--success-emphasis); }
.Progress--warn > span { background: var(--attention); }
.Progress--danger > span { background: var(--danger-emphasis); }

.flash {
  padding: 12px 16px; border: 1px solid var(--accent-border); border-radius: 6px;
  background: var(--accent-subtle);
}
.flash-success { background: var(--success-subtle); border-color: var(--success-border); }
.flash-warn { background: var(--attention-subtle); border-color: var(--attention-border); }
.flash-error { background: var(--danger-subtle); border-color: var(--danger-border); }

.blankslate { padding: 32px 16px; text-align: center; color: var(--fg-muted); }
.blankslate h2 { color: var(--fg); margin-bottom: 4px; }

.breadcrumb { color: var(--fg-muted); font-size: 14px; }
.breadcrumb > * + *::before { content: "/"; margin: 0 6px; color: var(--fg-muted); }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Mätvärden ---------- */

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { padding: 12px; border: 1px solid var(--border); border-radius: 6px; }
.stat-label { color: var(--fg-muted); font-size: 12px; }
.stat-value { font-size: 20px; font-weight: 600; line-height: 1.3; }
.stat-value.ok { color: var(--success); }
.stat-value.warn { color: var(--attention); }
.stat-value.danger { color: var(--danger); }
.stat-note { margin-top: 2px; color: var(--fg-muted); font-size: 12px; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--btn-bg); color: var(--fg);
  font: inherit; font-size: 14px; font-weight: 500; line-height: 20px; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--btn-hover); text-decoration: none; }
.btn-primary { background: var(--success-emphasis); border-color: #1f232826; color: #fff; }
.btn-primary:hover { background: var(--success-emphasis); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-emphasis); border-color: var(--danger-emphasis); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn.selected { border-color: var(--accent); color: var(--accent); }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Formulär ---------- */

.form-group { margin: 0 0 16px; }
.form-group > label, .form-label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.form-control {
  display: block; width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--fg);
  font: inherit; font-size: 16px; line-height: 20px;
}
textarea.form-control { resize: vertical; min-height: 64px; }
.form-control:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.note { margin: 4px 0 0; color: var(--fg-muted); font-size: 12px; }
.form-checkbox { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 12px; }
.form-checkbox input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.form-checkbox label { font-weight: 600; font-size: 14px; }
.form-checkbox .note { margin: 0; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
.input-unit { display: flex; align-items: center; gap: 8px; }
.input-unit .form-control { max-width: 120px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }

.access-table { width: 100%; border-collapse: collapse; }
.access-table th, .access-table td { padding: 10px 8px; border-top: 1px solid var(--border-muted); text-align: center; }
.access-table th { font-size: 12px; font-weight: 600; color: var(--fg-muted); border-top: 0; }
.access-table th:first-child, .access-table td:first-child { text-align: left; padding-left: 0; }
.access-table input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- Tabeller ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 8px 16px; text-align: left; border-top: 1px solid var(--border-muted); white-space: nowrap; }
.table th { font-size: 12px; font-weight: 600; color: var(--fg-muted); border-top: 0; }

details.confirm > summary { list-style: none; display: inline-flex; }
details.Box > summary { list-style: none; }
details.Box > summary::-webkit-details-marker { display: none; }
details.Box:not([open]) > .Box-header { border-radius: 6px; }
details.confirm > summary::-webkit-details-marker { display: none; }
details.confirm[open] > summary { display: none; }
.prose { font-size: 14px; }
.prose ol, .prose ul { margin: 0 0 12px; padding-left: 20px; }
.prose li { margin-bottom: 4px; }
.prose p { margin-bottom: 12px; }
.chart-box { position: relative; height: 200px; padding: 12px 8px 8px; }

.segmented {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; padding: 2px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg-subtle);
}
.segmented a {
  padding: 6px 8px; border-radius: 6px; text-align: center; white-space: nowrap;
  color: var(--fg); font-size: 13px; font-weight: 500;
}
.segmented a:hover { text-decoration: none; background: var(--neutral-muted); }
.segmented a.selected { background: var(--bg); box-shadow: 0 0 0 1px var(--border); font-weight: 600; }

/* ---------- Inloggning ---------- */

.auth { max-width: 340px; margin: 0 auto; padding: 40px 16px; }
.auth-head { text-align: center; margin-bottom: 16px; }
.auth-head h1 { font-size: 22px; font-weight: 400; margin-top: 12px; }
.auth-logo {
  display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px;
  border-radius: 50%; background: var(--header-bg); color: #fff;
}
.auth .Box { background: var(--bg-subtle); }

/* ---------- Större skärmar ---------- */

@media (min-width: 544px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .segmented { display: inline-grid; grid-template-columns: repeat(6, auto); }
  .form-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 768px) {
  body { font-size: 14px; }
  h1 { font-size: 24px; }
  .container { padding: 24px 16px; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .btn { padding: 5px 16px; }
  .btn-sm { padding: 3px 12px; }
  .form-control { padding: 5px 12px; font-size: 14px; }
  .UnderlineNav { margin: 0; padding: 0; }
  .chart-box { height: 240px; }
}
