@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  color-scheme: light;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E2E8F0;

  --text: #101828;
  --text-2: #51606F;
  --text-3: #8A96A3;

  --primary: #0B5FA5;
  --primary-dark: #084677;
  --primary-light: #EAF2FB;

  --teal: #0E9594;
  --teal-light: #E1F5F4;

  --green: #157F3C;
  --green-bg: #E8F6EC;

  --yellow: #9A6700;
  --yellow-bg: #FDF3DA;

  --red: #D1293D;
  --red-bg: #FBE9EB;

  --radius: 10px;
  --radius-sm: 7px;
  --radius-pill: 999px;
  --sidebar-w: 232px;
  --topbar-h: 64px;

  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 6px rgba(16, 24, 40, .06);

  --font-ui: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--primary-dark);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 16px;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 14.5px; font-weight: 700; color: #fff; letter-spacing: -0.01em; }
.brand-text span { font-size: 10.5px; color: rgba(255, 255, 255, 0.55); letter-spacing: 0.02em; }

.nav-scroll { flex: 1; padding: 10px 12px 20px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.68);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, 0.14); color: #fff; }

.nav-subgroup { margin: 2px 0 10px; padding-left: 16px; display: flex; flex-direction: column; gap: 1px; }
.nav-subitem {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.nav-subitem:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-subitem.active { background: rgba(255, 255, 255, 0.14); color: #fff; }

.sidebar-foot {
  padding: 14px 20px 18px;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 0.02em;
}

/* ---------- Main column ---------- */

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.search {
  flex: 1;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius-pill);
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-3);
}
.search svg { width: 16px; height: 16px; flex-shrink: 0; }
.search input { border: none; background: none; padding: 0; width: 100%; font-size: 13.5px; }
.search input:focus { outline: none; }

.admin-menu { position: relative; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  border: none;
}
.dropdown {
  position: absolute;
  top: 46px;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 200px;
  padding: 6px;
  z-index: 40;
  display: none;
}
.dropdown.open { display: block; }
.dropdown .who { padding: 8px 10px 10px; font-size: 12.5px; color: var(--text-2); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown a, .dropdown button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.dropdown a:hover, .dropdown button:hover { background: var(--bg); }
.dropdown svg { width: 15px; height: 15px; color: var(--text-3); }

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 32px 48px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.breadcrumb { font-size: 12px; color: var(--text-3); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.breadcrumb a { color: var(--text-3); text-decoration: none; font-weight: 600; }
.breadcrumb a:hover { color: var(--primary); }
.page-title { font-size: 22px; font-weight: 800; margin: 0; letter-spacing: -0.01em; }
.page-sub { color: var(--text-2); font-size: 13.5px; margin: 4px 0 0; }
.page-actions { display: flex; gap: 10px; flex-shrink: 0; }

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

.btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-danger-solid { background: var(--red); color: #fff; }
.btn-danger-solid:hover { background: #a81f30; }
.btn-ghost { background: none; color: var(--text-2); padding: 7px 10px; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-ghost-danger { background: none; color: var(--red); padding: 7px 10px; }
.btn-ghost-danger:hover { background: var(--red-bg); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- Card ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card h3, .section-head { font-size: 13.5px; margin: 0; font-weight: 700; color: var(--text); letter-spacing: -0.005em; }
.card p.hint { color: var(--text-2); font-size: 12.5px; margin: -6px 0 14px; }

/* ---------- Filters ---------- */

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.input, .select {
  font: inherit;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus { outline: none; border-color: var(--primary); }
.filter-chip {
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.filter-chip.on { background: var(--primary-light); color: var(--primary); border-color: var(--primary-light); }

/* ---------- Table ---------- */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-3); font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr:last-child td { border-bottom: none; }
tr.row-link { cursor: pointer; }
tr.row-link:hover { background: var(--bg); }
.mono { font-family: var(--font-mono); font-size: 12px; color: var(--text-2); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ---------- Chips / status ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.chip-green { background: var(--green-bg); color: var(--green); }
.chip-gray { background: var(--bg); color: var(--text-2); }
.chip-blue { background: var(--primary-light); color: var(--primary); }
.chip-teal { background: var(--teal-light); color: var(--teal); }
.chip-yellow { background: var(--yellow-bg); color: var(--yellow); }
.chip-red { background: var(--red-bg); color: var(--red); }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-green { background: var(--green); }
.dot-gray { background: var(--text-3); }
.dot-red { background: var(--red); }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 11px 4px;
  margin-right: 22px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- KPI grid ---------- */

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1000px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-label { font-size: 11.5px; color: var(--text-2); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; }

/* ---------- Form fields ---------- */

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .input, .field .select { width: 100%; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* ---------- Toggle ---------- */

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .tr-label { font-size: 13.5px; font-weight: 600; }
.toggle-row .tr-sub { font-size: 12px; color: var(--text-2); margin-top: 1px; }
.toggle {
  width: 40px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--border);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.3);
  transition: transform 0.15s ease;
}
.toggle.on { background: var(--primary); }
.toggle.on .knob { transform: translateX(18px); }

/* ---------- Danger zone ---------- */

.danger-zone {
  border: 1px solid var(--red-bg);
  background: var(--red-bg);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-top: 8px;
}
.danger-zone h3 { color: var(--red); margin: 0 0 4px; }
.danger-zone p { color: #8a2432; font-size: 12.5px; margin: 0 0 14px; }

/* ---------- Tree (Organisationen) ---------- */

.tree-row { display: flex; align-items: center; gap: 6px; }
.tree-toggle {
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tree-spacer { width: 20px; flex-shrink: 0; }
.tree-name { font-weight: 600; }

/* ---------- Credentials box ---------- */

.cred-box { border: 2px solid var(--primary); background: var(--primary-light); }
.cred-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.cred-row .input { flex: 1; background: var(--surface); }
.copy-btn { flex-shrink: 0; }

/* ---------- Info popup ---------- */

.info-wrap { position: relative; display: inline-flex; vertical-align: middle; margin-left: 7px; }
.info-icon-btn {
  width: 17px; height: 17px; padding: 0; border-radius: 50%;
  background: var(--bg); color: var(--text-3); border: none;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.info-icon-btn svg { width: 11px; height: 11px; }
.info-icon-btn:hover { background: var(--primary); color: #fff; }
.info-popup {
  display: none; position: absolute; z-index: 30; top: 22px; left: 0;
  width: 260px; max-width: 70vw; background: var(--text); color: #fff;
  font-size: 12px; font-weight: 400; line-height: 1.5; padding: 10px 12px;
  border-radius: 10px; box-shadow: 0 10px 28px rgba(16, 35, 60, 0.25);
}
.info-popup.open { display: block; }

/* ---------- Misc ---------- */

.error { color: var(--red); font-size: 12.5px; }
.muted { color: var(--text-2); font-size: 13px; }
.empty-state { text-align: center; padding: 30px 10px; color: var(--text-2); font-size: 13.5px; }
a.link { color: var(--primary); text-decoration: none; font-weight: 600; }
a.link:hover { text-decoration: underline; }

.bar-track { height: 8px; border-radius: var(--radius-pill); background: var(--bg); overflow: hidden; margin-top: 8px; }
.bar-fill { height: 100%; border-radius: var(--radius-pill); background: var(--primary); }

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

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { width: 360px; background: var(--surface); border-radius: var(--radius); padding: 40px 34px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.login-card .brand-mark { margin: 0 auto 18px; width: 46px; height: 46px; border-radius: var(--radius); font-size: 20px; background: var(--primary-light); color: var(--primary); }
.login-card h2 { text-align: center; margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.login-card .muted { text-align: center; margin-bottom: 24px; display: block; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card .btn { justify-content: center; padding: 12px; margin-top: 6px; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 42, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 1000;
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px 28px; max-width: 420px; width: 100%; max-height: 86vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; font-size: 16px; font-weight: 800; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Drawer (Gerätedetail etc.) ---------- */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 42, 0.35);
  display: flex;
  justify-content: flex-end;
  z-index: 900;
}
.drawer {
  width: min(720px, 56vw);
  max-width: 94vw;
  height: 100vh;
  background: var(--surface);
  box-shadow: -8px 0 24px rgba(16, 24, 40, 0.14);
  overflow-y: auto;
  padding: 24px 28px 48px;
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-close {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  padding: 7px;
  border-radius: 50%;
  display: flex;
  flex-shrink: 0;
}
.drawer-close svg { width: 16px; height: 16px; }
.drawer-close:hover { background: var(--bg); color: var(--text); }

@media (max-width: 860px) {
  .drawer { width: 100vw; max-width: 100vw; }
}

.spinner {
  display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%; vertical-align: middle; margin-right: 8px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 50; height: 100vh; transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 20px 16px 40px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Toast (Speichern-Bestätigung) ---------- */

.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 1100;
  display: flex; align-items: center; gap: 8px;
  background: var(--green-bg); color: var(--green); border: 1px solid var(--green);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 11px 16px; font-size: 14px; font-weight: 700;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.toast.out { opacity: 0; transform: translateY(6px); }
.toast .icon-inline { display: inline-flex; }
