/*
 * Netzplan-Labor — styles for the interactive network-planning (CPM / DIN 69900) trainer.
 * Uses only design tokens from theme.css so light/dark mode stay consistent; no hard-coded colors.
 */

#netzplan-lab {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 100%;
}

#netzplan-lab * {
  box-sizing: border-box;
}

#netzplan-lab button {
  font-family: var(--font-sans);
  cursor: pointer;
}

/* ---- Grundlagen ------------------------------------------------------------------------- */

.npl-grundlagen {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 4px 20px;
}

.npl-grundlagen > summary {
  cursor: pointer;
  padding: 14px 0;
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.npl-grundlagen > summary::-webkit-details-marker {
  display: none;
}

.npl-grundlagen > summary::before {
  content: '▸';
  color: var(--text-3);
  transition: transform 0.15s ease;
}

.npl-grundlagen[open] > summary::before {
  transform: rotate(90deg);
}

.npl-grundlagen-body {
  padding-bottom: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.npl-grundlagen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  margin-bottom: 20px;
}

.npl-grundlagen-col h4 {
  font-size: 0.92rem;
  margin-bottom: 8px;
  color: var(--text);
}

.npl-grundlagen-col p {
  font-size: 0.88rem;
  color: var(--text-2);
  margin-bottom: 10px;
}

.npl-legend-list {
  list-style: none;
  font-size: 0.85rem;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
}

.npl-legend-list strong {
  color: var(--text);
  font-family: var(--font-mono);
}

/* Static example node (Grundlagen) */

.npl-example-node {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 8px 0 14px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.npl-example-row.npl-example-outer {
  display: flex;
  justify-content: space-between;
  width: 168px;
  color: var(--text-3);
  padding: 0 4px;
}

.npl-example-box {
  width: 168px;
}

/* Shared DIN node box look (also used inside SVG foreignObjects) */

.npl-node-box {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text);
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.npl-node-name-row {
  padding: 4px 6px;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 0 auto;
}

.npl-node-sub-row {
  padding: 3px 6px;
  text-align: center;
  color: var(--text-2);
  font-size: 0.72rem;
}

.npl-node-value-row {
  display: flex;
  flex: 1;
  min-height: 0;
}

.npl-node-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 3px 2px;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.npl-node-cell:last-child {
  border-right: none;
}

.npl-cell-label {
  font-size: 10px;
  color: var(--text-3);
  font-weight: 600;
  line-height: 1;
}

.npl-cell-value {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

/* Step 1 structure-only node (activity id, duration, wrapped description) */

.npl-node-box.npl-node-struct {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 3px;
  padding: 6px 10px;
}

.npl-struct-letter {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.npl-struct-dauer {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1;
}

.npl-struct-desc {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.npl-node-box.npl-node-critical {
  border-color: var(--red);
}

.npl-node-box.npl-node-critical .npl-node-name-row {
  background: var(--red-soft);
  color: var(--red-text);
}

.npl-node-box.npl-node-marked {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.npl-node-box.npl-node-highlight {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px var(--amber-soft);
}

/* ---- Live demo -------------------------------------------------------------------------- */

.npl-demo {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.npl-demo h4 {
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.npl-demo-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 20px;
  margin-bottom: 16px;
}

.npl-demo-slider-row {
  display: grid;
  grid-template-columns: 100px 1fr 28px;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-2);
}

.npl-demo-slider-row input[type='range'] {
  accent-color: var(--accent);
  width: 100%;
}

.npl-demo-value {
  font-family: var(--font-mono);
  text-align: right;
  color: var(--text);
}

.npl-demo-svg-wrap {
  overflow-x: auto;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 8px;
}

.npl-demo-svg {
  display: block;
}

.npl-node-box-mini .npl-node-name-row {
  font-size: 11px;
  padding: 2px 4px;
}

.npl-node-box-mini .npl-node-cell {
  font-size: 11px;
  padding: 2px;
}

.npl-outer-row-mini {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-2);
  padding: 0 3px;
  box-sizing: border-box;
}

.npl-demo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.npl-demo-table th,
.npl-demo-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-family: var(--font-mono);
}

.npl-demo-table th {
  color: var(--text-3);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.74rem;
}

.npl-demo-critical td {
  color: var(--red-text);
}

.npl-badge-critical {
  display: inline-block;
  background: var(--red-soft);
  color: var(--red-text);
  border-radius: var(--radius-full);
  padding: 1px 7px;
  font-size: 0.68rem;
  font-family: var(--font-sans);
}

.npl-demo-end {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-2);
}

/* ---- Task picker -------------------------------------------------------------------------- */

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

.npl-task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.12s ease;
}

.npl-task-card:hover {
  border-color: var(--border-strong);
}

.npl-task-card.npl-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.npl-task-card-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text);
}

.npl-task-card-status {
  font-size: 0.76rem;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 4px;
}

.npl-task-card.npl-solved .npl-task-card-status {
  color: var(--green-text);
}

/* ---- Task panel --------------------------------------------------------------------------- */

.npl-task-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.npl-situation h3 {
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.npl-situation p {
  color: var(--text-2);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.npl-activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.npl-activity-table th,
.npl-activity-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.npl-activity-table th {
  color: var(--text-3);
  font-weight: 600;
  font-size: 0.74rem;
  text-transform: none;
}

.npl-activity-table td:first-child {
  font-family: var(--font-mono);
  font-weight: 600;
}

.npl-aufgabenstellung-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  margin-top: 14px;
  margin-bottom: 4px;
}

.npl-aufgabenstellung-list {
  margin: 0 0 4px 20px;
  font-size: 0.88rem;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---- Stepper ------------------------------------------------------------------------------ */

.npl-stepper {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.npl-step-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--text-2);
}

.npl-step-btn.npl-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-text);
}

.npl-step-btn.npl-done {
  color: var(--green-text);
}

.npl-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-3);
  font-size: 0.7rem;
  font-weight: 600;
}

/* ---- Explanation mode ---------------------------------------------------------------------- */

.npl-explain-bar {
  display: flex;
}

.npl-explain-panel {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.npl-explain-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.npl-explain-progress {
  font-size: 0.78rem;
  color: var(--text-2);
  font-family: var(--font-mono);
}

.npl-explain-panel h4 {
  font-size: 0.92rem;
  margin-bottom: 6px;
  color: var(--accent-text);
}

.npl-explain-panel p {
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.55;
}

/* ---- Step content --------------------------------------------------------------------------- */

.npl-step-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.npl-hint {
  font-size: 0.85rem;
  color: var(--text-2);
}

.npl-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.npl-chip {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.86rem;
  touch-action: none;
}

.npl-canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ---- Buttons -------------------------------------------------------------------------------- */

.npl-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.84rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.npl-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.npl-btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.npl-btn-primary:hover {
  background: var(--accent-hover);
}

.npl-btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.npl-btn-secondary:hover {
  border-color: var(--border-strong);
}

.npl-btn-danger {
  background: var(--surface);
  border-color: var(--red);
  color: var(--red-text);
}

.npl-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---- Canvas / SVG --------------------------------------------------------------------------- */

.npl-canvas-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

svg.npl-canvas {
  /* Rendered at 1:1 CSS pixels via explicit width/height attributes (see svgAttrsFor in
     netzplan-lab.js) — never stretched or shrunk to the container width. The wrapping
     .npl-canvas-wrap scrolls horizontally instead when the plan is wider than the column. */
  display: block;
  touch-action: none;
}

svg.npl-canvas:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.npl-node-handle {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2;
  cursor: crosshair;
}

.npl-edge {
  fill: none;
  stroke: var(--text-3);
  stroke-width: 1.75;
  cursor: pointer;
}

.npl-edge:hover {
  stroke: var(--text-2);
}

.npl-edge-selected {
  stroke: var(--accent);
  stroke-width: 2.25;
}

.npl-edge-critical {
  stroke: var(--red);
  stroke-width: 2.5;
}

.npl-arrowhead {
  fill: var(--text-3);
}

.npl-arrowhead-critical {
  fill: var(--red);
}

.npl-outer-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  height: 100%;
  padding: 1px 4px;
  box-sizing: border-box;
}

.npl-outer-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.npl-outer-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  line-height: 1;
  white-space: nowrap;
}

/* ---- Value fields --------------------------------------------------------------------------- */
/* Scoped under #netzplan-lab so these win over the site-wide .tab-content input[type="number"]
   rule in style.css (same-ish specificity otherwise, and we must not edit that file). */

#netzplan-lab input.npl-field-input {
  width: 44px;
  height: 30px;
  padding: 2px 4px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1;
  text-align: center;
  box-shadow: none;
}

#netzplan-lab input.npl-field-input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.npl-field-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 30px;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: help;
  font-weight: 600;
  font-size: 14px;
  box-sizing: border-box;
}

.npl-field-value.npl-field-prefilled {
  background: var(--blue-soft);
  color: var(--blue-text);
}

.npl-field-value.npl-field-solution {
  background: var(--green-soft);
  color: var(--green-text);
}

.npl-field-input.npl-field-correct {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-text);
}

.npl-field-input.npl-field-wrong {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red-text);
}

.npl-field-input.npl-field-followerror {
  border-style: dashed;
  border-color: var(--amber);
  background: var(--amber-soft);
  color: var(--amber-text);
}

/* ---- Feedback ------------------------------------------------------------------------------- */

.npl-feedback {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
}

.npl-feedback-ok {
  background: var(--green-soft);
  border-color: var(--green);
  color: var(--green-text);
}

.npl-feedback-error {
  background: var(--red-soft);
  border-color: var(--red);
  color: var(--red-text);
}

.npl-feedback p {
  margin-bottom: 4px;
}

.npl-feedback ul {
  margin: 4px 0 0 18px;
}

.npl-diagnosis-list {
  color: var(--text-2);
}

.npl-score-badge {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-2);
  background: var(--surface-3);
  border-radius: var(--radius-full);
  padding: 4px 12px;
}

/* ---- Step 4: questions ---------------------------------------------------------------------- */

.npl-question {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.npl-question-text {
  font-size: 0.92rem;
  color: var(--text);
}

.npl-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.npl-option {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.84rem;
  color: var(--text);
}

.npl-option:hover {
  border-color: var(--border-strong);
}

.npl-option-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.npl-option-correct {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-text);
}

.npl-option-wrong {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red-text);
}

.npl-reasoning-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-3);
}

.npl-reasoning {
  font-family: var(--font-sans);
  font-size: 0.84rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-height: 56px;
  resize: vertical;
}

.npl-reasoning:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ---- Task actions ----------------------------------------------------------------------------- */

.npl-task-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

/* ---- Popover -------------------------------------------------------------------------------- */

.npl-popover {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 14px 16px;
  z-index: 40;
  font-size: 0.84rem;
}

.npl-popover-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.npl-popover p {
  color: var(--text-2);
  margin-bottom: 10px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* ---- Responsive --------------------------------------------------------------------------- */

@media (max-width: 640px) {
  .npl-task-panel {
    padding: 14px;
  }

  .npl-grundlagen {
    padding: 4px 14px;
  }

  .npl-popover {
    left: 16px;
    right: 16px;
    max-width: none;
  }
}
