/* Scanner-Adressbuch – Admin-UI auf Basis des AHFCampus Design Systems.
   Bewusst nüchtern: Farben, Schrift und Formen aus den Tokens, ohne Papier-/Kippeffekte. */

@font-face {
  font-family: "Patua One";
  src: url("fonts/patua-one-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Marke */
  --campus-yellow: #ffba00;
  --primary: var(--campus-yellow);
  --ink: #000000;
  --on-primary: #000000;

  /* Flächen */
  --surface: #ffffff;
  --canvas: oklch(98.5% 0.002 247.839);          /* gray-50: Seitengrund unter den Panels */
  --highlight: oklch(96.7% 0.003 264.542);       /* gray-100: Hover */
  --line: oklch(92.8% 0.006 264.531);            /* gray-200 */
  --line-strong: oklch(87.2% 0.01 258.338);      /* gray-300: Eingabefelder */

  /* Text */
  --text-strong: oklch(21% 0.034 264.665);
  --text: oklch(37.3% 0.034 259.733);
  --text-muted: oklch(44.6% 0.03 256.802);
  --text-subtle: oklch(55.1% 0.027 264.364);

  /* Status (nur für Meldungen und Badges) */
  --ok-bg: oklch(96.2% 0.044 156.743);  --ok-text: oklch(44.8% 0.119 151.328);
  --warn-bg: oklch(98.7% 0.026 102.212); --warn-text: oklch(47.6% 0.114 61.907);
  --err-bg: oklch(97.1% 0.013 17.38);    --err-text: oklch(50.5% 0.213 27.518);

  --font-display: "Patua One", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-8: 32px;
  --radius-lg: 8px;
  --shadow-button: 0 1px 3px 0 #0000001a, 0 1px 2px -1px #0000001a;
  --page-width: 1600px;  /* breit genug für die Zuordnungs-Matrix, darunter flüssig */
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: oklch(21% 0.034 264.665);
    --canvas: oklch(18% 0.03 264.665);
    --highlight: oklch(27.8% 0.033 256.848);
    --line: oklch(37.3% 0.034 259.733);
    --line-strong: oklch(44.6% 0.03 256.802);
    --text-strong: #ffffff;
    --text: oklch(87.2% 0.01 258.338);
    --text-muted: oklch(87.2% 0.01 258.338);
    --text-subtle: oklch(70.7% 0.022 261.325);
    --on-primary: #ffffff;
    --ok-bg: oklch(26.6% 0.065 152.934);  --ok-text: oklch(87.1% 0.15 154.449);
    --warn-bg: oklch(28.6% 0.066 53.813); --warn-text: oklch(90.5% 0.182 98.111);
    --err-bg: oklch(25.8% 0.092 26.042);  --err-text: oklch(80.8% 0.114 19.571);
  }
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font: 400 15px/1.5 var(--font-sans);
}
a { color: var(--text-strong); text-decoration-color: color-mix(in oklab, var(--primary) 80%, transparent);
    text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--primary); }
code { font-size: 0.9em; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Kopf: App-Leiste, Seitentitel, Tabs ---------- */
.app-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.app-bar, .tab-row { max-width: var(--page-width); margin: 0 auto; padding-inline: var(--space-8); }
.app-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding-block: var(--space-3) 0; }
.brand { display: inline-flex; align-items: center; gap: var(--space-3); text-decoration: none; }
.brand img { display: block; height: 35px; width: auto; }
@media (prefers-color-scheme: dark) { .brand img { background: #fff; padding: 4px 6px; } } /* Logo nur auf hellem Grund */
.brand-app { padding-left: var(--space-3); border-left: 1px solid var(--line); color: var(--text-muted);
  font-size: 13px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.who { color: var(--text-subtle); font-size: 13px; }

/* Feste Höhe, damit die Tabs auf jeder Seite an derselben Stelle stehen */
.tab-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4);
  min-height: 56px; margin-top: var(--space-2); }
.tabs { display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: none; align-self: flex-end; }
.tab-actions { display: flex; align-items: center; gap: var(--space-3); align-self: center; flex-shrink: 0; }
.tab-actions .hint { margin: 0; }
.tabs a {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3) 10px; margin-bottom: -1px;
  color: var(--text-muted); font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  border-bottom: 3px solid transparent; border-radius: 6px 6px 0 0;
}
.tabs a:hover { color: var(--text-strong); background: var(--highlight); }
.tabs a.active { color: var(--text-strong); font-weight: 700; border-bottom-color: var(--primary); }
.nav-badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 9999px;
  background: color-mix(in oklab, var(--primary) 80%, transparent); color: var(--ink);
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }

/* ---------- Kontextzeile auf Detailseiten (im Inhalt, nicht im Kopf) ---------- */
.context { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3); margin-bottom: var(--space-4); }
.context .crumbs { margin: 0; }
.context .crumbs a:last-child::after { content: "/"; }
.context h1 { margin: 0; font: 400 22px/28px var(--font-display); color: var(--text-strong); }
.context h1 .badge { font: 600 12px/18px var(--font-sans); vertical-align: middle; }
.context-meta { color: var(--text-subtle); font-size: 13px; }

/* ---------- Inhalt ---------- */
main { max-width: var(--page-width); margin: 0 auto; padding: var(--space-5) var(--space-8) 64px; }
h2 { margin: 0 0 var(--space-2); font: 400 20px/28px var(--font-display); color: var(--text-strong); }
h3 { margin: var(--space-4) 0 var(--space-2); font-size: 14px; font-weight: 700; color: var(--text-strong); }
.hint { color: var(--text-subtle); font-size: 13px; margin: var(--space-1) 0; }
hr { border: none; border-top: 1px solid var(--line); margin: var(--space-4) 0; }

.card { background: var(--surface); border: 1px solid var(--line); padding: var(--space-4) var(--space-5); margin-bottom: var(--space-4); }
.card.highlight { border-left: 4px solid var(--primary); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.card-head h2 { margin-bottom: var(--space-1); }
details > summary { cursor: pointer; padding: var(--space-1) 0; color: var(--text-strong); font-weight: 600; }
details[open] > summary { margin-bottom: var(--space-2); }
details.card > summary h2 { display: inline; }
.actions { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.stat { background: var(--surface); border: 1px solid var(--line); padding: var(--space-3) var(--space-4);
  display: flex; flex-direction: column; color: inherit; text-decoration: none; }
a.stat:hover { border-color: var(--primary); }
.stat-value { font: 400 28px/34px var(--font-display); color: var(--text-strong); font-variant-numeric: tabular-nums; }
.stat-label { color: var(--text-subtle); font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.stats.compact .stat { padding: var(--space-2) var(--space-3); }
.stats.compact .stat-value { font-size: 22px; line-height: 28px; }

/* ---------- Buttons und Formulare ---------- */
button, a.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 36px; padding: 6px 14px; border-radius: var(--radius-lg);
  font: 600 14px/20px var(--font-sans); cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-strong);
  transition: background-color .15s, border-color .15s;
}
button:hover, a.button:hover { background: var(--highlight); }
button.primary, a.button.primary {
  border-color: color-mix(in oklab, var(--primary) 90%, transparent);
  background: color-mix(in oklab, var(--primary) 80%, transparent);
  color: var(--on-primary); box-shadow: var(--shadow-button);
}
button.primary:hover, a.button.primary:hover { background: color-mix(in oklab, var(--primary) 55%, transparent); }
@media (prefers-color-scheme: dark) {
  button.primary { border-color: color-mix(in oklab, var(--primary) 60%, transparent); background: color-mix(in oklab, var(--primary) 40%, transparent); }
  button.primary:hover { background: color-mix(in oklab, var(--primary) 60%, transparent); }
}
button.danger { color: var(--err-text); border-color: color-mix(in oklab, var(--err-text) 50%, transparent); }
button.danger:hover { background: var(--err-bg); }
button.small { min-height: 28px; padding: 2px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) { button { transition: none; } }

input:not([type=checkbox]):not([type=radio]), select {
  font: 400 14px/20px var(--font-sans); min-height: 36px; padding: 6px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text-strong);
}
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-3) var(--space-4); align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: var(--space-1); font-size: 13px; font-weight: 600; color: var(--text-muted); }
.form-grid label.inline { flex-direction: row; align-items: center; gap: var(--space-2); font-weight: 400; color: var(--text); }
.form-grid .full { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-bottom: var(--space-3); }
.filters label { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 14px; }
.filters input[type=search] { min-width: 260px; flex: 1 1 260px; max-width: 420px; }

.search-add { margin-bottom: var(--space-3); }
.search-add input { width: 100%; max-width: 480px; }
.search-results { list-style: none; padding: 0; margin: var(--space-2) 0 0; max-width: 640px; border: 1px solid var(--line); background: var(--surface); }
.search-results li { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  padding: 6px 10px; border-bottom: 1px solid var(--line); }
.search-results li:last-child { border-bottom: none; }

.sync-bar { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: center; }
.sync-bar { margin-top: var(--space-4); }

/* ---------- Meldungen und Badges ---------- */
.notice { padding: 10px 14px; margin: var(--space-2) 0; border: 1px solid transparent; border-left-width: 4px; }
.notice p { margin: var(--space-1) 0; }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); border-color: color-mix(in oklab, var(--ok-text) 35%, transparent); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); border-color: color-mix(in oklab, var(--warn-text) 35%, transparent); }
.notice.error { background: var(--err-bg); color: var(--err-text); border-color: color-mix(in oklab, var(--err-text) 35%, transparent); }
.notice a { color: inherit; }
.err { color: var(--err-text); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 9999px; font-size: 12px; font-weight: 600; line-height: 18px;
  background: var(--highlight); color: var(--text-muted); white-space: nowrap; }
.badge.user-active, .badge.run-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.user-disabled, .badge.run-aborted { background: var(--warn-bg); color: var(--warn-text); }
.badge.user-deleted, .badge.run-error { background: var(--err-bg); color: var(--err-text); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-subtle); font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  white-space: nowrap; background: color-mix(in oklab, var(--canvas) 60%, var(--surface)); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in oklab, var(--highlight) 60%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.center, td.center { text-align: center; }
th.check, td.check { width: 36px; text-align: center; }
td.message { color: var(--text-subtle); font-size: 13px; max-width: 360px; }
td.pre { white-space: pre-line; font-size: 13px; }
td.actions-cell { white-space: nowrap; }
td.actions-cell button { margin: 2px 0; }
tr.status-deleted td { color: var(--text-subtle); }
.matrix-wrap { max-height: 70vh; }
.assign-matrix thead th { position: sticky; top: 0; z-index: 1; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { margin: 2px 0; }
details.runs { margin-top: var(--space-4); }

.htmx-indicator { opacity: 0; transition: opacity .15s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

@media (max-width: 640px) {
  .app-bar, .tab-row, main { padding-inline: var(--space-4); }
  .brand-app, .who { display: none; }
  .tab-row { flex-wrap: wrap; }
  .tab-actions { order: -1; width: 100%; justify-content: flex-end; }
}

/* ---------- Filter der Zuordnung ---------- */
.filter-panel { background: var(--surface); border: 1px solid var(--line); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); }
.filter-main { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-3); }
.filter-main label { display: flex; flex-direction: column; gap: var(--space-1); font-size: 11px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-subtle); }
.filter-main select { width: 100%; text-transform: none; letter-spacing: 0; }
.filter-more { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3);
  margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--line); }
.filter-more input[type=search] { flex: 1 1 240px; max-width: 360px; }
.filter-more .check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 14px; }
.filter-more .reset { margin-left: auto; font-size: 13px; color: var(--text-muted); }

/* ---------- Zuordnungs-Matrix ---------- */
.matrix-count { margin: 0 0 var(--space-2); }
.assign-matrix th.device-col { text-align: center; white-space: normal; min-width: 120px; max-width: 170px;
  vertical-align: bottom; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text-strong); }
.assign-matrix th.device-col a { display: block; font-weight: 700; overflow-wrap: anywhere; }
.assign-matrix th.device-col .badge { margin-top: 2px; }
.col-count { display: block; margin: 2px 0 6px; font-weight: 400; color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.col-actions { display: inline-flex; gap: var(--space-1); }
.col-actions button.small { min-height: 24px; padding: 0 8px; font-size: 12px; }
.assign-matrix td:nth-child(2) { color: var(--text-muted); }

/* ---------- Seiten mit fester Höhe (Zuordnung): nur die Tabelle scrollt ---------- */
body.page-fill { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
body.page-fill .app-header { flex-shrink: 0; }
body.page-fill main { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; padding-bottom: var(--space-4); }
body.page-fill .filter-panel, body.page-fill .notice, body.page-fill .matrix-count { flex-shrink: 0; }
body.page-fill #assign-table { flex: 1; min-height: 0; display: flex; flex-direction: column; }
body.page-fill .matrix-wrap { flex: 1; min-height: 0; max-height: none; overflow: auto; }
@media (max-height: 560px), (max-width: 640px) {
  /* zu wenig Platz: normal scrollen statt fester Höhe */
  body.page-fill { height: auto; overflow: visible; display: block; }
  body.page-fill .matrix-wrap { max-height: 70vh; }
}

/* ---------- Login und Konto ---------- */
.who a { color: inherit; text-decoration: none; }
.who a:hover, .who a[aria-current] { color: var(--text-strong); text-decoration: underline; }
button.link { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; }
button.link:hover { background: none; color: var(--text-strong); }
a.button { text-decoration: none; }
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-box { width: min(420px, 100% - 32px); display: grid; gap: var(--space-4); padding: 0; }
.login-local { margin-top: var(--space-4); }
.agent-new { display: grid; gap: var(--space-3); }
.agent-prompt { width: 100%; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.5; padding: var(--space-3); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text-strong); resize: vertical; }
