/* Giao diện chung của ba trang thiết bị: Inverter, Power Meter, Weather Station.

   Để ở file toàn cục chứ không phải CSS scoped của từng component vì hai lý do:
   1. Badge trạng thái được dựng bằng RenderTreeBuilder rồi render bên trong TableCommon, nên
      nó KHÔNG mang scope-id của component gọi — CSS scoped sẽ không khớp.
   2. Ba component dùng chung y hệt bộ lớp này; CSS isolation không chia sẻ được giữa các
      component nên viết một chỗ là đủ.

   Mọi màu lấy từ biến theme trong app.css để chạy đúng ở cả chế độ tối lẫn sáng. */

.device-page {
    width: 100%;
    min-height: 100vh;
    padding: 24px;
    box-sizing: border-box;
}

.device-list {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
    box-sizing: border-box;
}

/* Dãy thẻ tổng quan phía trên bảng. Tự xuống hàng ở màn hẹp thay vì ép 4 cột. */
.device-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    width: 100%;
}

/* Bảng thiết bị hiện mọi thông số nên rất nhiều cột: chính bảng cuộn ngang (TableCommon
   ScrollX="true"), khung này chỉ giữ cho trang không bị đẩy rộng ra. min-width: 0 vì khung
   nằm trong flex cột — thiếu nó thì bảng max-content nong cả trang. */
.device-table-wrap {
    width: 100%;
    min-width: 0;
    overflow-x: auto;
}

.device-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.device-section-title {
    font-family: "Poppins", sans-serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.device-section-subtitle {
    font-family: "Poppins", sans-serif;
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

/* Ghi chú phạm vi — dùng ở trang Weather Station để nói rõ đây là thiết bị cấp nhà máy,
   tránh hiểu nhầm là trạm riêng của project vừa bấm sang. */
.device-scope-note {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-family: "Poppins", sans-serif;
    font-size: 13px;
}

.device-empty {
    padding: 24px;
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-family: "Poppins", sans-serif;
    font-size: 14px;
    text-align: center;
}

/* Liên kết phụ trên header, ví dụ "Inverter Intelligence →" */
.device-link-action {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: "Poppins", sans-serif;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background .18s ease, border-color .18s ease;
}

.device-link-action:hover {
    background: var(--bg-hover);
    border-color: var(--border-medium);
    color: var(--text-primary);
}

/* ===== Badge trạng thái inverter ===== */

.device-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-family: "Poppins", sans-serif;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
}

.device-status::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 auto;
}

/* Năm màu theo quy ước mã State chốt 07/10/2026 (InverterStatusDisplay — giữ hai nơi khớp nhau):
   0 lục = chạy, 1 xám = off, 2 cam = standby/mất kết nối, 3 đỏ = lỗi, 4 xanh dương = giới hạn
   công suất. Nền dùng alpha nên đọc được trên cả nền tối lẫn nền sáng. */
.device-status--running  { color: #16a34a; background: rgba(22, 163, 74, .14); }
.device-status--off      { color: #6b7280; background: rgba(107, 114, 128, .16); }
.device-status--standby  { color: #f97316; background: rgba(249, 115, 22, .14); }
.device-status--fault    { color: #dc2626; background: rgba(220, 38, 38, .14); }
.device-status--limited  { color: #2563eb; background: rgba(37, 99, 235, .14); }

/* "Không rõ" = Redis không có khoá State. Cố tình KHÔNG gộp vào Off: gộp là bịa ra một
   con số mà Redis không hề nói (xem chú thích trong FleetSnapshotService). */
.device-status--unknown  { color: var(--text-secondary); background: rgba(128, 128, 128, .12); }

/* ===== Lưới thông số cho đồng hồ đo và trạm thời tiết ===== */

.device-metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    width: 100%;
}

/* Đồng hồ đo: một lưới 6 cột cố định trải hết bề ngang (chủ dự án chốt 2026-10-06). Các
   nhóm thẻ nối tiếp nhau theo thứ tự trong PowerMeterList.GroupsOf; nhóm 3 pha luôn chiếm
   đúng nửa hàng nên A/B/C vẫn thẳng cột. minmax(0, 1fr) để chữ dài không đẩy cột rộng ra.
   Màn hẹp thì xuống 3 rồi 2 cột — cùng là ước của 6 nên nhóm 3 pha không bị cắt đôi. */
.device-metric-grid.device-metric-grid--six {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

@media (max-width: 1200px) {
    .device-metric-grid.device-metric-grid--six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
    .device-metric-grid.device-metric-grid--six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.device-metric {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--chart-container-bg);
    box-sizing: border-box;
}

.device-metric-label {
    font-family: "Poppins", sans-serif;
    font-size: 13px;
    color: var(--text-secondary);
}

.device-metric-value {
    font-family: "Poppins", sans-serif;
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
}

.device-metric-unit {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 4px;
}

@media (max-width: 768px) {
    .device-page { padding: 16px; }
    .device-metric-value { font-size: 18px; }
}

/* ===== Đưa CardTemplate về đúng theme =====

   Components/Basic/CardTemplate.razor.css hard-code nền #23282A và chữ #FFFFFF, tức nó chỉ
   đẹp ở chế độ tối; ở chế độ sáng thẻ thành một mảng đen giữa nền trắng. Trang Project
   General Information đã tự đè bằng rule riêng, ba trang thiết bị cũng cần như vậy.

   Đây là CSS toàn cục nên không bị chặn bởi scope-id của CardTemplate. Chọn ba lớp để chắc
   chắn thắng độ ưu tiên của rule .stat-card[b-xxx] trong file scoped. */
.device-list .device-kpi-grid .stat-card {
    background: var(--chart-container-bg);
    border: 1px solid var(--border-color);
}

.device-list .device-kpi-grid .stat-card .stat-value {
    color: var(--text-primary);
}

.device-list .device-kpi-grid .stat-card .stat-subtitle,
.device-list .device-kpi-grid .stat-card .stat-unit {
    color: var(--text-secondary);
}

/* Các khối phân tích (Coefficient, Performance Metrics, Heatmap) dưới bảng inverter —
   chuyển sang từ trang Inverter Intelligence cũ. */
.inverter-analysis-section {
    margin-top: 24px;
}
