/* Dark theme, monospace, compact */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111;
  --bg2: #1a1a1a;
  --bg3: #222;
  --border: #333;
  --text: #ddd;
  --text-dim: #888;
  --accent: #4af;
  --green: #4c4;
  --blue: #48f;
  --orange: #f84;
  --gray: #666;
  --red: #f44;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 13px;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- status bar ---- */
#statusbar {
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.indicator.online  { background: var(--green); }
.indicator.offline { background: var(--red); }

.sep { color: var(--border); }

.fms-free    { color: var(--green); font-weight: bold; }
.fms-einsatz { color: var(--blue);  font-weight: bold; }
.fms-rueck   { color: var(--orange); font-weight: bold; }

button {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 2px 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.active { background: var(--accent); color: #000; }

/* ---- main layout ---- */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#left-col {
  width: 52%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

#right-col {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
}

section {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
section:last-child { border-bottom: none; flex: 1; overflow-y: auto; }

h2 {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

/* ---- operations table ---- */
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
th {
  text-align: left;
  padding: 3px 6px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}
td {
  padding: 3px 6px;
  border-bottom: 1px solid var(--bg3);
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Spaltenbreiten fuer Einsatztabelle: lock | id | typ | phase | stichwort */
#ops-table th:nth-child(1), #ops-table td:nth-child(1) { width: 24px; }
#ops-table th:nth-child(2), #ops-table td:nth-child(2) { width: 22%; }
#ops-table th:nth-child(3), #ops-table td:nth-child(3) { width: 18%; }
#ops-table th:nth-child(4), #ops-table td:nth-child(4) { width: 22%; }
#ops-table th:nth-child(5), #ops-table td:nth-child(5) { width: auto; }
tr:hover td { background: var(--bg3); }
.empty { color: var(--text-dim); font-style: italic; }

/* ---- params section ---- */
#params-section {
  flex-shrink: 0;
}

.param-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.param-row label { min-width: 180px; }

input[type=range] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

.param-actions {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

select {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 2px 4px;
  font-family: inherit;
  font-size: 12px;
}

/* ---- vehicle grid ---- */
.wache-block {
  margin-bottom: 10px;
}
.wache-label {
  color: var(--text-dim);
  font-size: 11px;
  margin-bottom: 4px;
  text-transform: uppercase;
}
.vehicle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.vehicle-chip {
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 11px;
  cursor: default;
  min-width: 90px;
  text-align: center;
}
/* FMS colour coding */
.fms-s2 { border-color: var(--green);  color: var(--green); }
.fms-s3, .fms-s4 { border-color: var(--blue);   color: var(--blue); }
.fms-s7, .fms-s8 { border-color: var(--orange);  color: var(--orange); }
.fms-s1 { border-color: var(--gray);   color: var(--gray); }

/* State-Badge */
.state-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 6px;
}
.state-badge.state-idle    { background: #6c757d; color: #fff; }
.state-badge.state-running { background: #28a745; color: #fff; }
.state-badge.state-paused  { background: #ffc107; color: #000; }

/* State-Steuer-Buttons */
#state-controls button {
  margin-left: 4px;
}
#state-controls .btn-start,
#state-controls .btn-resume {
  background: #28a745;
  color: #fff;
  border: 1px solid #1f8c38;
}
#state-controls .btn-pause {
  background: #ffc107;
  color: #000;
  border: 1px solid #d39e00;
}
#state-controls .btn-stop {
  background: #dc3545;
  color: #fff;
  border: 1px solid #b32a37;
}

/* ===== Drei-Spalten-Layout ===== */

#main {
  display: grid;
  grid-template-columns: minmax(380px, 420px) 1fr 360px;
  gap: 12px;
  padding: 12px;
}

#main:has(#detail-col[hidden]) {
  grid-template-columns: minmax(380px, 420px) 1fr;
}

/* Grid-Children muessen schrumpfen duerfen, sonst sprengt eine breite Tabelle die Spalte. */
#left-col, #detail-col, #right-col {
  min-width: 0;
}

#detail-col {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 80px);
}

#detail-col[hidden] {
  display: none;
}

#detail-col h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin: 10px 0 6px;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.detail-header h2 {
  margin: 0;
  flex: 1;
  color: var(--text);
}
.detail-close {
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 1.4em;
  cursor: pointer;
}
.detail-close:hover { color: var(--accent); }

.lock-toggle {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
}
.lock-toggle.locked {
  background: #5a4400;
  border-color: var(--orange);
  color: #ffe066;
}

.detail-meta {
  margin-bottom: 12px;
  color: var(--text-dim);
}
.detail-meta strong { color: var(--text); }

.lifecycle-buttons,
.mutation-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.lifecycle-buttons button,
.mutation-buttons button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
}
.lifecycle-buttons button:not([disabled]):hover,
.mutation-buttons button:not([disabled]):hover {
  border-color: var(--accent);
  color: var(--accent);
}
.lifecycle-buttons button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}
.lifecycle-buttons button.active {
  background: #1a3a5c;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: bold;
}
.btn-storno:not([disabled]) {
  border-color: var(--red) !important;
  color: var(--red) !important;
}
.btn-storno:not([disabled]):hover {
  background: #4a1414 !important;
}

.inline-form {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.inline-form label {
  font-size: 0.9em;
  color: var(--text);
}
.inline-form input[type=text],
.inline-form input[type=number],
.inline-form textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 2px 4px;
  font-family: inherit;
  font-size: 12px;
}
.form-error {
  color: var(--red);
  font-size: 0.85em;
}

#detail-vehicles {
  list-style: none;
  padding: 0;
  margin: 0;
}
#detail-vehicles li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
#detail-vehicles .veh-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
#detail-vehicles button,
#detail-vehicles select {
  padding: 2px 6px;
  font-size: 0.8em;
}

/* Lock-Indikator in der Liste */
#ops-body tr.selected td {
  background: #1a3a5c;
  color: var(--accent);
}
#ops-body td.lock-cell {
  width: 1.5em;
  text-align: center;
}

#ops-body tr {
  cursor: pointer;
}
