/* =====================================================================
   Giao diện dùng chung của trang quản lý /admin (tiền tố .acc-*).

   ĐÂY LÀ CSS TOÀN CỤC, KHÔNG PHẢI scoped CSS — cố ý.
   AccountsTab và PlantsTab dùng chung bộ class này; nếu để trong
   AccountsTab.razor.css thì Blazor sẽ gắn scope attribute của riêng
   AccountsTab và PlantsTab sẽ không ăn style nào cả.
   Vì không scoped nên cũng không dùng ::deep — MudIcon nhận style trực tiếp.

   Chỉ dùng biến theme của app.css để tự hợp cả dark lẫn light mode.
   ===================================================================== */

.acc-layout {
    display: flex;
    align-items: stretch;
    gap: 16px;
    min-height: 0;
}

/* ------------------------------------------------------------ danh sách trái */

.acc-list-pane {
    flex: 0 0 34%;
    max-width: 420px;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.acc-list-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.acc-search {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    height: 34px;
    padding: 0 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.acc-search .acc-search-icon {
    font-size: 18px;
    color: var(--text-secondary);
    flex: 0 0 auto;
}

.acc-search-input {
    flex: 1 1 auto;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
}

    .acc-search-input::placeholder {
        color: var(--text-secondary);
    }

.acc-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    flex: 1 1 auto;
}

.acc-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 10px;
    margin-bottom: 4px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

    .acc-row:hover {
        background: var(--bg-hover);
    }

    .acc-row.is-selected {
        background: var(--bg-active);
        border-color: var(--border-color);
    }

.acc-row-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.acc-row-name {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.acc-you {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .4px;
    padding: 1px 5px;
    border-radius: 999px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.acc-row-groups {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.acc-row-side {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

/* Huy hiệu vai trò. Bốn màu này là accent riêng của thành phần, đủ tương phản trên
   cả hai nền vì chữ luôn nằm trên nền đậm của chính huy hiệu. */
.acc-role {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .3px;
    padding: 2px 8px;
    border-radius: 999px;
    color: #fff;
    white-space: nowrap;
}

.acc-role--superadmin {
    background: #b4232c;
}

.acc-role--admin {
    background: #b06a00;
}

.acc-role--operator {
    background: #1a6fb0;
}

.acc-role--viewer {
    background: #4a5560;
}

.acc-locked {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 999px;
    background: transparent;
    border: 1px solid #b4232c;
    color: #e0616a;
    white-space: nowrap;
}

/* ------------------------------------------------------------ chi tiết phải */

.acc-detail-pane {
    flex: 1 1 auto;
    min-width: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 16px 16px;
}

.acc-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.acc-detail-title {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.acc-readonly-note,
.acc-note {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 12px;
}

.acc-readonly-note {
    margin-bottom: 12px;
}

.acc-readonly-note .acc-note-icon {
    font-size: 17px;
}

/* Lưới form. fieldset mặc định có viền/lề riêng, phải dọn trước khi biến thành grid. */
.acc-form {
    border: none;
    margin: 0;
    padding: 0;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 20px;
}

    .acc-form:disabled {
        opacity: .72;
    }

.acc-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.acc-field--wide {
    grid-column: 1 / -1;
}

.acc-field label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
}

.acc-input {
    height: 34px;
    padding: 4px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    min-width: 0;
    transition: border-color .15s;
}

    .acc-input:focus {
        outline: none;
        border-color: #18a37f;
    }

    .acc-input:disabled {
        color: var(--text-secondary);
        cursor: not-allowed;
    }

.acc-hint {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.35;
}

.acc-groups {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.acc-chk {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}

.acc-chk--inline {
    font-weight: 500;
}

.acc-chk input {
    accent-color: #18a37f;
    cursor: pointer;
}

/* ------------------------------------------------------------------- nút */

.acc-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}

.acc-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, opacity .15s;
}

    .acc-btn:hover:not(:disabled) {
        background: var(--bg-hover);
    }

    .acc-btn:disabled {
        opacity: .5;
        cursor: not-allowed;
    }

.acc-btn .acc-btn-icon {
    font-size: 17px;
}

.acc-btn--primary {
    background: #18a37f;
    border-color: #18a37f;
    color: #fff;
}

    .acc-btn--primary:hover:not(:disabled) {
        background: #148c6c;
    }

.acc-btn--danger {
    background: transparent;
    border-color: #b4232c;
    color: #e0616a;
}

    .acc-btn--danger:hover:not(:disabled) {
        background: rgba(180, 35, 44, .12);
    }

/* ----------------------------------------------------------------- rỗng */

.acc-empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.acc-empty--tall {
    padding: 80px 16px;
}

/* Màn hẹp: xếp chồng hai cột và bỏ lưới hai cột của form. */
@media (max-width: 1200px) {
    .acc-layout {
        flex-direction: column;
    }

    .acc-list-pane {
        flex: 1 1 auto;
        max-width: none;
        width: 100%;
    }

    .acc-form {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ------------------------------------------------------ riêng tab Nhà máy */

.plant-showdeleted {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}

    .plant-showdeleted input {
        accent-color: #18a37f;
        cursor: pointer;
    }

/* Mã plantN — luôn hiển thị kèm tên vì đây là khoá mà Redis và các bảng dữ liệu dùng. */
.plant-code {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11px;
    font-weight: 500;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.plant-cap {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Nhà máy đã xoá mềm: làm mờ và gạch tên, vẫn đọc được để còn khôi phục. */
.acc-row.is-deleted .acc-row-name {
    text-decoration: line-through;
    opacity: .7;
}

.acc-textarea {
    height: auto;
    min-height: 68px;
    padding: 8px 10px;
    resize: vertical;
    line-height: 1.4;
}

/* Chọn số hiệu nhà máy (chỉ khi tạo mới) */
.plant-number-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.plant-number-prefix {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 13px;
    color: var(--text-secondary);
}

.plant-number-input {
    width: 110px;
    flex: 0 0 auto;
}

.plant-number-preview {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.plant-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.plant-chip {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid #18a37f;
    background: transparent;
    color: #2fbf9a;
    cursor: pointer;
    transition: background .15s;
}

    .plant-chip:hover {
        background: rgba(24, 163, 127, .14);
    }

    .plant-chip.is-picked {
        background: #18a37f;
        color: #fff;
    }

.plant-warn {
    color: #d08a00;
}

.plant-error {
    color: #e0616a;
}

/* ------------------------------------------- tab Cấu hình nhà máy + Nhật ký */

.cfg-section {
    margin: 18px 0 10px;
    font-size: 14px;
    font-weight: 600;
    color: #09cebd;
}

    .cfg-section:first-of-type {
        margin-top: 4px;
    }

.cfg-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

    .cfg-table th {
        text-align: left;
        font-weight: 600;
        font-size: 11px;
        letter-spacing: .3px;
        text-transform: uppercase;
        color: var(--text-secondary);
        padding: 6px 8px;
        border-bottom: 1px solid var(--border-color);
    }

    .cfg-table td {
        padding: 5px 8px;
        border-bottom: 1px solid var(--border-color);
        color: var(--text-primary);
    }

    .cfg-table th.num,
    .cfg-table td.num {
        text-align: center;
    }

.cfg-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.cfg-name {
    width: 100%;
    min-width: 110px;
}

.cfg-num {
    width: 60px;
    text-align: center;
}

/* Đơn vị trong tiêu đề cột: không viết hoa theo th (kWp chứ không phải KWP). */
.cfg-unit {
    text-transform: none;
}

/* Ô mô tả (tên thực) của project: rộng hơn ô tên vì là chữ tự do. */
.cfg-desc {
    width: 100%;
    min-width: 130px;
}

/* Model biến tần (08/10/2026). */
.cfg-model {
    width: 100%;
    min-width: 110px;
}

/* Công suất kWp/inverter: placeholder "Tự tính" nên rộng hơn ô đếm. */
.cfg-kwp {
    width: 84px;
}

.cfg-strings {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Nút xoá dòng: thu về đúng ô vuông chứa icon */
.cfg-rm {
    height: 28px;
    padding: 0 8px;
}

.cfg-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.cfg-note {
    margin-top: 12px;
    align-items: flex-start;
    line-height: 1.5;
}

.cfg-import {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
}

    .cfg-import .acc-field {
        min-width: 220px;
    }

.cfg-file {
    height: auto;
    padding: 6px 8px;
}

.cfg-report {
    margin: 12px 0 0;
    padding: 10px 12px 10px 28px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ------------------------------------------------------------ nhật ký */

.audit-pane {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px 16px;
}

.audit-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.audit-search {
    flex: 1 1 auto;
    max-width: 420px;
}

.audit-table {
    table-layout: fixed;
}

.audit-when {
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
    color: var(--text-secondary);
    width: 160px;
}

/* Cột detail là jsonb, có thể rất dài — cắt ngang chứ không cho phá vỡ bố cục bảng. */
.audit-detail {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11px;
    color: var(--text-secondary);
    word-break: break-all;
    max-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audit-action {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
    border: 1px solid;
}

.audit-action--danger {
    border-color: #b4232c;
    color: #e0616a;
}

.audit-action--warn {
    border-color: #b06a00;
    color: #d08a00;
}

.audit-action--create {
    border-color: #18a37f;
    color: #2fbf9a;
}

.audit-action--normal {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

/* ---------- Tab Groups: danh sách nhà máy trong nhóm ----------
   Đặt ở đây (global) chứ không phải scoped CSS của GroupsTab, cho khớp cách toàn bộ lớp
   .acc-* của khu quản trị đang được khai báo. */

.grp-plants {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    max-height: 420px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.grp-plant {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
}

    .grp-plant:last-child {
        border-bottom: none;
    }

    .grp-plant.is-member {
        background: var(--bg-hover);
    }

.grp-plant-label {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    cursor: pointer;
}

.grp-plant-name {
    color: var(--text-primary);
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Nhóm hiện tại của nhà máy — giúp thấy ngay việc tick sẽ KÉO nó ra khỏi nhóm nào. */
.grp-plant-group {
    flex: 0 0 auto;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}
