/* ==========================================
   EasyBMS Dashboard - Styles
   ========================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --text-dark: #2c3e50;
    --text-light: #ecf0f1;
    --bg-light: #f8f9fa;
    --bg-dark: #1e1e1e;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-dark);
}

body.subpage {
    background: var(--bg-light);
}

/* ==========================================
   Header & Navigation
   ========================================== */

header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--text-light);
    padding: 1rem 0;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

nav {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
}

.logo a {
    font-size: 1.8rem;
    font-weight: bold;
    letter-spacing: 2px;
    color: var(--text-light);
    text-decoration: none;
}

/* Nav Indicator Container (BMS status) */

.nav-indicators {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    margin-left: 1rem;
    margin-right: auto;
}

/* Nav BMS Status Indicators */

.nav-bms {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}

.nav-bms-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    line-height: 1;
}

.nav-bms-arrow {
    font-size: 0.5rem;
    width: 0.5rem;
    text-align: center;
    margin-right: -0.3rem;
}

.nav-bms-arrow-up {
    color: #2ecc71;
}

.nav-bms-arrow-down {
    color: #e74c3c;
}

.nav-bms-mac {
    color: rgba(255,255,255,0.7);
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    width: 2.2rem;
    text-align: right;
}

.nav-bms-bar {
    display: inline-block;
    width: 36px;
    height: 7px;
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    overflow: hidden;
}

.nav-bms-fill {
    display: block;
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s;
}

/* ==========================================
   Hero Section
   ========================================== */

.hero {
    background: linear-gradient(135deg, var(--bg-dark), var(--primary-color));
    color: var(--text-light);
    padding: 120px 2rem 80px;
    text-align: center;
    margin-top: 60px;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
    animation: fadeInUp 1s ease;
}

.hero p {
    font-size: 1.3rem;
    max-width: 800px;
    margin: 0 auto;
    opacity: 0.9;
    animation: fadeInUp 1s ease 0.2s both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================
   BMS Status Page
   ========================================== */

.bms-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 2rem;
}

.bms-status-message {
    text-align: center;
    font-size: 1.2rem;
    color: #888;
    padding: 2rem;
}

.bms-table-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.bms-table-container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    overflow: hidden;
}

.bms-table {
    border-collapse: collapse;
    white-space: nowrap;
}

.bms-table thead {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--text-light);
}

.bms-table th {
    padding: 1rem 2.5rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.3px;
}

.bms-table td {
    padding: 1rem 2.5rem;
    border-bottom: 1px solid #eee;
    font-size: 1rem;
}

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

.bms-table tbody tr:hover {
    background: #f0f6ff;
}

.bms-totals-row td {
    border-top: 2px solid var(--primary-color);
    border-bottom: none !important;
    font-weight: 600;
}

.bms-soc-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.bms-soc-bar {
    width: 90px;
    height: 16px;
    background: #eee;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.bms-soc-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    border-radius: 8px;
    transition: width 0.5s;
}

/* Shadow / drift-corrected SOC estimate.  Lighter version of the
 * solid fill.  Stacking is controlled by DOM order in socBar():
 *  - estimate > reported  → shadow rendered first (paints behind)
 *  - estimate < reported  → shadow rendered last  (paints in front) */
.bms-soc-shadow {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    border-radius: 8px;
    opacity: 0.45;
    transition: width 0.5s;
}

.bms-soc-pct {
    font-weight: 700;
    font-size: 0.95rem;
}

.bms-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.bms-badge-idle {
    background: #eee;
    color: #666;
}

.bms-badge-charge {
    background: #d4edda;
    color: #155724;
}

.bms-badge-discharge {
    background: #fff3cd;
    color: #856404;
}

.bms-badge-sleep {
    background: #d6d8db;
    color: #495057;
}

.bms-badge-offline {
    background: #d6d8db;
    color: #495057;
}

.bms-badge-fault {
    background: #f8d7da;
    color: #721c24;
    animation: bms-fault-pulse 2s ease-in-out infinite;
}

.bms-badge-warn {
    background: #fff3cd;
    color: #856404;
}

/* Steady-red variant — same colors as bms-badge-fault but no animation.
 * Used for diagnostic-tier alerts (Battery Report w/ caution-tier
 * findings) where the issue isn't urgent enough to warrant strobing. */
.bms-badge-fault-steady {
    background: #f8d7da;
    color: #721c24;
}

@keyframes bms-fault-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.bms-ts {
    color: #888;
    font-size: 0.85rem;
}

/* Ryobi inverter section */
.ryobi-section-title {
    text-align: center;
    font-size: 1.4rem;
    margin: 0 0 1rem 0;
    color: #333;
}

.ryobi-bats-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ryobi-bat-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ryobi-bat-name {
    font-size: 0.7rem;
    color: #666;
    width: 32px;
    text-align: right;
    flex-shrink: 0;
}

.ryobi-bat-segs {
    display: flex;
    gap: 2px;
}

.ryobi-seg {
    width: 12px;
    height: 10px;
    background: #e0e0e0;
    border-radius: 2px;
}

.ryobi-seg-on {
    transition: background 0.5s;
}

.ryobi-seg-absent {
    background: #f5f5f5;
    border: 1px dashed #ddd;
}

/* 818: 2-column battery grid */
.ryobi-bats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 12px;
}

.ryobi-model-cell {
    text-align: center;
    vertical-align: middle;
}

.ryobi-model-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 4px;
}

.ryobi-card-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    vertical-align: middle;
    margin-right: 6px;
    border-radius: 3px;
}

.ryobi-1000-bat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 120px;
}

.ryobi-1000-detail {
    font-size: 0.8em;
    color: #aaa;
    white-space: nowrap;
}

/* Mobile BMS cards (hidden on desktop) */
.bms-cards {
    display: none;
}

/* BMS detail page charts */
.bms-detail-section {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.bms-charts {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.bms-chart-box {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    padding: 1rem 1.2rem;
}

.bms-chart-box h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    color: #333;
}

.bms-chart-box canvas {
    width: 100% !important;
    height: 200px !important;
}

.bms-card-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.bms-card-table td,
.bms-card-table th {
    padding: 8px 12px;
    border: 1px solid #ddd;
}

.bms-card-header {
    background: var(--bg-dark, #2c3e50);
    color: #fff;
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    padding: 10px 12px;
}

.bms-card-label {
    width: 33%;
    font-weight: 600;
    color: #666;
}

.bms-card-footer {
    text-align: center;
    padding: 10px 12px;
    border-bottom: none;
}

.bms-updated {
    text-align: center;
    font-size: 0.85rem;
    color: #999;
    margin-top: 1.5rem;
}

/* ==========================================
   Footer
   ========================================== */

footer {
    background: var(--bg-dark);
    color: var(--text-light);
    text-align: center;
    padding: 2rem;
}

/* ==========================================
   Responsive Design
   ========================================== */

@media (max-width: 768px) {
    .nav-indicators {
        display: none;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .hero p {
        font-size: 1.1rem;
    }

    .bms-soc-bar {
        width: 60px;
    }

    .bms-table-container {
        display: none;
    }

    .bms-totals-row {
        display: none;
    }

    .bms-cards {
        display: block;
    }
}
