/* =====================================================
   Variablen
   ===================================================== */
:root{
  /* Grundfarben */
  --bg: #0e0f12;
  --fg: #e8eaed;
  --muted: #a7abb4;

  /* Flächen */
  --card: #171a1f;      /* Karten-Hintergrund */
  --tile: #1e232b;      /* Teilkachel-Hintergrund */

  /* Rahmen & Akzente */
  --border: #2a3040;    /* Standard-Rahmenfarbe */
  --tile-border: #2f3544; /* Teilkachel-Rahmen */
  --header-border: #31384a; /* Header-Rahmen */
  --room-accent: #3a7afe;   /* Akzentfarbe für Raum */

  /* Statusfarben */
  --ok: #1e8e3e;   /* state-0 */
  --warn: #f29900; /* state-1 */
  --crit: #d93025; /* state-2 */

  /* Abstände & Rundungen */
  --gap: 12px;
  --br: 14px;
}


/* =====================================================
   Reset & Basistypografie
   ===================================================== */
*{
  box-sizing: border-box;
}
html, body{
  height: 100%;
}
body{
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
}


/* =====================================================
   Seiten-Layout & Header
   ===================================================== */
.page{
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

h1{
  margin: 10px 0 18px;
  font-size: 22px;
  font-weight: 700;
}

.page-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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


/* =====================================================
   Buttons & Links
   ===================================================== */
.btn, .back{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-right: 10px;
  padding: 8px 12px;
  min-height: 36px;
  font-weight: 600;
  line-height: 1;
  background: #232833;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover, .back:hover{
  border-color: #3c455a;
  background: #262c38;
}
.btn:focus-visible, .back:focus-visible{
  outline: 2px solid var(--room-accent);
  outline-offset: 2px;
}

/* Native-Button-Reset für .btn auf <button> */
.btn[type="button"],
.btn[type="submit"],
.btn[type="reset"],
button.btn{
  -webkit-appearance: none;
  appearance: none;
  background-clip: padding-box;
}

/* Link-Verhalten innerhalb Anleitungs-Inhalt angleichen */
.content a{
  color: color-mix(in srgb, var(--room-accent) 70%, #aab6ff);
  text-decoration: none;
}
.content a:hover{
  text-decoration: underline;
}

/* Buttons in Anleitungen sollen wie App-Buttons aussehen (ohne Link-Optik) */
.content a.btn,
.content a.btn:visited{
  color: var(--fg);
  text-decoration: none;
}
.content a.btn:hover{
  text-decoration: none;
}


/* =====================================================
   Grid-Board (Kachelübersicht)
   ===================================================== */
.rechner-board{
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(2, 1fr);
  align-items: start;
}


/* =====================================================
   Karten / Kacheln (Rechner & Raum)
   ===================================================== */
.rechner{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--br);
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

/* Raum-Gesamtkachel: leicht getönt */
.rechner--gesamt{
  background: color-mix(in srgb, var(--room-accent) 8%, var(--card));
  border-color: color-mix(in srgb, var(--room-accent) 30%, var(--border));
  box-shadow: 0 0 0 1px rgba(58,66,86,0.30);
}
.rechner--gesamt .tile-header{
  background: color-mix(in srgb, var(--room-accent) 12%, #232a36);
  border-color: color-mix(in srgb, var(--room-accent) 35%, #31384a);
  position: relative; /* für .modal-close Positionierung kompatibel lassen */
}
.rechner--gesamt .tile-header .pc{ color: color-mix(in srgb, var(--room-accent) 60%, var(--fg)); }
.rechner--gesamt > div:not(.tile-header){
  background: color-mix(in srgb, var(--room-accent) 6%, var(--tile));
  border-color: color-mix(in srgb, var(--room-accent) 25%, #3a4256);
}

/* Kachel-Header */
.tile-header{
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #202530;
  border: 1px solid var(--header-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
}
.tile-header .room{ color: var(--muted); }
.tile-header .pc{ color: var(--fg); }

/* Einzelkacheln */
.rechner > div:not(.tile-header){
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 500;
  transition: background 120ms ease, border-color 120ms ease, transform 100ms ease;
}

/* letzte Teilkachel ganz breit */
.rechner > div:last-child:not(.tile-header):nth-child(even){ grid-column: 1 / -1; }

/* Statusfarben (Outlines nur für Kachel-Divs) */
.rechner > div.state-0{ outline: 2px solid var(--ok); }
.rechner > div.state-1{ outline: 2px solid var(--warn); }
.rechner > div.state-2{ outline: 2px solid var(--crit); }

/* Link zur Anleitung innerhalb von Teilkacheln */
.tile-link{
  margin-left: auto;
  text-decoration: none;
  font-weight: 700;
  border: 1px solid var(--tile-border);
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--fg);
}

/* Klickbare Kacheln / Interaktionen */
.tile-linkable{ cursor: pointer; }
.tile-linkable:hover{ border-color: #3c455a; }
.rechner > div.tile-linkable:hover{ border-color: #3c455a; transform: translateY(-1px); }
.rechner > div.tile-linkable:focus-visible{ outline: 2px solid var(--room-accent); outline-offset: 2px; }

/* Einspaltiges Layout (z. B. Login) */
.rechner--single{ grid-template-columns: 1fr; max-width: 560px; margin: 0 auto; }


/* =====================================================
   Modal
   ===================================================== */
.modal-backdrop[hidden]{
  display: none;
}
.modal-backdrop{
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.5);
  display: grid;
  place-items: center;
}
.modal{
  background: #111418;
  color: var(--fg);
  width: min(680px, 92vw);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.modal h2{
  margin: 0 0 10px;
  font-size: 18px;
}
.modal-close{
  position: absolute;
  right: 14px;
  top: 10px;
  background: transparent;
  color: var(--fg);
  border: 0;
  font-size: 20px;
  cursor: pointer;
}

/* Key/Value-Liste im Modal */
.kv{
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px 12px;
}
.kv dt{
  color: var(--muted);
}
.kv dd{
  margin: 0;
}


/* =====================================================
   Formulare
   ===================================================== */
.form-grid{
  display: grid;
  gap: 12px;
}
.form-row{
  display: grid;
  gap: 6px;
}
.form-row-inline{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.form-row .checkbox{
  display: flex;
  align-items: center;
  gap: 8px;
}

label{
  color: var(--muted);
  font-weight: 600;
}
input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
select{
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--tile-border);
  background: var(--tile);
  color: var(--fg);
}
input::placeholder{
  color: var(--muted);
}
input:focus-visible,
select:focus-visible{
  outline: 2px solid var(--room-accent);
  outline-offset: 2px;
}
.link-muted{
  color: var(--muted);
  text-decoration: none;
}
.link-muted:hover{
  text-decoration: underline;
}

/* Busy-Status (AJAX) */
.rechner > div.is-busy{
  opacity: .65;
  filter: saturate(.6);
  pointer-events: none;
  position: relative;
}
.rechner > div.is-busy::after{
  content: '…';
  position: absolute;
  right: 10px;
  top: 6px;
  font-weight: 700;
  opacity: .8;
}


/* =====================================================
   Errorliste (Tabellenlayout)
   ===================================================== */
.em-table{
  width: 100%;
  max-width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  table-layout: auto;
}
.em-table th,
.em-table td{
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  line-height: 1.6;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.em-table thead th{
  position: sticky;
  top: 0;
  background: var(--card);
  border-bottom: 2px solid #3a4256;
  z-index: 1;
}

.em-table th a{ color: inherit; text-decoration: none; }
.em-table th a:hover{ text-decoration: underline; }

/* Zeilenstatus (Hintergrund statt Outline) */
.em-table tr.state-1 td{
  background: color-mix(in srgb, var(--warn) 22%, var(--card));
}
.em-table tr.state-2 td{
  background: color-mix(in srgb, var(--crit) 28%, var(--card));
}
.em-table tr.state-3 td{
  background: color-mix(in srgb, var(--ok) 22%, var(--card));
}

/* Sonstiges */
.em-table tr.state-3{
  opacity: .85;
}
.em-actions .btn{
  margin: 0;
}

/* keine Outline auf Tabellenzeilen mit state-X */
.em-table tr.state-0,
.em-table tr.state-1,
.em-table tr.state-2,
.em-table tr.state-3{
  outline: none;
}

/* Utility-Styles für Errorliste */
.list-controls{
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0 0 12px;
}
.badge{
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--tile-border);
  border-radius: 999px;
  font-size: 12px;
}
.dim{
  color: var(--muted);
}

/* Statuspunkte in der Tabelle */
.status-dot{
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}
.st1{
  background: var(--warn);
}
.st2{
  background: var(--crit);
}
.st3{
  background: var(--ok);
}

/* Tabelle über volle Breite der Karte */
.rechner .em-table{
  grid-column: 1 / -1;
}

/* Spalten-Umbruchregeln: Nur „Meldung“ bricht um */
.em-table th:nth-child(1), .em-table td:nth-child(1),
.em-table th:nth-child(2), .em-table td:nth-child(2),
.em-table th:nth-child(4), .em-table td:nth-child(4),
.em-table th:nth-child(5), .em-table td:nth-child(5),
.em-table th:nth-child(6), .em-table td:nth-child(6){
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
}
.em-table th:nth-child(3),
.em-table td:nth-child(3){
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}


/* =====================================================
   Anleitungen (Seitenlayout & Typografie)
   ===================================================== */
/* Kopfbereich mit Buttons über der Kachel */
.content-head{
  max-width: 820px;
  margin: 16px auto 8px;
  display: flex;
  justify-content: flex-end;
}
.content-head .btn{
  margin: 0;
}

/* Kachelrahmen für den eigentlichen Inhalt */
.content{
  max-width: 820px;
  margin: 16px auto;
  padding: 18px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--br);
  box-shadow: 0 8px 22px rgba(0,0,0,0.35);
}
.content h1{
  font-size: 28px;
  margin: 0 0 14px;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.content h2{
  font-size: 20px;
  margin: 18px 0 8px;
}
.content p{
  margin: 8px 0 14px;
}
.content ul{
  margin: 8px 0 16px 1.2em;
  padding: 0;
}
.content li{
  margin: 6px 0;
}
.content em{
  color: var(--fg);
  opacity: .95;
}

/* Back-Link (falls separat genutzt) */
.back-link{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px;
  padding: 6px 10px;
  line-height: 1;
  font-weight: 600;
  background: #232833;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
}
.back-link:hover{
  border-color: #3c455a;
  background: #262c38;
}
.back-link:focus-visible{
  outline: 2px solid var(--room-accent);
  outline-offset: 2px;
}

/* Issue-Liste im Modal */
.issue-list{
  margin: 8px 0 0 1.2em;
  padding: 0;
}
.issue-list li{
  margin: 4px 0;
}


/* =====================================================
   Media Queries
   ===================================================== */
@media (max-width: 820px){
  .rechner-board{
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px){
  .kv{
    grid-template-columns: 1fr;
  }
}

/* =====================================================
   Userverwaltung
   ===================================================== */

/* Tabelle in der Userverwaltung nutzt das bestehende Errorlisten-Layout */
.user-table{
  width: 100%;
  max-width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  table-layout: auto;
}

/* Falls die User-Tabelle zusätzlich .em-table nutzt, einfach etwas enger machen */
.em-table.user-table th,
.em-table.user-table td{
  padding-top: 10px;
  padding-bottom: 10px;
}

/* Rollenkürzel optisch hervorheben */
.badge-role--admin{
  background: color-mix(in srgb, var(--crit) 25%, var(--card));
  border-color: color-mix(in srgb, var(--crit) 50%, var(--tile-border));
}
.badge-role--user{
  background: color-mix(in srgb, var(--ok) 20%, var(--card));
  border-color: color-mix(in srgb, var(--ok) 45%, var(--tile-border));
}
.badge-role--na{
  background: color-mix(in srgb, var(--muted) 25%, var(--card));
  border-color: color-mix(in srgb, var(--muted) 45%, var(--tile-border));
  color: var(--bg);
}

/* kleine Utility-Klasse für die Userverwaltungs-Aktionsspalte */
.user-actions{
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.user-actions .btn{
  padding-inline: 10px;
  min-height: 30px;
  font-size: 14px;
}