:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232d;
  --line: #2a3340;
  --text: #dbe2ea;
  --muted: #8392a5;
  --accent: #5ad1b5;
  --accent-ink: #062a22;
  --warn: #f0b44c;
  --bad: #ef6b6b;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  --sans: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); }
body { min-height: 100vh; --grid: color-mix(in srgb, var(--line) 35%, transparent); background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 48px 48px; background-position: -1px -1px; background-attachment: fixed; }
body::before { content: ""; position: fixed; inset: 0; background: radial-gradient(ellipse at top, transparent 0%, var(--bg) 70%); pointer-events: none; z-index: -1; }
[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel-2); border-radius: 6px; padding: 7px 12px; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:disabled { opacity: .45; cursor: not-allowed; }
button.danger { color: var(--bad); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); }
input, select { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error { color: var(--bad); font-size: 13px; min-height: 1.2em; margin-top: 10px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(340px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 26px; }
.login button { width: 100%; margin-top: 18px; }
.login button.passkey { margin-top: 8px; background: transparent; }
.userlist li .hint { font-family: var(--sans); }

/* Kopf */
header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 12px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--mono); font-weight: 700; letter-spacing: .14em; font-size: 14px; }
.brand span { color: var(--accent); }
.slots { display: flex; gap: 4px; margin-left: 6px; }
.slots i { width: 10px; height: 18px; border-radius: 2px; background: var(--panel-2); border: 1px solid var(--line); }
.slots i.on { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 60%, transparent); }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }

main { padding: 22px 20px 60px; max-width: 1180px; margin: 0 auto; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* VM-Karte */
.vm { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.vm-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.led { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.led.ready.running { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.led.ready.stopped { background: var(--muted); }
.led.creating, .led.deleting { background: var(--warn); animation: blink 1s infinite; }
.led.error { background: var(--bad); box-shadow: 0 0 10px var(--bad); }
@keyframes blink { 50% { opacity: .3; } }
.vm-name { font-family: var(--mono); font-weight: 700; font-size: 16px; }
.vm-tpl { color: var(--muted); font-size: 12px; margin-left: auto; text-align: right; }
.vm-body { padding: 0 16px 12px; flex: 1; }
.kv { display: grid; grid-template-columns: 74px 1fr auto; gap: 4px 8px; align-items: center; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
.copy { padding: 2px 7px; font-size: 11px; color: var(--muted); }
.copy.done { color: var(--accent); border-color: var(--accent); }
.progress { margin-top: 4px; }
.progress ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 3px; font-size: 13px; }
.progress li { color: var(--muted); padding-left: 18px; position: relative; }
.progress li::before { content: "○"; position: absolute; left: 0; }
.progress li.done { color: var(--text); }
.progress li.done::before { content: "●"; color: var(--accent); }
.progress li.now { color: var(--warn); }
.progress li.now::before { content: "◐"; animation: blink 1s infinite; }
.progress li.fail { color: var(--bad); }
.progress li.fail::before { content: "✕"; }
.errbox { background: color-mix(in srgb, var(--bad) 12%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); color: #ffc9c9; border-radius: 6px; padding: 8px 10px; font-size: 13px; margin-top: 10px; overflow-wrap: anywhere; }
.vm-foot { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel-2); flex-wrap: wrap; }
.vm-foot .primary { flex: 1; }
details.sql { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
details.sql summary { cursor: pointer; color: var(--muted); font-size: 13px; }
pre.file { font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; }

.empty { border: 1px dashed var(--line); border-radius: 10px; padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* Dialoge */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(440px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog form, dialog .inner { padding: 22px; }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.tpls { display: grid; gap: 6px; }
.tpls label { display: flex; align-items: center; gap: 10px; margin: 0; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); cursor: pointer; }
.tpls input { width: auto; accent-color: var(--accent); }
.tpls label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.userlist { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
.userlist li { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; font-family: var(--mono); }
.row { display: flex; gap: 8px; }
button.lock { color: var(--muted); }
button.lock.on { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
button.lock.on::before { content: "🔒 "; }
.snaplist li { font-family: var(--sans); gap: 10px; }

/* Vorlagen */
.tabs { display: flex; gap: 2px; margin-left: 10px; border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 5px; }
.tab.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
h2.section { font-size: 15px; margin: 8px 0 12px; font-weight: 600; }
h2.section:not(:first-child) { margin-top: 32px; }
h2.section .hint { font-weight: 400; margin-left: 8px; }
.tpl-list { display: grid; gap: 8px; }
.tpl { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 12px 14px; flex-wrap: wrap; }
.tpl.retired { border-left-color: var(--muted); opacity: .8; }
.tpl .tag { margin-left: 4px; }
.led.publishing { background: var(--warn); animation: blink 1s infinite; }

/* Datenbanken */
dialog.wide { width: min(720px, calc(100% - 32px)); }
.dbserver { margin-top: 18px; }
.dbserver h3 { font-size: 15px; margin: 0 0 8px; }
.dbtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dbtable th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 6px 8px; }
.dbtable td { border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); padding: 6px 8px; }
.dbtable td:nth-child(2) { white-space: nowrap; }
.mono { font-family: var(--mono); overflow-wrap: anywhere; }
.tag { font-family: var(--mono); font-size: 12px; color: var(--accent-ink); background: var(--accent); border-radius: 4px; padding: 1px 6px; }

/* Fernzugriff */
.remote { background: #000; overflow: hidden; height: 100vh; }
.remote body, body.remote { background: #000; background-image: none; }
.remote-bar { position: fixed; top: 0; left: 50%; transform: translate(-50%, -100%); transition: transform .15s; z-index: 10; display: flex; gap: 6px; padding: 6px 8px 8px; background: var(--panel); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 10px 10px; align-items: center; }
.remote-bar.open, .remote-bar:hover, .remote-bar:focus-within { transform: translate(-50%, 0); }
.remote-bar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -14px; height: 14px; }
.remote-bar .tab { position: absolute; left: 50%; bottom: -16px; transform: translateX(-50%); width: 46px; height: 16px; background: var(--panel); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; }
.remote-bar .name { font-family: var(--mono); font-size: 13px; padding: 0 6px; color: var(--accent); }
/* isolate: Guacamole legt Canvas mit z-index -1 an, sonst liegt es hinter dem Body-Hintergrund */
#screen { width: 100vw; height: 100vh; display: grid; place-items: center; isolation: isolate; }
#screen > div { cursor: none; }
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.75); z-index: 20; text-align: center; padding: 16px; }
.overlay .box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px 26px; max-width: 420px; }
.clip { position: fixed; top: 52px; left: 50%; transform: translateX(-50%); z-index: 11; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; width: min(420px, calc(100% - 32px)); }
.clip textarea { width: 100%; height: 120px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; font-family: var(--mono); font-size: 12px; padding: 8px; }

/* Dateien */
.files-bar { display: flex; align-items: center; gap: 10px; }
.crumbs { flex: 1; display: flex; align-items: center; flex-wrap: wrap; font-family: var(--mono); color: var(--muted); }
.crumbs button { padding: 4px 6px; font-family: var(--mono); color: var(--text); }
#files-view.drag { outline: 2px dashed var(--accent); outline-offset: -8px; border-radius: 12px; }
#uploads, .files { display: grid; gap: 6px; margin-top: 14px; }
.file { display: grid; grid-template-columns: 1fr 90px 130px auto; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.file .name { font-family: var(--mono); color: var(--text); text-decoration: none; overflow-wrap: anywhere; text-align: left; background: none; border: 0; padding: 0; }
.file button.name:hover, .file .dir:hover { color: var(--accent); }
.file .dir { color: var(--accent); }
.file .dl { color: var(--accent); font-weight: 700; margin-right: 8px; }
.file.up { grid-template-columns: 1fr 2fr 50px; }
.file progress { width: 100%; accent-color: var(--accent); }

@media (max-width: 560px) {
  .file { grid-template-columns: 1fr auto; }
  .file > .hint { display: none; }
  header { padding: 10px 14px; gap: 10px; }
  .who, .slots, #btn-dbs, #btn-users { display: none; }
  header button { padding: 6px 9px; font-size: 14px; }
  main { padding: 16px 14px 40px; }
  .grid { grid-template-columns: 1fr; }
}
