/* ========== Reset & Base ========== */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}

.hide-desktop {
  display: none !important;
}

/* Screenreader-only helper */
.sr-only {
  position: absolute !important;
  height: 1px;
  width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}

/* ========== Theme (VfL Osnabrück) ========== */
:root {
  --primary: #51247A;
  /* VfL Lila */
  --primary-600: #612c92;
  --primary-400: #7A4DA3;
  /* helleres Lila */
  --accent: #9c6dd0;

  --readonly-bg: #f3f1f6;
  --readonly-text: #2c2c2c;

  --bg: #ffffff;
  --bg-card: #f5f6f8;
  --bg-elev: #ffffff;
  --text: #202124;

  --header-bg: var(--primary);
  --sidebar-bg: #f3f1f6;

  --border: #dde1e7;
  --muted: #6b7280;
  --shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

body.dark {
  --primary: #7A4DA3;
  --primary-600: #8756b6;
  --primary-400: #b18bd9;
  --accent: #c2a3e6;

  --readonly-bg: #20222a;
  --readonly-text: #ffffff;

  --bg: #16161a;
  --bg-card: #1e1f24;
  --bg-elev: #20222a;
  --text: #e8e9ee;

  --header-bg: #1c1d22;
  --sidebar-bg: #1b1c21;

  --border: #2c2f36;
  --muted: #9aa0ad;
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

input[readonly],
input:disabled,
textarea[readonly],
textarea:disabled,
select[readonly],
select:disabled,
.readonly-field {
  background: var(--readonly-bg) !important;
  color: var(--readonly-text) !important;
  border-color: color-mix(in srgb, var(--readonly-text) 10%, transparent) !important;
  cursor: not-allowed;
}

/* Links */
a {
  color: var(--primary-600);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ========== Layout ========== */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--header-bg);
  color: #fff;
  box-shadow: var(--shadow);
}

header .left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-weight: 800;
  letter-spacing: .2px;
  color: var(--primary-400);
}

.top-nav {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 auto;
}

.top-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
}

.top-nav a:hover {
  background: color-mix(in oklab, var(--primary-400) 35%, #0000);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-toggle {
  display: none;
  background: transparent;
  color: #fff;
  border: 1px solid color-mix(in oklab, #fff 25%, #0000);
  border-radius: 8px;
  padding: 6px 10px;
}

.sidebar-toggle:hover {
  background: rgba(0, 0, 0, 0.06);
}

/* Buttons */
.btn,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: .18s ease-in-out;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.btn {
  padding: 8px 12px;
}

.icon-btn {
  padding: 8px;
  background: transparent;
  color: inherit;
}

.icon-btn:hover {
  background: color-mix(in oklab, #fff 12%, #0000);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-600);
}

.btn-secondary {
  background: color-mix(in oklab, var(--primary-400) 12%, #0000);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: color-mix(in oklab, var(--primary-400) 18%, #0000);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px dashed var(--border);
}

.btn-ghost:hover {
  border-color: var(--primary-400);
  color: var(--primary-600);
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

/* Main layout */
main {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  padding: 16px;
}

/* Dreispaltiges Layout (links – content – rechts) */
.main-triple {
  grid-template-columns: 260px 1fr 260px;
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  height: fit-content;
  display: grid;
  gap: 10px;
  /* sorgt für Abstand zwischen allen .sidebar-card-Elementen */
}

.sidebar h3 {
  margin: 0 0 8px 0;
  color: var(--primary-600);
}

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 8px 0 12px;
}

.sidebar li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

.sidebar li a:hover {
  background: color-mix(in oklab, var(--primary-400) 14%, #0000);
}

.sidebar li a.active {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.sidebar-card {
  display: grid;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.sidebar-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--text);
}

/* Metadata table inside sidebar (2 columns, no borders) */
.sidebar-card table.meta {
  width: 100%;
  border-collapse: collapse;
}

.sidebar-card table.meta td,
.sidebar-card table.meta th {
  border: none;
  padding: 4px 0;
}

.sidebar-card table.meta td.label {
  font-weight: 600;
  padding-right: 12px;
  white-space: nowrap;
}

/* Content area */
.content {
  min-width: 0;
}

/* Cards */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  margin: 0;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
}

.card>*:not(.card-header) {
  padding: 12px 14px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat-title {
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 4px;
}

/* Map placeholder */
.map-placeholder {
  height: 280px;
  border-radius: 10px;
  border: 2px dashed var(--border);
  display: grid;
  place-items: center;
  background:
    repeating-linear-gradient(45deg,
      color-mix(in oklab, var(--primary-400) 6%, #0000),
      color-mix(in oklab, var(--primary-400) 6%, #0000) 10px,
      transparent 10px, transparent 20px);
  color: var(--muted);
  font-weight: 700;
}



/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-group {
  display: grid;
  gap: 6px;
}

.form-group.col-span-2 {
  grid-column: span 2;
}

label,
legend {
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .2s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary-400);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary-400) 22%, #0000);
}

form input[type="submit"],
form input[type="button"] {
  margin-right: 8px;
  /* horizontaler Abstand */
  margin-top: 8px;
  /* optional: vertikaler Abstand */
}

textarea {
  resize: vertical;
}

.unstyled {
  background: transparent;
  border: 1px dashed var(--border);
  box-shadow: none;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 12px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

/* Alerts & Badges */
.alert {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: color-mix(in oklab, var(--primary-400) 12%, #0000);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 8px;
}

.badges {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 700;
  background: var(--primary-400);
  color: #fff;
}

.badge-alt {
  background: color-mix(in oklab, var(--primary-400) 18%, #0000);
  color: var(--text);
}

.badge-outline {
  background: transparent;
  border: 1px solid var(--primary-400);
  color: var(--primary-400);
}

/* Table */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  /* horizontal scrollen, falls Tabelle zu breit */
  -webkit-overflow-scrolling: touch;
  /* sanftes Scrollen auf iOS */
}

.table-responsive table {
  width: 100%;
  /* passt Tabelle an Container an */
  border-collapse: collapse;
  min-width: 400px;
  /* optional: Mindestbreite für bessere Lesbarkeit */
}

thead th {
  text-align: left;
  font-weight: 700;
  font-size: .92rem;
  background: color-mix(in oklab, var(--primary-400) 12%, #0000);
  color: var(--text);
}

th,
td {
  padding: 0.25em;
  border: 1px solid var(--border);
  white-space: normal;
  /* <-- Umbruch zulassen */
  word-break: break-word;
  /* lange Wörter/Emails umbrechen */
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.pagination {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* Header controls */
.menu-toggle {
  display: none;
  background: transparent;
  color: #fff;
  border: 1px solid color-mix(in oklab, #fff 25%, #0000);
  border-radius: 8px;
  padding: 6px 10px;
}

.overlay[data-overlay] {
  display: none;
}

footer {
  margin-left: 16px;
  margin-right: 16px;
}

/* ========== Responsive ========== */
@media (max-width: 1024px) {
  main {
    grid-template-columns: 1fr;
  }

  .main-triple {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 2;
  }

  .content {
    order: 1;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .hide-desktop {
    display: inline-flex !important;
  }

  .app-header {
    position: relative;
  }

  .app-header .menu-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1300;
    height: 2.5rem;
    width: 2.5rem;
    border-radius: 0.5rem;
  }

  .top-nav {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 0.5rem;
    gap: 0.25rem;
    z-index: 1150;
  }

  body.show-main-nav .top-nav,
  .top-nav.show {
    display: flex;
    flex-direction: column;
    background: var(--header-bg);
  }

  #left-sidebar,
  #right-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: min(80vw, 360px);
    max-width: 90vw;
    background: var(--sidebar-bg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    z-index: 1200;
    overflow-y: auto;
    transition: transform 200ms ease;
  }

  #left-sidebar {
    left: 0;
    transform: translateX(-105%);
  }

  #right-sidebar {
    right: 0;
    transform: translateX(105%);
  }

  body.show-left-sidebar #left-sidebar {
    transform: translateX(0);
  }

  body.show-right-sidebar #right-sidebar {
    transform: translateX(0);
  }

  body.show-left-sidebar,
  body.show-right-sidebar,
  body.show-main-nav {
    overflow: hidden;
  }

  .overlay[data-overlay] {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    z-index: 900;
  }

  body.show-left-sidebar .overlay[data-overlay],
  body.show-right-sidebar .overlay[data-overlay],
  body.show-main-nav .overlay[data-overlay] {
    display: block;
  }
}

@media (max-width: 820px) {
  html {
    font-size: 17px;
  }

  body {
    line-height: 1.55;
  }

  header {
    padding: 12px 14px;
  }

  .logo {
    font-size: 1rem;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0.65rem;
  }

  .top-nav {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 56px;
    padding: 8px;
    gap: 6px;
    flex-direction: column;
    background: var(--header-bg);
    border-bottom: 1px solid color-mix(in oklab, #000 25%, #0000);
  }

  .top-nav.show {
    display: flex;
  }

  .top-nav a {
    min-height: 2.75rem;
    padding: 0.8rem 0.9rem;
    border-radius: 10px;
  }

  .sidebar {
    padding: 16px;
  }

  .sidebar li a {
    min-height: 2.75rem;
    padding: 0.75rem 0.85rem;
  }

  .sidebar-card {
    padding: 12px;
  }

  .btn,
  .icon-btn,
  .sidebar-toggle,
  input,
  select,
  textarea {
    font-size: 1rem;
  }

  .btn,
  .icon-btn,
  .sidebar-toggle {
    min-height: 2.75rem;
  }

  .btn {
    padding: 0.8rem 1rem;
  }

  .icon-btn,
  .sidebar-toggle {
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0.7rem;
  }

  input,
  select,
  textarea {
    min-height: 2.9rem;
    padding: 0.8rem 0.9rem;
  }

  .card-header h2 {
    font-size: 1.1rem;
  }

  .card > *:not(.card-header) {
    padding: 14px;
  }

  .card-actions {
    flex-wrap: wrap;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Customizations: Right sidebar actions only ===== */
/* Hide header actions in overview cards; actions live in right sidebar */
.card-actions {
  display: none !important;
}

/* Make action buttons in right sidebar take full width */
.sidebar-card .btn,
.sidebar-card a.btn {
  width: 100%;
  justify-content: center;
}

.selection-dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow);
  width: min(32rem, calc(100vw - 2rem));
  padding: 0;
}

.selection-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.selection-dialog-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.selection-dialog-body h2 {
  margin: 0;
}

.permission-assignment-toolbar {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.permission-assignment-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.permission-empty-state {
  color: var(--muted);
}
