:root {
  /* Theme & Layout Tokens (dev) */
  --bg-header: #1f2937;
  --bg-nav: #111827;
  --fg-on-dark: #f9fafb;
  --fg-muted: #d1d5db;
  --bg-surface: #f3f4f6;
  --bg-card: #ffffff;
  --fg-default: #111827;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --border-subtle: rgba(148, 163, 184, 0.35);
  --shadow-soft: 0 12px 24px rgba(15, 23, 42, 0.18);
  --shadow-raised: 0 16px 40px rgba(15, 23, 42, 0.22);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2rem;
  --font-family-sans: 'Inter', 'Segoe UI', 'Helvetica Neue', Arial, system-ui, sans-serif;
  --header-height: 72px;

  /* Codex-Extras, die wir nutzen */
  --header-padding-x: clamp(1rem, 3vw, 2.5rem);
  --header-gap: clamp(0.5rem, 1vw, 1rem);
  --nav-radius: 1rem;
  --nav-item-height: 3rem;
  --focus-ring: 0 0 0 3px rgba(99, 102, 241, 0.35);
}
@media (max-width: 768px) {
  :root {
    --header-height: 88px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-family-sans);
  background: var(--bg-surface);
  color: var(--fg-default);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
body.nav-open {
  overflow: hidden;
}

.app-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}
.app-shell__form {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  width: 100%;
  background: linear-gradient(135deg, var(--bg-header), var(--bg-nav));
  color: var(--fg-on-dark);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.4);
  z-index: 1000;
}
.app-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  row-gap: 0.75rem;
  padding: 0.75rem clamp(1rem, 2vw, 2rem);
  min-height: var(--header-height);
}

.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(249, 250, 251, 0.4);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  color: inherit;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}
.nav-toggle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.nav-toggle__bar {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  margin-block: 3px;
  border-radius: 999px;
}
.nav-toggle__text {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Main nav */
.main-nav {
  flex: 1 1 480px;
  display: flex;
  align-items: stretch;
  min-width: 0;
}
.main-nav__list {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem 0.75rem;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
  width: 100%;
  overflow: visible;
}

.main-nav__empty {
  display: none;
  margin-left: auto;
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.12);
  color: var(--fg-muted);
  font-weight: 500;
  align-self: center;
}

.main-nav__item {
  position: relative;
  display: flex;
  align-items: stretch;
  color: var(--fg-on-dark);
}
.main-nav__item[hidden],
.main-nav__submenu-item[hidden] {
  display: none !important;
}
/* für Suchfilter: */
.main-nav__item.is-filtered-out {
  display: none !important;
}

.main-nav__link,
.main-nav__sublink {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  border-radius: var(--radius-md);
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--fg-on-dark);
  transition:
    background 0.2s,
    color 0.2s,
    box-shadow 0.2s;
  min-height: 44px;
}
.main-nav__link:visited,
.main-nav__sublink:visited {
  color: var(--fg-on-dark);
}
/* Suchzustände (für Live-Filter) */
.main-nav__link.is-hidden-by-search,
.main-nav__sublink.is-hidden-by-search {
  display: none !important;
}
.main-nav__link.is-search-match,
.main-nav__sublink.is-search-match {
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.35);
}

.main-nav__link:hover,
.main-nav__link:focus-visible,
.main-nav__sublink:hover,
.main-nav__sublink:focus-visible {
  background: rgba(99, 102, 241, 0.24);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.35);
  outline: none;
}
.main-nav__link[aria-current='page'],
.main-nav__item.is-active > .main-nav__link {
  background: rgba(79, 70, 229, 0.2);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}
[data-active-match] {
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.65);
  border-radius: var(--radius-md);
}

.main-nav__icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.main-nav__icon img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.main-nav__submenu {
  position: absolute;
  inset-inline-start: 0;
  top: 100%;
  min-width: 15rem;
  padding: 0.85rem 0.9rem;
  border-radius: var(--radius-lg);
  background: rgba(17, 24, 39, 0.96);
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: var(--fg-on-dark);
  display: none;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 10;
}
.main-nav__submenu-item {
  list-style: none;
}
.main-nav__submenu-item .main-nav__sublink {
  width: 100%;
  color: var(--fg-on-dark);
  font-weight: 500;
}
.main-nav__item.is-open > .main-nav__submenu,
.main-nav__item:hover > .main-nav__submenu,
.main-nav__item:focus-within > .main-nav__submenu {
  display: flex;
}
.main-nav__submenu--nested {
  margin-top: 0.35rem;
  margin-left: 1.25rem;
  padding-left: 0.75rem;
  border-left: 1px solid rgba(99, 102, 241, 0.35);
}

/* Suche + Usercluster */
.app-header__search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 280px;
  max-width: 100%;
}
.app-header__search input[type='search'] {
  width: 100%;
  border: none;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.12);
  padding: 0.65rem 1rem;
  color: var(--fg-on-dark);
  font-size: 0.95rem;
}
.app-header__search input[type='search']::placeholder {
  color: rgba(249, 250, 251, 0.6);
}
.app-header__search input[type='search']:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: rgba(255, 255, 255, 0.18);
}

.app-header__spacer {
  flex: 1 1 auto;
  min-width: 120px;
}

.user-cluster {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--fg-on-dark);
}
.user-cluster__name {
  font-weight: 600;
  white-space: nowrap;
}
.user-cluster__actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.user-cluster__logout,
.user-cluster__badge {
  border: none;
  border-radius: var(--radius-md);
  padding: 0.5rem 0.9rem;
  min-height: 40px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  transition:
    background 0.2s,
    color 0.2s,
    box-shadow 0.2s;
  background: rgba(255, 255, 255, 0.12);
  color: var(--fg-on-dark);
}
.user-cluster__badge {
  width: 44px;
  height: 44px;
  padding: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  border-radius: 50%;
}
.user-cluster__logout {
  background: var(--accent);
  color: #fff;
}
.user-cluster__logout.is-loading {
  opacity: 0.7;
  pointer-events: none;
}
.user-cluster__logout:hover,
.user-cluster__badge:hover,
.user-cluster__logout:focus-visible,
.user-cluster__badge:focus-visible {
  background: rgba(79, 70, 229, 0.35);
  box-shadow: 0 0 0 1px rgba(79, 70, 229, 0.5);
  outline: none;
}
.user-cluster__logout:hover,
.user-cluster__logout:focus-visible {
  background: var(--accent-hover);
}

.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
body.nav-open .nav-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* Breadcrumbs */
.app-header__breadcrumbs {
  padding: 0.25rem clamp(1rem, 2vw, 2rem) 0.75rem;
  background: rgba(17, 24, 39, 0.92);
}
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  margin: 0;
  font-size: 0.9rem;
  color: var(--fg-muted);
  line-height: 1.3;
}
.breadcrumbs__list {
  display: contents;
}
.breadcrumbs__item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.breadcrumbs__item + .breadcrumbs__item::before {
  content: '›';
  opacity: 0.5;
  font-size: 0.85em;
}
.breadcrumbs a {
  color: #cbd5f5;
  text-decoration: none;
}
.breadcrumbs a:hover,
.breadcrumbs a:focus-visible {
  text-decoration: underline;
  outline: none;
}

/* Main / Content */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.9), rgba(229, 231, 235, 0.9));
  overflow: hidden;
}
.app-main > .app-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: clamp(1rem, 3vw, 2.5rem);
  margin: 0;
  width: 100%;
  max-width: none;
  overflow: auto;
}
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
}
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
  min-height: 0;
}

.main-surface {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: rgba(255, 255, 255, 0.92);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: clamp(1rem, 3vw, 2.5rem);
  min-height: 0;
}

/* Cards, Tables, Buttons */
#toptabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}
.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-tabs li {
  display: flex;
}
.nav-tabs a {
  border-radius: var(--radius-md);
  padding: 0.5rem 0.9rem;
  background: rgba(99, 102, 241, 0.16);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.nav-tabs a:hover,
.nav-tabs a:focus-visible {
  background: rgba(79, 70, 229, 0.22);
  border-color: rgba(79, 70, 229, 0.5);
  outline: none;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-2);
}
.card,
.dashboard-grid > * {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-2);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.table-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: inset 0 0 0 1px var(--border-subtle);
  overflow: auto;
  max-width: 100%;
}
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
}
table thead th {
  position: sticky;
  top: 0;
  background: rgba(249, 250, 251, 0.95);
  color: var(--fg-default);
  text-align: left;
  font-weight: 700;
  padding: 0.75rem 1rem;
  box-shadow: inset 0 -1px 0 rgba(148, 163, 184, 0.4);
}
table tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  font-size: 0.95rem;
}
table tbody tr:hover {
  background: rgba(99, 102, 241, 0.12);
}

#bottomtabs,
#buttons {
  position: sticky;
  bottom: 0;
  background: rgba(249, 250, 251, 0.9);
  backdrop-filter: blur(8px);
  padding: 0.75rem clamp(1rem, 3vw, 2.5rem);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.12);
  z-index: 20;
}
#bottomtabs ul,
#buttons ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
#bottomtabs a,
#buttons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  padding: 0.5rem 1.25rem;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  min-height: 44px;
  transition:
    background 0.2s,
    box-shadow 0.2s;
}
#bottomtabs a:hover,
#bottomtabs a:focus-visible,
#buttons a:hover,
#buttons a:focus-visible {
  background: var(--accent-hover);
  outline: none;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

button,
input,
select,
textarea {
  font: inherit;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Gridflächen für Ergebnisse */
.result-grid,
[data-grid='cards'] {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-2);
}
.result-grid > *,
[data-grid='cards'] > * {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-1);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

/* Breakpoints */
@media (max-width: 1280px) {
  .app-header__search {
    flex: 0 0 220px;
  }
}

@media (max-width: 1024px) {
  .nav-toggle {
    display: inline-flex;
  }
  .main-nav {
    position: fixed;
    inset: 0;
    background: var(--bg-nav);
    flex-direction: column;
    padding: var(--space-2);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    z-index: 990;
  }
  body.nav-open .main-nav {
    transform: translateX(0);
  }
  .main-nav__list {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    flex-wrap: nowrap;
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.6) transparent;
  }
  .main-nav__list::-webkit-scrollbar {
    height: 6px;
  }
  .main-nav__list::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.6);
    border-radius: 999px;
  }
  .main-nav__item {
    width: 100%;
  }
  .main-nav__link {
    width: 100%;
    justify-content: flex-start;
  }
  .main-nav__submenu {
    display: none;
    background: rgba(17, 24, 39, 0.85);
    margin-top: 0.5rem;
    position: static;
  }
  .main-nav__item.is-open > .main-nav__submenu {
    display: flex;
  }
  .app-header__search {
    display: none;
  }
}

@media (max-width: 768px) {
  .app-header__inner {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .app-header__brand {
    min-width: 0;
    margin-right: var(--space-2);
  }
  .app-header__brand-mark {
    max-height: 44px;
  }
  .user-cluster__name {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 640px) {
  table.table--responsive {
    display: block;
  }
  table.table--responsive thead {
    display: none;
  }
  table.table--responsive tbody {
    display: grid;
    gap: 1rem;
  }
  table.table--responsive tr {
    display: grid;
    gap: 0.5rem;
    padding: 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(148, 163, 184, 0.4);
  }
  table.table--responsive td {
    display: grid;
    grid-template-columns: minmax(9ch, 1fr) 1fr;
    gap: 0.5rem;
    border: none;
    padding: 0;
  }
  table.table--responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: rgba(55, 65, 81, 0.85);
  }
  .ct-modal__dialog {
    width: min(96vw, 420px);
    padding: 1.25rem 1.5rem;
  }
}

/* Login Page Layout */
.page-login {
  display: flex;
  /* oben links platzieren, unabhängig von Fenstergröße */
  align-items: flex-start;
  justify-content: flex-start;
  min-height: 100vh;
  height: 100vh;
  /* kein Padding - flush */
  padding: 0;
  /* force weißen Hintergrund */
  background: #ffffff !important;
  /* kein Scrollbalken */
  overflow: hidden !important;
}

/* Hide footer and header on login page */
body:has(.page-login) .app-footer {
  display: none;
}
body:has(.page-login) .app-header {
  display: none;
}
/* Ensure page background is white on the login page */
body:has(.page-login) .app-main,
body:has(.page-login) #content,
body:has(.page-login) html,
body:has(.page-login) body {
  background: #ffffff !important;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Login Card Styles */
.login-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  width: min(100%, 360px);
  margin: 0; /* sits at top-left */
  padding: 10px 14px;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid rgba(99, 146, 240, 0.1);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
  text-align: left;
  margin-top: 0;
}

.login-card__logo {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 0;
}

.login-card__logo img {
  max-width: 100px;
  height: auto;
  display: block;
  margin: 2px auto 6px auto;
}

/* Desktop: Login MITTIG platzieren */
@media (min-width: 1200px) {
  .page-login {
    justify-content: center !important; /* ZENTRIERT statt flex-end */
    align-items: center !important; /* VERTIKAL zentriert */
    padding: 2rem !important;
  }
  .login-card {
    width: 400px;
  }
}

.login-card__body {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: left;
}

.login-field__label {
  font-weight: 600;
  color: #1f2937;
  font-size: 0.9rem;
  text-align: center; /* Label zentriert über dem Feld */
  display: block;
  margin-bottom: 0.25rem;
}

.login-field__input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

.login-field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.login-card__actions {
  display: flex;
  justify-content: center;
  margin-top: var(--space-1);
}

.login-card__submit {
  width: 100%;
  padding: 0.7rem 1rem;
  background: linear-gradient(90deg, #64b5ff 0%, #4f8ef0 100%);
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    filter 0.12s ease,
    transform 0.08s ease;
}

.login-card__submit:hover {
  background: var(--accent-hover);
}

.login-card__submit:active {
  transform: translateY(1px);
}

@media (max-width: 480px) {
  .login-card {
    margin: 1.5rem auto;
    padding: clamp(20px, 6vw, 32px);
  }

  .login-field__label {
    font-size: 0.9rem;
  }

  .login-field__input {
    padding: 0.625rem 0.875rem;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
