/*
 * components.css — Wiederverwendbare UI-Bausteine
 * Keine Layout-Struktur hier (→ layout.css).
 * Keine Farbhardcodierung — ausschließlich var(--...) aus tokens.css.
 */

/* ═══════════════════════════════════════════════════════
   STATUS-BADGES
   Produkt: 3 Stufen (aktiv / prüfen / keine-verbindung)
   Debug:   4 Stufen (ok / auffällig / fehler / kritisch)
   ═══════════════════════════════════════════════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0.2em 0.65em;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    line-height: 1.4;
    white-space: nowrap;
}

/* Dot vor dem Badge-Text */
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Produktbereich */
.badge-aktiv {
    background: var(--status-ok-bg);
    color: var(--status-ok-text);
}
.badge-aktiv::before { background: var(--status-ok); }

.badge-pruefen {
    background: var(--status-warn-bg);
    color: var(--status-warn-text);
}
.badge-pruefen::before { background: var(--status-warn); }

.badge-offline {
    background: var(--status-critical-bg);
    color: var(--status-critical-text);
}
.badge-offline::before { background: var(--status-critical); }

/* Debugbereich */
.badge-ok {
    background: var(--status-ok-bg);
    color: var(--status-ok-text);
}
.badge-ok::before { background: var(--status-ok); }

.badge-auffaellig {
    background: var(--status-warn-bg);
    color: var(--status-warn-text);
}
.badge-auffaellig::before { background: var(--status-warn); }

.badge-fehler {
    background: var(--status-error-bg);
    color: var(--status-error-text);
}
.badge-fehler::before { background: var(--status-error); }

.badge-kritisch {
    background: var(--status-critical-bg);
    color: var(--status-critical-text);
}
.badge-kritisch::before { background: var(--status-critical); }

/* Alarm (biologisch) — intensiver */
.badge-alarm {
    background: var(--status-alarm-bg);
    color: var(--status-critical-text);
    border: 1px solid rgba(239,68,68,0.3);
}
.badge-alarm::before { background: var(--status-alarm); }

/* Pulsierendes Dot für aktiven Online-Status */
.badge-aktiv::before,
.badge-ok::before {
    animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* Inline-Badge ohne Dot (z. B. für Text-only-Labels) */
.badge-plain {
    display: inline-flex;
    align-items: center;
    padding: 0.15em 0.55em;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════
   KARTEN
   ═══════════════════════════════════════════════════════ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.card-sm {
    padding: var(--space-4);
    border-radius: var(--radius-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.card-title {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

/* Karte mit linkem Akzentstreifen (für Alarme/Status) */
.card-accent-left {
    border-left: 3px solid var(--accent);
}

.card-accent-ok       { border-left: 3px solid var(--status-ok); }
.card-accent-warn     { border-left: 3px solid var(--status-warn); }
.card-accent-error    { border-left: 3px solid var(--status-error); }
.card-accent-critical { border-left: 3px solid var(--status-critical); }
.card-accent-alarm    { border-left: 3px solid var(--status-alarm); }

/* ═══════════════════════════════════════════════════════
   KPI-KACHELN
   ═══════════════════════════════════════════════════════ */
.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.kpi-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-value {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: 1.1;
}

.kpi-value.value-sm {
    font-size: var(--text-lg);
}

.kpi-sub {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: auto;
}

.kpi-sub.good { color: var(--status-ok-text); }
.kpi-sub.warn { color: var(--status-warn-text); }
.kpi-sub.crit { color: var(--status-critical-text); }

/* Farbige Oberkante */
.kpi-top-accent    { border-top: 2px solid var(--accent); }
.kpi-top-ok        { border-top: 2px solid var(--status-ok); }
.kpi-top-warn      { border-top: 2px solid var(--status-warn); }
.kpi-top-error     { border-top: 2px solid var(--status-error); }
.kpi-top-critical  { border-top: 2px solid var(--status-critical); }

/* ═══════════════════════════════════════════════════════
   PANELS (Debug-Sektionen)
   ═══════════════════════════════════════════════════════ */
.section-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: var(--space-4);
}

.section-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5);
    background: var(--bg-muted);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

.section-panel-title {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.section-panel-toggle {
    color: var(--text-muted);
    font-size: var(--text-xs);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.section-panel.collapsed .section-panel-toggle {
    transform: rotate(-90deg);
}

.section-panel-body {
    padding: var(--space-5);
}

.section-panel.collapsed .section-panel-body {
    display: none;
}

/* Drilldown-Trigger innerhalb eines Panels */
.panel-drilldown {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    cursor: pointer;
    border: none;
    background: none;
    font-family: var(--font-sans);
    padding: var(--space-2) 0;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: var(--border-strong);
}

.panel-drilldown:hover {
    color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════
   ALARM-BANNER
   ═══════════════════════════════════════════════════════ */
.alarm-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) var(--content-padding);
    border-left: 4px solid var(--status-alarm);
    background: var(--status-alarm-bg);
    flex-wrap: wrap;
}

.alarm-banner + .alarm-banner {
    border-top: 1px solid var(--border);
}

.alarm-banner-left {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    flex: 1;
    min-width: 0;
}

.alarm-banner-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.alarm-banner-title {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.alarm-banner-detail {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin-top: 2px;
}

.alarm-banner-ack {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-sans);
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.alarm-banner-ack:hover {
    background: var(--bg-muted);
    color: var(--text-primary);
}

.alarm-banner.alarm-acked {
    opacity: 0.45;
    filter: saturate(0.4);
}

/* Verbindungs-Alarm (weniger intensiv als biologischer Alarm) */
.alarm-banner-connection {
    border-left-color: var(--status-critical);
    background: var(--status-critical-bg);
}

/* ═══════════════════════════════════════════════════════
   GERÄTE-STATUS-LEISTE (unter Topbar, über Tabs)
   ═══════════════════════════════════════════════════════ */
.device-status-bar {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-2) var(--content-padding);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    background: var(--bg-surface);
}

.device-status-notes {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.device-note {
    font-size: var(--text-xs);
    padding: 2px var(--space-2);
    border-radius: var(--radius-full);
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.device-note.note-warn { background: var(--status-warn-bg); color: var(--status-warn-text); }
.device-note.note-crit { background: var(--status-critical-bg); color: var(--status-critical-text); }

/* ═══════════════════════════════════════════════════════
   ZUSAMMENFASSUNGS-PANEL (Betrieb/Übersicht)
   ═══════════════════════════════════════════════════════ */
.summary-panel {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--border-strong);
}

.summary-panel.level-ok       { background: var(--status-ok-bg); border-left-color: var(--status-ok); }
.summary-panel.level-warn     { background: var(--status-warn-bg); border-left-color: var(--status-warn); }
.summary-panel.level-critical { background: var(--status-critical-bg); border-left-color: var(--status-critical); }

.summary-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.summary-text { font-size: var(--text-sm); line-height: 1.6; color: var(--text-primary); }

/* ═══════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    font-family: var(--font-sans);
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--bg-muted);
    color: var(--text-primary);
}

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

.btn-accent:hover {
    background: var(--accent-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
}

/* ═══════════════════════════════════════════════════════
   SELECT / TIME-RANGE-CONTROL
   ═══════════════════════════════════════════════════════ */
.select-input {
    appearance: none;
    -webkit-appearance: none;
    padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
    background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239e9e9e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: border-color 0.15s;
}

.select-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Zeitraum-Tabs (nebeneinander, nicht Dropdown) */
.time-tabs {
    display: flex;
    gap: var(--space-1);
    background: var(--bg-muted);
    border-radius: var(--radius-md);
    padding: 3px;
}

.time-tab {
    padding: var(--space-1) var(--space-3);
    border-radius: calc(var(--radius-md) - 2px);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    cursor: pointer;
    border: none;
    background: none;
    font-family: var(--font-sans);
    transition: background 0.15s, color 0.15s;
}

.time-tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
}

.time-tab:hover:not(.active) {
    color: var(--text-primary);
}

/* Ereignis-Filter-Chips (Waagen-Detail, Phase 7) — Toggle-Pills */
.ev-chip {
    padding: var(--space-1) var(--space-3);
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    cursor: pointer;
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.12));
    background: none;
    font-family: var(--font-sans);
    transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}

.ev-chip.active {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--accent, #d97706);
}

.ev-chip:not(.active) {
    opacity: 0.55;
}

.ev-chip:hover {
    color: var(--text-primary);
}

/* Touch: größere Tap-Ziele für Diagramm-Bedienelemente (nur grobe Zeiger). */
@media (pointer: coarse) {
    .time-tab, .ev-chip { min-height: 40px; padding-top: var(--space-2); padding-bottom: var(--space-2); }
    #waRangeTabs, #waEventFilters { gap: .5rem; }
    #waZoomReset, #waManualBtn, #waSelClear { min-height: 40px; }
    #waEvTypeFilter { min-height: 38px; }
    /* Buttons im Ereignis-Dialog (anlegen/bestätigen/verwerfen/…) gut tappbar */
    #waEvDlgBody .btn { min-height: 40px; }
}

/* ═══════════════════════════════════════════════════════
   TABELLEN
   ═══════════════════════════════════════════════════════ */
.table-base {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table-base th {
    background: var(--bg-muted);
    padding: var(--space-2) var(--space-3);
    text-align: left;
    font-weight: var(--weight-semibold);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.table-base th.align-right,
.table-base td.align-right {
    text-align: right;
}

.table-base td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.table-base tr:last-child td {
    border-bottom: none;
}

.table-base tr:hover td {
    background: rgba(255,255,255,0.025);
}

/* Null-Wert */
.null-val {
    color: var(--text-muted);
    font-style: italic;
}

/* Ereignis-Tabellenzeilen — farbige linke Border */
.ev-row-boot    td:first-child { border-left: 3px solid #a78bfa; }
.ev-row-fail-e  td:first-child { border-left: 3px solid var(--status-critical); }
.ev-row-fail-x  td:first-child { border-left: 3px solid var(--status-ok); }
.ev-row-queue   td:first-child { border-left: 3px solid var(--status-warn); }

/* Lücken-Zeilen */
.ev-row-gap     { background: var(--gap-warn) !important; }
.ev-row-gap-big { background: var(--gap-error) !important; }

/* ═══════════════════════════════════════════════════════
   KEY-VALUE-GRID (Debug-Panels)
   ═══════════════════════════════════════════════════════ */
.kv-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3) var(--space-6);
}

@media (max-width: 480px) {
    .kv-grid {
        grid-template-columns: 1fr;
    }
}

.kv-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kv-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.kv-value {
    font-size: var(--text-sm);
    color: var(--text-primary);
    font-weight: var(--weight-medium);
}

.kv-value.mono {
    font-family: var(--font-mono);
}

.kv-value.ok       { color: var(--status-ok-text); }
.kv-value.warn     { color: var(--status-warn-text); }
.kv-value.error    { color: var(--status-error-text); }
.kv-value.critical { color: var(--status-critical-text); }

/* ═══════════════════════════════════════════════════════
   JSON-PANEL (Rohdaten / Payload)
   ═══════════════════════════════════════════════════════ */
.json-panel {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    overflow-x: auto;
    line-height: 1.7;
    white-space: pre;
}

.json-key    { color: #93c5fd; }  /* Blau */
.json-string { color: #86efac; }  /* Grün */
.json-number { color: #fde68a; }  /* Amber */
.json-bool   { color: #f9a8d4; }  /* Pink */
.json-null   { color: var(--text-muted); }

/* Aufklapp-Toggle für JSON-Panel */
.json-panel-wrapper {
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.json-panel-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    background: var(--bg-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    border: none;
    font-family: var(--font-sans);
    width: 100%;
    text-align: left;
}

.json-panel-toggle:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.json-panel-wrapper .json-panel {
    border: none;
    border-radius: 0;
    border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════
   CHART-CONTAINER
   ═══════════════════════════════════════════════════════ */
.chart-container {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
}

.chart-canvas-wrap {
    position: relative;
    height: 280px;
}

@media (min-width: 768px) {
    .chart-canvas-wrap {
        height: 320px;
    }
}

/* Chart-Tab-Leiste (über dem Chart) */
.chart-tabs {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-3);
    flex-wrap: wrap;
}

.chart-tab {
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chart-tab:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.chart-tab.active {
    background: var(--bg-muted);
    color: var(--text-primary);
    border-color: var(--accent);
}

.chart-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-3);
}

/* RSSI-Balken (Debug) */
.rssi-bar {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    vertical-align: middle;
}

.rssi-bar span {
    display: inline-block;
    width: 4px;
    border-radius: 1px;
    background: var(--bg-elevated);
}

.rssi-bar span:nth-child(1) { height: 6px; }
.rssi-bar span:nth-child(2) { height: 9px; }
.rssi-bar span:nth-child(3) { height: 12px; }
.rssi-bar span:nth-child(4) { height: 15px; }

.rssi-bar span.rssi-on  { background: var(--status-ok); }
.rssi-bar span.rssi-med { background: var(--status-warn); }
.rssi-bar span.rssi-low { background: var(--status-critical); }

/* ═══════════════════════════════════════════════════════
   LEERE ZUSTÄNDE (Empty States)
   ═══════════════════════════════════════════════════════ */
.empty-state {
    text-align: center;
    padding: var(--space-10) var(--space-5);
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 2rem;
    margin-bottom: var(--space-3);
    opacity: 0.5;
}

.empty-state-title {
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.empty-state-body {
    font-size: var(--text-sm);
    max-width: 28ch;
    margin: 0 auto;
    line-height: 1.6;
}

/* Lade-Zustand */
.loading-row {
    text-align: center;
    padding: var(--space-8) var(--space-5);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

/* ═══════════════════════════════════════════════════════
   SENSOR-KARTEN (Messwerte-Tab)
   ═══════════════════════════════════════════════════════ */
.sensor-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-sm);
}

.sensor-card-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--space-1);
}

.sensor-card-value {
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: 1.2;
}

.sensor-card-sub {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

/* ═══════════════════════════════════════════════════════
   SECTION-LABEL (Überschriften innerhalb von Seiten)
   ═══════════════════════════════════════════════════════ */
.section-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: var(--space-3);
}

/* ═══════════════════════════════════════════════════════
   CONTROLS-LEISTE (Zeitraum-Auswahl + Statusanzeige)
   ═══════════════════════════════════════════════════════ */
.controls-bar {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--content-padding);
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    flex-wrap: wrap;
}

.controls-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
}

.controls-status {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.controls-status.ok   { color: var(--status-ok-text); }
.controls-status.err  { color: var(--status-critical-text); }

/* ═══════════════════════════════════════════════════════
   TRAFFIC-SEKTION
   ═══════════════════════════════════════════════════════ */
.traffic-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

@media (min-width: 600px) {
    .traffic-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.traffic-cell {
    padding: var(--space-4) var(--space-5);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}

.traffic-cell:nth-child(2n)   { border-right: none; }
.traffic-cell:nth-last-child(-n+2) { border-bottom: none; }

@media (min-width: 600px) {
    .traffic-cell:nth-child(2n)   { border-right: 1px solid var(--border); }
    .traffic-cell:nth-child(4n)   { border-right: none; }
    .traffic-cell:nth-last-child(-n+4) { border-bottom: none; }
}

.traffic-cell-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-1);
}

.traffic-cell-value {
    font-size: var(--text-base);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
}

.traffic-cell-note {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ═══════════════════════════════════════════════════════
   GERÄTE-KARTE (Dashboard)
   ═══════════════════════════════════════════════════════ */
.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    position: relative;
}

.device-card:hover {
    background: var(--bg-elevated);
    border-color: var(--border-strong);
}

/* Farbiger linker Rand wenn nicht aktiv */
.device-card.status-pruefen      { border-left: 3px solid var(--status-warn); }
.device-card.status-keine-verbindung { border-left: 3px solid var(--status-critical); }

/* Kopfzeile: Name + Badge */
.device-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: 1.5rem;
}

.device-card-name {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hauptwert: Gewicht */
.device-card-weight {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.device-card-value {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: 1.1;
}

.device-card-delta {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-weight: var(--weight-medium);
}

.device-card-delta.positive { color: var(--status-ok-text); }
.device-card-delta.negative { color: var(--status-critical-text); }

/* Klimainfo */
.device-card-climate {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* GPS-Standort in der Karte */
.device-card-location {
    font-size: var(--text-xs);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}
.device-card-location a {
    color: inherit;
    text-decoration: none;
}
.device-card-location a:hover { color: var(--text-secondary); }

/* Alarm-Badge in der Karte */
.device-card-alarm {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--status-critical-text);
    background: var(--status-alarm-bg);
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(239,68,68,0.25);
}

/* Fußzeile: letzter Kontakt + Pfeil */
.device-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: var(--space-2);
    border-top: 1px solid var(--border);
}

.device-card-lastseen {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.device-card-arrow {
    font-size: var(--text-sm);
    color: var(--text-muted);
    transition: color 0.15s, transform 0.15s;
}

.device-card:hover .device-card-arrow {
    color: var(--accent);
    transform: translateX(3px);
}

/* Skeleton-Lade-Karte */
.device-card-skeleton {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    height: 180px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
}

/* ═══════════════════════════════════════════════════════
   DASHBOARD-KOPFZEILE
   ═══════════════════════════════════════════════════════ */
.dashboard-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.dashboard-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.dashboard-summary {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════
   FEHLERSEITE (unbekannte ID etc.)
   ═══════════════════════════════════════════════════════ */
.error-page {
    max-width: 400px;
    margin: var(--space-10) auto;
    text-align: center;
    padding: var(--space-5);
}

.error-page-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-4);
    opacity: 0.6;
}

.error-page-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-3);
}

.error-page-body {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: var(--space-6);
}

/* ═══════════════════════════════════════════════════════
   DEBUG-SEKTIONEN — Primäre Metrik-Zeile
   Wichtigste 2–4 Kennzahlen oben, gut sichtbar.
   ═══════════════════════════════════════════════════════ */

.debug-loading {
    font-size: var(--text-xs);
    color: var(--text-muted);
    padding: var(--space-2) 0;
}

/* Zeile mit den Top-Kennzahlen einer Debug-Sektion */
.debug-primary-row {
    display: flex;
    gap: var(--space-6);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

/* Einzelne Kennzahl: Wert über Label */
.debug-metric {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 70px;
}

.debug-metric-value {
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    font-family: var(--font-mono);
    color: var(--text-primary);
    line-height: 1.25;
}

.debug-metric-value.ok       { color: var(--status-ok-text); }
.debug-metric-value.warn     { color: var(--status-warn-text); }
.debug-metric-value.error    { color: var(--status-error-text); }
.debug-metric-value.critical { color: var(--status-critical-text); }

.debug-metric-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Sensor-Statusblöcke (Sektion E) */
.debug-sensor-row {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.debug-sensor-block {
    flex: 1;
    min-width: 140px;
    background: var(--bg-muted);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    border-left: 3px solid var(--status-ok);
}

.debug-sensor-block.sensor-invalid { border-left-color: var(--status-critical); }
.debug-sensor-block.sensor-unknown { border-left-color: var(--border-strong); }

.debug-sensor-name {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.debug-sensor-addr {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

.debug-sensor-values {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.8;
}

/* Technisches Ereignislog — Zeilen */
.debug-log-entry {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--border);
    border-left: 3px solid transparent;
    align-items: flex-start;
}

.debug-log-entry.sev-ok         { border-left-color: var(--status-ok); }
.debug-log-entry.sev-auffaellig { border-left-color: var(--status-warn); }
.debug-log-entry.sev-fehler     { border-left-color: var(--status-error); }
.debug-log-entry.sev-kritisch   { border-left-color: var(--status-critical); }
/* sev-datengap: kein gestrichelter Rand mehr — Schweregrad steuert die Farbe */

/* ═══════════════════════════════════════════════════════
   GLOBALES DIAGNOSE-BANNER (Debug-Seite)
   ═══════════════════════════════════════════════════════ */
.diagnosis-banner {
    display: flex;
    align-items: flex-start;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--status-ok);
    background: var(--status-ok-bg);
    margin-bottom: var(--space-5);
}
.diagnosis-banner.warn  { border-left-color: var(--status-warn);     background: var(--status-warn-bg); }
.diagnosis-banner.error { border-left-color: var(--status-critical);  background: var(--status-critical-bg); }

.diagnosis-icon   { font-size: 1.4rem; flex-shrink: 0; line-height: 1; margin-top: 2px; }
.diagnosis-body   { flex: 1; min-width: 0; }
.diagnosis-title  { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-primary); margin-bottom: 3px; }
.diagnosis-desc   { font-size: var(--text-xs); color: var(--text-secondary); line-height: 1.5; }
.diagnosis-action {
    flex-shrink: 0;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    padding: 3px var(--space-3);
    border-radius: var(--radius-full);
    align-self: center;
    white-space: nowrap;
}
.diagnosis-banner .diagnosis-action          { background: var(--status-ok-bg);       color: var(--status-ok-text); }
.diagnosis-banner.warn  .diagnosis-action    { background: var(--status-warn-bg);      color: var(--status-warn-text); }
.diagnosis-banner.error .diagnosis-action    { background: var(--status-critical-bg);  color: var(--status-critical-text); }

/* ═══════════════════════════════════════════════════════
   SYSTEM-SUMMARY CARD (kompakte Übersicht)
   ═══════════════════════════════════════════════════════ */
.sys-summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    margin-bottom: var(--space-4);
}

.sys-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
}

.sys-metric {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sys-metric-value {
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    font-family: var(--font-mono);
    line-height: 1.2;
}

.sys-metric-value.ok       { color: var(--status-ok-text); }
.sys-metric-value.warn     { color: var(--status-warn-text); }
.sys-metric-value.error    { color: var(--status-critical-text); }

.sys-metric-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sys-action-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--border);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
}

.sys-action-row.ok    { color: var(--status-ok-text); }
.sys-action-row.warn  { color: var(--status-warn-text); }
.sys-action-row.error { color: var(--status-critical-text); }

/* ═══════════════════════════════════════════════════════
   TIMELINE BAR
   ═══════════════════════════════════════════════════════ */
.timeline-wrap {
    margin-bottom: var(--space-4);
}

.timeline-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-family: var(--font-mono);
}

.timeline-bar {
    display: flex;
    height: 14px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-elevated);
    gap: 1px;
}

.timeline-seg-online   { background: var(--status-ok);       opacity: 0.75; }
.timeline-seg-warn     { background: var(--status-warn);      opacity: 0.9; }
.timeline-seg-error    { background: var(--status-error);     opacity: 0.9; }
.timeline-seg-critical { background: var(--status-critical);  opacity: 1; }

/* ═══════════════════════════════════════════════════════
   CONNECTIVITY SUMMARY (in Verbindungs-Sektion)
   ═══════════════════════════════════════════════════════ */
.conn-verdict {
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    margin-bottom: 3px;
}

.conn-context {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
    line-height: 1.5;
}

.conn-stats-row {
    display: flex;
    gap: var(--space-5);
    flex-wrap: wrap;
    padding: var(--space-3) 0;
    border-top: 1px solid var(--border);
}

.conn-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conn-stat-value {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.conn-stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.debug-log-icon { font-size: 0.9rem; flex-shrink: 0; margin-top: 2px; }

.debug-log-label {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.debug-log-meta {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.5;
}


/* ══════════════════════════════════════════════════════════════════
   TOOLTIP-SYSTEM
   Nutzung: <span class="tip-icon" data-tip="Erklärungstext">i</span>
   Das globale JS in ui.js rendert ein einzelnes Popup-Element am <body>.
   ══════════════════════════════════════════════════════════════════ */

.tip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    font-size: 9px;
    font-style: italic;
    font-weight: 700;
    font-family: Georgia, 'Times New Roman', serif; /* 'i' immer als Serif-Kursiv */
    color: var(--text-muted);
    border: 1px solid rgba(255, 255, 255, .12);
    cursor: help;
    margin-left: 4px;
    vertical-align: middle;
    flex-shrink: 0;
    transition: color .15s, border-color .15s;
    user-select: none;
    line-height: 1;
}
.tip-icon:hover {
    color: var(--text-secondary);
    border-color: var(--text-muted);
}

/* Tooltip-Trigger für Tabellen-Header oder beliebige Elemente */
.th-tip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    cursor: help;
}

/* Das Popup — wird per JS positioniert und an <body> gehängt */
#ui-tooltip {
    position: fixed;
    z-index: 9999;
    background: #1c1e26;
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: 8px;
    padding: 9px 13px;
    font-size: 12.5px;
    font-family: var(--font-sans, system-ui, sans-serif);
    font-weight: 400;
    color: #e5e7eb;
    line-height: 1.55;
    max-width: 280px;
    white-space: normal;
    text-align: left;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .55);
    pointer-events: none;
    opacity: 0;
    transition: opacity .12s ease;
}

/* ═══════════════════════════════════════════════════════
   KLIMA-TAB (Waagendetailseite)
   ═══════════════════════════════════════════════════════ */
.kl-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
}
.kl-panel-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 var(--space-4);
}
.kl-panel-grid .kv-label { font-family: inherit; }
@media (min-width: 900px) {
    .kl-kpi-grid   { grid-template-columns: repeat(4, 1fr); }
    .kl-panel-grid { grid-template-columns: repeat(3, 1fr); }
}
