/* ─── Reset & Base ─────────────────────────────────────────── */
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    touch-action: manipulation;
}
body {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    background: #F1F5F9;
    color: var(--navy);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ─── Page Wrapper ──────────────────────────────────────────── */
.page-wrapper {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px 40px;
}

/* ─── Nav ───────────────────────────────────────────────────── */
nav.topbar {
    background: var(--navy);
    height: 56px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    gap: 16px;
}
.brand {
    color: var(--white);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.3px;
    text-decoration: none;
    white-space: nowrap;
}
.brand span { color: var(--teal); }
.nav-links-row {
    display: flex;
    align-items: center;
    gap: 4px;
}
.nav-links {
    color: rgba(255,255,255,0.75);
    font-size: 13px;
    text-decoration: none;
    margin-left: 20px;
    white-space: nowrap;
    transition: opacity 100ms;
}
.nav-links:hover { color: var(--white); }
.nav-badge {
    display: inline-block;
    background: var(--teal);
    color: var(--white);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    margin-left: 6px;
    font-weight: 600;
}
.nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

/* ─── Page Header ───────────────────────────────────────────── */
.page-header {
    padding: 28px 0 20px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-end;
}
.page-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--navy);
    margin: 0;
}
.page-subtitle {
    color: var(--slate);
    font-size: 13px;
    margin-top: 4px;
}

/* ─── Summary Cards ─────────────────────────────────────────── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.summary-card {
    background: var(--white);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 20px 24px;
    cursor: pointer;
    transition: transform 100ms, box-shadow 100ms;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    min-height: 44px;
    -webkit-user-select: none;
    user-select: none;
    overflow: hidden;
}
.summary-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.10);
}
.summary-card.active {
    border-width: 2px;
}
.card-total.active  { border-color: var(--teal);  background: var(--teal-light); }
.card-ok.active     { border-color: var(--ok);    background: var(--ok-bg); }
.card-warning.active{ border-color: var(--warn);  background: var(--warn-bg); }
.card-replace.active{ border-color: var(--rep);   background: var(--rep-bg); }
.card-number {
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 6px;
}
.card-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--slate);
}
.card-icon {
    float: right;
    font-size: 28px;
    opacity: 0.15;
}

/* ─── Filter Bar ────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 16px;
    background: var(--white);
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
}
.filter-label {
    color: var(--slate);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}
.filter-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.filter-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--white);
    cursor: pointer;
    font-size: 13px;
    transition: all 100ms;
    color: var(--slate);
    min-height: 44px;
    font-family: inherit;
}
.filter-btn:hover { border-color: var(--teal); color: var(--teal); }
.filter-btn.active { background: var(--teal); color: var(--white); border-color: var(--teal); }
.search-wrapper {
    position: relative;
    width: 180px;
}
.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--slate-light);
    font-size: 14px;
    pointer-events: none;
}
.search-input {
    padding: 6px 12px 6px 32px;
    border-radius: 20px;
    border: 1px solid var(--border);
    font-size: 13px;
    outline: none;
    width: 100%;
    font-family: inherit;
    transition: border-color 100ms;
}
.search-input:focus { border-color: var(--teal); }

/* ─── Table Section ─────────────────────────────────────────── */
.table-section {
    background: var(--white);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.table-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.table-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--navy);
}
.refresh-indicator {
    font-size: 12px;
    color: var(--slate-light);
    display: flex;
    align-items: center;
    gap: 6px;
}
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--teal);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}
table {
    width: 100%;
    border-collapse: collapse;
}
thead th {
    background: var(--navy);
    color: var(--white);
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-align: left;
    white-space: nowrap;
}
tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 150ms;
    cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { filter: brightness(0.96); }
tbody td {
    padding: 11px 16px;
    vertical-align: middle;
}
.battery-id-cell {
    font-weight: 600;
    color: var(--teal);
    font-size: 13px;
}
.voltage-badge {
    font-size: 11px;
    color: var(--slate);
    background: #F1F5F9;
    padding: 2px 8px;
    border-radius: 10px;
}
tr.row-ok      { background: var(--ok-bg); }
tr.row-warning { background: var(--warn-bg); }
tr.row-replace { background: var(--rep-bg); }

/* ─── Status Badges ─────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-ok      { background: var(--ok-bg);   color: var(--ok);   border: 1px solid var(--ok-border); }
.badge-warning { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-border); }
.badge-replace { background: var(--rep-bg);  color: var(--rep);  border: 1px solid var(--rep-border); }
.badge-icon { font-size: 11px; }

/* ─── Ratio Bar ─────────────────────────────────────────────── */
.ratio-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 90px;
}
.ratio-bar-bg {
    flex: 1;
    height: 4px;
    background: #E2E8F0;
    border-radius: 2px;
    overflow: hidden;
}
.ratio-bar-fill {
    height: 4px;
    border-radius: 2px;
}
.ratio-text {
    font-size: 12px;
    color: var(--slate);
    min-width: 35px;
}

/* ─── Battery Detail ────────────────────────────────────────── */
.detail-header {
    background: var(--white);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}
.detail-meta {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 16px;
}
.readings-table-wrapper {
    background: var(--white);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}
.back-link {
    color: var(--teal);
    text-decoration: none;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
    min-height: 44px;
}
.back-link:hover { text-decoration: underline; }

/* ─── Empty State ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--slate);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }

/* ─── Footer ────────────────────────────────────────────────── */
footer {
    text-align: center;
    padding: 1.25rem;
    color: var(--slate);
    font-size: 12px;
    border-top: 1px solid var(--border);
    background: var(--white);
    margin-top: auto;
}

/* ─── Links ─────────────────────────────────────────────────── */
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Animation ─────────────────────────────────────────────── */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

/* ─── Touch / Hover improvements ───────────────────────────── */
@media (hover: none) {
    .summary-card:hover {
        transform: none;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    }
    tbody tr:hover { filter: none; }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Tablet  (≤960px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 960px) {
    nav.topbar { padding: 0 16px; height: 52px; }
    .page-wrapper { padding: 0 16px 32px; }
    .cards-grid { grid-template-columns: repeat(2, 1fr); }
    .detail-meta { grid-template-columns: repeat(2, 1fr); }

    /* Hide Current (A) column — 4th col */
    thead th:nth-child(4),
    tbody td:nth-child(4) { display: none; }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Mobile  (≤640px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
    /* Nav stacks */
    nav.topbar {
        height: auto;
        flex-direction: column;
        align-items: flex-start;
        padding: 14px 16px;
        gap: 8px;
    }
    .nav-links-row { flex-wrap: wrap; gap: 0; }
    .nav-right { display: none; }

    .page-wrapper { padding: 0 12px 24px; }

    .page-header {
        flex-direction: column;
        gap: 12px;
        padding: 16px 0 14px;
    }
    .page-title { font-size: 18px; }

    /* Cards: 2 columns, smaller */
    .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .summary-card { padding: 14px 16px; }
    .card-number  { font-size: 28px; }
    .card-icon    { font-size: 20px; }

    /* Filter bar stacks */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 12px;
    }
    .filter-btn { padding: 7px 12px; font-size: 12px; }
    .search-wrapper { width: 100%; }
    .search-input   { width: 100%; }

    /* Table header */
    .table-header {
        flex-direction: column;
        gap: 4px;
        padding: 12px 14px;
        align-items: flex-start;
    }
    .table-title      { font-size: 14px; }
    .refresh-indicator{ font-size: 11px; }

    /* Card-style table rows on mobile */
    table, thead, tbody, th, td, tr { display: block; }
    thead tr { display: none; }
    tbody tr {
        margin-bottom: 12px;
        border-radius: 10px;
        border: 1px solid var(--border);
        padding: 14px 16px;
        display: flex;
        flex-direction: column;
        gap: 6px;
        cursor: pointer;
    }
    tbody tr.row-ok      { border-left: 4px solid var(--ok); }
    tbody tr.row-warning { border-left: 4px solid var(--warn); }
    tbody tr.row-replace { border-left: 4px solid var(--rep); }

    /* Hide Current column on mobile too */
    tbody td:nth-child(4) { display: none; }

    /* data-label before each cell */
    td::before {
        content: attr(data-label);
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--slate-light);
        font-weight: 600;
        display: block;
        margin-bottom: 1px;
    }
    /* Battery ID cell — no label, prominent */
    td:first-child {
        font-size: 16px;
        font-weight: 700;
        border-bottom: 1px solid var(--border);
        padding-bottom: 8px;
        margin-bottom: 4px;
    }
    td:first-child::before { display: none; }

    /* Hide ratio bar on mobile */
    .ratio-bar-bg { display: none; }

    /* Detail page */
    .detail-header { padding: 16px; }
    .detail-meta   { grid-template-columns: repeat(2, 1fr); gap: 12px; }

    /* Detail readings table — same card approach */
    .readings-table-wrapper table,
    .readings-table-wrapper thead,
    .readings-table-wrapper tbody,
    .readings-table-wrapper th,
    .readings-table-wrapper td,
    .readings-table-wrapper tr { display: block; }
    .readings-table-wrapper thead tr { display: none; }
    .readings-table-wrapper tbody tr {
        margin-bottom: 10px;
        border-radius: 8px;
        border: 1px solid var(--border);
        padding: 12px 14px;
        display: flex;
        flex-direction: column;
        gap: 4px;
    }
    /* Hide # (counter) column and Current on detail mobile */
    /* Column layout: 1=# 2=Timestamp 3=Battery 4=Voltage 5=Current 6=Temp 7=Ratio 8=Status */
    .readings-table-wrapper td:nth-child(1),
    .readings-table-wrapper td:nth-child(5) { display: none; }
    /* Ensure Voltage (col 4) stays visible — overrides the global td:nth-child(4) hide */
    .readings-table-wrapper td:nth-child(4) { display: flex; }
}

/* ═══════════════════════════════════════════════════════════
   FEATURE 1 — IDENTITY CARD
   ═══════════════════════════════════════════════════════════ */

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--slate);
    padding: 16px 0 12px;
}
.breadcrumb a { color: var(--teal); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--slate-light); }
.breadcrumb-current { color: var(--navy); font-weight: 500; }

/* Identity Card */
.identity-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.identity-strip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}
.identity-strip-ok      { background: var(--ok-bg); }
.identity-strip-warning { background: var(--warn-bg); }
.identity-strip-replace { background: var(--rep-bg); }
.identity-strip-unknown { background: var(--surface); }
.identity-id {
    font-size: 22px;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: -0.3px;
}
.identity-serial {
    display: block;
    font-size: 11px;
    color: var(--slate);
    margin-top: 2px;
    font-family: monospace;
    letter-spacing: 0.05em;
}
.identity-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
}
.identity-field {
    padding: 14px 20px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.identity-field:nth-child(3n)      { border-right: none; }
.identity-field:nth-last-child(-n+3) { border-bottom: none; }
.identity-label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--slate-light);
    font-weight: 600;
    margin-bottom: 4px;
}
.identity-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--navy);
}
.identity-notes {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.identity-notes-text {
    font-size: 13px;
    color: var(--slate);
    margin-top: 6px;
    line-height: 1.6;
}

/* Live Stats Row */
.live-stats-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.live-stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
}
.live-stat-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--slate-light);
    font-weight: 600;
    margin-bottom: 8px;
}
.live-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--navy);
    line-height: 1;
    margin-bottom: 6px;
}
.live-stat-unit {
    font-size: 13px;
    font-weight: 400;
    color: var(--slate);
    margin-left: 2px;
}
.live-stat-sub { font-size: 11px; color: var(--slate-light); }

/* Traceability Badge */
.trace-badge {
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
}
.trace-id {
    font-size: 12px;
    font-weight: 700;
    color: var(--teal);
    font-family: monospace;
    letter-spacing: 0.05em;
}
.trace-sn {
    font-size: 10px;
    color: var(--slate-light);
    background: var(--surface);
    padding: 1px 5px;
    border-radius: 3px;
}

/* Table subtitle */
.table-subtitle {
    display: block;
    font-size: 12px;
    color: var(--slate-light);
    margin-top: 3px;
}

/* Print button */
.btn-print {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    background: var(--navy);
    color: var(--white);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: background 120ms;
}
.btn-print:hover { background: var(--navy-mid); text-decoration: none; }

/* ── Responsive: identity card + live stats ── */
@media (max-width: 960px) {
    .live-stats-row { grid-template-columns: repeat(3, 1fr); }
    .identity-grid  { grid-template-columns: repeat(2, 1fr); }
    .identity-field:nth-child(3n)  { border-right: 1px solid var(--border); }
    .identity-field:nth-child(2n)  { border-right: none; }
    /* Detail table: hide Current (col 5), keep Voltage (col 4) visible */
    .readings-table-wrapper thead th:nth-child(5),
    .readings-table-wrapper tbody td:nth-child(5) { display: none; }
    .readings-table-wrapper thead th:nth-child(4),
    .readings-table-wrapper tbody td:nth-child(4) { display: table-cell; }
}
@media (max-width: 640px) {
    .live-stats-row { grid-template-columns: repeat(2, 1fr); }
    .identity-grid  { grid-template-columns: 1fr; }
    .identity-field { border-right: none; border-bottom: 1px solid var(--border); }
    .identity-field:nth-last-child(-n+3) { border-bottom: 1px solid var(--border); }
    .identity-field:last-child { border-bottom: none; }
    .identity-strip { flex-direction: column; align-items: flex-start; gap: 10px; }
    .identity-id    { font-size: 18px; }
}
