:root {
  --bg: #0f172a;            /* slate-900 */
  --panel: #1e293b;         /* slate-800 */
  --panel-soft: rgba(30, 41, 59, 0.5);
  --border: #334155;        /* slate-700 */
  --border-soft: rgba(51, 65, 85, 0.7);
  --text: #f1f5f9;          /* slate-100 */
  --text-muted: #94a3b8;    /* slate-400 */
  --text-faint: #64748b;    /* slate-500 */
  --accent: #2563eb;        /* blue-600 */
  --accent-hover: #3b82f6;  /* blue-500 */
  --ok: #10b981;            /* emerald-500 */
  --err: #ef4444;           /* red-500 */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
body.dashboard-body { height: 100vh; height: 100dvh; overflow: hidden; }

@keyframes flash { 0% { opacity: .4; } 100% { opacity: 1; } }
.flash { animation: flash .5s ease-out; }

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* ── Logo ── */
.logo-full { display: block; width: 100%; max-width: 340px; height: auto; margin: 0 0 24px; }
.logo-square { display: block; height: 32px; width: 32px; object-fit: contain; flex-shrink: 0; }
.sidebar-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-weight: 700; font-size: 0.95rem; }
.topbar-title { display: flex; align-items: center; gap: 10px; }
.topbar-title h1 { margin: 0; }

h1, h2, h3 { margin: 0 0 8px; font-weight: 700; }
h1 { font-size: 1.25rem; }
p.muted { color: var(--text-muted); font-size: 0.875rem; margin: 0 0 20px; }

label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="number"] {
  width: 100%;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
input:focus { border-color: var(--accent); }

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.85rem;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s ease;
}
button:hover, .btn:hover { background: var(--accent-hover); }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.danger { background: var(--err); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.error { color: var(--err); font-size: 0.8rem; margin-top: 10px; }
.field { margin-bottom: 16px; }

footer {
  text-align: center;
  padding: 16px;
  font-size: 0.75rem;
  color: var(--text-faint);
  flex-shrink: 0;
}
footer a { color: var(--text-muted); text-decoration: none; margin: 0 8px; }
footer a:hover { color: var(--text); text-decoration: underline; }

/* ── Dashboard-Layout ── */
.app-shell { display: flex; flex: 1; min-height: 0; width: 100%; }
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.sidebar h2 { font-size: 0.9rem; }
.instance-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: var(--panel-soft);
  font-size: 0.8rem;
  cursor: pointer;
}
.instance-item.active { border-color: var(--accent); }
.instance-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 6px; flex-shrink: 0; }
.instance-item-label { display: flex; align-items: center; min-width: 0; overflow: hidden; }
.instance-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.instance-item-actions { display: flex; gap: 2px; flex-shrink: 0; margin-left: 6px; }
.icon-btn {
  background: transparent; color: var(--text-faint); padding: 2px 6px; font-size: 0.75rem;
  border-radius: 6px; transition: background .15s, color .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.1); color: var(--text); }
.icon-btn.remove:hover { color: var(--err); }
.instance-rename-input {
  flex: 1; min-width: 0; background: #0b1220; border: 1px solid var(--accent); border-radius: 6px;
  padding: 2px 6px; color: var(--text); font-size: 0.8rem; outline: none;
}

.main {
  flex: 1; min-width: 0; padding: 18px 24px; display: flex; flex-direction: column;
  gap: 12px; overflow: hidden;
}
.main-header { flex-shrink: 0; }
.main-header h1 { margin-bottom: 2px; }
.main-header p.muted { margin: 0; }
.toolbar-row { flex-shrink: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Quellen-Tabs (nur sichtbar bei >1 Quelle) ── */
.source-tabs { flex-shrink: 0; display: flex; align-items: center; gap: 4px; overflow-x: auto; }
.source-tab-btn {
  flex-shrink: 0; padding: 6px 14px; border-radius: 8px; font-size: 0.8rem; font-weight: 500;
  background: transparent; border: none; color: var(--text-muted); transition: background .15s, color .15s;
}
.source-tab-btn.active { background: rgba(37,99,235,.3); color: var(--text); outline: 1px solid rgba(59,130,246,.4); }
.source-tab-btn:not(.active):hover { background: rgba(30,41,59,.6); }

/* ── Panels füllen die gesamte verbleibende Fläche dynamisch aus (wie Native App) ── */
.panels-viewport { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.panel-container {
  position: absolute; inset: 0; display: none; flex-direction: column;
  gap: 12px; box-sizing: border-box;
}
.panel-container.active { display: flex; }
.panel-title-row { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.panel-title { font-size: 0.95rem; margin: 0; }

.live-badge {
  font-size: 0.68rem; font-weight: 700; padding: 3px 10px 3px 8px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}
.live-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.live-badge-green { background: rgba(16,185,129,.18); color: #6ee7b7; }
.live-badge-orange { background: rgba(245,158,11,.18); color: #fcd34d; }
.live-badge-red { background: rgba(239,68,68,.18); color: #fca5a5; }

.split-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tiles-outer { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tiles-outer-hint { font-size: 0.68rem; color: var(--text-faint); margin: 0 0 6px; user-select: none; flex-shrink: 0; }
.tile-grid-wrap { flex: 1; min-height: 0; position: relative; }
.tile-grid { display: grid; width: 100%; height: 100%; align-content: stretch; }

.tile {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: var(--tile-pad, 10px);
  text-align: center;
  cursor: pointer;
  user-select: none;
  position: relative;
  overflow: hidden;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  min-height: 0; min-width: 0;
  transition: border-color 0.2s, background 0.2s;
}
.tile.inactive { opacity: 0.4; }

.tile-badge-row { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 5px; max-width: 100%; min-width: 0; }
.tile-curve-badge { font-weight: 800; border-radius: 6px; padding: 0 7px; font-size: var(--tile-curve-font, 12px); line-height: 1.7; flex-shrink: 0; }
.tile-label {
  font-size: var(--tile-label-font, 12px); font-weight: 700; color: #d1d9e6; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.tile-value { font-size: var(--tile-value-font, 20px); font-weight: 700; font-variant-numeric: tabular-nums; margin: 3px 0; line-height: 1; }
.tile-unit { font-size: var(--tile-unit-font, 9px); color: var(--text-faint); margin-top: 2px; }

.tile-green  { border-color: rgba(52,211,153,.7); background: linear-gradient(135deg,rgba(6,78,59,.4) 0%,rgba(15,23,42,.6) 100%); }
.tile-green  .tile-value { color: #6ee7b7; }
.tile-amber  { border-color: rgba(251,191,36,.7); background: linear-gradient(135deg,rgba(120,53,15,.4) 0%,rgba(15,23,42,.6) 100%); }
.tile-amber  .tile-value { color: #fcd34d; }
.tile-red    { border-color: rgba(239,68,68,.7); background: linear-gradient(135deg,rgba(127,29,29,.4) 0%,rgba(15,23,42,.6) 100%); }
.tile-red    .tile-value { color: #fca5a5; }
.tile-slate  { border-color: rgba(71,85,105,.45); background: linear-gradient(135deg,rgba(15,23,42,.35) 0%,rgba(15,23,42,.6) 100%); }
.tile-slate  .tile-value { color: #94a3b8; font-size: clamp(11px, var(--tile-label-font, 12px), 20px); }

.tile-progress {
  position: absolute; left: 0; right: 0; bottom: 0; height: 15px;
  background: rgba(255,255,255,.08); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.tile-progress-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: var(--text-faint); transition: width .5s linear; }
.tile-progress-label {
  position: relative; font-size: var(--tile-progress-font, 9px); font-weight: 700; color: #f1f5f9;
  text-shadow: 0 1px 2px rgba(0,0,0,.7); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 94%; padding: 0 4px;
}

/* ── Verschiebbarer Splitter zwischen Kacheln und Verlauf (wie Native App) ── */
.panel-splitter {
  flex: 0 0 26px; display: flex; align-items: center; justify-content: center; gap: 10px;
  cursor: row-resize; margin: 0; -webkit-tap-highlight-color: transparent; touch-action: none;
}
.panel-splitter-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--border); transition: background .15s; }
.panel-splitter:hover .panel-splitter-grip { background: var(--text-faint); }
.panel-splitter-btn {
  width: 22px; height: 22px; padding: 0; border-radius: 6px; border: none; background: rgba(255,255,255,.06);
  color: var(--text-faint); cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .15s, color .15s; font-size: 0;
}
.panel-splitter-btn:hover { background: rgba(255,255,255,.14); color: var(--text); }
.panel-splitter-btn:active { transform: scale(.92); }

.chart-panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel-soft); border: 1px solid var(--border-soft); border-radius: 14px; overflow: hidden;
}
.chart-panel-header {
  flex-shrink: 0; padding: 8px 12px; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.chart-timeframes { display: flex; gap: 4px; }
.chart-tf-btn {
  background: transparent; border: none; color: var(--text-faint);
  padding: 4px 10px; font-size: 0.72rem; border-radius: 8px;
}
.chart-tf-btn.active { background: var(--accent); color: #fff; }
.chart-canvas-wrap { flex: 1; min-height: 0; position: relative; padding: 8px; }

.empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--text-faint); }
.empty-state.hidden { display: none; }
.hidden { display: none !important; }
.metrics-count-badge {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 999px;
  background: rgba(37,99,235,.2); color: #93c5fd; border: 1px solid rgba(37,99,235,.4);
}
.preset-badge { font-size: 0.72rem; padding: 3px 10px; border-radius: 999px; background: var(--panel-soft); color: var(--text-faint); border: 1px solid var(--border-soft); }
.preset-badge-active { background: rgba(16,185,129,.18); color: #6ee7b7; border-color: rgba(16,185,129,.4); }

/* ── Messwerte-Modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
  align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; width: 100%; max-width: 560px; max-height: 85vh; overflow-y: auto;
}
.modal-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.modal-header h3 { margin: 0; }
.metrics-view-switch { display: flex; gap: 6px; background: var(--panel-soft); padding: 4px; border-radius: 12px; margin: 14px 0; }
.metrics-view-switch-btn { flex: 1; background: transparent; color: var(--text-muted); border-radius: 9px; padding: 8px; }
.metrics-view-switch-btn.active { background: var(--accent); color: #fff; }
.modal-tabs { display: flex; gap: 6px; background: var(--panel-soft); padding: 4px; border-radius: 12px; margin-bottom: 12px; }
.modal-tab { flex: 1; background: transparent; color: var(--text-muted); border-radius: 9px; padding: 8px; }
.modal-tab.active { background: var(--accent); color: #fff; }
.modal-group { margin-bottom: 14px; }
.modal-group-title { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin-bottom: 6px; }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }
.modal-actions button { flex: 1; }

.preset-card {
  background: rgba(15,23,42,.5); border: 1px solid var(--border-soft); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 10px;
}
.preset-card-active { border-color: rgba(52,211,153,.6); box-shadow: 0 0 0 1px rgba(52,211,153,.35); }
.preset-card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.preset-active-tag { font-size: 0.7rem; font-weight: 700; color: #6ee7b7; background: rgba(16,185,129,.18); padding: 4px 10px; border-radius: 8px; }
.preset-norm { font-size: 0.72rem; color: #93c5fd; font-weight: 600; margin: 0 0 4px; }
.preset-note { font-size: 0.68rem; color: var(--text-faint); line-height: 1.5; margin: 0 0 8px; }
.preset-metric-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-metric-chip { display: inline-flex; padding: 3px 9px; border-radius: 999px; border: 1px solid; font-size: 0.68rem; }
.custom-preset-form { display: flex; gap: 8px; margin: 10px 0 6px; }
.custom-preset-form input { flex: 1; }

.metrics-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  background: var(--panel-soft);
  color: var(--text-muted);
}
.chip.selected { background: var(--accent); color: #fff; border-color: var(--accent); }

.qr-box { text-align: center; margin: 16px 0; }
.qr-box img { border-radius: 12px; border: 1px solid var(--border); }
.status-line { font-size: 0.8rem; color: var(--text-muted); margin: 10px 0; }
