@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");

:root {
  --bg: #f5f8fc;
  --bg-soft: #e8f1f8;
  --ink: #1f2937;
  --muted: #6b7280;
  --brand: #4c81b7;
  --brand-dark: #3a6a9a;
  --brand-deep: #3e5199;
  --brand-soft: #d6e6f4;
  --sky: #7eb3d9;
  --line: #d5e0ea;
  --card: #ffffff;
  --ok: #1f6b3a;
  --bad: #9b2c2c;
  --warn: #8a6d1d;
  --shadow: 0 8px 24px rgba(62, 81, 153, 0.08);
  --radius: 6px;
  --font: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  --display: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  --sidebar-w: 268px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    linear-gradient(180deg, #eaf3fa 0%, transparent 220px),
    linear-gradient(90deg, rgba(126, 179, 217, 0.12), transparent 40%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 15px;
}
a { color: var(--brand-deep); text-decoration: none; }
a:hover { color: var(--brand); text-decoration: underline; }
code {
  background: var(--bg-soft);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
}

/* —— Shell —— */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(185deg, #3e5199 0%, #4c81b7 48%, #3a6a9a 100%);
  color: #f4f8fc;
  padding: 1.15rem 0.9rem 1.5rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  display: block;
  text-decoration: none !important;
  margin: 0 0.35rem 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
.sidebar-brand .brand-script {
  font-family: var(--font);
  font-size: 1.15rem;
  line-height: 1.25;
  color: #fff;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.sidebar-brand .brand-sub {
  opacity: 0.85;
  font-size: 0.78rem;
  margin: 0.15rem 0 0;
  letter-spacing: 0.02em;
}

.nav-group { margin-bottom: 0.85rem; }
.nav-group-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin: 0.35rem 0.55rem 0.25rem;
  font-weight: 700;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar a.nav-link {
  color: #eef4fb;
  padding: 0.48rem 0.7rem;
  border-radius: var(--radius);
  text-decoration: none !important;
  font-size: 0.94rem;
  font-weight: 600;
  display: block;
}
.sidebar a.nav-link:hover,
.sidebar a.nav-link.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}
.sidebar a.nav-link.active {
  box-shadow: inset 3px 0 0 #fff;
}
.sidebar .userbox {
  margin-top: auto;
  padding: 0.9rem 0.55rem 0.2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 0.88rem;
}
.sidebar .userbox a { color: #fff; font-weight: 600; }

.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 35;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  padding-top: max(0.65rem, env(safe-area-inset-top));
  background: linear-gradient(90deg, #3e5199, #4c81b7);
  color: #fff;
  box-shadow: 0 4px 16px rgba(30, 50, 100, 0.2);
}
.mobile-bar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  text-decoration: none !important;
  color: #fff !important;
}
.mobile-bar-brand span {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-toggle {
  display: none;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: var(--radius);
  padding: 0.65rem 0.95rem;
  min-height: 44px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(30, 40, 70, 0.45);
  z-index: 28;
  border: 0;
  padding: 0;
  cursor: pointer;
}
body.nav-open .nav-backdrop { display: block; }
body.nav-open { overflow: hidden; }

.content {
  padding: 1.5rem 2rem 3rem;
  max-width: none;
  width: 100%;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1.35rem;
  padding-bottom: 0.85rem;
  border-bottom: 2px solid var(--brand-soft);
}
.topbar > div:first-child { min-width: 0; flex: 1; }
.topbar .actions { flex-shrink: 0; }
.topbar h1 {
  font-family: var(--font);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--brand-deep);
  margin: 0;
  letter-spacing: -0.02em;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--brand);
  font-weight: 700;
  margin: 0 0 0.25rem;
}
.page-lead {
  color: var(--muted);
  margin: -0.5rem 0 1.25rem;
  max-width: 52rem;
}

/* —— Surfaces —— */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.05rem 1.15rem;
  margin-bottom: 1rem;
}
.card h2,
.card-title {
  margin: 0 0 0.65rem !important;
  font-family: var(--font) !important;
  font-size: 1.05rem !important;
  font-weight: 700 !important;
  color: var(--brand-deep);
  letter-spacing: 0;
}
.card-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: -0.35rem 0 0.85rem;
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
  margin-bottom: 0.25rem;
  width: 100%;
}
.stat {
  padding: 1rem 1.05rem;
  border-top: 3px solid var(--brand);
}
.stat .label { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.stat .value {
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.55rem;
  color: var(--brand-deep);
  margin-top: 0.25rem;
  letter-spacing: -0.02em;
}
.stat.stat-warn { border-top-color: var(--warn); }
.stat.stat-warn .value { color: var(--warn); }
.stat.stat-bad { border-top-color: var(--bad); }
.stat.stat-bad .value { color: var(--bad); }
.stat.stat-ok { border-top-color: var(--ok); }

.task-list { display: grid; gap: 0.55rem; }
.task-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.9rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none !important;
  color: inherit;
}
.task-item:hover {
  border-color: var(--brand);
  background: #fff;
}
.task-item .task-title { font-weight: 700; color: var(--brand-deep); }
.task-item .task-meta { font-size: 0.85rem; color: var(--muted); }
.task-item .task-count {
  min-width: 2rem;
  text-align: center;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.9rem;
}
.task-item.urgent .task-count { background: var(--bad); }

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
}
.quick-link {
  display: block;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  text-decoration: none !important;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.quick-link:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow);
}
.quick-link strong {
  display: block;
  color: var(--brand-deep);
  margin-bottom: 0.2rem;
}
.quick-link span { font-size: 0.85rem; color: var(--muted); }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}
.table tr:hover td { background: rgba(76, 129, 183, 0.05); }

/* Mobile: Tabellen als Karten stapeln */
.table-wrap.table-stack .table thead { display: none; }
.table-wrap.table-stack .table,
.table-wrap.table-stack .table tbody {
  display: block;
  width: 100%;
}
.table-wrap.table-stack .table tr {
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  padding: 0.35rem 0;
  box-shadow: var(--shadow);
}
.table-wrap.table-stack .table tr:hover td { background: transparent; }
.table-wrap.table-stack .table td {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.85rem;
}
.table-wrap.table-stack .table td:last-child { border-bottom: none; }
.table-wrap.table-stack .table td::before {
  content: attr(data-label);
  flex: 0 0 38%;
  max-width: 9rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding-top: 0.1rem;
}
.table-wrap.table-stack .table td[data-label=""] {
  display: block;
}
.table-wrap.table-stack .table td[data-label=""]::before { display: none; }
.table-wrap.table-stack .table td > * { max-width: 100%; }

/* —— Controls —— */
.btn, button.btn {
  display: inline-block;
  background: linear-gradient(180deg, #5a8fc0, var(--brand));
  color: #fff !important;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1.05rem;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none !important;
  box-shadow: 0 2px 6px rgba(62, 81, 153, 0.18);
}
.btn:hover { background: var(--brand-dark); }
.btn-secondary {
  background: #fff;
  color: var(--brand-deep) !important;
  border: 1px solid var(--brand);
  box-shadow: none;
}
.btn-secondary:hover { background: var(--brand-soft); }
.btn-danger { background: var(--bad); box-shadow: none; }
.btn-sm { padding: 0.32rem 0.7rem; font-size: 0.85rem; }
.btn:disabled, button.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.form { display: grid; gap: 0.75rem; max-width: 960px; width: 100%; }
.form.wide { max-width: none; }
.form.card { max-width: none; }
.form label { display: grid; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
.form input, .form select, .form textarea {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}
.form textarea { min-height: 100px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-check { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  user-select: none;
  min-height: 28px;
}
.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.toggle-track {
  position: relative;
  width: 24px;
  height: 14px;
  flex-shrink: 0;
  background: #c5d0dc;
  border-radius: 999px;
  transition: background 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.28s ease;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
}
.toggle-thumb {
  position: absolute;
  top: 1.5px;
  left: 1.5px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1),
              box-shadow 0.28s ease;
  will-change: transform;
}
.toggle:hover .toggle-track {
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), 0 0 0 3px rgba(76, 129, 183, 0.12);
}
.toggle input:checked + .toggle-track {
  background: linear-gradient(180deg, #5a8fc0, var(--brand));
}
.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(10px);
  box-shadow: 0 1px 4px rgba(62, 81, 153, 0.35);
}
.toggle input:active + .toggle-track .toggle-thumb {
  transform: scale(0.92);
}
.toggle input:checked:active + .toggle-track .toggle-thumb {
  transform: translateX(10px) scale(0.92);
}
.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--brand-soft);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .toggle-track,
  .toggle-thumb {
    transition: none;
  }
}
.toggle-text { font-size: 0.88rem; line-height: 1.3; }
.toggle-sm { min-height: 24px; gap: 0.4rem; }
.toggle-sm .toggle-track { width: 20px; height: 12px; }
.toggle-sm .toggle-thumb { width: 9px; height: 9px; top: 1.5px; left: 1.5px; }
.toggle-sm input:checked + .toggle-track .toggle-thumb { transform: translateX(8px); }
.toggle-sm input:checked:active + .toggle-track .toggle-thumb { transform: translateX(8px) scale(0.92); }
.toggle-sm .toggle-text { font-size: 0.8rem; }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: #fde8e8; color: var(--bad); border: 1px solid #f2c1c1; }
.alert-ok, .alert-success { background: #e7f6ec; color: var(--ok); border: 1px solid #bfe5cb; }

.toast-stack {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(30, 40, 70, 0.18);
  background: #fff;
  border: 1px solid var(--line);
  animation: toast-in 0.35s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}
.toast.toast-out {
  animation: toast-out 0.28s ease forwards;
}
.toast-ok {
  border-color: #bfe5cb;
  background: #f3fbf5;
  color: var(--ok);
}
.toast-error {
  border-color: #f2c1c1;
  background: #fff5f5;
  color: var(--bad);
}
.toast-text {
  margin: 0;
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}
.toast-close {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.65;
  padding: 0;
  min-width: 1.25rem;
}
.toast-close:hover { opacity: 1; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(8px) scale(0.96); }
}
@media (prefers-reduced-motion: reduce) {
  .toast, .toast.toast-out { animation: none; }
}
.muted { color: var(--muted); }
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge.ok { background: #e7f6ec; color: var(--ok); }
.badge.bad { background: #fde8e8; color: var(--bad); }
.badge.warn { background: #fff4d6; color: var(--warn); }
.badge.neutral { background: #eceff3; color: var(--muted); }

/* —— Auth / Install —— */
.auth-body, .install-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    linear-gradient(160deg, #3e5199 0%, #4c81b7 42%, #7eb3d9 100%);
}
.auth-body::before,
.install-body::before {
  content: "";
  position: fixed;
  inset: auto 0 0 0;
  height: 28vh;
  background:
    radial-gradient(ellipse at 20% 100%, rgba(255,255,255,0.18), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(255,255,255,0.12), transparent 45%);
  pointer-events: none;
}
.auth-card, .install-card {
  width: min(440px, 100%);
  background: #fff;
  border: none;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(30, 50, 100, 0.28);
  padding: 1.6rem 1.5rem 1.4rem;
  position: relative;
  z-index: 1;
}
.install-card { width: min(640px, 100%); }
.auth-logo {
  display: block;
  width: min(240px, 80%);
  margin: 0 auto 0.85rem;
}
.auth-card h1, .install-card h1 {
  font-family: var(--font);
  font-size: clamp(1.6rem, 4vw, 2rem);
  font-weight: 800;
  color: var(--brand-deep);
  margin: 0 0 0.35rem;
  text-align: center;
  line-height: 1.2;
  letter-spacing: -0.03em;
}
.auth-card .eyebrow, .install-card .eyebrow {
  text-align: center;
}
.auth-card .form, .install-card .form { max-width: none; }
.auth-footer {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.9rem;
}
.steps { display: flex; gap: 0.4rem; list-style: none; padding: 0; margin: 0 0 1.2rem; flex-wrap: wrap; }
.steps li { font-size: 0.8rem; padding: 0.25rem 0.55rem; border-radius: 4px; background: var(--bg-soft); color: var(--muted); }
.steps li.on { background: var(--brand); color: #fff; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
  align-items: end;
  padding: 0.85rem 1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.filters label { font-size: 0.82rem; font-weight: 600; color: var(--muted); display: grid; gap: 0.25rem; }
.filters input, .filters select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}

.panel-split {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1rem;
  align-items: start;
  width: 100%;
}

@media (max-width: 980px) {
  .panel-split { grid-template-columns: 1fr; }
  .mobile-bar { display: flex; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-w), 86vw);
    max-width: 320px;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar a.nav-link {
    padding: 0.72rem 0.85rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 1rem;
  }
  .content {
    padding: 1rem 0.85rem 2.5rem;
    padding-bottom: max(2.5rem, env(safe-area-inset-bottom));
  }
  .form-row { grid-template-columns: 1fr; }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
  }
  .topbar h1 { font-size: 1.35rem; word-break: break-word; }
  .topbar .actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  .topbar .actions .btn,
  .topbar .actions button.btn,
  .topbar .actions form {
    width: 100%;
    margin: 0;
  }
  .topbar .actions form .btn { width: 100%; }
  .topbar .actions > .btn:only-child,
  .topbar .actions > a.btn:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  .actions .btn,
  .actions button.btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }
  .grid-stats {
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
  }
  .stat { padding: 0.85rem; }
  .stat .value { font-size: 1.3rem; }
  .quick-grid { grid-template-columns: 1fr; }
  .quick-link { padding: 0.95rem 1rem; min-height: 44px; }
  .task-item { min-height: 52px; padding: 0.85rem 1rem; }
  .filters {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .filters label { width: 100%; }
  .filters input,
  .filters select,
  .filters .btn {
    width: 100%;
    min-height: 44px;
  }
  .form input,
  .form select,
  .form textarea,
  .filters input,
  .filters select {
    font-size: 16px; /* verhindert iOS-Zoom */
    max-width: 100%;
  }
  .form { max-width: none; }
  .card { padding: 0.9rem; }
  .page-lead { margin-top: 0; }
  .auth-body, .install-body {
    padding: 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    align-items: start;
  }
  .auth-card, .install-card {
    width: 100%;
    margin-top: 1rem;
    padding: 1.25rem 1rem;
  }
  .auth-card h1, .install-card h1 { font-size: 1.5rem; }
  .btn, button.btn { min-height: 44px; }
  code { word-break: break-word; }
}

@media (max-width: 480px) {
  .grid-stats { grid-template-columns: 1fr; }
  .topbar .actions { grid-template-columns: 1fr; }
}
