:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ed;
  --text: #1b231e;
  --muted: #5d6b62;
  --border: #d9dfda;
  --accent: #1f6f4a;
  --accent-text: #ffffff;
  --accent-soft: #e2f0e8;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --ok: #1f7a3f;
  --ok-soft: #e0f3e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --nav-w: 232px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #1a201c;
    --surface-2: #232b26;
    --text: #e6ebe7;
    --muted: #9aa8a0;
    --border: #2f3a33;
    --accent: #4cb784;
    --accent-text: #08130d;
    --accent-soft: #1d3428;
    --danger: #ff8a80;
    --danger-soft: #3a1d1b;
    --warn: #ffcc66;
    --warn-soft: #3a2f14;
    --ok: #6fdc9a;
    --ok-soft: #173023;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

h1,
h2,
h3 {
  margin: 0 0 0.6em;
  line-height: 1.25;
}

h1 {
  font-size: 1.45rem;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  font-size: 1rem;
}

.boot {
  padding: 2rem;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.86rem;
}

.mono {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 0.88em;
  word-break: break-all;
}

/* --- Buttons & forms --- */

button,
.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
}

button:hover {
  background: var(--surface-2);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.primary:hover {
  filter: brightness(1.08);
}

button.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

button.danger:hover {
  background: var(--danger-soft);
}

button.link {
  border: 0;
  background: none;
  color: var(--accent);
  padding: 0.2rem 0.3rem;
  min-height: 0;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

input,
select,
textarea {
  font: inherit;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 42px;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

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

.field {
  margin-bottom: 0.9rem;
}

.field .hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.check input {
  width: 20px;
  height: 20px;
  min-height: 0;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.grid-plz {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0 1rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.error {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  margin-bottom: 0.9rem;
}

/* --- Login --- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login .card {
  width: 100%;
  max-width: 400px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand .logo {
  height: 26px;
  width: auto;
  display: block;
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.brand-full {
  text-align: center;
  margin: 0.4rem 0 1.4rem;
}

.brand-full .logo {
  display: block;
  width: 100%;
  max-width: 300px;
  height: auto;
  margin: 0 auto 0.6rem;
}

/* The logo is black; show it white on dark backgrounds. */
@media (prefers-color-scheme: dark) {
  .logo {
    filter: invert(1);
  }
}

.qr {
  background: #fff;
  padding: 0.6rem;
  border-radius: 8px;
  width: 200px;
  margin: 0.4rem auto 0.8rem;
}

.qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.login details {
  margin-bottom: 1rem;
}

.code-input {
  font-size: 1.5rem;
  letter-spacing: 0.35em;
  text-align: center;
}

/* --- Layout --- */

.shell {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  min-height: 100dvh;
}

.topbar,
.scrim {
  display: none;
}

nav.side {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  position: sticky;
  top: 0;
  height: 100dvh;
}

nav.side .brand {
  padding: 0.4rem 0.75rem 1.2rem;
}

nav.side a {
  display: block;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

nav.side a:hover {
  background: var(--surface-2);
}

nav.side a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

nav.side .version {
  font-size: 0.75rem;
  margin-top: 0.3rem;
  opacity: 0.8;
}

nav.side .spacer {
  flex: 1;
}

nav.side .who {
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

main {
  padding: 1.5rem 2rem 3rem;
  max-width: 1200px;
  width: 100%;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.page-head h1 {
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
  margin-bottom: 1rem;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.tile .num {
  font-size: 1.8rem;
  font-weight: 700;
}

.tile .lbl {
  color: var(--muted);
  font-size: 0.88rem;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.toolbar input {
  max-width: 320px;
}

/* --- Tables that become cards on small screens --- */

table.list {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.list th,
table.list td {
  text-align: left;
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.list th {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
}

table.list tr:last-child td {
  border-bottom: 0;
}

table.list tr.clickable {
  cursor: pointer;
}

table.list tr.clickable:hover td {
  background: var(--surface-2);
}

table.list td.right {
  text-align: right;
}

.empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.bad {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.35rem;
  background: var(--muted);
}

.dot.online {
  background: var(--ok);
}

.dot.offline {
  background: var(--danger);
}

.chips {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

/* --- Dialogs --- */

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 2rem);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgb(0 0 0 / 25%);
}

dialog::backdrop {
  background: rgb(0 0 0 / 40%);
}

dialog .dlg-head {
  padding: 1rem 1.2rem 0.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

dialog .dlg-head h2 {
  margin: 0;
}

dialog .dlg-body {
  padding: 0.6rem 1.2rem 1.2rem;
}

.secret-box {
  background: var(--warn-soft);
  border-radius: 8px;
  padding: 0.8rem;
  margin: 0.6rem 0;
}

.secret-box .mono {
  font-size: 1.3rem;
  font-weight: 700;
  word-break: normal;
}

/* --- Maintenance banner --- */

.maintenance-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* --- Remote maintenance --- */

pre.config {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.82rem;
  margin: 0.6rem 0;
}

details.card > summary {
  cursor: pointer;
}

.remote-start {
  display: flex;
  align-items: flex-end;
}

main > h2 {
  margin-top: 1.2rem;
}

.remote-row {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.8rem;
}

.remote-row .actions {
  margin-top: 0.5rem;
}

/* --- Welcome greeting --- */

.welcome {
  text-align: center;
  padding: 0.4rem 0.4rem 0.6rem;
}

.welcome-emoji {
  font-size: 4rem;
  line-height: 1;
  margin: 0.4rem 0 0.8rem;
  animation: welcome-bounce 1.2s ease-in-out 2;
}

.welcome h3 {
  font-size: 1.2rem;
}

.welcome p {
  font-size: 1.02rem;
  margin: 0 0 0.8rem;
}

.welcome button {
  margin-top: 0.6rem;
  font-size: 1.05rem;
  padding: 0.7rem 1.4rem;
}

@keyframes welcome-bounce {
  0%,
  100% {
    transform: translateY(0) rotate(0);
  }
  30% {
    transform: translateY(-12px) rotate(-8deg);
  }
  60% {
    transform: translateY(0) rotate(6deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .welcome-emoji {
    animation: none;
  }
}

/* --- Toasts --- */

#toasts {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 100;
  width: min(420px, calc(100vw - 2rem));
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.toast.err {
  background: var(--danger);
  color: #fff;
}

/* --- Detail page --- */

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
}

.access-row {
  display: grid;
  grid-template-columns: 1fr 190px;
  gap: 0.6rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}

.access-row:last-child {
  border-bottom: 0;
}

/* --- Mobile --- */

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    padding-top: max(0.6rem, env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  nav.side {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 85vw);
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .nav-open nav.side {
    transform: none;
  }

  .nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 35%);
    z-index: 25;
  }

  main {
    padding: 1rem 1rem 3rem;
  }

  .detail-grid,
  .grid2 {
    grid-template-columns: 1fr;
  }

  table.list,
  table.list tbody,
  table.list tr,
  table.list td {
    display: block;
    width: 100%;
  }

  table.list thead {
    display: none;
  }

  table.list {
    border: 0;
    background: none;
  }

  table.list tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.6rem;
    padding: 0.4rem 0;
  }

  table.list td {
    border: 0;
    padding: 0.3rem 0.9rem;
    display: grid;
    grid-template-columns: 7.5rem 1fr;
    gap: 0.5rem;
  }

  table.list td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
  }

  table.list td.right {
    text-align: left;
  }

  .access-row {
    grid-template-columns: 1fr;
  }
}

.site-pick {
  display: grid;
  gap: 0.4rem;
}

.site-pick select[size] {
  padding: 0.25rem;
}

.site-pick select[size] option {
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
}

dialog details {
  margin-top: 1rem;
}

dialog details > summary {
  cursor: pointer;
  font-weight: 600;
}

/* ----- device list (Fernwartung) ----- */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.2rem;
}
.section-head h2 {
  margin: 0;
}
.this-pc {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--muted);
}
.this-pc select {
  width: auto;
  min-width: 14rem;
  padding: 0.35rem 0.6rem;
}
.device-list {
  padding: 0;
  margin-top: 0.6rem;
}
.device-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 11.5rem auto;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.1rem;
}
.device-row + .device-row {
  border-top: 1px solid var(--border);
}
.device-row.blocked .device-info {
  opacity: 0.6;
}
.device-info .badge {
  margin-left: 0.5rem;
}
.device-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
}
.segmented {
  display: inline-flex;
}
.segmented button {
  border-radius: 0;
  white-space: nowrap;
}
.segmented button:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}
.segmented button:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-left: -1px;
}
details.menu {
  position: relative;
}
details.menu > summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.8rem;
  font-weight: 700;
  line-height: 1.2;
  user-select: none;
}
details.menu > summary::-webkit-details-marker {
  display: none;
}
details.menu[open] > summary {
  background: var(--surface-2);
}
.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 0.3rem);
  z-index: 20;
  display: grid;
  min-width: 13rem;
  padding: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu-items button {
  white-space: nowrap;
  border: 0;
  text-align: left;
  background: none;
}
.menu-items button:hover {
  background: var(--surface-2);
}
@media (max-width: 700px) {
  .device-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .device-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

.card.center {
  text-align: center;
}

/* ----- running sessions stand out ----- */
.live-box {
  margin: 1.2rem 0;
}
.live-box h2 {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.live-box.active {
  padding: 0.9rem 1rem 1rem;
  border: 1px solid color-mix(in srgb, var(--ok) 55%, var(--border));
  border-left: 5px solid var(--ok);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--ok-soft) 70%, var(--surface));
  box-shadow: var(--shadow);
}
.live-box.active h2 {
  margin-top: 0;
  color: var(--ok);
}
.live-box.active table.list {
  margin-bottom: 0;
}
.live-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--ok);
  animation: live-pulse 1.6s ease-out infinite;
}
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
  100% { box-shadow: 0 0 0 0.6rem transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
}
.live-count {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--ok);
  color: var(--surface);
}
.clock {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
