:root {
  --bg-0: #f4f6fb;
  --bg-1: #edf2f9;
  --surface: #ffffff;
  --surface-soft: #f7f9fe;
  --ink-0: #1b2430;
  --ink-1: #637188;
  --line: #cfd7e6;
  --brand: #d33;
  --brand-strong: #a11f1f;
  --accent: #5b78ad;
  --shadow: 0 2px 10px rgba(16, 33, 68, 0.06);

  /* ERK Design tokens */
  --field-bg: #fff;
  --field-border: #b9c4d6;
  --result-bg: #fffaf2;
  --result-border: #eed8b0;
  --btn-secondary-bg: #e9eef7;
  --btn-secondary-border: #9fb1cf;
  --toast-success: #1f6d39;
  --toast-error: #d33;
  --toast-info: #5b78ad;
  --toast-warn: #9d5d0a;

  /* ERK form grid -- labels/units now auto-sized */

  /* Layout tokens */
  --topbar-height: 60px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink-0);
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  background: linear-gradient(160deg, var(--bg-1), var(--bg-0));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  max-width: 1500px;
  margin: 8px auto 8px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

#brandLogo {
  height: 40px;
  width: auto;
  display: block;
}

.brand-copy {
  display: grid;
  gap: 2px;
}

.brand-wrap h1 {
  margin: 0;
  font-size: clamp(1.3rem, 2vw, 1.8rem);
  letter-spacing: 0.02em;
}

.app-version {
  margin-left: 8px;
  font-size: 0.68em;
  font-weight: 500;
  color: #8c98ac;
  vertical-align: middle;
}

.brand-wrap p {
  margin: 0;
  color: var(--ink-1);
}

.layout-shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 0 24px;
  position: relative;
  min-height: calc(100vh - 100px);
}

.workspace {
  --sidebar-width: 320px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.3);
}

.sidebar-divider {
  display: none;
}

.main-area {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.auth-card {
  max-width: 420px;
  margin: 0 auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

h2,
h3,
h4 {
  margin: 0;
}

h2 {
  font-size: 1.12rem;
}

h3 {
  font-size: 0.98rem;
  color: var(--ink-1);
}

label {
  display: grid;
  gap: 5px;
  font-size: 0.9rem;
}

.stack {
  display: grid;
  gap: 10px;
}

.compact {
  margin-top: 8px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 10px;
}

.variation-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.inline-check {
  display: flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}

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

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink-0);
  background: #fff;
  min-height: 42px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(211, 51, 51, 0.18);
  border-color: var(--brand);
}

button {
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 14px;
  min-height: 42px;
  cursor: pointer;
  transition: transform 0.11s ease, box-shadow 0.11s ease;
}

button:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  box-shadow: 0 8px 18px rgba(211, 51, 51, 0.24);
}

.btn-archive {
  background: var(--brand);
  color: #fff;
  border: 2px solid var(--brand-strong);
  font-size: 0.92rem;
  font-weight: 400;
  padding: 8px 18px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.btn-archive:hover {
  background: var(--brand-strong);
  box-shadow: 0 4px 12px rgba(211, 51, 51, 0.3);
}

.btn-outline {
  background: #fff;
  color: var(--ink-0);
  border-color: var(--line);
}

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

.btn-accent:hover {
  box-shadow: 0 8px 18px rgba(217, 93, 56, 0.25);
}

.btn-run {
  background: var(--brand);
  color: #fff;
  width: 100%;
  font-weight: 700;
}

.btn-run:hover {
  box-shadow: 0 10px 22px rgba(211, 51, 51, 0.28);
}

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

.tree {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  min-height: 240px;
  max-height: 46vh;
  overflow: auto;
  padding: 8px;
}

.sidebar-action-frame {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.run-sidebar-panel {
  margin-top: 10px;
}

.run-filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.run-list-sidebar {
  max-height: 34vh;
}

.sidebar-action-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.action-trigger {
  padding: 7px 6px;
  font-size: 0.82rem;
}

.action-trigger.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.action-trigger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.action-panels {
  margin-top: 8px;
}

.action-panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  max-height: 34vh;
  overflow: auto;
}

.action-panel.active {
  display: block;
}

.revision-actions-grid {
  grid-template-columns: 1fr;
}

/* Tree: collapsible project/revision/loadcase structure */

.tree-fold {
  border: none;
  padding: 0;
  margin: 0;
  background: none;
}

.tree-fold > summary {
  list-style: none;
  cursor: default;
}

.tree-fold > summary::-webkit-details-marker {
  display: none;
}

.tree-fold > summary::before {
  content: "\25B6";
  font-size: 0.6em;
  margin-right: 4px;
  color: var(--ink-1);
  display: inline-block;
  transition: transform 0.15s;
}

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

.tree-node-row {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 1px 0;
}

.tree-item {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  padding: 2px 6px;
  color: var(--ink-0);
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
}

button.tree-item {
  min-height: unset;
}

.tree-item:hover {
  background: #e7eef4;
}

.tree-item.active {
  border-color: #9bc8d6;
  background: #dcf1f9;
}

.tree-item strong {
  font-weight: 600;
}

.tree-l1 { margin-left: 12px; }
.tree-l2 { margin-left: 12px; }
.tree-l3 { margin-left: 12px; font-size: 0.78rem; color: var(--ink-1); }

.tree-empty {
  margin-left: 12px;
  font-size: 0.76rem;
  color: var(--ink-1);
  padding: 2px 6px;
  font-style: italic;
}

/* Status dots (replaces W:/R: tags) */
.tree-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-left: 4px;
  vertical-align: middle;
}
.dot-ok { background: #4caf50; }
.dot-pending { background: #5b78ad; animation: pulse 1.5s infinite; }
.dot-warn { background: #df9c3f; }
.dot-none { background: var(--line); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.tree-tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  vertical-align: middle;
  margin-left: 4px;
}
.tree-tag-dummy {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffc107;
}

/* Rename button */
.tree-rename {
  opacity: 0;
  min-height: 20px;
  min-width: 20px;
  padding: 0 4px;
  font-size: 0.7rem;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 3px;
  background: none;
  color: var(--ink-1);
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.tree-node-row:hover .tree-rename,
.tree-node-row:hover .tree-delete {
  opacity: 0.5;
}

.tree-rename:hover {
  opacity: 1 !important;
  color: var(--accent);
  background: rgba(91, 120, 173, 0.08);
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  padding: 4px 9px;
  color: var(--ink-1);
  background: #fff;
  max-width: 100%;
}

.dummy-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 6px;
  font-size: 0.85rem;
}
.dummy-banner .dummy-banner-text { flex: 1; font-weight: 600; color: #856404; }

.chip.warn {
  border-color: #df9c3f;
  color: #9d5d0a;
}

.chip.ok {
  border-color: #88c39d;
  color: #1f6d39;
}

.chip.pending {
  border-color: #9fb3cf;
  color: #4f6b92;
}

.list {
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fafcfe;
  min-height: 80px;
  max-height: 300px;
  overflow: auto;
  padding: 8px;
}

.compact-list {
  min-height: 120px;
}

.list-item {
  border: 1px solid #e4ebf2;
  border-radius: 9px;
  background: #fff;
  padding: 8px;
  margin-bottom: 7px;
  cursor: pointer;
}

.list-item:last-child {
  margin-bottom: 0;
}

.list-item.active {
  border-color: #9bc8d6;
  background: #eef8fc;
}

.run-group {
  margin-bottom: 10px;
}

.run-group:last-child {
  margin-bottom: 0;
}

.run-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.run-group-title {
  font-size: 0.84rem;
  color: var(--ink-1);
  font-weight: 600;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.item-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.surface-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.component-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafcfe;
  min-height: 220px;
  padding: 10px;
  overflow: visible;
}

.surface-editor-single {
  display: grid;
  gap: 10px;
}

.component-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

@media (min-width: 1360px) {
  .component-field-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.surface-item {
  display: grid;
  gap: 4px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

@media (min-width: 1360px) {
  .kv-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.kv-item {
  border: 1px solid #e3ebf3;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.kv-key {
  font-size: 0.78rem;
  color: var(--ink-1);
  margin-bottom: 3px;
}

.kv-value {
  font-size: 0.95rem;
}

details {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  padding: 8px;
}

details summary {
  cursor: pointer;
  color: var(--ink-1);
  margin-bottom: 8px;
}

.console {
  margin: 10px 0 0;
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
  background: #0f1720;
  color: #e8eef4;
  border-radius: 10px;
  padding: 10px;
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 0.81rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.run-result-panel {
  margin-top: 8px;
}

.result-zoom-container {
  position: relative;
}

.result-zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 0.82rem;
  color: var(--ink-1);
}

.zoom-btn {
  min-height: 30px;
  min-width: 34px;
  padding: 2px 8px;
  font-size: 0.85rem;
  font-weight: 700;
}

#zoomLevel {
  min-width: 42px;
  text-align: center;
}

.result-zoom-wrapper {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-height: 460px;
  max-height: none;
  position: relative;
  resize: both;
}

.result-frame {
  width: 100%;
  height: 600px;
  border: none;
  display: block;
}

.hint {
  margin: 5px 0 0;
  color: var(--ink-1);
  font-size: 0.84rem;
}

.session-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.statusbar {
  display: none;
}

.hidden {
  display: none !important;
}

.advanced-toggle {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  padding: 7px 10px;
}

.advanced-toggle summary {
  cursor: pointer;
  color: var(--ink-1);
  font-size: 0.86rem;
}

.run-secondary-row {
  justify-content: flex-end;
  margin-bottom: 8px;
}

.run-cta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.run-cta-row .btn-run {
  flex: 1 1 220px;
  width: auto;
}

.run-cta-row .btn-outline {
  flex: 1 1 160px;
}

/* =============================================
   ERK 3-Column Form Grid (Label | Input | Unit)
   ============================================= */

.erk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 4px;
}

/* Text fields (title, fuel etc.) span full row */
.erk-row.erk-text {
  grid-column: 1 / -1;
}

.erk-row {
  display: grid;
  grid-template-columns: var(--erk-label-w, auto) minmax(60px, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  background: var(--field-bg);
  border: 1px solid #e8edf5;
  font-size: 0.85rem;
  min-width: 0;
}

.erk-row:hover {
  background: var(--surface-soft);
}

.erk-label {
  font-size: 0.82rem;
  color: var(--ink-1);
  white-space: nowrap;
}

.erk-row input {
  min-height: 28px;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  min-width: 0;
  width: 100%;
}

.erk-unit {
  font-size: 0.78rem;
  color: var(--ink-1);
  text-align: right;
  white-space: nowrap;
}

.erk-row.readonly input {
  background: var(--result-bg);
  border-color: var(--result-border);
  color: var(--ink-0);
}

.core-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: start;
}

@media (max-width: 1100px) {
  .core-layout {
    grid-template-columns: 1fr;
  }
}

.core-box {
  min-width: 0;
}

.core-right {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.fuel-section {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.fuel-header {
  font-size: 0.84rem;
  color: var(--ink-0);
  margin-bottom: 4px;
}

.fuel-comp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 6px 0;
}

.fuel-comp-table th,
.fuel-comp-table td {
  border: 1px solid var(--line);
  padding: 3px 8px;
  text-align: left;
}

.fuel-comp-table th {
  background: var(--bg-1);
  font-weight: 600;
  font-size: 0.76rem;
  color: var(--ink-1);
}

.fuel-comp-table td:first-child {
  width: 30px;
  text-align: center;
  color: var(--ink-1);
}

/* =============================================
   Toast Notification System
   ============================================= */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.88rem;
  line-height: 1.4;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast--success {
  background: var(--toast-success);
}

.toast--error {
  background: var(--toast-error);
}

.toast--info {
  background: var(--toast-info);
}

.toast--warning {
  background: var(--toast-warn);
}

/* =============================================
   Result / Read-only Field Styling
   ============================================= */

.result-value {
  background: var(--result-bg);
  border-color: var(--result-border);
}

/* =============================================
   Drag & Drop Zone
   ============================================= */

.drop-zone {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  text-align: center;
  color: var(--ink-1);
  font-size: 0.88rem;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(91, 120, 173, 0.06);
}

.drop-zone.drag-over {
  border-style: solid;
}

.drop-zone-icon {
  display: block;
  font-size: 1.6rem;
  margin-bottom: 6px;
  opacity: 0.5;
}

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  min-height: unset;
  width: 100%;
  height: 100%;
}

/* =============================================
   Mobile Hamburger Sidebar Toggle
   ============================================= */

.hamburger-btn {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--ink-0);
  cursor: pointer;
  min-height: 38px;
}

.hamburger-btn:hover {
  background: var(--bg-1);
}

/* =============================================
   Progress Bar for Runs
   ============================================= */

.progress-bar {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* =============================================
   Delete Buttons (tree + runs)
   ============================================= */

.tree-delete {
  opacity: 0;
  min-height: 22px;
  min-width: 22px;
  padding: 0 5px;
  font-size: 0.72rem;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  color: var(--ink-1);
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.tree-node-row:hover .tree-delete {
  opacity: 0.6;
}

.tree-delete:hover {
  opacity: 1 !important;
  color: var(--brand);
  background: rgba(211, 51, 51, 0.08);
  border-color: rgba(211, 51, 51, 0.2);
}

.btn-delete-run {
  padding: 2px 6px;
  font-size: 0.72rem;
  min-height: 24px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  color: var(--ink-1);
  cursor: pointer;
}

.btn-delete-run:hover {
  color: var(--brand);
  background: rgba(211, 51, 51, 0.08);
  border-color: rgba(211, 51, 51, 0.2);
}

/* =============================================
   Diff View
   ============================================= */

.run-diff-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.diff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-bottom: 8px;
}

.diff-table th,
.diff-table td {
  border: 1px solid var(--line);
  padding: 4px 8px;
  text-align: left;
}

.diff-table th {
  background: var(--bg-1);
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--ink-1);
}

.diff-table td.diff-del {
  color: #9d3030;
  background: #fef2f2;
  text-decoration: line-through;
}

.diff-table td.diff-add {
  color: #1f6d39;
  background: #edf7f0;
  font-weight: 600;
}

/* =============================================
   Modal Dialog
   ============================================= */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.4);
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  padding: 20px 24px;
  min-width: 340px;
  max-width: min(480px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
}

.modal-box h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.modal-box label {
  display: grid;
  gap: 4px;
  font-size: 0.84rem;
  margin-bottom: 10px;
}

.modal-box input {
  font-size: 0.88rem;
}

.modal-box .hint {
  margin: 0 0 10px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

.modal-actions button {
  min-height: 36px;
  font-size: 0.86rem;
  padding: 6px 16px;
}

/* =============================================
   Preflight Status
   ============================================= */

.preflight-status {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  line-height: 1.4;
  margin: 6px 0;
}

.preflight-status ul {
  margin: 4px 0 0 16px;
  padding: 0;
}

.preflight-status li {
  margin-bottom: 3px;
}

.preflight-loading {
  background: var(--bg-1);
  border: 1px solid var(--line);
  color: var(--ink-1);
}

.preflight-loading::before {
  content: "\23F3 ";
}

.preflight-ok {
  background: #edf7f0;
  border: 1px solid #88c39d;
  color: var(--toast-success);
}

.preflight-ok::before {
  content: "\2714 ";
}

.preflight-error {
  background: #fef2f2;
  border: 1px solid #e8a0a0;
  color: var(--toast-error);
}

.preflight-error::before {
  content: "\26A0 ";
}

/* =============================================
   Responsive: Desktop (>= 980px)
   ============================================= */

@media (min-width: 980px) {
  .workspace {
    grid-template-columns: minmax(260px, var(--sidebar-width)) 10px minmax(0, 1fr);
    gap: 0;
  }

  .sidebar {
    position: sticky;
    top: 10px;
    border-right: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  .sidebar-divider {
    display: block;
    width: 10px;
    cursor: col-resize;
    align-self: stretch;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: linear-gradient(90deg, transparent 0, #d7deeb 50%, transparent 100%);
  }

  .main-area {
    padding-left: 14px;
  }

  .details-grid {
    grid-template-columns: 1fr;
  }

  .variation-grid {
    grid-template-columns: 1fr repeat(4, minmax(0, 1fr));
  }

  .tree {
    min-height: 360px;
    max-height: min(56vh, calc(100vh - 360px));
  }

  .run-list-sidebar {
    max-height: min(40vh, calc(100vh - 420px));
  }
}

@media (max-width: 1220px) {
  .sidebar-action-buttons {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 979px) {
  .hamburger-btn {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(360px, 85vw);
    z-index: 1000;
    border-radius: 0;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    box-shadow: none;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .sidebar-divider {
    display: none;
  }

  .tree {
    max-height: 360px;
  }

  .two-col,
  .details-grid,
  .surface-grid {
    grid-template-columns: 1fr;
  }

  .erk-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }

  .erk-row {
    grid-template-columns: var(--erk-label-w, auto) minmax(50px, 1fr) auto;
  }

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

  .row > button {
    width: 100%;
  }

  .run-cta-row {
    flex-direction: column;
  }

  .run-cta-row .btn-run,
  .run-cta-row .btn-outline {
    width: 100%;
    flex: 1 1 auto;
  }
}

body.resizing-sidebar {
  cursor: col-resize;
  user-select: none;
}

@media (max-width: 760px) {
  .topbar,
  .card {
    border-radius: 0;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
    margin-top: 0;
    padding: 8px 12px;
    gap: 8px;
  }

  .topbar .brand-wrap {
    flex: 1 1 auto;
    min-width: 0;
  }

  #brandLogo {
    height: 30px;
  }

  .brand-copy p {
    display: none;
  }

  .app-version {
    display: none;
  }

  .layout-shell {
    padding-inline: 0;
  }

  .main-area .card {
    border-left: 0;
    border-right: 0;
  }

  .tree {
    max-height: 45vh;
    min-height: 200px;
  }

  .tree-line {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 8px;
    min-height: 44px;
  }

  .tree-line > span:first-child {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
  }

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

  .statusbar {
    padding: 8px 12px 14px;
  }

  .run-secondary-row .btn-outline {
    width: 100%;
  }

  .toast-container {
    bottom: 12px;
    right: 12px;
    left: 12px;
    max-width: none;
  }

  .erk-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .erk-row {
    grid-template-columns: var(--erk-label-w, auto) minmax(40px, 1fr) auto;
    padding: 2px 4px;
  }

  button {
    min-height: 44px;
  }

  input, select, textarea {
    min-height: 44px;
    font-size: 16px;
  }
}

@media (max-width: 700px) {
  .kv-grid,
  .component-field-grid {
    grid-template-columns: 1fr;
  }

  .result-frame {
    min-height: 340px;
  }
}

/* =============================================
   Archive / Design-Uebersicht
   ============================================= */

.archive-panel {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg-0);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.archive-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.archive-topbar h2 {
  flex: 1;
  margin: 0;
  font-size: 1.1rem;
}

.archive-scan-area {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--ink-1);
}

.archive-layout {
  display: grid;
  grid-template-columns: var(--archive-sidebar-w, 300px) 4px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.archive-sidebar {
  overflow-y: auto;
  padding: 10px;
  background: var(--surface);
  border-right: none;
}

.archive-sidebar-divider {
  width: 4px;
  cursor: col-resize;
  background: var(--line);
  transition: background 0.15s;
}
.archive-sidebar-divider:hover,
.archive-sidebar-divider:active {
  background: var(--accent);
}

.archive-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px 14px;
}

.archive-main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.archive-stats {
  font-size: 0.86rem;
  color: var(--ink-1);
  font-weight: 600;
}

.archive-results {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.archive-pagination {
  flex-shrink: 0;
  padding-top: 8px;
}

/* --- Filter Groups --- */

.archive-filter-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  margin-bottom: 6px;
}

.archive-filter-group summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--ink-0);
  margin-bottom: 6px;
  user-select: none;
}

.archive-filter-body {
  display: grid;
  gap: 8px;
}

.archive-filter-item {
  display: grid;
  gap: 3px;
}

.archive-filter-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-1);
}

.archive-filter-input {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

/* --- Range Inputs (Min / Max) --- */

.archive-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.archive-range-input {
  min-height: 28px;
  padding: 3px 6px;
  font-size: 0.8rem;
}

/* --- Checkbox Grid --- */

.archive-checkbox-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
}

.archive-checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 0;
}

.archive-checkbox-item input[type="checkbox"] {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

/* --- Radio Grid --- */

.archive-radio-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.archive-radio-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  cursor: pointer;
}

.archive-radio-item input[type="radio"] {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

/* --- Year Chips --- */

.archive-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.archive-chip {
  min-height: 26px;
  padding: 2px 8px;
  font-size: 0.74rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink-1);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.archive-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: none;
}

.archive-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- Results Table --- */

.archive-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.archive-table th,
.archive-table td {
  border: 1px solid var(--line);
  padding: 4px 6px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-table th {
  position: sticky;
  top: 0;
  background: var(--bg-1);
  font-weight: 600;
  font-size: 0.74rem;
  color: var(--ink-1);
  user-select: none;
  z-index: 1;
}

.col-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  background: transparent;
}

.col-resize-handle:hover {
  background: var(--accent);
  opacity: 0.4;
}

.col-config-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink-1);
  padding: 0;
  min-height: unset;
  min-width: unset;
}

.col-config-btn:hover {
  color: var(--brand);
}

.col-chooser h3 {
  margin-bottom: 8px;
}

.col-chooser-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 4px;
  margin: 10px 0;
  max-height: 50vh;
  overflow-y: auto;
}

.col-chooser-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.col-chooser-item:hover {
  background: var(--bg-1);
}

.col-chooser-item input[type="checkbox"] {
  min-height: unset;
  width: 16px;
  height: 16px;
}

.hf-detail-wrapper {
  margin-top: 4px;
}

.hf-detail-fields {
  margin-top: 6px;
  display: grid;
  gap: 6px;
}

.hf-field-label {
  font-size: 0.74rem;
}

.hf-filter-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 8px;
  margin-bottom: 2px;
  padding: 2px 0;
  border-bottom: 1px solid var(--line);
}

.archive-th-sortable {
  cursor: pointer;
}

.archive-th-sortable:hover {
  color: var(--ink-0);
  background: #e0e8f3;
}

.archive-th-active {
  color: var(--brand) !important;
}

.archive-th-active[data-direction="asc"]::after {
  content: " \25B2";
  font-size: 0.65em;
}

.archive-th-active[data-direction="desc"]::after {
  content: " \25BC";
  font-size: 0.65em;
}

.archive-row {
  cursor: pointer;
  transition: background 0.1s;
}

.archive-row:hover {
  background: #eef4fb;
}

.archive-row:nth-child(even) {
  background: var(--surface-soft);
}

.archive-row:nth-child(even):hover {
  background: #eef4fb;
}

/* --- Pagination --- */

.archive-pagination-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.archive-page-btn {
  min-height: 30px;
  min-width: 32px;
  padding: 2px 8px;
  font-size: 0.78rem;
}

.archive-page-btn.archive-page-active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.archive-page-dots {
  padding: 0 4px;
  color: var(--ink-1);
  font-size: 0.82rem;
}

/* --- Detail Modal --- */

.archive-detail-modal {
  max-width: min(720px, 92vw);
  min-width: 0;
  max-height: 85vh;
}

.archive-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.archive-detail-header h3 {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-detail-section {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.archive-detail-section:last-of-type {
  border-bottom: none;
}

.archive-detail-section h4 {
  font-size: 0.88rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.archive-detail-fuel {
  margin-bottom: 8px;
  padding: 6px 8px;
  border: 1px solid #e8edf5;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.archive-detail-fuel strong {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 6px;
}

.archive-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.archive-detail-table th,
.archive-detail-table td {
  border: 1px solid var(--line);
  padding: 4px 8px;
  text-align: left;
}

.archive-detail-table th {
  background: var(--bg-1);
  font-weight: 600;
  font-size: 0.76rem;
  color: var(--ink-1);
}

/* --- Archive Responsive: Mobile --- */

@media (max-width: 760px) {
  .archive-layout {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto 1fr;
  }

  .archive-sidebar-divider { display: none; }

  .archive-sidebar {
    border-bottom: 1px solid var(--line);
    max-height: 40vh;
    overflow-y: auto;
  }

  .archive-topbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .archive-topbar h2 {
    order: -1;
    flex-basis: 100%;
    font-size: 0.98rem;
  }

  .archive-table th,
  .archive-table td {
    padding: 4px 5px;
    font-size: 0.75rem;
    max-width: 100px;
  }

  .archive-page-btn {
    min-height: 36px;
    min-width: 36px;
  }

  .archive-detail-modal {
    max-width: 98vw;
    max-height: 90vh;
    padding: 14px;
  }
}
