/* ── Reset & Basis ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:      #2563eb;
  --blue-dk:   #1d4ed8;
  --blue-lt:   #dbeafe;
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #0f172a;
  --muted:     #64748b;
  --danger:    #ef4444;
  --gantt-bar: #3b82f6;
  --gantt-bg:  #eff6ff;
  --radius:    6px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

html { height: 100%; }

[x-cloak] { display: none !important; }

/* ── Header ────────────────────────────────────────────────────── */
.app-header {
  background: var(--blue);
  color: #fff;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}
.app-header h1 { font-size: 17px; font-weight: 600; white-space: nowrap; }
.header-meta { font-size: 12px; opacity: .85; margin-left: auto; white-space: nowrap; }

/* ── Status-Meldungen ──────────────────────────────────────────── */
.state-msg {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 15px;
}
.state-msg.error { color: var(--danger); }

.content-host {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* ── Filter-Leiste ─────────────────────────────────────────────── */
.filter-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 20px;

}
.filter-bar-inner {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 1600px;
  margin: 0 auto;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.filter-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.filter-select,
.filter-input,
.filter-time {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.filter-select:focus,
.filter-input:focus,
.filter-time:focus { border-color: var(--blue); }
.filter-input { width: 160px; }
.filter-select { min-width: 130px; }
.time-range {
  display: flex;
  align-items: center;
  gap: 4px;
}
.time-range span { color: var(--muted); }
.filter-time { width: 84px; padding: 0 6px; }

/* Multi-Select Dropdown */
.multiselect { position: relative; }
.filter-btn {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 100px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filter-btn:hover { border-color: var(--blue); }
.filter-btn.active { border-color: var(--blue); background: var(--blue-lt); color: var(--blue-dk); }
.filter-btn .caret { margin-left: auto; opacity: .6; flex-shrink: 0; }
.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 140px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 200;
}
.dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}
.dd-item:hover { background: var(--bg); }
.dd-item input[type=checkbox],
.dd-item input[type=radio] { cursor: pointer; accent-color: var(--blue); }

/* Toggle-Button */
.toggle-btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}
.toggle-btn.active {
  border-color: var(--blue);
  background: var(--blue-lt);
  color: var(--blue-dk);
  font-weight: 600;
}

/* Aktions-Buttons */
.filter-actions { display: flex; gap: 6px; align-items: flex-end; padding-bottom: 0; margin-left: auto; }
.btn-primary, .btn-secondary {
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  border: none;
  white-space: nowrap;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dk); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

/* ── Stats-Leiste ──────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  max-width: 100%;
  padding: 0 20px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 24px;
  border-right: 1px solid var(--border);
}
.stat:last-child { border-right: none; }
.stat-value { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }

/* ── Ansichts-Tabs ─────────────────────────────────────────────── */
.view-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 10px 20px 0;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  max-width: 100%;
}
.tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab:hover { color: var(--text); background: var(--border); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); background: var(--surface); }
.tab-count { margin-left: auto; font-size: 12px; color: var(--muted); padding-bottom: 8px; }

/* ── Inhaltsbereich ────────────────────────────────────────────── */
.view-content {
  padding: 16px 20px;
  max-width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Datentabelle ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead tr { background: var(--bg); }
.data-table th {
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text); background: var(--border); }
.sort-icon { font-size: 10px; opacity: .6; }
.data-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr.no-data { opacity: .45; }

.td-name { font-weight: 600; font-family: "Courier New", monospace; font-size: 12px; cursor: pointer; color: var(--blue); }
.td-name:hover { text-decoration: underline; }
.td-school { color: var(--blue); font-weight: 600; }
.td-serial { font-family: monospace; font-size: 11px; color: var(--muted); }
.td-dur { font-weight: 500; }
.td-rest { text-align: center; }
.th-gantt, .td-gantt { min-width: 180px; width: 220px; }

/* ── Gantt-Balken ──────────────────────────────────────────────── */
.gantt-track {
  position: relative;
  height: 16px;
  background: var(--gantt-bg);
  border-radius: 3px;
  overflow: hidden;
  width: 100%;
}
.gbar {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--gantt-bar);
  border-radius: 2px;
  min-width: 2px;
  opacity: .85;
  transition: opacity .15s;
}
.gbar:hover { opacity: 1; }

/* ── Timeline-Ansicht ──────────────────────────────────────────── */
.timeline-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.tl-header {
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tl-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  min-height: 30px;
}
.tl-row:last-child { border-bottom: none; }
.tl-row:hover { background: #f8fafc; }
.tl-label-col {
  width: 130px;
  min-width: 130px;
  padding: 4px 12px;
  font-size: 11px;
  font-family: monospace;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-right: 1px solid var(--border);
}
.tl-track-col {
  flex: 1;
  padding: 4px 12px;
  min-width: 0;
}
.tl-axis {
  position: relative;
  height: 22px;
}
.tl-tick {
  position: absolute;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.tl-row .gantt-track { height: 18px; }

/* ── Schulen-Ansicht ───────────────────────────────────────────── */
.schools-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .schools-content { grid-template-columns: 1fr; } }

.chart-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  height: 500px;
  min-height: 500px;
  position: relative;
}

#schoolChart {
  width: 100%;
  height: 100%;
  min-height: 460px;
  display: block;
}
.school-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  overflow: hidden;
}
.school-table th {
  padding: 9px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.school-table td {
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.school-table tbody tr:last-child td { border-bottom: none; }
.school-table tbody tr:hover { background: #f8fafc; }
.school-table td:first-child { font-weight: 600; color: var(--blue); }

/* ── Modals (Gerät-Detail + Upload) ───────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%;
  max-width: 860px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-sm { max-width: 440px; }
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-header h2 { font-size: 16px; font-weight: 700; margin: 0; }
.modal-meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; font-size: 12px; color: var(--muted); }
.modal-meta span { display: flex; gap: 4px; }
.modal-close {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border: none; background: none;
  font-size: 16px; cursor: pointer;
  color: var(--muted); border-radius: var(--radius);
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body {
  overflow-y: auto;
  padding: 16px 20px;
  flex: 1;
}

/* Gerät-Statistik-Karten */
.device-stats-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.device-stat {
  flex: 1 1 110px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  text-align: center;
}
.device-stat span   { display: block; font-size: 18px; font-weight: 700; color: var(--text); }
.device-stat small  { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Gerät-Tages-Tabelle */
.device-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.device-table th {
  padding: 8px 10px;
  text-align: left;
  font-size: 12px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.device-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.device-table tbody tr:last-child td { border-bottom: none; }
.device-table tbody tr:hover { background: var(--bg); }
.device-table td:first-child { font-weight: 600; white-space: nowrap; }
.device-table .td-gantt { min-width: 160px; }

.device-modal-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

/* Upload-Bereich */
.upload-hint { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.upload-hint code { background: var(--bg); padding: 2px 5px; border-radius: 3px; font-family: monospace; }
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  transition: border-color .15s;
}
.upload-area:hover, .upload-area.drag { border-color: var(--blue); background: var(--blue-lt); }
.upload-area input[type=file] { position: absolute; opacity: 0; width: 0; height: 0; }
.upload-label {
  cursor: pointer;
  font-size: 14px;
  color: var(--blue);
  font-weight: 500;
}
.upload-result {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
}
.upload-ok  { background: #dcfce7; color: #166534; }
.upload-err { background: #fee2e2; color: #991b1b; }
