:root {
  --bg: #0b1118;
  --panel: #111923;
  --border: #243041;
  --text: #d7e2ef;
  --muted: #8ea0b5;
  --accent: #00a651;
  --accent-soft: rgba(0, 166, 81, 0.15);
  --danger: #ff6b6b;
  --mono: "Consolas", "Cascadia Mono", "SFMono-Regular", "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: radial-gradient(circle at top, #152131 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--mono);
}

body {
  display: flex;
  flex-direction: column;
}

.app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-width: 1920px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  gap: 12px;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px) 340px;
  gap: 12px;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(17, 25, 35, 0.92);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  border: 1px solid var(--border);
  background: #182433;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-green {
  border-color: #00a651;
  background: rgba(0, 166, 81, 0.18);
  color: #b8f0d0;
}

.btn-green:hover:not(:disabled) {
  border-color: #00c060;
  background: rgba(0, 166, 81, 0.32);
}

.btn-clear-fault {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
}

.btn-clear-fault:hover:not(:disabled) {
  border-color: #60a5fa;
  background: rgba(59, 130, 246, 0.32);
}

.btn-clear-setup {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
}

.btn-clear-setup:hover:not(:disabled) {
  border-color: #60a5fa;
  background: rgba(59, 130, 246, 0.32);
}

.btn-fault {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
}

.btn-fault:hover:not(:disabled) {
  border-color: #f87171;
  background: rgba(239, 68, 68, 0.32);
}

.terminal {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(8, 12, 18, 0.96);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
  overflow: hidden;
  cursor: text;
}

.terminal.cli-locked {
  border-color: rgba(0, 166, 81, 0.55);
  box-shadow:
    inset 0 0 0 1px rgba(0, 166, 81, 0.2),
    0 0 0 2px rgba(0, 166, 81, 0.12);
}

.output {
  flex: 1;
  overflow: auto;
  padding: 18px 20px 8px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  font-size: 14px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: rgba(12, 18, 26, 0.98);
}

.prompt {
  color: var(--accent);
  white-space: nowrap;
  user-select: none;
}

.command-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  caret-color: var(--accent);
}

.command-input:disabled {
  opacity: 0.5;
}

.cli-focus-hint {
  flex-shrink: 0;
  font-size: 11px;
  color: #86efac;
  white-space: nowrap;
  user-select: none;
}

.cli-focus-hint.hidden {
  display: none;
}

.resume-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 12, 0.72);
  padding: 20px;
}

.resume-dialog.hidden {
  display: none;
}

.resume-card {
  width: min(520px, 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.resume-card h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.resume-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  margin: 0 0 18px;
  color: var(--muted);
}

.resume-meta dt {
  font-weight: 600;
  color: var(--text);
}

.resume-actions {
  display: grid;
  gap: 8px;
}

.resume-actions button:first-child {
  border-color: var(--accent);
}

.status-line {
  color: var(--muted);
}

.error-line {
  color: var(--danger);
}

.diagram-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(17, 25, 35, 0.92);
  overflow: hidden;
}

.diagram-panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.diagram-panel-header h2 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--accent);
}

.diagram-panel-header p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.diagram-scroll {
  flex: 1;
  overflow: auto;
  padding: 8px;
  min-height: 0;
  width: 100%;
  border: none;
  background: transparent;
  cursor: zoom-in;
  text-align: left;
}

.diagram-scroll:hover .diagram-svg {
  outline: 2px solid rgba(0, 166, 81, 0.45);
  outline-offset: 2px;
}

.diagram-scroll:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.diagram-svg {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  pointer-events: none;
}

.diagram-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 12, 0.88);
  padding: 20px;
  z-index: 110;
}

.diagram-modal.hidden {
  display: none;
}

.diagram-modal-card {
  width: min(1280px, 100%);
  max-height: min(96vh, 980px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.diagram-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 18, 26, 0.98);
}

.diagram-modal-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
  color: var(--accent);
}

.diagram-modal-subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.diagram-modal-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.diagram-modal-body {
  overflow: auto;
  padding: 20px 24px 24px;
  display: flex;
  justify-content: center;
}

.diagram-modal-svg {
  width: min(1100px, 100%);
  min-width: 680px;
  height: auto;
  display: block;
}

.lab-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(17, 25, 35, 0.92);
  overflow: hidden;
}

.lab-sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.lab-sidebar-header h2 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--accent);
}

.lab-sidebar-header p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.lab-list {
  overflow: auto;
  padding: 10px;
  display: grid;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.lab-card {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 10px 12px;
  border-color: rgba(0, 166, 81, 0.25);
}

.lab-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.lab-card strong {
  color: #b8f0d0;
  font-size: 12px;
}

.lab-card span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.lab-detail {
  border-top: 1px solid var(--border);
  padding: 12px 16px 16px;
  background: rgba(8, 12, 18, 0.6);
}

.lab-detail.hidden {
  display: none;
}

.lab-detail h3 {
  margin: 0 0 8px;
  font-size: 13px;
}

.lab-detail-summary {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.lab-detail-objectives {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: 11px;
  color: var(--text);
  line-height: 1.45;
}

.lab-detail-objectives li {
  margin-bottom: 4px;
}

.btn-run-lab {
  width: 100%;
  border-color: var(--accent);
  background: rgba(0, 166, 81, 0.22);
  color: #b8f0d0;
}

.btn-run-lab:hover:not(:disabled) {
  background: rgba(0, 166, 81, 0.36);
}

.btn-lab-help {
  width: 100%;
  margin-top: 8px;
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
}

.btn-lab-help:hover:not(:disabled) {
  border-color: #60a5fa;
  background: rgba(59, 130, 246, 0.32);
}

.lab-help {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 8px;
  background: rgba(8, 14, 24, 0.85);
}

.lab-help.hidden {
  display: none;
}

.lab-help-step-label {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #93c5fd;
}

.lab-help-objective {
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
}

.lab-help-commands {
  margin: 0 0 10px;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.lab-help-commands li {
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border);
  font-size: 11px;
  color: #dbeafe;
  word-break: break-word;
  cursor: pointer;
}

.lab-help-commands li:hover {
  border-color: #60a5fa;
}

.lab-help-nav {
  display: flex;
  gap: 8px;
}

.lab-help-nav button {
  flex: 1;
  font-size: 11px;
  padding: 6px 8px;
}

.fault-panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 12, 0.8);
  padding: 16px;
  z-index: 100;
}

.fault-panel.hidden {
  display: none;
}

.setup-panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 12, 0.8);
  padding: 16px;
  z-index: 100;
}

.setup-panel.hidden {
  display: none;
}

.setup-card {
  width: min(720px, 100%);
  max-height: min(90vh, 760px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.setup-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 18, 26, 0.98);
}

.setup-header h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: #00a651;
}

.setup-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.setup-close {
  flex-shrink: 0;
}

.profile-list {
  overflow: auto;
  padding: 16px 20px 20px;
  display: grid;
  gap: 10px;
}

.profile-btn {
  display: grid;
  gap: 6px;
  text-align: left;
  padding: 12px 14px;
  border-color: rgba(0, 166, 81, 0.35);
}

.profile-btn strong {
  color: #b8f0d0;
  font-size: 13px;
}

.profile-btn span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.profile-btn em {
  color: #86efac;
  font-style: normal;
  font-size: 11px;
}

.fault-card {
  width: min(920px, 100%);
  max-height: min(90vh, 860px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.fault-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 18, 26, 0.98);
}

.fault-header h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: #e07030;
}

.fault-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.fault-close {
  flex-shrink: 0;
}

.fault-body {
  overflow: auto;
  padding: 16px 20px 20px;
  display: grid;
  gap: 18px;
}

.fault-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.scenario-list {
  display: grid;
  gap: 8px;
}

.scenario-btn {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 10px 12px;
}

.scenario-btn strong {
  color: #e07030;
  font-size: 13px;
}

.scenario-btn span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.fault-console {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.fault-output {
  min-height: 140px;
  max-height: 220px;
  overflow: auto;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(8, 12, 18, 0.96);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.45;
}

.fault-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fault-input-row .prompt {
  color: #e07030;
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 340px;
  }

  .diagram-panel {
    display: none;
  }
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .diagram-panel {
    display: flex;
    max-height: 260px;
  }

  .lab-sidebar {
    max-height: 280px;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 8px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1;
  }
}
