:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --accent: #06b6d4;
  --dark: #0b0c2f;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e3e7f0;
  --text: #0f172a;
  --muted: #64748b;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --crit: #dc2626;
  --crit-bg: #fee2e2;
  --off: #94a3b8;
  --off-bg: #f1f5f9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}

h1 { font-size: 1.6rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--crit); margin: .5rem 0 0; font-size: .9rem; }

/* Buttons & Inputs */
.btn {
  font: inherit; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .55rem 1rem; border-radius: 8px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #c7cede; background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { border-color: transparent; background: transparent; color: #cbd5e1; }
.btn-ghost:hover { background: rgba(255,255,255,.08); border-color: transparent; color: #fff; }
.btn-small { padding: .3rem .65rem; font-size: .85rem; }
.btn-danger { color: var(--crit); }
.btn-block { width: 100%; }

input, select {
  font: inherit; width: 100%;
  padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid rgba(37, 99, 235, .25); border-color: var(--primary); }
label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: .9rem; }
label > input, label > select { margin-top: .3rem; font-weight: 400; }

/* Login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, #1e1f4b 0%, var(--dark) 60%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  padding: 2rem; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-logo { height: 44px; display: block; margin-bottom: 1.2rem; }
.login-card h1 { font-size: 1.4rem; }
.login-card .muted:first-of-type { margin: 0 0 1.5rem; }
.login-card .small { margin: 1.2rem 0 0; text-align: center; }

/* Topbar */
.topbar { background: var(--dark); color: #fff; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: .7rem 16px;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .7rem; color: #fff; text-decoration: none; font-weight: 600; }
.brand img { height: 30px; background: #fff; border-radius: 6px; padding: 3px 6px; }
.topnav { display: flex; gap: .3rem; }
.topnav a { color: #cbd5e1; text-decoration: none; padding: .4rem .8rem; border-radius: 8px; }
.topnav a.active, .topnav a:hover { color: #fff; background: rgba(255,255,255,.1); }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.user-menu .muted { color: #94a3b8; margin-right: .4rem; font-size: .9rem; }

.demo-banner { background: var(--warn-bg); color: #92400e; text-align: center; padding: .5rem 16px; font-size: .9rem; }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 2rem 16px 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head p { margin: 0; }
.page-actions { display: flex; gap: .5rem; align-items: center; }
.page-actions select { min-width: 260px; }

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

/* Kennzahlen */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.tile-label { font-size: .85rem; color: var(--muted); }
.tile-value { font-size: 1.8rem; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile-value.ok { color: var(--ok); }
.tile-value.warn { color: var(--warn); }

/* Filter */
.filters { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input { max-width: 280px; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { font: inherit; font-size: .88rem; border: 1px solid var(--border); background: var(--surface); padding: .35rem .85rem; border-radius: 999px; cursor: pointer; color: var(--muted); }
.chip.active { background: var(--dark); border-color: var(--dark); color: #fff; }

/* Geräte */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.device {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .8rem;
  border-top: 3px solid var(--ok);
}
.device.health-warning { border-top-color: var(--warn); }
.device.health-critical { border-top-color: var(--crit); }
.device.is-offline { border-top-color: var(--off); }
.device.is-offline.health-warning { border-top-color: var(--warn); }

.device-head { display: flex; justify-content: space-between; gap: .8rem; align-items: flex-start; }
.device-name { font-weight: 650; font-size: 1.05rem; word-break: break-word; }
.device-sub { color: var(--muted); font-size: .88rem; }
.badge { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 600; padding: .2rem .6rem; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge-online { background: var(--ok-bg); color: var(--ok); }
.badge-offline { background: var(--off-bg); color: #64748b; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem 1rem; font-size: .88rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .78rem; }
.facts dd { margin: 0; font-weight: 500; }

.disk { font-size: .85rem; }
.disk-row { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: .2rem; }
.bar { height: 7px; background: #eef1f6; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar > span.warn { background: var(--warn); }
.bar > span.crit { background: var(--crit); }

.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.alerts li { font-size: .85rem; padding: .45rem .65rem; border-radius: 8px; background: #eff6ff; color: #1e3a8a; }
.alerts li.sev-warning { background: var(--warn-bg); color: #92400e; }
.alerts li.sev-critical { background: var(--crit-bg); color: #991b1b; }
.all-good { font-size: .85rem; color: var(--ok); }

details.more summary { cursor: pointer; font-size: .88rem; color: var(--primary); user-select: none; }
details.more[open] summary { margin-bottom: .6rem; }

.contract { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding-top: .7rem; border-top: 1px dashed var(--border); font-size: .88rem; }
.contract strong { font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 3rem 1rem; }

/* Admin */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; align-items: end; }
.form-actions { margin-bottom: .9rem; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: .8rem; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.table td { padding: .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table td:last-child { text-align: right; white-space: nowrap; }
.tag { font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: var(--off-bg); color: var(--muted); }
.tag-admin { background: #e0e7ff; color: #3730a3; }
.tag-off { background: var(--crit-bg); color: var(--crit); }

/* Dialoge */
dialog { border: none; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(11, 12, 47, .5); }
.dialog-body { padding: 1.5rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.credentials { background: var(--bg); padding: 1rem; border-radius: 8px; white-space: pre-wrap; word-break: break-all; font-size: .9rem; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--dark); color: #fff; padding: .7rem 1.2rem; border-radius: 10px; font-size: .9rem;
  box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 10;
}

@media (max-width: 600px) {
  .devices { grid-template-columns: 1fr; }
  .page-actions { width: 100%; }
  .page-actions select { min-width: 0; flex: 1; }
  .user-menu { margin-left: 0; width: 100%; }
  .user-menu .muted { width: 100%; }
  .filters input { max-width: none; }
}
.contract > span:last-child { display: flex; align-items: center; gap: .6rem; white-space: nowrap; }

/* Kunden-Editor */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
dialog.dlg-wide { width: min(820px, calc(100vw - 32px)); }
.hint { margin: -.3rem 0 1rem; }
.picker-tools { display: flex; gap: .8rem; flex-wrap: wrap; align-items: center; margin-bottom: .6rem; }
.picker-tools input { max-width: 300px; }
.picker { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.pick { display: flex; align-items: center; gap: .7rem; padding: .45rem .8rem; border-bottom: 1px solid var(--border); margin: 0; font-weight: 400; cursor: pointer; }
.pick:last-child { border-bottom: none; }
.pick:hover { background: #f8fafc; }
.pick input { width: auto; margin: 0; flex: none; }
.pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-meta { display: flex; gap: .3rem; flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.dot.on { background: var(--ok); }
.tag-kw { background: #e0f2fe; color: #075985; }
.tag-man { background: #ede9fe; color: #5b21b6; }
.tag-ex { background: var(--crit-bg); color: var(--crit); }
.tag-other { background: var(--warn-bg); color: #92400e; }
.table td .muted { font-size: .85rem; }
