/* ============================================================
   CRM DETAIL VIEW — Stylesheet v2
   ============================================================ */

/* ---------- 1. WRAPPER ---------- */
.crm-detail-wrap {
    max-width: 1140px;
    margin: 28px auto;
    padding: 0;
    background: #f4f6f9;
    border: none;
    border-radius: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: #2d3748;
    overflow: hidden;
}

/* ---------- 2. HEADER ---------- */
.crm-detail-header {
    background: #fff;
    padding: 16px 22px;
    border-bottom: 1px solid #e8ecf1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.crm-detail-header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    color: #1a202c;
    letter-spacing: -0.3px;
    text-transform: uppercase;
}

/* ---------- 3. STATUS WIDGET ---------- */
.crm-status-container {
    display: inline-flex;
    align-items: center;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    overflow: hidden;
    flex-shrink: 0;
}

#current-status-label {
    padding: 9px 16px;
    font-weight: 700;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: #fff;
    transition: background 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 100px;
    white-space: nowrap;
}

.crm-status-controls {
    display: flex;
    align-items: center;
    padding: 0 8px 0 10px;
    background: #f8fafc;
    border-left: 1.5px solid #e2e8f0;
    gap: 5px;
}

#crm_new_status_select {
    border: none !important;
    background: transparent !important;
    font-size: 12.5px;
    font-weight: 500;
    color: #374151;
    padding: 6px 26px 6px 6px !important;
    cursor: pointer;
    outline: none !important;
    box-shadow: none !important;
    appearance: none;
    -webkit-appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%236b7280%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E') !important;
    background-repeat: no-repeat !important;
    background-position: right 5px center !important;
    background-size: 9px !important;
}

#btn-update-status {
    background: #2271b1;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.18s ease;
    white-space: nowrap;
}

#btn-update-status:hover {
    background: #135e96;
    transform: translateY(-1px);
}

#btn-update-status .dashicons {
    font-size: 15px;
    width: 15px;
    height: 15px;
    transition: transform 0.35s ease;
}

#btn-update-status:hover .dashicons {
    transform: rotate(180deg);
}

/* ---------- 4. BODY GRID ---------- */
.crm-detail-body {
    display: grid;
    grid-template-columns: 40% 60%;
    gap: 0;
    background: #f4f6f9;
    align-items: start;
}

/* ---------- 5. SIDEBAR ---------- */
.crm-detail-sidebar {
    background: #fff;
    border-right: 1px solid #e8ecf1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    /* Giữ sidebar ở trên khi scroll */
    position: sticky;
    top: 32px;
}

.crm-sidebar-section {
    background: #fafbfc;
    border: 1px solid #e8ecf1;
    border-radius: 10px;
    overflow: hidden;
}

.crm-sidebar-section-title {
    padding: 9px 13px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #6b7280;
    background: #f1f5f9;
    border-bottom: 1px solid #e8ecf1;
}

/* ---------- 6. INFO TABLE ---------- */
.crm-info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    table-layout: fixed;
}

.crm-info-table tr {
    border-bottom: 1px solid #f0f4f8;
    transition: background 0.1s;
}

.crm-info-table tr:last-child { border-bottom: none; }
.crm-info-table tr:hover { background: #f8fbff; }

.crm-info-table td {
    padding: 8px 12px;
    vertical-align: top;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.crm-info-table td:first-child {
    color: #6b7280;
    font-weight: 600;
    font-size: 12.5px;
    white-space: normal;
    width: 110px;
    min-width: 110px;
    padding-right: 8px;
    vertical-align: top;
    line-height: 1.4;
}

.crm-info-table td:last-child {
    color: #1a202c;
    font-weight: 600;
    font-size: 13.5px;
}

/* Màu giá trị */
.crm-info-table td.val-blue   { color: #2271b1; }
.crm-info-table td.val-pink   { color: #d63384; }
.crm-info-table td.val-orange { color: #c0392b; }
.crm-info-table td.val-green  { color: #16a34a; }

/* Inline edit span trong sidebar */
.crm-info-table .inline-edit {
    display: inline-block;
    border-bottom: 1px dashed currentColor;
    cursor: pointer;
    min-width: 60px;
    padding: 1px 4px;
    border-radius: 3px;
    transition: background 0.15s;
    font-size: 12.5px;
    word-break: break-word;
    max-width: 100%;
}

.crm-info-table .inline-edit:hover {
    background: #f0f7ff;
}

.crm-info-table .inline-edit:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(34,113,177,0.2);
}

/* ---------- 7. SIDEBAR NAV BUTTONS ---------- */
.crm-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
}

.crm-sidebar-nav a {
    display: block;
    width: 100%;
    text-align: center;
    padding: 10px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 12.5px;
    text-decoration: none !important;
    transition: all 0.15s;
    box-sizing: border-box;
}

.crm-sidebar-nav a.btn-primary {
    background: #2271b1;
    color: #fff !important;
}

.crm-sidebar-nav a.btn-primary:hover {
    background: #135e96;
    box-shadow: 0 4px 10px rgba(34,113,177,0.25);
}

.crm-sidebar-nav a.btn-secondary {
    background: #6b7280;
    color: #fff !important;
}

.crm-sidebar-nav a.btn-secondary:hover {
    background: #4b5563;
}

/* ---------- 8. MAIN CONTENT ---------- */
.crm-detail-main {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;          /* ← Fix: ngăn main vượt quá grid column */
}

/* ---------- 9. SECTION CARDS (interaction, loan, etc.) ---------- */
.crm-detail-main > div,
.crm-detail-main > .interaction-container {
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e8ecf1;
    overflow: hidden;
}

/* Section headers (h3 inline) */
.crm-detail-main h3 {
    border-left: 4px solid #2271b1;
    padding: 10px 16px;
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: #1a202c;
    background: #f8fafc;
    border-bottom: 1px solid #e8ecf1;
}

.crm-detail-main h4 {
    font-size: 13px;
    color: #4b5563;
    margin: 0 0 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f4f8;
}

/* Nội dung bên trong section */
.crm-section-body {
    padding: 14px 16px;
}

/* ---------- 10. LOAN / HỌC PHÍ TABLE ---------- */
#crm-loan-box {
    /* Box là 1 card bình thường trong crm-detail-main */
    margin-top: 0 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    background: transparent !important;
}

/* h3 bên trong loan box dùng chung style với main */
#crm-loan-box > h3 {
    border-left-color: #faad14 !important;
    color: #856404 !important;
}

/* Wrapper form bên trong */
#crm-loan-box > div {
    padding: 0;
}

#table_reg_courses {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    table-layout: fixed;
}

#table_reg_courses thead tr {
    background: #fafafa;
}

#table_reg_courses th {
    padding: 8px 10px;
    border-bottom: 2px solid #e8ecf1;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #6b7280;
    text-align: left;
}

#table_reg_courses th:nth-child(1) { width: auto; }
#table_reg_courses th:nth-child(2) { width: 105px; }
#table_reg_courses th:nth-child(3) { width: 65px; }
#table_reg_courses th:nth-child(4) { width: 115px; }
#table_reg_courses th:nth-child(5) { width: 34px; }

#table_reg_courses td {
    padding: 6px 8px;
    border-bottom: 1px solid #f0f4f8;
    vertical-align: middle;
}

#table_reg_courses input[type="text"],
#table_reg_courses input[type="number"] {
    width: 100%;
    padding: 5px 6px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    font-size: 12.5px;
    box-sizing: border-box;
    background: #fafafa;
}

#table_reg_courses input[readonly] {
    background: #f3f4f6;
    color: #6b7280;
}

/* 4 ô tổng kết (A/B/C/nợ) */
.crm-loan-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    background: #fffbe6;
    border: 1px solid #ffe58f;
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
}

.crm-loan-summary > div {
    min-width: 0;
}

.crm-loan-summary label {
    display: block;
    font-size: 9.5px;
    font-weight: 700;
    color: #856404;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-loan-summary input {
    width: 100%;
    font-size: 14px;
    font-weight: 700;
    padding: 7px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-sizing: border-box;
    text-align: right;
}

/* ---------- 11. HISTORY LIST ---------- */
#care-history-display-list {
    max-height: 200px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e8ecf1;
    border-radius: 6px;
    scrollbar-width: thin;
}

#care-history-display-list > div {
    display: flex;
    border-bottom: 1px solid #f0f0f0;
    padding: 7px 10px;
    font-size: 12px;
    align-items: flex-start;
    gap: 8px;
}

#care-history-display-list > div:last-child {
    border-bottom: none;
}

/* ---------- 12. COMMENT / PHẢN HỒI CMHS ---------- */
#staff-realtime-chat-list > div {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 7px;
    font-size: 13px;
}

/* ---------- 13. TEXTAREA & BUTTONS IN MAIN ---------- */
.crm-detail-main textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
    background: #fafafa;
    transition: border-color 0.15s;
}

.crm-detail-main textarea:focus {
    border-color: #2271b1;
    background: #fff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(34,113,177,0.1);
}

/* Các nút submit full-width */
.crm-detail-main button[type="submit"],
.crm-detail-main button[style*="width: 100%"],
.crm-detail-main button[style*="width:100%"] {
    border-radius: 8px !important;
    font-weight: 700 !important;
    transition: opacity 0.15s, transform 0.15s !important;
}

.crm-detail-main button[type="submit"]:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* ---------- 14. RESPONSIVE ---------- */
@media (max-width: 860px) {
    .crm-detail-body {
        grid-template-columns: 1fr;
    }

    .crm-detail-sidebar {
        border-right: none;
        border-bottom: 1px solid #e8ecf1;
        position: static;
    }

    .crm-detail-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .crm-status-container {
        flex-wrap: wrap;
    }

    .crm-loan-summary {
        grid-template-columns: repeat(2, 1fr);
    }
}
