:root {
    --bg-color: #f4f6f8;
    --card-bg: #ffffff;
    --text-color: #1f2937;
    --muted-color: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --open-color: #10b981;
    --closed-color: #6b7280;
    --error-color: #ef4444;
    --border-radius: 16px;
    --box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

/* Dashboard Layout */
.dashboard-header {
    background-color: var(--card-bg);
    border-bottom: 1px solid #e5e7eb;
    padding: 20px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dashboard-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 24px;
    align-items: start;
}

/* Reusable Widget Card Base */
.widget-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 28px 24px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.widget-card:hover {
    box-shadow: 0 14px 28px -5px rgba(0, 0, 0, 0.1), 0 10px 12px -6px rgba(0, 0, 0, 0.05);
}

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.widget-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-color);
}

/* Reusable Widget Action Button / Status Pill */
.status-badge {
    position: relative;
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 18px 24px;
    border-radius: 9999px;
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 12px;
    margin-bottom: 8px;
    overflow: hidden;
    border: none;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
}

.status-badge:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.status-badge:active:not(:disabled) {
    transform: scale(0.98);
}

.status-badge:disabled {
    cursor: not-allowed;
    opacity: 0.9;
}

.status-badge-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background-color: currentColor;
    opacity: 0.18;
    border-radius: 9999px;
    pointer-events: none;
    transition: width 0.05s linear;
}

.status-icon-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    position: relative;
    flex-shrink: 0;
    z-index: 1;
}

.state-icon {
    width: 22px;
    height: 22px;
    position: absolute;
    inset: 0;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.status-badge.open .icon-open {
    opacity: 1;
    transform: scale(1);
}

.status-badge.closed .icon-closed {
    opacity: 1;
    transform: scale(1);
}

.status-badge.unknown .icon-unknown {
    opacity: 1;
    transform: scale(1);
}

/* Pulsating state icon during active operation */
.status-badge.operating .state-icon {
    opacity: 1 !important;
    transform: scale(1) !important;
    animation: pulseIcon 0.8s ease-in-out infinite alternate;
}

@keyframes pulseIcon {
    0% {
        transform: scale(0.85);
        opacity: 0.5;
    }
    100% {
        transform: scale(1.15);
        opacity: 1;
    }
}

.status-badge.open {
    background-color: rgba(16, 185, 129, 0.15);
    color: var(--open-color);
}

.status-badge.closed {
    background-color: rgba(107, 114, 128, 0.15);
    color: var(--closed-color);
}

.status-badge.unknown {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--error-color);
}

.status-text {
    position: relative;
    z-index: 1;
    display: inline-block;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.error-message {
    color: var(--error-color);
    font-size: 0.9rem;
    margin-top: 12px;
    display: none;
}

/* Photovoltaic Widget Styles */
.pv-battery-container {
    background-color: var(--bg-color);
    border-radius: 12px;
    padding: 16px;
    margin-top: 12px;
    margin-bottom: 16px;
}

.pv-battery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 10px;
}

.pv-metric-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pv-title-icon {
    width: 18px;
    height: 18px;
    color: var(--muted-color);
    flex-shrink: 0;
}

.pv-battery-bar-bg {
    height: 18px;
    background-color: #e5e7eb;
    border-radius: 9999px;
    position: relative;
    display: flex;
    align-items: center;
    overflow: hidden;
}

.pv-battery-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 9999px;
    background-color: var(--open-color);
    transition: width 0.5s ease, background-color 0.5s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* Vertical Black Line indicating lowest battery discharge limit */
.pv-battery-min-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1.5px;
    background-color: #000000;
    z-index: 2;
    display: none;
    border-radius: 1px;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
    transition: left 0.5s ease;
}

/* Discharging Arrows (INSIDE right edge of fill bar, Red, pointing Left) */
.battery-arrow-inside {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    align-items: center;
    color: #b91c1c;
    z-index: 3;
}

/* Charging Arrows (OUTSIDE right edge of fill bar, Green, pointing Right) */
.battery-arrow-outside {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    align-items: center;
    margin-left: 4px;
    color: #059669;
    transition: left 0.5s ease;
    z-index: 3;
}

.battery-arrow-inside.active,
.battery-arrow-outside.active {
    display: flex;
    animation: arrowBlink 1.2s ease-in-out infinite alternate;
}

.arrow-icon-svg {
    width: 14px;
    height: 14px;
}

@keyframes arrowBlink {
    0% {
        opacity: 0.35;
    }
    100% {
        opacity: 1;
    }
}

.pv-battery-subtext {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--muted-color);
    margin-top: 8px;
}

.pv-metrics-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pv-metric-item {
    background-color: var(--bg-color);
    border-radius: 12px;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
}

.pv-metric-item:hover {
    background-color: #eef2f6;
}

.pv-metric-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.95rem;
}

.pv-metric-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pv-metric-chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
    color: var(--muted-color);
}

.pv-metric-item.expanded .pv-metric-chevron {
    transform: rotate(180deg);
}

.pv-phase-breakdown {
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #d1d5db;
    font-size: 0.85rem;
    color: var(--muted-color);
}

.pv-metric-item.expanded .pv-phase-breakdown {
    display: grid;
}

.pv-phase-tag {
    background-color: var(--card-bg);
    border-radius: 6px;
    padding: 4px 8px;
    text-align: center;
    font-weight: 500;
}

/* Vertical Double Arrow for Main Summary Rows */
.pv-row-arrow {
    width: 14px;
    height: 14px;
    margin-right: 4px;
    vertical-align: middle;
    display: inline-block;
}

.pv-row-arrow.pv-arrow-up {
    color: #059669;
}

.pv-row-arrow.pv-arrow-down {
    color: #b91c1c;
}

.pv-smallest-date {
    font-size: 0.78rem;
    color: var(--muted-color);
    text-align: right;
    margin-top: 12px;
}


