:root {
  --page-bg: #070a0f;
  --bezel: #05080d;
  --screen: #0c1521;
  --panel: #101d2e;
  --panel-2: #132131;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #e6ecf3;
  --text-dim: #8296ab;
  --text-faint: #617489;
  --gold: #e8b84b;
  --blue: #6fb0f0;
  --teal: #5dcaa5;
  --danger: #e8705f;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page-bg);
  font-family: var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
svg { width: 1em; height: 1em; display: block; }

/* ---------- Tablet-Rahmen ---------- */
/* ---------- Geraeterahmen ---------- */
/* Das Gehaeuse fuellt das gesamte Browserfenster und umrandet es. */
.device-stage {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
  background: #070a0f;
}
.device {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Rahmenbreite = Innenabstand; das Display sitzt so weit vom Fensterrand ein */
  padding: 16px;
  border-radius: 0;                 /* buendig am Browserfenster */
  background: linear-gradient(160deg, #171d25 0%, #0a0d12 55%, #05070a 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
/* Kamera-Punkt oben mittig */
.device::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2a3746 0%, #0b0f14 70%);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.05);
}
/* Home-Leiste unten (v. a. am Smartphone sichtbar) */
.device::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.16);
  display: none;
}
.device-screen {
  flex: 1;
  border-radius: 20px;
  overflow: hidden;
  background: var(--screen);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6);
}

/* ---------- Kopfleiste ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  background: #0a1119;
  border-bottom: 1px solid var(--line);
}
.topbar-brand { display: flex; align-items: center; gap: 11px; }
.brand-badge {
  width: 34px; height: 34px; border-radius: 8px;
  background: #12233a; border: 1px solid #23425f;
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-size: 19px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 14px; font-weight: 600; letter-spacing: 0.01em; }
.brand-text small { font-size: 11px; color: var(--text-dim); }

.topbar-nav { display: flex; gap: 6px; margin-left: 8px; }
.topbar-nav a {
  font-size: 13px; color: var(--text-dim);
  padding: 7px 13px; border-radius: 8px;
}
.topbar-nav a:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.topbar-nav a.is-active { color: var(--text); background: rgba(111,176,240,0.12); }

.topbar-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: right; }
.user-meta strong { font-size: 13px; font-weight: 600; }
.user-meta small { font-size: 11px; color: var(--text-dim); }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #1c3350; color: #9dc4f0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.icon-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 6px; border-radius: 8px;
  display: flex;
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.logout-form { display: flex; }

/* ---------- Dashboard ---------- */
.tablet-body { padding: 24px 26px 28px; }
.section-label {
  margin: 4px 0 18px; font-size: 12px; letter-spacing: 0.05em;
  color: var(--text-faint); text-transform: none;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}
.app-tile {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 22px 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: #101c2c;
  position: relative;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
a.app-tile:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.22); }
.app-icon { font-size: 30px; }
.app-name { font-size: 13px; color: #cdd8e4; }
.app-tag {
  position: absolute; top: 9px; right: 9px;
  font-size: 10px; padding: 2px 6px; border-radius: 6px;
  background: rgba(255,255,255,0.06); color: var(--text-faint);
}
.app-tile.is-locked { opacity: 0.55; }
.app-tile.is-placeholder {
  opacity: 0.4; border-style: dashed; background: #0f1721;
}
.app-tile.is-placeholder .app-icon,
.app-tile.is-locked .app-icon { color: var(--text-faint) !important; }

/* Tile-Farben */
.color-blue   { background: #122740; border-color: #24405c; }
.color-blue   .app-icon { color: var(--blue); }
.color-teal   { background: #142c28; border-color: #2b5449; }
.color-teal   .app-icon { color: var(--teal); }
.color-purple { background: #241f33; border-color: #453a5c; }
.color-purple .app-icon { color: #a99be6; }
.color-amber  { background: #2e261a; border-color: #574526; }
.color-amber  .app-icon { color: #e0a94a; }
.color-slate  { background: #172230; border-color: #324356; }
.color-slate  .app-icon { color: #9db1c7; }

.tablet-status {
  margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 9px;
  font-size: 12px; color: var(--text-dim);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); }

/* Kacheln blenden beim Laden gestaffelt ein (wie ein aufwachender Homescreen). */
.app-grid .app-tile { animation: tileIn 0.34s cubic-bezier(0.4, 0, 0.2, 1) both; }
@keyframes tileIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* App-Oeffnen: farbige Flaeche zoomt von der Kachel auf Vollbild. */
.app-launch {
  position: fixed;
  z-index: 9999;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: left 0.42s cubic-bezier(0.4, 0, 0.2, 1),
    top 0.42s cubic-bezier(0.4, 0, 0.2, 1),
    width 0.42s cubic-bezier(0.4, 0, 0.2, 1),
    height 0.42s cubic-bezier(0.4, 0, 0.2, 1),
    border-radius 0.42s ease;
}
.app-launch-icon {
  font-size: 30px;
  color: #fff;
  opacity: 0.92;
  transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.42s ease;
}
.app-launch.go {
  left: 0 !important;
  top: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  border-radius: 0;
}
.app-launch.go .app-launch-icon { transform: scale(2.6); opacity: 0; }
.is-launching { overflow: hidden; }

/* ---------- Login / Setup / Fehler ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #16273d 0%, rgba(22,39,61,0) 60%),
    #0c1521;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 18px; padding: 34px 30px;
  box-shadow: 0 24px 60px -24px rgba(0,0,0,0.6);
  text-align: center;
}
.auth-badge {
  width: 54px; height: 54px; margin: 0 auto 16px;
  border-radius: 12px; background: #12233a; border: 1px solid #23425f;
  color: var(--gold); font-size: 28px;
  display: flex; align-items: center; justify-content: center;
}
.auth-title { margin: 0; font-size: 20px; font-weight: 600; }
.auth-sub { margin: 6px 0 20px; font-size: 13px; color: var(--text-dim); }
.auth-form { text-align: left; display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-dim); }

/* ---------- Formularelemente ---------- */
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%; padding: 10px 12px;
  background: #0c1723; border: 1px solid #263a52; border-radius: 9px;
  color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus, select:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(111,176,240,0.18);
}
select { appearance: none; background-image: none; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 9px; cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: inherit;
  background: #1c2b3d; color: var(--text); border: 1px solid #2c405a;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: #223349; }
.btn-primary { background: #2f6fb3; border-color: #3a80c8; color: #fff; }
.btn-primary:hover { background: #367ec8; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.btn-danger { background: #7a2f2a; border-color: #9a3d36; color: #ffdad4; }
.btn-danger:hover { background: #8c352f; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- Verwaltung ---------- */
.admin-shell { display: grid; grid-template-columns: 200px 1fr; min-height: 520px; }
.admin-nav {
  border-right: 1px solid var(--line); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px; background: #0b1420;
}
.admin-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  font-size: 13px; color: var(--text-dim); font-size: 14px;
}
.admin-nav a svg { font-size: 17px; }
.admin-nav a:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.admin-nav a.is-active { background: rgba(111,176,240,0.12); color: var(--text); }

.admin-main { padding: 22px 24px 30px; min-width: 0; }
.admin-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-bottom: 18px;
}
.admin-head h1 { margin: 0; font-size: 19px; font-weight: 600; }
.admin-head .muted { margin: 2px 0 0; }
.section-heading { font-size: 15px; font-weight: 600; margin: 26px 0 12px; }
.muted { color: var(--text-dim); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.hint { font-size: 12px; color: var(--text-faint); margin: 10px 0 0; }
.ta-right { text-align: right; }
.ta-center { text-align: center; }

.card {
  background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 12px; padding: 18px 18px; margin-bottom: 16px;
}
.card-title { margin: 0 0 14px; font-size: 14px; font-weight: 600; }
.form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px;
}
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-dim); }
.check-inline { flex-direction: row !important; align-items: center; gap: 9px !important; color: var(--text) !important; font-size: 13px !important; }
.check-inline input { width: auto; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; }
.inline-add { display: flex; gap: 10px; align-items: center; }
.inline-add input { max-width: 320px; }

/* Tabellen */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.data-table td { padding: 11px 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.row-muted td { opacity: 0.55; }

.pill {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 6px;
  background: rgba(255,255,255,0.07); color: var(--text-dim); margin-left: 6px; vertical-align: middle;
}
.pill-admin { background: rgba(232,184,75,0.16); color: var(--gold); }

/* Tool-Karten in der Nutzerbearbeitung */
.tool-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  margin-bottom: 4px; flex-wrap: wrap;
}
.tool-card-title { display: flex; align-items: center; gap: 10px; }
.app-icon.mini { width: 30px; height: 30px; border-radius: 8px; font-size: 17px;
  display: flex; align-items: center; justify-content: center; border: 1px solid var(--line-strong); }
.role-select { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.role-select select { width: auto; min-width: 150px; }

.perm-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.perm-table th { font-size: 11px; color: var(--text-faint); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-weight: 600; }
.perm-table td { padding: 8px 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
.perm-table .cat-row td { color: var(--text-faint); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; padding-top: 12px; border-bottom: none; }
.perm-label { color: var(--text); }
.eff { font-size: 10px; padding: 1px 6px; border-radius: 5px; margin-left: 8px; }
.eff-on { background: rgba(93,202,165,0.16); color: var(--teal); }
.eff-off { background: rgba(255,255,255,0.05); color: var(--text-faint); }
.ov-select { width: auto; min-width: 118px; font-size: 12px; padding: 5px 8px; }

.danger-card { border-color: rgba(232,112,95,0.3); }
.danger-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.danger-row p { margin: 3px 0 0; }

/* Flash */
.flashes { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 13px; border-radius: 9px; font-size: 13px; }
.flash-success { background: rgba(93,202,165,0.14); color: #a7e6cf; border: 1px solid rgba(93,202,165,0.3); }
.flash-error { background: rgba(232,112,95,0.14); color: #f2b9b0; border: 1px solid rgba(232,112,95,0.3); }

/* ---------- Responsiv ---------- */
@media (max-width: 820px) {
  .app-grid { grid-template-columns: repeat(3, 1fr); }
  .admin-shell { grid-template-columns: 1fr; }
  .admin-nav { flex-direction: row; border-right: none; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .form-grid { grid-template-columns: 1fr; }
}
/* Smartphone: schmalerer Rahmen, rundere Display-Ecken, Home-Leiste – ebenfalls fensterfuellend */
@media (max-width: 640px) {
  .device {
    padding: 11px 10px 18px;
    border-radius: 0;
  }
  .device-screen {
    border-radius: 30px;
  }
  .device::before { top: 6px; }        /* Frontkamera */
  .device::after { display: block; }   /* Home-Leiste einblenden */
}

@media (max-width: 520px) {
  .app-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-nav { order: 3; width: 100%; margin-left: 0; }
  .user-meta { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .app-launch { display: none !important; }
}
