/* nativeai Verwaltung
   Leitidee: ruhige Schieferflächen, eine einzige Akzentfarbe (Ocker, "Sand"),
   und Füllstandsanzeigen als segmentierte Balken – der Blick soll sofort sehen,
   wie voll jeder Sandkasten ist. */

:root {
  --ground: #e9edf1;
  --panel: #ffffff;
  --ink: #18202b;
  --muted: #5b6676;
  --line: #d5dbe2;
  --sand: #b9831f;
  --sand-soft: #f3e6cb;
  --empty: #e3e8ee;
  --ok: #2f855a;
  --bad: #c53030;
  --bad-soft: #fbe3e3;
  --focus: #2b6cb0;

  --r-sm: 6px;
  --r-md: 10px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #14181e;
    --panel: #1c222a;
    --ink: #e6eaf0;
    --muted: #93a0b2;
    --line: #2c343f;
    --sand: #e0a93a;
    --sand-soft: #3a3120;
    --empty: #2a313b;
    --ok: #57b885;
    --bad: #f07272;
    --bad-soft: #3d2326;
    --focus: #7fb0ea;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- Kopfzeile */

.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 12px max(16px, calc((100vw - 1120px) / 2));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.mark { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; text-decoration: none; }
.mark span { font-weight: 400; color: var(--muted); }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px; border-radius: var(--r-sm);
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--ground); }
.bar-actions { margin-left: auto; display: flex; gap: 8px; }

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

main { max-width: 1120px; margin: 0 auto; padding: 28px 16px 64px; outline: none; }
h1 { font-size: 26px; line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 4px; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 650; letter-spacing: -0.005em; }
.lede { color: var(--muted); margin: 0 0 24px; max-width: 68ch; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head .lede { margin: 0; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--ink); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 20px;
}
.stack > * + * { margin-top: var(--gap); }
.cols { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--gap); align-items: start; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- Host-Leiste */

.host {
  display: flex; flex-wrap: wrap; gap: 12px 32px; align-items: center;
  padding: 14px 20px; margin-bottom: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md);
}
.host-item { display: grid; gap: 4px; min-width: 150px; }
.host-item .k { color: var(--muted); font-size: 13px; }
.host-item .v { font-weight: 600; }
.host-name { font-weight: 650; margin-right: auto; }
.host-name small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }

.services { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.svc { display: inline-flex; align-items: center; gap: 6px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.active { background: var(--ok); }
.dot.failed, .dot.inactive { background: var(--bad); }
.dot.activating, .dot.deactivating, .dot.reloading { background: var(--sand); }

/* ---------------------------------------------------------------- Füllstand (das eine prägnante Element) */

.meter { display: grid; gap: 5px; }
.meter-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.meter-top .k { color: var(--muted); }
.meter-top .v { font-weight: 600; white-space: nowrap; }
.cells { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; height: 10px; }
.cells i { background: var(--empty); border-radius: 2px; }
.cells i.on { background: var(--sand); }
.meter.full .cells i.on { background: var(--bad); }
.meter.full .v { color: var(--bad); }
.meter.unknown .cells i { background: repeating-linear-gradient(45deg, var(--empty) 0 3px, transparent 3px 6px); }

/* ---------------------------------------------------------------- Mandantenliste */

.tenants { padding: 0; overflow: hidden; }
.trow {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) repeat(3, minmax(120px, 1fr)) 170px;
  gap: 24px; align-items: center;
  padding: 16px 20px;
  text-decoration: none;
  border-top: 1px solid var(--line);
}
.trow:first-child { border-top: 0; }
.trow:hover { background: color-mix(in srgb, var(--ground) 55%, var(--panel)); }
.tname { font-weight: 650; font-size: 16px; }
.tsub { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.tflags { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 860px) {
  .trow { grid-template-columns: 1fr 1fr; gap: 14px 20px; }
}
@media (max-width: 520px) {
  .trow { grid-template-columns: 1fr; gap: 12px; }
}
@media (max-width: 860px) {
  .trow > :first-child { grid-column: 1 / -1; }
  .tflags { justify-content: flex-start; grid-column: 1 / -1; }
}

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px;
  font-size: 12.5px; font-weight: 500;
  background: var(--ground); color: var(--muted);
  border: 1px solid var(--line);
}
.tag.warn { background: var(--sand-soft); color: var(--ink); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.empty { text-align: center; padding: 56px 20px; }
.empty p { color: var(--muted); margin: 6px auto 20px; max-width: 46ch; }

/* ---------------------------------------------------------------- Formulare */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }
label { display: grid; gap: 6px; font-weight: 550; font-size: 14px; align-content: start; }
label small { font-weight: 400; color: var(--muted); }
.lbl small { margin-left: 4px; }
label .help { margin-top: -2px; }
.field { position: relative; display: flex; align-items: center; }
.field .unit { position: absolute; right: 12px; color: var(--muted); pointer-events: none; font-weight: 400; }
input[type=text], input[type=number], input[type=password], select {
  width: 100%; padding: 9px 12px; font: inherit; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm);
}
input[type=number] { padding-right: 44px; }
input:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
input[aria-invalid=true] { border-color: var(--bad); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-weight: 550; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 42px; height: 24px; border-radius: 999px; background: var(--empty); position: relative; flex: none;
  transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--panel); box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .15s;
}
.switch input:checked + .track { background: var(--sand); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

/* ---------------------------------------------------------------- Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; font: inherit; font-weight: 600; font-size: 14px;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.btn-primary:hover { opacity: .9; border-color: var(--ink); }
.btn-quiet { border-color: transparent; color: var(--muted); background: transparent; }
.btn-quiet:hover { color: var(--ink); border-color: transparent; }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ---------------------------------------------------------------- Apps-Tabelle */

.apps { width: 100%; border-collapse: collapse; }
.apps th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 0 10px 8px 0; }
.apps td { padding: 10px 10px 10px 0; border-top: 1px solid var(--line); vertical-align: middle; }
.apps td:last-child, .apps th:last-child { padding-right: 0; text-align: right; }
.apps .aname { font-weight: 600; }
.apps .aname a { text-decoration: none; }
.apps .aname a:hover { text-decoration: underline; }
.apps .state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.apps .btns { display: inline-flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 600px) {
  .apps thead { display: none; }
  .apps tr { display: grid; grid-template-columns: 1fr auto; padding: 10px 0; border-top: 1px solid var(--line); }
  .apps td { border: 0; padding: 2px 0; }
  .apps td.btnscell { grid-column: 1 / -1; text-align: left; }
  .apps .btns { justify-content: flex-start; margin-top: 6px; }
}

/* ---------------------------------------------------------------- Login */

.login { max-width: 380px; margin: 12vh auto 0; }
.login .mark { display: block; margin-bottom: 18px; font-size: 20px; }
.login .btn { width: 100%; margin-top: 16px; }
.msg { padding: 10px 12px; border-radius: var(--r-sm); background: var(--bad-soft); color: var(--bad); margin: 12px 0 0; }
.msg.info { background: var(--sand-soft); color: var(--ink); }

/* ---------------------------------------------------------------- Gefahrenzone */

.danger { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.danger-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.danger-row + .danger-row { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.danger-row p { margin: 2px 0 0; color: var(--muted); font-size: 14px; max-width: 56ch; }

/* ---------------------------------------------------------------- Ausgaben */

pre.out {
  margin: 0; padding: 14px; max-height: 60vh; overflow: auto;
  background: var(--ground); border-radius: var(--r-sm);
  font: 12.5px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
pre.out .l-ok { color: var(--ok); }
pre.out .l-warn { color: var(--sand); }
pre.out .l-bad { color: var(--bad); font-weight: 600; }
pre.out .l-head { font-weight: 700; }

.copyrow { display: flex; gap: 8px; align-items: stretch; }
.copyrow code {
  flex: 1; min-width: 0; padding: 9px 12px; border-radius: var(--r-sm);
  background: var(--ground); font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- Dialog */

dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--panel); color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / .28);
}
dialog.wide { width: min(900px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(15 20 28 / .45); }
.dialog-body { padding: 22px; display: grid; gap: 14px; }
.dialog-body h2 { margin: 0; font-size: 19px; }
.dialog-body p { margin: 0; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: pop .16s ease-out; }
  @keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }
}

/* ---------------------------------------------------------------- Toasts */

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast {
  padding: 10px 14px; border-radius: var(--r-sm); max-width: 380px;
  background: var(--ink); color: var(--panel); font-weight: 500; font-size: 14px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .2);
}
.toast.bad { background: var(--bad); color: #fff; }

/* ---------------------------------------------------------------- Kleinkram */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; }
@media (prefers-reduced-motion: no-preference) { .spinner { animation: spin .7s linear infinite; } }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { color: var(--muted); display: flex; gap: 10px; align-items: center; padding: 40px 0; }

@media (max-width: 640px) {
  .bar { flex-wrap: wrap; gap: 10px 16px; }
  .bar-actions { margin-left: 0; width: 100%; }
  .bar-actions .btn-primary { flex: 1; }
  main { padding-top: 20px; }
  h1 { font-size: 22px; }
}

/* Hilfsklassen (statt Inline-Styles, die die Content-Security-Policy blockiert) */
.host-meter { min-width: 190px; }
.narrow { max-width: 640px; }
.gap-below { margin-bottom: 18px; }
.gap-below-sm { margin-bottom: 10px; }
.normal { font-weight: 400; }
.spaced { margin-top: var(--gap); }
.inline { display: flex; gap: 8px; align-items: center; }
select.auto { width: auto; }
.after { margin-top: 14px; }
.flush { margin-top: 0; }
