/* ==========================================
   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 {
    /* 3-column grid (name | bar | arrow) shared across every row via the
       items' display:contents, so all bars line up in one column and the
       names right-justify up to it. The name column sizes to the longest
       label (max-content), pushing the bar + charge/discharge arrow right
       for long names. */
    display: grid;
    grid-template-columns: max-content auto auto;
    align-items: center;
    justify-content: center;
    column-gap: 0.35rem;
    row-gap: 2px;
}

.nav-bms-item {
    display: contents;   /* arrow/name/bar become cells of the .nav-bms grid */
    text-decoration: none;
}

.nav-bms-arrow {
    font-size: 0.5rem;
    width: 0.5rem;
    text-align: center;
    line-height: 1;
}

.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;
    text-align: right;
    white-space: nowrap;
    line-height: 1;
    text-decoration: none;
}

.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-bat-iv {
    font-size: 0.65rem;
    color: #888;
    margin-left: 6px;
    white-space: nowrap;
}

.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;
    }

    /* ===== App-like dark theme (mobile only) =====
       Below 768px the dashboard adopts the Android app's Material3
       dark look: dark ground, compact two-line battery cards. Desktop
       (>768px) is untouched — these rules live entirely inside this
       media query. */
    body.subpage {
        background: #141821;
        color: #E6E1E5;
    }
    .hero {
        background: transparent;
        padding: 1rem 1rem 0.25rem;
        box-shadow: none;
    }
    .hero h1 {
        color: #E6E1E5;
        font-size: 1.5rem;
        margin: 0;
    }
    .bms-section {
        padding: 0 0.75rem 1rem;
    }
    .bms-status-message {
        color: #9aa0aa;
    }

    /* Parent flex-wrap centers + shrink-wraps its children by default
       (align-items:center). On mobile we want the card stack to fill
       the viewport, so stretch it. Without this the cards collapse to
       content width and the flex:1 SOC bar gets ~no space → renders as
       a vertical sliver. */
    .bms-table-wrap {
        align-items: stretch;
    }
    .bms-cards {
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }
    .app-card {
        width: 100%;
        box-sizing: border-box;
        background: #1f2330;
        border-radius: 12px;
        padding: 13px 15px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: background 0.12s;
    }
    .app-card:active {
        background: #262b3a;
    }
    .app-card-head {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 6px;
    }
    .app-card-title {
        font-weight: 600;
        font-size: 15px;
        color: #E6E1E5;
        margin-right: auto;
    }
    .app-card-tags {
        display: inline-flex;
        flex-wrap: wrap;
        gap: 4px;
        align-items: center;
    }
    .app-card-row {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-top: 9px;
    }
    .app-card-va {
        font-size: 14px;
        color: #E6E1E5;
        white-space: nowrap;
        font-variant-numeric: tabular-nums;
    }
    .app-card-va small,
    .app-card-w small {
        font-size: 11px;
        color: #9aa0aa;
        margin-left: 1px;
    }
    .app-card-socwrap {
        flex: 1 1 auto;
        min-width: 0;
    }
    .app-card-socwrap .bms-soc-wrap {
        width: 100%;
        gap: 8px;
    }
    .app-card-socwrap .bms-soc-bar {
        flex: 1 1 auto;
        width: auto;        /* override the fixed 60px mobile width */
        min-width: 0;
        height: 16px;
    }
    .app-card-socwrap .bms-soc-pct {
        flex: 0 0 auto;
        font-size: 0.85rem;
        color: #E6E1E5;
    }
    .app-card-w {
        font-size: 14px;
        color: #E6E1E5;
        white-space: nowrap;
        font-variant-numeric: tabular-nums;
        min-width: 48px;
        text-align: right;
    }
    .app-card-muted {
        color: #9aa0aa;
        font-size: 13px;
    }
}

/* ===== Banks (VPDs) + shunts ===== */
.bms-bank-row > td { background: rgba(109, 76, 168, 0.10); font-weight: 600; }
.bms-bank-row > td:first-child { border-left: 3px solid #6d4ca8; }
.bank-caret { cursor: pointer; color: #6d4ca8; font-weight: 700; user-select: none; }
.bank-caret:hover { opacity: 0.65; }
.dev-icon { width: 14px; height: 14px; vertical-align: -2px; margin-right: 5px; }
.bms-bank-members { font-weight: 400; font-size: 0.78rem; color: #6d4ca8; margin-top: 2px; }
.bms-member > td:first-child { padding-left: 2.2rem; border-left: 3px solid #6d4ca8; }
.bms-member > td:first-child::before { content: "\21B3  "; color: #6d4ca8; font-weight: 700; }
.bms-member > td { background: rgba(109, 76, 168, 0.06); }
.bms-badge-bank   { background: #6d4ca8; color: #fff; }
.bms-badge-source { background: #34495e; color: #fff; }
.bms-badge-shunt  { background: #138d75; color: #fff; }
.bms-badge-info   { background: #d7dbe0; color: #2c3340; }
/* Mobile cards: bank gets a colored spine, members indent under it. */
.app-card-bank   { border-left: 3px solid #6d4ca8; }
.app-card-member { margin-left: 1.25rem; border-left: 2px solid #6d4ca8; }
.app-card-members { font-size: 0.8rem; color: #b9a3e0; padding: 0 14px 8px; }
.bank-rename { text-decoration: none; margin-left: 6px; opacity: 0.55; cursor: pointer; font-weight: 400; }
.bank-rename:hover { opacity: 1; }
