:root {
  --bg: #14161b;
  --panel: #1c1f26;
  --panel-2: #242832;
  --line: #333845;
  --text: #e6e8ee;
  --muted: #9aa1b2;
  --accent: #5865f2;
  --accent-hover: #6d78f5;
  --ok: #57c98a;
  --err: #f0737a;
  --warn: #f2b84b;
  --tank: #4c9be8;
  --heal: #57c98a;
  --support: #e8c44c;
  --melee: #e8705a;
  --ranged: #b48cf2;
  --row: 44px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.spacer { flex: 1; }

/* --- Bedienelemente ------------------------------------------------------ */

.btn, select, input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-height: 34px;
}
.btn { cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled, select:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--err); }
.btn.icon { padding: 0; width: 30px; min-height: 30px; flex: none; line-height: 1; }
.btn.big { display: inline-block; padding: 12px 22px; font-size: 16px; }
:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 1px; }

.notice {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.notice.err { border-color: var(--err); color: var(--err); }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

/* --- Login --------------------------------------------------------------- */

body.login { display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(420px, 100%);
  padding: 32px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.login-card h1 { font-size: 24px; margin-bottom: 8px; }
.login-card p { color: var(--muted); }
.login-card .notice { text-align: left; }

/* --- Rahmen -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.status { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }
.user { display: flex; align-items: center; gap: 8px; }
.user img { border-radius: 50%; }

.layout {
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100% - 52px);
}
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.panel-head h2 { margin-right: auto; }
.toolbar { flex-wrap: wrap; }
.toolbar h2 { margin-right: 0; }
.toolbar select { min-width: 180px; max-width: 100%; }
.editor { overflow-y: auto; }

/* --- Spieler ------------------------------------------------------------- */

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.filters input[type="search"] { flex: 1 1 100%; }
.filters select { flex: 1 1 0; min-width: 0; }
.check { display: flex; align-items: center; gap: 4px; color: var(--muted); white-space: nowrap; }

.player-list { flex: 1; min-height: 120px; overflow-y: auto; border-top: 1px solid var(--line); }

.player {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--row);
  padding: 0 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  cursor: grab;
  user-select: none;
}
.player:hover { background: var(--panel-2); }
.player.assigned { cursor: default; }
.player.assigned .avatar, .player.assigned .pname, .player.assigned .cls-icon,
.player.assigned .badge { opacity: .45; }
.player.unknown .pname { color: var(--muted); font-style: italic; }
.player.ghost { opacity: .35; }

.avatar { width: 28px; height: 28px; border-radius: 50%; flex: none; background: var(--panel-2); }
.cls-icon { width: 24px; height: 24px; flex: none; }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}
.cls-select { width: 96px; min-height: 30px; padding: 3px 4px; font-size: 13px; flex: none; }

.badge {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 22px;
  flex: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  color: #14161b;
  background: var(--muted);
}
.badge.none { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.badge.role-tank { background: var(--tank); }
.badge.role-heal { background: var(--heal); }
.badge.role-support { background: var(--support); }
.badge.role-melee { background: var(--melee); }
.badge.role-ranged { background: var(--ranged); }

/* --- Vorlage ------------------------------------------------------------- */

.alliance { margin-bottom: 12px; color: var(--muted); }
.groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.group {
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.group header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.slots {
  min-height: calc(var(--rows, 6) * var(--row));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  /* leere Plätze als Zeilenraster */
  background: repeating-linear-gradient(to bottom,
    transparent 0, transparent calc(var(--row) - 1px), var(--line) calc(var(--row) - 1px), var(--line) var(--row));
}
.slots .player .cls-select, .slots .player .add, .slots .player .tag { display: none; }
.summary { min-height: 20px; margin-top: 8px; color: var(--muted); font-size: 13px; }
.warn { min-height: 20px; color: var(--warn); font-size: 13px; }

/* --- Reiter, Raids, Abwesenheiten ---------------------------------------- */

.tabs { display: flex; gap: 4px; margin: -4px 0 14px; border-bottom: 1px solid var(--line); }
.tab {
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.section { margin: 18px 0 10px; }
.hint.top { margin: 0 0 12px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

.raid-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 12px;
  align-items: end;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.raid-form h2, .raid-form .wide { grid-column: 1 / -1; }
.raid-form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; min-width: 0; }
.raid-form label.check { flex-direction: row; align-items: center; min-height: 34px; grid-column: span 3; }
.raid-form input:not([type="checkbox"]), .raid-form select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-height: 34px;
  width: 100%;
}
.raid-form + .notice { margin: 10px 0 0; }
.raid-form.edit { margin-bottom: 12px; }
.raid-form.edit .btn { justify-self: end; }
.raid-form.edit .btn.primary { justify-self: stretch; }
.player.fits { box-shadow: inset 3px 0 0 var(--ok); }
.notice.ok { border-color: var(--ok); color: var(--ok); }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.row-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; flex: 1 1 220px; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.chip.warn { border-color: var(--warn); color: var(--warn); }
.chip.ok { border-color: var(--ok); color: var(--ok); }

.btn.small { min-height: 28px; padding: 2px 8px; font-size: 13px; flex: none; }
.slots.fitted { min-height: 0; background: none; border-bottom: 1px solid var(--line); border-radius: 6px; }
.slots.fitted > :last-child, .slots.fitted > :last-child .player { border-bottom: 0; }
.player.fixed { cursor: default; }
.player.absent .avatar, .player.absent .cls-icon, .player.absent .badge { opacity: .4; }
.player.absent .pname { color: var(--muted); }
.player.sub { box-shadow: inset 3px 0 0 var(--accent); }
.drop-hint { color: var(--muted); font-size: 12px; white-space: nowrap; }
.dropzone { position: relative; }
.dropzone > .player:not(.fixed) {   /* der gerade hineingezogene Spieler */
  position: absolute; inset: 0; z-index: 1;
  background: var(--panel-2);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
.dropzone > .player:not(.fixed) .cls-select, .dropzone > .player:not(.fixed) .add,
.dropzone > .player:not(.fixed) .tag { display: none; }
.slots.reserve { max-width: 520px; }

@media (min-width: 1700px) {
  .groups { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* --- Handy: untereinander, Liste bleibt als scrollbarer Block oben -------- */

@media (max-width: 900px) {
  html, body { height: auto; }
  .layout { grid-template-columns: 1fr; height: auto; padding: 10px; gap: 10px; }
  .player-list { flex: none; height: 38vh; }
  .editor { overflow: visible; }
  .groups { grid-template-columns: 1fr; }
  .user-name { display: none; }
  .cls-select { width: 92px; }
  .raid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .raid-form label.check { grid-column: 1 / -1; }
  .drop-hint { display: none; }
  .player-list .cls-select:nth-of-type(2) { display: none; }  /* Zweitklasse nur am Desktop */
}
