/* JanusSight – Gestaltung
   Farben als Variablen, hell und dunkel; eine Spalte auf dem Handy */
:root {
  --brand: #0f2a3d;
  --brand-2: #16405c;
  --accent: #1a9e8e;
  --accent-strong: #137a6e;
  --accent-soft: #e2f4f1;
  --pulse: #e5a52a;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #17212b;
  --muted: #5b6b79;
  --border: #dde3e8;
  --border-strong: #c3ccd4;
  --danger: #c0392b;
  --danger-soft: #fbeae8;
  --warning: #9a6200;
  --warning-soft: #fdf2dc;
  --success: #1e7b45;
  --success-soft: #e3f4ea;
  --info: #1d5f98;
  --info-soft: #e5eff8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 42, 61, .06), 0 4px 16px rgba(15, 42, 61, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #0b1f2d;
    --brand-2: #133449;
    --accent: #35c7b3;
    --accent-strong: #5fd8c7;
    --accent-soft: #123a37;
    --bg: #0e161d;
    --surface: #16212b;
    --surface-2: #1b2833;
    --text: #e6edf2;
    --muted: #93a4b2;
    --border: #273744;
    --border-strong: #35495a;
    --danger: #f08070;
    --danger-soft: #3a1f1c;
    --warning: #f0c060;
    --warning-soft: #3a2f16;
    --success: #6fd49a;
    --success-soft: #16331f;
    --info: #86b9ea;
    --info-soft: #172c40;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
h1 { font-size: 1.55rem; line-height: 1.25; margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 600; }
a { color: var(--accent-strong); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Ebenen-Farben ----------
   Plattform dunkel, Partner blau, Kunde petrol – so sieht man immer, wo man ist */
:root { --lvl-platform: #0f2a3d; --lvl-partner: #1f4f86; --lvl-customer: #0e5f59; }
@media (prefers-color-scheme: dark) {
  :root { --lvl-platform: #0b1f2d; --lvl-partner: #173d68; --lvl-customer: #0b4a45; }
}

/* ---------- Kopfzeile ---------- */
#app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 58px;
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .2px; }
#context-nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#context-nav a {
  color: rgba(255, 255, 255, .78); text-decoration: none; padding: 7px 12px; border-radius: 8px; white-space: nowrap; font-size: .92rem;
}
#context-nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
#context-nav a.active { color: #fff; background: rgba(255, 255, 255, .14); }
.header-right { display: flex; align-items: center; gap: 8px; position: relative; }
#context-switch {
  max-width: 240px; background: var(--brand-2); color: #fff; border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px; padding: 6px 8px; font: inherit; font-size: .88rem;
}
#user-menu-button { color: #fff; border-color: rgba(255, 255, 255, .25); }
#app-header.level-platform { background: var(--lvl-platform); }
#app-header.level-partner { background: var(--lvl-partner); }
#app-header.level-customer { background: var(--lvl-customer); }
#app-header #context-switch { background: rgba(0, 0, 0, .18); }
#context-switch option { color: #17212b; background: #fff; }

/* Pfad unter der Kopfzeile */
#context-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap;
  padding: 7px 20px; font-size: .88rem; background: var(--surface); border-bottom: 1px solid var(--border);
  border-left: 4px solid var(--lvl-platform);
}
#context-bar.level-partner { border-left-color: var(--lvl-partner); }
#context-bar.level-customer { border-left-color: var(--lvl-customer); }
.trail { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.trail a { color: var(--muted); text-decoration: none; }
.trail a:hover { color: var(--accent-strong); text-decoration: underline; }
.trail-sep { color: var(--border-strong); }
.trail-current { font-weight: 600; }
.level-chip {
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: #fff;
  padding: 2px 8px; border-radius: 999px; background: var(--lvl-platform); margin-right: 4px;
}
#context-bar.level-partner .level-chip { background: var(--lvl-partner); }
#context-bar.level-customer .level-chip { background: var(--lvl-customer); }
.entered-hint { color: var(--warning); background: var(--warning-soft); padding: 3px 10px; border-radius: 6px; font-size: .84rem; }

.search-input {
  width: 100%; max-width: 420px; font: inherit; padding: 9px 12px; margin-bottom: 12px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text);
}
.menu {
  position: absolute; right: 0; top: 46px; min-width: 240px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; z-index: 30;
}
.menu-email { padding: 8px 10px; color: var(--muted); font-size: .85rem; border-bottom: 1px solid var(--border); margin-bottom: 4px; word-break: break-all; }
.menu-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 6px; background: none; border: 0; font: inherit; color: inherit;
  text-decoration: none; cursor: pointer; text-align: left;
}
.menu-row:hover { background: var(--surface-2); }
.menu-row select { font: inherit; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

#maintenance-banner {
  background: var(--warning-soft); color: var(--warning); padding: 8px 20px; font-size: .9rem; border-bottom: 1px solid var(--border);
}

/* ---------- Inhalt ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; outline: none; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.subtitle { margin: 4px 0 0; color: var(--muted); }
.back-link { display: inline-block; font-size: .88rem; margin-bottom: 6px; text-decoration: none; color: var(--muted); }
.back-link:hover { color: var(--accent-strong); }
.page-actions, .card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 18px; }
.notice {
  background: var(--info-soft); color: var(--info); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.empty { color: var(--muted); margin: 6px 0; }

/* ---------- Knöpfe ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  font: inherit; font-weight: 550; font-size: .92rem; line-height: 1.2;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 6px 10px; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
#app-header .btn-ghost { border: 1px solid rgba(255, 255, 255, .25); }
#app-header .btn-ghost:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; padding: 11px 14px; }
.btn-icon { font-weight: 700; }
.is-busy { position: relative; color: transparent !important; }
.is-busy::after {
  content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid #fff; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .is-busy::after { animation: none; } }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; margin-left: 6px; vertical-align: middle; }
td > .badge:first-child, .facts .badge:first-child { margin-left: 0; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td select { font: inherit; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* ---------- Formulare und Dialoge ---------- */
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row label { font-weight: 550; font-size: .9rem; }
.req { color: var(--danger); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
.form-row-check label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.help { color: var(--muted); font-size: .82rem; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 8px 12px; border-radius: 8px; margin: 0 0 12px; font-size: .9rem; }
.warning-text { background: var(--warning-soft); color: var(--warning); padding: 8px 12px; border-radius: 8px; font-size: .9rem; }
.checkbox-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.checkbox { display: flex; gap: 8px; align-items: flex-start; font-weight: 400 !important; font-size: .9rem; }
.checkbox input { margin-top: 3px; }

.dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 22px 24px; width: min(480px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  max-height: calc(100vh - 40px); overflow-y: auto;
}
.dialog-wide { width: min(680px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 20, 30, .45); }
.dialog h2 { margin-bottom: 14px; font-size: 1.15rem; }
.dialog-intro { color: var(--muted); margin: -6px 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.copy-field { display: flex; gap: 8px; }
.copy-input { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .88rem; }

/* ---------- Anmeldung und Auswahl ---------- */
.center-page { min-height: calc(100vh - 60px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 0; }
.narrow { width: min(420px, 100%); }
.auth-card h1 { font-size: 1.25rem; margin: 18px 0 16px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-name { font-weight: 750; font-size: 1.25rem; color: var(--text); }
.auth-links { text-align: center; margin: 14px 0 0; font-size: .9rem; }
.plain-list { list-style: none; padding: 0; margin: 8px 0; }
.plain-list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }

/* ---------- Übersicht ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-tile {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.stat-value { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .9rem; }
.steps { margin: 0; padding-left: 22px; }
.steps li { margin: 6px 0; }
.steps li.done { color: var(--muted); text-decoration: line-through; }

/* ---------- Standortbaum ---------- */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 22px; border-left: 2px solid var(--border); margin-left: 10px; }
.tree-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.tree-row:hover { background: var(--surface-2); }
.tree-name { font-weight: 550; flex: 1; }
.tree-type { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-strong); }
.tree-actions { display: flex; gap: 2px; opacity: .85; }

/* ---------- Meldungen ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--brand); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: 380px; transition: opacity .35s, transform .35s;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast.leaving { opacity: 0; transform: translateY(6px); }

/* ---------- Handy ---------- */
@media (max-width: 760px) {
  #app-header { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  #context-nav { order: 3; flex-basis: 100%; }
  .header-right { margin-left: auto; }
  #context-switch { max-width: 150px; }
  #context-bar { padding: 7px 14px; }
  main { padding: 18px 14px 56px; }
  .grid-2 { grid-template-columns: 1fr; }
  .checkbox-list { grid-template-columns: 1fr; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  td { border: 0; padding: 4px 4px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; text-align: left; }
  td.actions::before { content: none; }
  td.num { text-align: right; }
  .tree-row { flex-wrap: wrap; }
  #toasts { left: 14px; right: 14px; }
}

/* ---------- Maschinen, Geräte, Filter ---------- */
.type-machine { background: var(--info-soft); color: var(--info); }
.tree-machine .tree-name { text-align: left; }
.link-button { background: none; border: 0; padding: 0; font: inherit; font-weight: 550; color: inherit; cursor: pointer; }
.link-button:hover { color: var(--accent-strong); text-decoration: underline; }
.tree-meta { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  font: inherit; font-size: .85rem; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.form-heading { font-size: .95rem; margin: 18px 0 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.unit { color: var(--muted); font-weight: 400; }
.field-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.field-row { display: grid; grid-template-columns: 2fr 1.1fr 1fr 2fr auto; gap: 6px; align-items: center; }
.field-row input, .field-row select { font: inherit; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); min-width: 0; }
.field-row [hidden] { display: block !important; visibility: hidden; }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
@media (max-width: 760px) {
  .field-row { grid-template-columns: 1fr 1fr; }
  .tree-meta { white-space: normal; }
}
@media (max-width: 760px) {
  .tree-actions { flex-wrap: wrap; width: 100%; }
  .tree ul { padding-left: 10px; margin-left: 6px; }
  .tree-actions .btn { padding: 6px 8px; }
}
.script-box { width: 100%; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .78rem; padding: 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-2); color: var(--text); }
