:root {
  color-scheme: dark;
  --bg: #0d1422;
  --panel: #151f31;
  --panel-2: #1c293d;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #334155;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --accent: #38bdf8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, .08), transparent 34rem),
    var(--bg);
  color: var(--text);
}

header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 22px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, .92);
  backdrop-filter: blur(12px);
}

h1, h2, p { margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 17px; margin-bottom: 14px; }
header p { color: var(--muted); margin-top: 4px; }
.muted { color: var(--muted); line-height: 1.45; }

.header-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  max-width: min(720px, 56vw);
}

.header-system {
  position: relative;
  min-width: 150px;
  border-color: rgba(148, 163, 184, .28);
  background: rgba(15, 23, 42, .72);
}

.header-system summary {
  padding: 9px 12px;
}

.header-system[open] {
  position: absolute;
  top: 74px;
  right: 22px;
  z-index: 20;
  width: min(820px, calc(100vw - 44px));
  box-shadow: 0 24px 70px rgba(0, 0, 0, .42);
}

main {
  padding: 22px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  min-width: 0;
  box-shadow: 0 14px 38px rgba(0, 0, 0, .16);
}

.hero-panel,
.diagnostics-panel {
  grid-column: 1 / -1;
}

.hero-panel {
  border-color: rgba(56, 189, 248, .32);
  background: linear-gradient(180deg, rgba(21, 31, 49, .98), rgba(18, 27, 42, .98));
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin-bottom: 5px;
}

.compact-actions {
  justify-content: flex-end;
  margin-top: 0;
  max-width: 640px;
}

.workstation-tools {
  display: grid;
  grid-template-columns: minmax(0, .95fr) minmax(320px, 1.05fr);
  gap: 16px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(148, 163, 184, .18);
}

.workstation-tools h2 {
  margin-bottom: 10px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.status {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.status b { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.ok { color: var(--good); }
.fail { color: var(--bad); }
.warn-text { color: var(--warn); }

button, input, select {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
}
button {
  background: #2563eb;
  color: white;
  padding: 9px 12px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease, border-color .12s ease, opacity .12s ease;
}
button.secondary { background: #334155; }
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
#recordStop.recording-pulse,
#recordStart.recording-pulse {
  position: relative;
  background: #dc2626;
  border-color: rgba(248, 113, 113, .9);
  box-shadow: 0 0 0 0 rgba(248, 113, 113, .75);
  animation: recordingPulse 1.15s ease-in-out infinite;
  font-weight: 800;
}
#recordStart.recording-ready {
  background: #15803d;
  border-color: rgba(74, 222, 128, .65);
}
.voiceki-playing {
  position: relative;
  z-index: 0;
  background: #0ea5e9 !important;
  border-color: rgba(125, 211, 252, .95) !important;
  box-shadow: 0 0 0 0 rgba(56, 189, 248, .8);
  animation: voicekiPulse 1s ease-in-out infinite;
  font-weight: 800;
}
@keyframes recordingPulse {
  0% { box-shadow: 0 0 0 0 rgba(248, 113, 113, .65); }
  70% { box-shadow: 0 0 0 9px rgba(248, 113, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}
@keyframes voicekiPulse {
  0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, .75); }
  70% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
  100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}
#startCrmRun {
  background: #16a34a;
  font-weight: 700;
}
#startCrmRun:disabled {
  background: #2563eb;
}
.danger-soft {
  background: #7f1d1d;
  border-color: rgba(248, 113, 113, .65);
  font-weight: 800;
  letter-spacing: .08em;
}
input, select {
  width: 100%;
  padding: 9px 10px;
  background: #0f172a;
  color: var(--text);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
label { color: var(--muted); }
.stack-label {
  display: block;
  margin: 12px 0 7px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 6px 0 12px;
  color: var(--text);
}
.check-row input {
  width: auto;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  max-height: 260px;
  overflow: auto;
}

textarea {
  width: 100%;
  min-height: 130px;
  margin-top: 12px;
  padding: 11px 12px;
  resize: vertical;
  color: var(--text);
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  line-height: 1.45;
}

.workstation {
  border-color: rgba(56, 189, 248, .4);
}

.sound-buttons,
.disposition-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.compact-dispositions {
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
}

.checklist {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 4px 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 23, 42, .55);
}

.sound-buttons button,
.disposition-buttons button {
  text-align: left;
  background: #1f3a5f;
}

.sound-buttons button b {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-width: 22px;
  height: 22px;
  margin-right: 6px;
  color: #0f172a;
  background: #bae6fd;
  border-radius: 999px;
}

.warning {
  padding: 10px;
  border: 1px solid rgba(245, 158, 11, .5);
  background: rgba(245, 158, 11, .12);
  color: #fbbf24;
  border-radius: 10px;
  margin-bottom: 12px;
}

.preview-card {
  margin: 10px 0 13px;
  padding: 11px 12px;
  border: 1px solid rgba(56, 189, 248, .35);
  background: rgba(56, 189, 248, .09);
  border-radius: 10px;
  line-height: 1.45;
}
.preview-card b {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}
.test-contact {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  margin: 10px 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, .28);
  background: rgba(15, 23, 42, .28);
  border-radius: 10px;
}
.test-contact b {
  color: #e2e8f0;
}
.test-contact span {
  color: var(--muted);
}
.hidden { display: none; }

.inline-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, .24);
  border-radius: 12px;
  background: rgba(15, 23, 42, .35);
}

.loading {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid rgba(56, 189, 248, .45);
  background: rgba(14, 165, 233, .1);
  border-radius: 10px;
}
.loading b,
.loading small {
  display: block;
}
.loading small {
  color: var(--muted);
  margin-top: 4px;
}
.bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #0b1220;
  border: 1px solid var(--border);
  margin-bottom: 10px;
}
.bar span {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #38bdf8, #22c55e);
  animation: loading-slide 1.1s ease-in-out infinite;
}

@keyframes loading-slide {
  0% { transform: translateX(-105%); }
  100% { transform: translateX(275%); }
}

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
th, td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 9px;
  vertical-align: top;
}
th { color: var(--muted); font-weight: 700; }

.sync-box {
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px solid rgba(148, 163, 184, .22);
}

details {
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 12px;
  background: rgba(15, 23, 42, .28);
}

summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  color: var(--text);
  font-weight: 800;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "aufklappen";
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

details[open] summary {
  border-bottom: 1px solid rgba(148, 163, 184, .18);
}

details[open] summary::after {
  content: "zuklappen";
}

details > :not(summary) {
  margin-left: 16px;
  margin-right: 16px;
}

details > :last-child {
  margin-bottom: 16px;
}

@media (max-width: 900px) {
  header, main { padding: 16px; }
  header { flex-direction: column; }
  .header-tools {
    justify-content: flex-start;
    max-width: none;
    width: 100%;
  }
  .header-system[open] {
    position: static;
    width: 100%;
  }
  main { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .panel-head {
    flex-direction: column;
  }
  .compact-actions {
    justify-content: flex-start;
    max-width: none;
  }
  .workstation-tools {
    grid-template-columns: 1fr;
  }
}
