:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d7dde4;
  --text: #17202a;
  --muted: #667085;
  --accent: #0f766e;
  --accent-dark: #0b5d58;
  --danger: #b42318;
  --warning: #b54708;
  --ok: #027a48;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.primary:hover { background: var(--accent-dark); }
.secondary { background: #f8fafc; }

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem 1.5rem;
  background: #0f172a;
  color: #fff;
}

.topbar h1 { margin: 0; font-size: 1.35rem; }
.topbar p { margin: 0.25rem 0 0; color: #cbd5e1; }

.tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tab {
  color: #e2e8f0;
  border-color: rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
}

.tab.active {
  background: #fff;
  color: #0f172a;
}

main { padding: 1rem; }

.view { display: none; gap: 1rem; }
.view.active { display: grid; grid-template-columns: 320px minmax(0, 1fr); }
.single-column.active { display: block; max-width: 1100px; margin: 0 auto; }

.sidebar { display: flex; flex-direction: column; gap: 1rem; }
.content-grid { display: grid; grid-template-rows: minmax(360px, 55vh) minmax(260px, auto); gap: 1rem; min-width: 0; }
.montage-grid { grid-template-rows: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1rem;
  min-width: 0;
}

.panel h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }
.panel-head h2 { margin: 0; }
.panel-head.compact { margin-bottom: 0.5rem; }
.muted { color: var(--muted); margin: 0.15rem 0 0; }

select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #fff;
}

.form-stack { display: grid; gap: 0.75rem; }
.form-stack label { display: grid; gap: 0.35rem; color: #344054; }

.tree { display: grid; gap: 0.4rem; }
.tree button {
  width: 100%;
  text-align: left;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}
.tree button.active { border-color: var(--accent); background: #ecfdf3; }
.tree .child { padding-left: 1.2rem; }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
  background: #eef2f6;
  color: #344054;
  font-size: 0.78rem;
  white-space: nowrap;
}

.drawing-panel { overflow: hidden; }
.drawing-stage {
  position: relative;
  height: calc(100% - 3.5rem);
  min-height: 320px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  overflow: auto;
  background: #fff;
}

.drawing-wrap {
  position: relative;
  width: min(100%, 1100px);
  margin: 0 auto;
}

.drawing-wrap img {
  display: block;
  width: 100%;
  height: auto;
}

.hotspot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 2px solid #111827;
  background: rgba(255, 255, 255, 0.88);
  color: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0,0,0,0.16);
}
.hotspot:hover, .hotspot.active { background: #fef3c7; border-color: #b45309; }

.empty-state { color: var(--muted); padding: 2rem; text-align: center; }

.table-wrap { overflow: auto; max-height: 52vh; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { border-bottom: 1px solid var(--line); padding: 0.6rem 0.65rem; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #f8fafc; z-index: 1; }
tr.active { background: #fef3c7; }
.part-number { font-weight: 700; white-space: nowrap; }
.availability { font-size: 0.85rem; color: var(--muted); }
.availability.available { color: var(--ok); }
.availability.low { color: var(--warning); }
.availability.not_available { color: var(--danger); }

.machine-list { display: grid; gap: 0.5rem; max-height: 40vh; overflow: auto; }
.machine-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  background: #fff;
  cursor: pointer;
}
.machine-card:hover, .machine-card.active { border-color: var(--accent); background: #ecfdf3; }
.machine-card strong { display: block; }
.machine-card span { color: var(--muted); font-size: 0.9rem; }

.checklist { display: grid; gap: 1rem; }
.job {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.job-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: #f8fafc;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
}
.job-head h3 { margin: 0; font-size: 1rem; }
.job-items { display: grid; }
.check-item {
  display: grid;
  grid-template-columns: 80px minmax(170px, 1fr) 120px 170px minmax(160px, 1fr);
  gap: 0.6rem;
  align-items: center;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
}
.check-item:last-child { border-bottom: 0; }
.check-item.status-installed, .check-item.status-checked { background: #ecfdf3; }
.check-item.status-missing, .check-item.status-problem { background: #fef3f2; }
.check-item.status-changed { background: #fffaeb; }
.check-item small { color: var(--muted); display: block; margin-top: 0.2rem; }
.status-select { min-width: 150px; }
.qty-input { max-width: 110px; }
.comment-input { min-width: 150px; }

.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.75rem; }
.search-results { display: grid; gap: 0.75rem; margin-top: 1rem; }
.result-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem;
}
.result-card h3 { margin: 0 0 0.25rem; }
.result-card p { margin: 0.2rem 0; }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.9rem 1.5rem;
  color: var(--muted);
}
.footer label { display: flex; align-items: center; gap: 0.5rem; }
.footer input { width: 220px; }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  min-width: 240px;
  max-width: min(420px, calc(100vw - 2rem));
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(0.5rem);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1050px) {
  .view.active { grid-template-columns: 1fr; }
  .content-grid { grid-template-rows: auto auto; }
  .drawing-stage { height: 420px; }
  .check-item { grid-template-columns: 1fr; }
  .topbar { align-items: start; flex-direction: column; }
}

/* Admin-Erweiterung */
.admin-view.active { display: grid; grid-template-columns: 320px minmax(0, 1fr); }
.admin-content { display: grid; gap: 1rem; min-width: 0; }
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.admin-nav { display: grid; gap: 0.5rem; }
.admin-nav-btn { text-align: left; }
.admin-nav-btn.active { background: #0f766e; color: #fff; border-color: #0f766e; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(260px, 1fr)); gap: 1rem; }
.admin-card, .upload-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  background: #fff;
}
.admin-card h3 { margin: 0 0 0.5rem; }
.admin-card.wide { grid-column: 1 / -1; }
.two-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.admin-list { display: grid; gap: 0.5rem; margin-top: 1rem; }
.admin-list-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.hotspot-toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-bottom: 1rem; }
.hotspot-toolbar label { min-width: 220px; }
.hotspot-editor-stage { min-height: 520px; }
.hotspot-editor-stage .drawing-wrap { cursor: crosshair; }
.hotspot.pending { background: #f79009; border-color: #fff; }
.code-output {
  white-space: pre-wrap;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
  min-height: 80px;
  overflow: auto;
}
@media (max-width: 900px) {
  .admin-view.active { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .two-cols { grid-template-columns: 1fr; }
}
