:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #232c38;
  --border: #2e3947;
  --text: #e6edf3;
  --muted: #8b97a6;
  --primary: #4f8cff;
  --primary-dark: #3b6fd4;
  --danger: #ff5f56;
  --radius: 10px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0;
  font-size: 1.3rem;
}

.brand .subtitle {
  color: var(--muted);
  font-size: 0.8rem;
}
.conf-title {
  display: block;
  margin-top: 2px;
  width: 240px;
  max-width: 50vw;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.15rem 0.35rem;
}
.conf-title:hover { border-color: var(--border); }
.conf-title:focus { color: var(--text); border-color: var(--primary); background: var(--bg); }

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.start-time {
  display: flex;
  flex-direction: column;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.start-time input {
  margin-top: 2px;
}

.header-buttons {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover { background: #2c3744; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost { background: transparent; }
.btn-secondary { }

.btn-icon {
  padding: 0.2rem 0.45rem;
  font-size: 0.8rem;
  line-height: 1;
}

input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type="color"] { padding: 2px; width: 38px; height: 34px; cursor: pointer; }

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  padding: 1rem;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-head .hint { color: var(--muted); font-size: 0.7rem; }

/* Template palette */
.template-form {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.template-form .row {
  display: flex;
  gap: 0.5rem;
}
.template-form #tplName { width: 100%; }
.template-form #tplDuration { width: 70px; }
.tpl-blocking {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
}
.tpl-blocking input { width: auto; }

.template-list {
  list-style: none;
  margin: 0;
  padding: 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.template-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  cursor: grab;
  border-left: 4px solid var(--chip-color, var(--primary));
}
.template-chip:active { cursor: grabbing; }
.template-chip.dragging { opacity: 0.4; }
.template-chip.is-blocking {
  border-style: solid;
  box-shadow: inset 0 0 0 1px var(--chip-color, var(--primary));
}

.template-chip .tpl-info { flex: 1; min-width: 0; }
.template-chip .tpl-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.template-chip .tpl-dur { color: var(--muted); font-size: 0.75rem; }
.template-chip .tpl-actions { display: flex; gap: 0.25rem; }

.empty-hint {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 1rem;
  font-style: italic;
}

/* Board tools / zoom */
.board { overflow: hidden; }
.board-tools { display: flex; align-items: center; gap: 0.75rem; }
.zoom { display: flex; align-items: center; gap: 0.3rem; }
.zoom-label {
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 64px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Timeline board (horizontal lanes, shared vertical time axis) */
.track-board {
  flex: 1;
  display: flex;
  gap: 0;
  padding: 1rem;
  overflow: auto;
  align-items: flex-start;
}

.lane {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
.lane:first-child { border-left: 1px solid var(--border); }

.lane-head {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 92px;
  box-sizing: border-box;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.lane-head .track-name-row { display: flex; align-items: center; gap: 0.35rem; }
.lane-head .track-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  background: transparent;
  border: 1px solid transparent;
  padding: 0.2rem 0.35rem;
}
.lane-head .track-name:hover { border-color: var(--border); }
.lane-head .track-meta {
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
}
.lane-head .add-gap {
  font-size: 0.72rem;
  padding: 0.25rem 0.4rem;
  align-self: flex-start;
}

/* Ruler lane */
.ruler-lane { flex: 0 0 76px; }
.ruler-lane .lane-head { background: var(--panel); }
.ruler-body { position: relative; flex: 1; }
.ruler-cell {
  position: relative;
  box-sizing: border-box;
  border-top: 1px solid var(--border);
}
.ruler-cell.is-plen { border-top-color: var(--primary); }
.ruler-cell.is-end { height: 0; }
.ruler-time {
  position: absolute;
  top: -1px;
  left: 0.4rem;
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transform: translateY(-50%);
  background: var(--panel);
  padding-right: 3px;
}
.ruler-insert {
  position: absolute;
  bottom: 2px;
  left: 2px;
  right: 2px;
  font-size: 0.6rem;
  padding: 1px 0;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 5px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}
.ruler-cell:hover .ruler-insert { opacity: 1; }
.ruler-insert:hover { border-color: var(--primary); color: var(--primary); }

/* Track body — Abschnitte (seg-zone) + Plenum-Bänder */
.lane-body { position: relative; flex: 1; display: flex; flex-direction: column; }

.seg-zone {
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}
.seg-zone.drag-over { background-color: rgba(79, 140, 255, 0.10); }
.seg-zone.is-slim {
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(45deg,
    rgba(139, 151, 166, 0.05) 0, rgba(139, 151, 166, 0.05) 6px,
    transparent 6px, transparent 12px);
}
.seg-slim-hint {
  font-size: 0.62rem;
  color: var(--muted);
  opacity: 0.55;
  pointer-events: none;
  letter-spacing: 0.03em;
}
.seg-zone.is-slim:hover .seg-slim-hint { opacity: 0.9; }
.seg-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  opacity: 0.4;
  font-size: 1.2rem;
  pointer-events: none;
}
.seg-wait {
  background:
    repeating-linear-gradient(45deg,
      rgba(139, 151, 166, 0.07) 0, rgba(139, 151, 166, 0.07) 6px,
      transparent 6px, transparent 12px);
  pointer-events: none;
}

/* Plenum-Band (volle Breite, über alle Tracks gleich) */
.plenum-bar {
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.1rem 0.5rem;
  background: color-mix(in srgb, var(--block-color, var(--primary)) 22%, var(--panel));
  border-top: 2px solid var(--block-color, var(--primary));
  border-bottom: 2px solid var(--block-color, var(--primary));
  overflow: hidden;
}
.plenum-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plenum-time { font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.plenum-actions {
  position: absolute;
  top: 2px;
  right: 3px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}
.plenum-bar:hover .plenum-actions { opacity: 1; }
.plenum-actions button {
  border: none;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 5px;
}
.plenum-actions .act-del:hover { background: var(--danger); color: #fff; }
.plenum-actions .act-edit:hover { background: var(--primary); color: #fff; }

.block {
  position: relative;
  box-sizing: border-box;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  border-left: 5px solid var(--block-color, var(--primary));
  background: var(--block-bg, var(--panel));
  padding: 0.25rem 0.5rem;
  cursor: grab;
  overflow: hidden;
}
.block:active { cursor: grabbing; }
.block.dragging { opacity: 0.4; }
.block.is-gap {
  border-left-style: dashed;
  background:
    repeating-linear-gradient(45deg,
      rgba(139, 151, 166, 0.10) 0, rgba(139, 151, 166, 0.10) 7px,
      transparent 7px, transparent 14px);
  color: var(--muted);
  font-style: italic;
}
.block-time {
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.block-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.block-dur { font-size: 0.68rem; color: var(--muted); }
.block.is-tiny { padding-top: 0.1rem; padding-bottom: 0.1rem; }
.block.is-tiny .block-time,
.block.is-tiny .block-dur { display: none; }

.block-actions {
  position: absolute;
  top: 3px;
  right: 3px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}
.block:hover .block-actions { opacity: 1; }
.block-actions button {
  border: none;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 5px;
}
.block-actions .act-del:hover { background: var(--danger); color: #fff; }
.block-actions .act-edit:hover { background: var(--primary); color: #fff; }

.block-drop-placeholder {
  height: 0;
  border-top: 3px solid var(--primary);
  box-shadow: 0 0 6px var(--primary);
}
.block-drop-placeholder.plenum-drop {
  border-top: 5px solid #6e7bff;
  box-shadow: 0 0 8px #6e7bff;
  margin: 0 -0.6rem;
}

.add-track-tile {
  flex: 0 0 150px;
  align-self: stretch;
  margin-left: 0.75rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}
.add-track-tile:hover { border-color: var(--primary); color: var(--primary); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(360px, 92vw);
  padding: 1.25rem;
}
.modal h3 { margin: 0 0 1rem; font-size: 1.05rem; }
.modal-fields { display: flex; flex-direction: column; gap: 0.75rem; }
.modal-field { display: flex; flex-direction: column; gap: 0.25rem; }
.modal-field label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.modal-field input { width: 100%; }
.modal-field.is-check { flex-direction: row; align-items: center; gap: 0.5rem; }
.modal-field.is-check input { width: auto; }
.modal-field.is-check label { text-transform: none; letter-spacing: 0; font-size: 0.85rem; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius);
  z-index: 50;
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; overflow: visible; }
  body { overflow: auto; }
}
