/* ============================================================
   overview_v2.css - Dashboard v2 (parallel zum alten Stack)
   Seitenspezifische Klassen verwenden das v2-Praefix.
   Setzt theme_v2.css voraus (CSS-Variablen --v2-*).
   ============================================================ */

* {
    box-sizing: border-box;
}

html {
    transition: background-color 0.2s ease, color 0.2s ease;
}

.v2-body {
    margin: 0;
    padding: 0;
    background: var(--v2-bg-primary);
    color: var(--v2-text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 Oxygen, Ubuntu, sans-serif;
    min-height: 100vh;
}

/* --- Header --- */

.v2-header {
    background: var(--v2-bg-secondary);
    border-bottom: 1px solid var(--v2-border);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.v2-header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.v2-header-title h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--v2-text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.v2-badge {
    font-size: 0.65rem;
    background: var(--v2-accent);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.05em;
}
.v2-subtitle {
    font-size: 0.82rem;
    color: var(--v2-text-secondary);
    margin-top: 2px;
}

.v2-header-stats {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    flex: 1 1 auto;
    justify-content: center;
}

.v2-stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: var(--v2-bg-elevated);
    border: 1px solid var(--v2-border);
    font-size: 0.88rem;
    color: var(--v2-text-secondary);
    white-space: nowrap;
}
.v2-stat-pill strong {
    color: var(--v2-text-primary);
    font-weight: 700;
}
.v2-stat-pill.v2-stat-online        { color: var(--v2-status-ok); }
.v2-stat-pill.v2-stat-online strong { color: var(--v2-status-ok); }
.v2-stat-pill.v2-stat-warning        { color: var(--v2-status-warning); }
.v2-stat-pill.v2-stat-warning strong { color: var(--v2-status-warning); }
.v2-stat-pill.v2-stat-offline        { color: var(--v2-status-critical); }
.v2-stat-pill.v2-stat-offline strong { color: var(--v2-status-critical); }
.v2-stat-pill.v2-stat-time           { color: var(--v2-text-muted); }

.v2-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Buttons --- */

.v2-btn,
.v2-theme-toggle {
    background: transparent;
    border: 1px solid var(--v2-border);
    color: var(--v2-text-primary);
    border-radius: 8px;
    padding: 0.5rem 0.85rem;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: inherit;
    transition: all 0.15s ease;
}
.v2-btn:hover,
.v2-theme-toggle:hover {
    background: var(--v2-bg-hover);
    border-color: var(--v2-border-strong);
}
.v2-btn-primary {
    background: var(--v2-accent);
    border-color: var(--v2-accent);
    color: white;
}
.v2-btn-primary:hover {
    background: var(--v2-accent-light);
    border-color: var(--v2-accent-light);
}

.v2-theme-toggle .v2-icon-sun  { display: none; }
.v2-theme-toggle .v2-icon-moon { display: inline; }
[data-theme="light"] .v2-theme-toggle .v2-icon-sun  { display: inline; }
[data-theme="light"] .v2-theme-toggle .v2-icon-moon { display: none; }

@media (max-width: 768px) {
    .v2-header { padding: 1rem; }
    .v2-header-content { flex-direction: column; align-items: stretch; }
    .v2-header-stats { justify-content: center; }
    .v2-btn-label { display: none; }
}

/* --- Container --- */

.v2-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
}

@media (max-width: 768px) {
    .v2-container { padding: 1rem; }
}

/* --- Locations Grid --- */

.v2-locations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 350px), 1fr));
    gap: 1.1rem;
    align-items: stretch;
}

/* --- Location Card --- */

.v2-location-card {
    background: var(--v2-bg-card);
    border: 1px solid var(--v2-border);
    border-radius: 14px;
    padding: 1.05rem;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease,
                box-shadow 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    box-shadow: var(--v2-shadow-card);
    height: 100%;
}
.v2-location-card:hover {
    transform: translateY(-2px);
    border-color: var(--v2-accent);
    box-shadow: var(--v2-shadow-hover);
}

/* Kompakter Kartenkopf ohne reservierte Leerzeile. */
.v2-location-card-header {
    min-height: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}
.v2-location-card-title {
    flex: 1;
    min-width: 0;
}
.v2-location-card-title h3 {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.3;
    color: var(--v2-text-primary);
    overflow-wrap: break-word;
    word-break: break-word;
}
.v2-location-card-title .v2-city {
    max-width: 100%;
    margin-top: 0.18rem;
    font-size: 0.95rem;
    line-height: 1.35;
    font-weight: 600;
    color: var(--v2-text-secondary);
    overflow-wrap: anywhere;
}

/* Status-Badge */
.v2-location-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}
.v2-location-status .v2-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: currentColor;
}
.v2-location-status.ok       { background: var(--v2-status-ok-bg);       color: var(--v2-status-ok); }
.v2-location-status.warning  { background: var(--v2-status-warning-bg);  color: var(--v2-status-warning); }
.v2-location-status.critical { background: var(--v2-status-critical-bg); color: var(--v2-status-critical); }
.v2-location-status.offline  { background: var(--v2-status-offline-bg);  color: var(--v2-status-offline); }

/* --- Werte-Grid: 4 Werte in fester Reihenfolge --- */

.v2-location-values {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}
.v2-value-tile {
    min-width: 0;
    background: var(--v2-bg-elevated);
    border: 1px solid var(--v2-border);
    border-radius: 10px;
    padding: 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 80px;
}
.v2-value-tile-label {
    font-size: 0.78rem;
    color: var(--v2-text-secondary);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 550;
    white-space: nowrap;
}
.v2-value-tile-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--v2-text-primary);
    line-height: 1.1;
}
.v2-value-tile-value .v2-unit {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--v2-text-muted);
    margin-left: 0.25rem;
}
.v2-value-tile-value.v2-is-empty {
    color: var(--v2-text-muted);
}

/* --- Footer der Karte --- */

.v2-location-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.75rem;
    border-top: 1px solid var(--v2-divider);
    font-size: 0.82rem;
    color: var(--v2-text-muted);
    margin-top: auto;   /* drueckt Footer ans untere Ende der Karte */
}
.v2-container-count {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.v2-btn-hmi {
    background: var(--v2-accent-soft);
    border: 1px solid var(--v2-accent);
    color: var(--v2-accent-light);
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s ease;
}
.v2-btn-hmi:hover {
    background: var(--v2-accent);
    color: white;
}

/* --- Loading Spinner --- */

.v2-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4rem 2rem;
}
.v2-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--v2-border);
    border-top-color: var(--v2-accent);
    border-radius: 50%;
    animation: v2-spin 0.8s linear infinite;
}
@keyframes v2-spin { to { transform: rotate(360deg); } }

/* Klickbare Wert-Kachel (oeffnet Verlaufs-Modal auf der Detail-Seite) */

.v2-value-tile.v2-tile-clickable {
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.v2-value-tile.v2-tile-clickable:hover {
    border-color: var(--v2-accent);
    background: var(--v2-bg-hover);
}

/* --- Statuspunkte, lokale SVG-Symbole und Auto-Refresh --- */
.v2-icon {
    display: inline-block;
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 auto;
    fill: currentColor;
    vertical-align: middle;
}
.v2-icon-sun,
.v2-icon-moon,
.v2-icon-btn > span {
    display: inline-flex;
}
.v2-theme-toggle .v2-icon-sun { display: none; }
.v2-theme-toggle .v2-icon-moon { display: inline-flex; }
[data-theme="light"] .v2-theme-toggle .v2-icon-sun { display: inline-flex; }
[data-theme="light"] .v2-theme-toggle .v2-icon-moon { display: none; }
.v2-theme-toggle,
.v2-icon-btn {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    justify-content: center;
}
.v2-refresh-status {
    color: var(--v2-text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
}
.v2-refresh-status.loading { color: var(--v2-accent-light); }
.v2-refresh-status.error { color: var(--v2-status-warning); }
.v2-status-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.v2-status-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    flex: 0 0 9px;
    border-radius: 50%;
    background: var(--v2-status-offline);
}
.v2-status-dot.ok { background: var(--v2-status-ok); }
.v2-status-dot.warning { background: var(--v2-status-warning); }
.v2-status-dot.critical { background: var(--v2-status-critical); }
.v2-status-dot.offline { background: var(--v2-status-offline); }
.v2-status-dot.unknown {
    border: 2px solid var(--v2-status-offline);
    background: transparent;
}
.v2-location-status.unknown {
    background: var(--v2-status-offline-bg);
    color: var(--v2-status-offline);
}
.v2-stat-pill.v2-stat-ok,
.v2-stat-pill.v2-stat-ok strong { color: var(--v2-status-ok); }
.v2-stat-pill.v2-stat-critical,
.v2-stat-pill.v2-stat-critical strong { color: var(--v2-status-critical); }
.v2-stat-pill.v2-stat-unknown,
.v2-stat-pill.v2-stat-unknown strong { color: var(--v2-status-offline); }
.v2-stat-pill.v2-stat-offline,
.v2-stat-pill.v2-stat-offline strong { color: var(--v2-status-offline); }
.v2-location-card-header {
    align-items: center;
    flex-wrap: nowrap;
}
.v2-location-status {
    border: 0;
}
button.v2-value-tile {
    width: 100%;
    color: inherit;
    font: inherit;
    text-align: left;
}
.v2-value-tile-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.v2-metric-heat .v2-icon { color: #e9b840; }
.v2-metric-temp .v2-icon { color: #ff727b; }
.v2-metric-temp span { white-space:normal; overflow-wrap:break-word; hyphens:auto; min-width:0; }
.v2-metric-storage .v2-icon { color: #6ba7ff; }
.v2-metric-electric .v2-icon { color: #6bd4e2; }
[data-theme="light"] .v2-metric-heat .v2-icon { color: #946700; }
[data-theme="light"] .v2-metric-temp .v2-icon { color: #b62232; }
[data-theme="light"] .v2-metric-storage .v2-icon { color: #235ab1; }
[data-theme="light"] .v2-metric-electric .v2-icon { color: #087589; }
.v2-empty-grid {
    grid-column: 1 / -1;
    padding: 2rem;
    color: var(--v2-text-secondary);
    text-align: center;
}

@media (max-width: 768px) {
    .v2-header-content {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 0.65rem;
    }
    .v2-header-title {
        min-width: 0;
    }
    .v2-header-title h1,
    .v2-header-title .v2-subtitle {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .v2-header-actions {
        grid-column: 2;
        grid-row: 1;
    }
    .v2-header-stats {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    .v2-stat-pill {
        padding: 0.3rem 0.55rem;
        font-size: 0.78rem;
    }
    .v2-refresh-label {
        display: none;
    }
    .v2-location-card-title h3,
    .v2-location-card-title .v2-city {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

@media (max-width: 390px) {
    .v2-header { padding: 0.75rem; }
    .v2-container { padding: 0.75rem; }
    .v2-header-title h1 { font-size: 1rem; }
    .v2-subtitle { font-size: 0.72rem; }
    .v2-header-actions { gap: 0.25rem; }
    .v2-theme-toggle,
    .v2-icon-btn {
        width: 2.25rem;
        height: 2.25rem;
        flex-basis: 2.25rem;
    }
    .v2-location-card {
        padding: 0.8rem;
        gap: 0.75rem;
    }
    .v2-location-card-header { gap: 0.5rem; }
    .v2-location-card-title h3 { font-size: 0.92rem; }
    .v2-location-card-title .v2-city { font-size: 0.78rem; }
    .v2-location-status {
        gap: 0.35rem;
        padding: 0.3rem 0.5rem;
        font-size: 0.74rem;
    }
    .v2-status-dots { gap: 3px; }
    .v2-status-dot {
        width: 8px;
        height: 8px;
        flex-basis: 8px;
    }
    .v2-location-values { gap: 0.5rem; }
    .v2-value-tile {
        min-height: 74px;
        padding: 0.65rem;
    }
    .v2-value-tile-label {
        font-size: 0.68rem;
        letter-spacing: 0;
        text-transform: none;
    }
    .v2-value-tile-value { font-size: 1.25rem; }
}
