:root {
  --bg: #0e1116;
  --bg-2: #151a21;
  --surface: #1a212b;
  --surface-2: #212a36;
  --border: #2a323d;
  --border-2: #38424f;
  --text: #e6edf3;
  --muted: #8b97a6;
  --faint: #5c6773;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --online: #22c55e;
  --offline: #6b7280;
  --alarm: #ef4444;
  --warn: #f59e0b;
  --temp: #f97316;
  --hum: #38bdf8;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #18222e 0%, var(--bg) 55%);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.material-symbols-outlined { font-variation-settings: 'wght' 400; vertical-align: middle; }
button { font-family: inherit; }

/* ---------------- Top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 22px;
  padding: 14px 24px;
  background: rgba(14,17,22,.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 19px; letter-spacing: .2px; }
.brand img { height: 60px; width: auto; border-radius: 8px; }

/* Eigener Bestätigungs-Dialog (statt window.confirm) */
.dx-confirm-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 10000; padding: 20px; opacity: 0; transition: opacity .15s; }
.dx-confirm-scrim.open { opacity: 1; }
.dx-confirm { background: var(--card, #161b22); color: var(--text, #e6edf3); border: 1px solid var(--border, #2a3038); border-radius: 14px; max-width: 420px; width: 100%; padding: 22px 24px; box-shadow: 0 24px 64px rgba(0,0,0,.55); transform: translateY(10px) scale(.98); transition: transform .15s; }
.dx-confirm-scrim.open .dx-confirm { transform: none; }
.dx-confirm-title { font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.dx-confirm-msg { font-size: 14px; color: var(--muted, #9aa4b2); line-height: 1.5; margin-bottom: 18px; }
.dx-confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Info-/Sperr-Symbole bei den Experten-Parametern (Tooltip via title) */
.pinfo { font-size: 13px; color: var(--faint, #5c6773); cursor: help; vertical-align: middle; margin-left: 3px; transition: color .15s; }
.pinfo:hover { color: var(--accent, #2563eb); }
/* Breites Diagramm-Modal */
.chart-modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10000; padding: 24px; opacity: 0; transition: opacity .15s; }
.chart-modal-scrim.open { opacity: 1; }
.chart-modal { background: var(--card, #161b22); border: 1px solid var(--border, #2a3038); border-radius: 16px; width: 94vw; max-width: 1150px; padding: 18px 22px; box-shadow: 0 24px 64px rgba(0,0,0,.55); }
.kpis { display: flex; gap: 10px; }
.kpi {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
}
.kpi .dot { width: 9px; height: 9px; border-radius: 50%; }
.kpi .num { font-size: 15px; font-weight: 800; }
.kpi.online .dot { background: var(--online); box-shadow: 0 0 8px var(--online); }
.kpi.offline .dot { background: var(--offline); }
.kpi.alarm .dot { background: var(--alarm); box-shadow: 0 0 8px var(--alarm); }
.kpi.alarm { color: #fca5a5; border-color: #4a2a2a; }
.kpi .label { color: var(--muted); font-weight: 500; }
.spacer { flex: 1; }

/* Navigation (Tabs in der Topbar) */
.nav { display: flex; gap: 4px; }
.nav a { display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; border-radius: 9px; color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 600; text-decoration: none; }
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a.active { background: var(--surface-2); color: #fff; }
.nav a .material-symbols-outlined { font-size: 19px; }

/* Gruppen-Überschriften im Cockpit */
.grp-company { font-size: 16px; font-weight: 800; margin: 22px 2px 4px; color: var(--text); }
.grp-prop { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 2px 10px; }
.grp-prop .material-symbols-outlined { font-size: 17px; color: var(--faint); }
.grp-company + .grp-prop { margin-top: 6px; }

/* Verwaltungs-Ansichten: Kopf + Tabellen */
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.view-head h1 { margin: 0; font-size: 22px; }
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.tbl th, table.tbl td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
table.tbl th { background: var(--bg-2); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.tbl tbody tr { cursor: pointer; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }
.right { text-align: right; }

/* Status-Pillen */
.pill.green { background: rgba(34,197,94,.15); color: #4ade80; }
.pill.amber { background: rgba(245,158,11,.15); color: #fbbf24; }
.pill.blue  { background: rgba(59,130,246,.15); color: #93c5fd; }
.pill.gray  { background: rgba(107,114,128,.18); color: #9aa4b1; }
.pill.red   { background: rgba(239,68,68,.15); color: #fca5a5; }
.live-badge { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.live-badge .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--online); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.25} }

.tbtn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-size: 13px; font-weight: 600;
}
.tbtn:hover { background: var(--surface-2); border-color: var(--border-2); }
.tbtn.primary { background: var(--accent); border-color: var(--accent); }
.tbtn.primary:hover { background: var(--accent-2); }
.tbtn .material-symbols-outlined { font-size: 18px; }

/* ---------------- Layout ---------------- */
.wrap { padding: 22px 24px 60px; max-width: 1500px; margin: 0 auto; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 26px 4px 12px; font-weight: 700; }

/* ---------------- Alarm strip ---------------- */
.alarm-strip { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.alarm-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-radius: 12px; cursor: pointer;
  background: linear-gradient(90deg, rgba(239,68,68,.16), rgba(239,68,68,.05));
  border: 1px solid #4a2a2a;
}
.alarm-row:hover { border-color: var(--alarm); }
.alarm-row .ic { color: var(--alarm); display: flex; }
.alarm-row .txt { flex: 1; }
.alarm-row .txt b { color: #fecaca; }
.alarm-row .when { color: var(--muted); font-size: 12px; }

/* ---------------- Device grid ---------------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.tile {
  position: relative; cursor: pointer;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 16px 12px; overflow: hidden;
  transition: transform .1s ease, border-color .15s ease, box-shadow .15s ease;
}
.tile:hover { transform: translateY(-3px); border-color: var(--border-2); box-shadow: var(--shadow); }
.tile.alarm { border-color: #5b2b2b; box-shadow: inset 0 0 0 1px rgba(239,68,68,.25); }
.tile.offline { opacity: .72; }
.tile .top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.tile .name { font-weight: 700; font-size: 16px; }
.tile .sn { color: var(--faint); font-size: 12px; margin-top: 2px; }
.tile .st {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 9px; border-radius: 999px;
}
.tile .st .d { width: 7px; height: 7px; border-radius: 50%; }
.st.online { background: rgba(34,197,94,.12); color: #4ade80; }
.st.online .d { background: var(--online); box-shadow: 0 0 6px var(--online); }
.st.offline { background: rgba(107,114,128,.15); color: #9aa4b1; }
.st.offline .d { background: var(--offline); }
.st.alarm { background: rgba(239,68,68,.15); color: #fca5a5; }
.st.alarm .d { background: var(--alarm); box-shadow: 0 0 6px var(--alarm); }

.readout { display: flex; gap: 18px; align-items: baseline; margin-bottom: 8px; }
.readout .big { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.readout .big small { font-size: 15px; color: var(--muted); font-weight: 600; margin-left: 2px; }
.readout .temp { color: var(--temp); }
.readout .hum { color: var(--hum); }
.spark { width: 100%; height: 38px; display: block; margin: 2px 0 10px; }
.tile .foot { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.tile .foot .cust { display: flex; align-items: center; gap: 6px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .material-symbols-outlined { font-size: 46px; color: var(--faint); display: block; margin-bottom: 10px; }

/* ---------------- Drawer (slide-over) ---------------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 94vw);
  background: var(--bg-2); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .25s cubic-bezier(.4,0,.2,1);
  z-index: 41; display: flex; flex-direction: column; box-shadow: -20px 0 50px rgba(0,0,0,.5);
}
.drawer.open { transform: translateX(0); }
.drawer header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.drawer header h2 { margin: 0; font-size: 18px; }
.drawer header .sub { color: var(--faint); font-size: 12px; margin-top: 3px; }
.drawer .body { padding: 20px 22px; overflow-y: auto; flex: 1; }

.gauges { display: flex; gap: 14px; margin-bottom: 18px; }
.gauge { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; }
.gauge .v { font-size: 26px; font-weight: 800; }
.gauge .v.temp { color: var(--temp); }
.gauge .v.hum { color: var(--hum); }
.gauge .l { color: var(--muted); font-size: 12px; margin-top: 3px; }

.range-row { display: flex; gap: 7px; margin: 14px 0 10px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 600; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; height: 240px; position: relative; }

.acc { border: 1px solid var(--border); border-radius: 12px; margin-top: 16px; overflow: hidden; }
.acc summary { padding: 13px 16px; cursor: pointer; font-weight: 700; background: var(--surface); list-style: none; display: flex; align-items: center; gap: 8px; }
.acc summary::-webkit-details-marker { display: none; }
.acc .acc-body { padding: 16px; }

.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
input, select {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text); font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
input[readonly] { color: var(--muted); }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 10px 16px; border-radius: 10px; border: none; cursor: pointer; font-size: 14px; font-weight: 700; background: var(--accent); color: #fff; }
.btn:hover { background: var(--accent-2); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--alarm); }
.btn.danger:hover { background: #dc2626; }
.btn.block { width: 100%; justify-content: center; }
.btn .material-symbols-outlined { font-size: 18px; }
.row-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.keybox { background: var(--bg); border: 1px dashed var(--border-2); border-radius: 9px; padding: 11px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; color: var(--accent-2); }

.list { display: flex; flex-direction: column; gap: 8px; }
.list .item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item .grow .t { font-weight: 600; }
.list .item .grow .s { color: var(--muted); font-size: 12px; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 700; }
.pill.red { background: rgba(239,68,68,.15); color: #fca5a5; }
.pill.gray { background: rgba(107,114,128,.18); color: #9aa4b1; }

/* ---------------- Modal ---------------- */
.modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-scrim.open { display: flex; }
.modal { background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; font-size: 17px; }
.modal .body { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal .foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------- Toast ---------------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text); padding: 13px 20px; border-radius: 12px; box-shadow: var(--shadow); z-index: 100; opacity: 0; transition: all .22s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--alarm); color: #fca5a5; }

/* ---------------- Login ---------------- */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { background: var(--bg-2); border: 1px solid var(--border); padding: 38px 34px; border-radius: 18px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-card .logo { text-align: center; margin-bottom: 8px; }
.login-card .logo img { height: 40px; }
.login-card h1 { text-align: center; font-size: 19px; margin: 0 0 24px; font-weight: 700; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.login-error { color: #fca5a5; font-size: 13px; margin-top: 12px; text-align: center; min-height: 18px; }

@media (max-width: 640px) {
  .kpis .label { display: none; }
  .topbar { gap: 12px; padding: 12px 14px; }
  .param-grid { grid-template-columns: 1fr; }
}
