/* ==========================================================================
   Teams Presence Tracker - zentrales Stylesheet

   Saemtliche Farben liegen als CSS-Variablen vor (Auftrag Abschnitt 41).
   Die Statuspalette wurde fuer hellen und dunklen Modus auf Unterscheidbarkeit
   bei Farbfehlsichtigkeit und ausreichenden Kontrast geprueft. Status wird nie
   allein ueber Farbe vermittelt: Badges tragen Punkt und Text, Offline einen
   Ring, "keine Daten" zusaetzlich eine Schraffur.
   ========================================================================== */

:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface2: #f7f9fb;
  --ink: #1c2530;
  --muted: #5a6675;
  --border: #dce2e9;
  --border-soft: #e8ecf1;

  /* Markenfarbe - bewusst getrennt von allen Statusfarben */
  --accent: #2f5570;
  --accent-ink: #ffffff;
  --accent-soft: #e7eef3;

  --st-available: #1f8a4c;
  --st-busy: #c43d3d;
  --st-meeting: #6a4fc3;
  --st-call: #1f78c1;
  --st-presenting: #8e2d77;
  --st-donotdisturb: #922f2f;
  --st-away: #b07c0c;
  --st-berightback: #c0913a;
  --st-offline: #7a8089;
  --st-outofoffice: #5a5fa8;
  --st-unknown: #8a8f98;
  --st-other: #6b7280;
  --st-nodata: #aeb6bf;

  --ok: #1f8a4c;
  --warn: #b07c0c;
  --crit: #c43d3d;

  --shadow: 0 1px 2px rgba(28, 37, 48, 0.06), 0 4px 14px rgba(28, 37, 48, 0.05);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181d;
    --surface: #1c2228;
    --surface2: #20272e;
    --ink: #e5eaef;
    --muted: #98a3af;
    --border: #313a44;
    --border-soft: #2a323b;

    --accent: #86aecb;
    --accent-ink: #0f1a22;
    --accent-soft: #26343f;

    --st-available: #2e9e5c;
    --st-busy: #cc4e4e;
    --st-meeting: #8170d8;
    --st-call: #3e8ccb;
    --st-presenting: #b052b8;
    --st-donotdisturb: #c24040;
    --st-away: #b8862a;
    --st-berightback: #c79a4c;
    --st-offline: #8b929c;
    --st-outofoffice: #8489cf;
    --st-unknown: #9aa1ac;
    --st-other: #8b929c;
    --st-nodata: #5a626c;

    --ok: #2e9e5c;
    --warn: #b8862a;
    --crit: #cc4e4e;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  --bg: #14181d;
  --surface: #1c2228;
  --surface2: #20272e;
  --ink: #e5eaef;
  --muted: #98a3af;
  --border: #313a44;
  --border-soft: #2a323b;

  --accent: #86aecb;
  --accent-ink: #0f1a22;
  --accent-soft: #26343f;

  --st-available: #2e9e5c;
  --st-busy: #cc4e4e;
  --st-meeting: #8170d8;
  --st-call: #3e8ccb;
  --st-presenting: #b052b8;
  --st-donotdisturb: #c24040;
  --st-away: #b8862a;
  --st-berightback: #c79a4c;
  --st-offline: #8b929c;
  --st-outofoffice: #8489cf;
  --st-unknown: #9aa1ac;
  --st-other: #8b929c;
  --st-nodata: #5a626c;

  --ok: #2e9e5c;
  --warn: #b8862a;
  --crit: #cc4e4e;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
}

h1, h2, h3 { line-height: 1.25; text-wrap: balance; margin: 0; }
a { color: var(--accent); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.dim { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* --- Navigation ---------------------------------------------------------- */
.appnav {
  display: flex; align-items: center; gap: 26px;
  background: var(--surface); padding: 0 26px;
  border-bottom: 1px solid var(--border); height: 54px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; text-decoration: none; color: var(--ink); }
.brand .mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.appnav nav { display: flex; gap: 2px; height: 100%; }
.appnav nav a {
  display: flex; align-items: center; padding: 0 13px;
  color: var(--muted); text-decoration: none; font-weight: 550;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.appnav nav a:hover { color: var(--ink); }
.appnav nav a.active { color: var(--ink); border-bottom-color: var(--accent); }
.appnav .navright { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 12.5px; color: var(--muted); }
.livedot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 6px; }
.livedot.stale { background: var(--warn); }
.livedot.off { background: var(--muted); }
.userchip {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  text-decoration: none;
}

/* --- Seitenaufbau -------------------------------------------------------- */
.page { padding: 22px 26px 40px; max-width: 1680px; margin: 0 auto; }
.page-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 21px; font-weight: 650; }
.page-head .sub { color: var(--muted); font-size: 13.5px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card-h {
  display: flex; align-items: center; gap: 10px; padding: 13px 18px;
  border-bottom: 1px solid var(--border-soft); font-weight: 650; font-size: 14px;
  flex-wrap: wrap;
}
.card-h .spacer { margin-left: auto; }
.card-b { padding: 16px 18px; }
.card-b.tight { padding: 6px 18px 10px; }

/* --- Bedienelemente ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border-radius: 8px;
  padding: 7px 14px; font: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 45%, transparent); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn:focus-visible, .chip:focus-visible, .input:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.input, select.input, input.input {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; font: inherit; font-size: 13.5px; color: var(--ink);
}
.input::placeholder { color: var(--muted); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 5px 13px; font: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer;
}
.chip:hover { color: var(--ink); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.filterbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filterbar .sep { width: 1px; height: 24px; background: var(--border); }

.banner {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  background: color-mix(in srgb, var(--warn) 9%, var(--surface));
  border-radius: 9px; padding: 9px 14px; font-size: 13.5px; margin-bottom: 14px;
  flex-wrap: wrap;
}
.banner .bicon { color: var(--warn); font-weight: 800; }
.banner.error { border-color: color-mix(in srgb, var(--crit) 45%, transparent); background: color-mix(in srgb, var(--crit) 9%, var(--surface)); }
.banner.error .bicon { color: var(--crit); }
.banner.ok { border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 9%, var(--surface)); }
.banner.ok .bicon { color: var(--ok); }

/* --- Statusdarstellung --------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px;
  font-weight: 600; border-radius: 999px; padding: 3px 11px 3px 9px;
  white-space: nowrap;
  background: color-mix(in srgb, var(--sc, var(--muted)) 11%, transparent);
  color: var(--sc, var(--muted));
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--sc, var(--muted)); flex: none; }
.badge.ring::before { background: none; border: 2px solid var(--sc); width: 6px; height: 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; font-size: 12px; font-weight: 650; padding: 2px 11px; }
.pill.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.pill.crit { background: color-mix(in srgb, var(--crit) 12%, transparent); color: var(--crit); }
.pill.neutral { background: var(--surface2); color: var(--muted); }

/* Statusfarbe je Kategorie - eine Stelle fuer Badges, Punkte und Balken */
[data-status="Available"] { --sc: var(--st-available); }
[data-status="Busy"] { --sc: var(--st-busy); }
[data-status="Meeting"] { --sc: var(--st-meeting); }
[data-status="Call"] { --sc: var(--st-call); }
[data-status="Presenting"] { --sc: var(--st-presenting); }
[data-status="DoNotDisturb"] { --sc: var(--st-donotdisturb); }
[data-status="Away"] { --sc: var(--st-away); }
[data-status="BeRightBack"] { --sc: var(--st-berightback); }
[data-status="Offline"] { --sc: var(--st-offline); }
[data-status="OutOfOffice"] { --sc: var(--st-outofoffice); }
[data-status="Unknown"] { --sc: var(--st-unknown); }
[data-status="Other"] { --sc: var(--st-other); }
[data-status="NoData"] { --sc: var(--st-nodata); }

/* --- Tabellen ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); font-weight: 650; padding: 10px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
thead th.sorted { color: var(--accent); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
tbody tr:hover { background: var(--surface2); }
tbody tr.clickable { cursor: pointer; }
td.r, th.r { text-align: right; }
.emp { display: flex; align-items: center; gap: 11px; }
.emp .av {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center;
  font-size: 11.5px; font-weight: 700; flex: none;
}
.emp .av.lg { width: 42px; height: 42px; font-size: 14px; }
.emp .nm { font-weight: 600; }
.emp .dp { font-size: 12px; color: var(--muted); }
.tfoot { display: flex; align-items: center; gap: 10px; padding: 11px 16px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.pager { margin-left: auto; display: flex; gap: 4px; }
.pager button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 6px;
  min-width: 28px; padding: 3px 7px; font: inherit; font-size: 12.5px;
  color: var(--muted); cursor: pointer;
}
.pager button.cur { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pager button:disabled { opacity: 0.4; cursor: not-allowed; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* --- Kennzahlen ---------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
.kpi .lbl { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 650; }
.kpi .val { font-size: 24px; font-weight: 650; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* --- Timeline ------------------------------------------------------------ */
.tl-wrap { position: relative; padding-top: 6px; }
.tl-axis { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; margin-bottom: 6px; }
.tl { display: flex; gap: 2px; height: 40px; border-radius: 7px; overflow: hidden; }
.tl i { display: block; background: var(--sc); min-width: 2px; cursor: default; }
.tl i[data-status="NoData"] {
  background: repeating-linear-gradient(135deg, var(--st-nodata) 0 5px, transparent 5px 10px);
  border: 1px dashed var(--st-nodata);
}
.tl i:hover { filter: brightness(1.12); }
.tl-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 7px; }
.lg i { width: 11px; height: 11px; border-radius: 3px; background: var(--sc); flex: none; }
.lg i[data-status="NoData"] {
  background: repeating-linear-gradient(135deg, var(--st-nodata) 0 4px, transparent 4px 8px);
  border: 1px dashed var(--st-nodata);
}
.tooltip {
  position: absolute; background: var(--ink); color: var(--bg); border-radius: 8px;
  padding: 8px 13px; font-size: 12.5px; line-height: 1.5; box-shadow: var(--shadow);
  pointer-events: none; z-index: 20; white-space: nowrap; transform: translateX(-50%);
}
.tooltip b { font-weight: 650; }

/* --- Statussummen -------------------------------------------------------- */
.sums { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.sum { border: 1px solid var(--border); border-radius: 9px; padding: 10px 13px; background: var(--surface); }
.sum .t { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); font-weight: 600; }
.sum .t i { width: 9px; height: 9px; border-radius: 50%; background: var(--sc); flex: none; }
.sum .v { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.sum.zero .v { color: var(--muted); font-weight: 500; }

/* --- Diagramme ----------------------------------------------------------- */
.chartgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.chartgrid.two { grid-template-columns: repeat(2, 1fr); }
.chart-h { font-size: 13px; font-weight: 650; margin-bottom: 2px; }
.chart-s { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.chart-empty { color: var(--muted); font-size: 12.5px; padding: 24px 0; text-align: center; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 8px; border-bottom: 1px solid var(--border); }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; min-width: 6px; }
.bars .b i { display: block; background: var(--sc, var(--accent)); border-radius: 4px 4px 0 0; min-height: 2px; }
.bxl { display: flex; gap: 8px; margin-top: 6px; }
.bxl span { flex: 1; text-align: center; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; overflow: hidden; }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hb { display: grid; grid-template-columns: 96px 1fr 58px; align-items: center; gap: 10px; font-size: 12.5px; }
.hb .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb .tr { height: 14px; border-radius: 4px; background: var(--sc, var(--accent)); min-width: 3px; }
.hb .vl { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.rangecol { display: flex; gap: 8px; height: 170px; border-bottom: 1px solid var(--border); position: relative; }
.rangecol .rc { flex: 1; position: relative; min-width: 6px; }
.rangecol .rc i { position: absolute; left: 50%; transform: translateX(-50%); width: 8px; border-radius: 4px; background: var(--accent); }
.grid-lines { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.grid-lines b { border-top: 1px solid var(--border-soft); height: 0; position: relative; font-weight: 400; }
.grid-lines b span { position: absolute; right: 100%; top: -8px; margin-right: 8px; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.donutrow { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.dlegend { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.dlegend .lg { display: flex; align-items: center; gap: 8px; min-width: 190px; }
.dlegend .lg b { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink); }
svg text { font-family: inherit; font-variant-numeric: tabular-nums; }

/* --- Administration ------------------------------------------------------ */
.admingrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.kv { display: grid; grid-template-columns: 190px 1fr; row-gap: 9px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; }
.toggle {
  width: 36px; height: 20px; border-radius: 999px; background: var(--border);
  position: relative; display: inline-block; vertical-align: middle; cursor: pointer;
  border: 0; padding: 0; flex: none;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: left 0.15s;
}
.toggle.on { background: var(--ok); }
.toggle.on::after { left: 18px; }
@media (prefers-reduced-motion: reduce) { .toggle::after { transition: none; } }
.setrow { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; flex-wrap: wrap; }
.setrow:last-child { border-bottom: 0; }
.setrow .grow { flex: 1; min-width: 200px; }
.setrow .desc { font-size: 12px; color: var(--muted); }
.checkgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 22px; }
.ck { display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: 13.5px; cursor: pointer; }
.ck .box { width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid var(--border); display: grid; place-items: center; flex: none; font-size: 11px; font-weight: 800; color: transparent; }
.ck.on .box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ck .sdot { width: 9px; height: 9px; border-radius: 50%; background: var(--sc); flex: none; }
.danger-zone { border: 1px solid color-mix(in srgb, var(--crit) 35%, transparent); border-radius: 9px; padding: 12px 15px; margin-top: 14px; }
.danger-zone h4 { margin: 0 0 4px; font-size: 13px; color: var(--crit); }
.danger-zone p { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); }
.danger-zone .btn + .btn { margin-left: 6px; }

/* --- Anmeldung ----------------------------------------------------------- */
.login-stage { display: grid; place-items: center; min-height: 100vh; padding: 40px 20px; background: var(--bg); }
.login-card { width: 360px; max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 30px 30px 26px; text-align: center; }
.login-card .mark { width: 44px; height: 44px; border-radius: 11px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; margin: 0 auto 12px; }
.login-card h1 { font-size: 18px; font-weight: 650; }
.login-card p { font-size: 12.5px; color: var(--muted); margin: 6px 0 18px; }
.login-card .input { width: 100%; margin-bottom: 12px; text-align: left; }
.login-card .btn { width: 100%; justify-content: center; }
.login-card .foot { font-size: 11.5px; color: var(--muted); margin-top: 16px; }

/* --- Hinweise ------------------------------------------------------------ */
.footnote { padding: 10px 18px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border-soft); }
.disclaimer { color: var(--muted); font-size: 11.5px; padding: 18px 26px 0; max-width: 1680px; margin: 0 auto; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .chartgrid, .chartgrid.two { grid-template-columns: 1fr; }
  .admingrid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .appnav { gap: 12px; padding: 0 14px; overflow-x: auto; }
  .page { padding: 16px 14px 30px; }
  .kpis { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; row-gap: 2px; }
  .checkgrid { grid-template-columns: 1fr; }
}
