/*
 * CASHBANK GATEWAY SIMULATOR - ENTERPRISE PRO STYLESHEET
 * Nâng cấp: Bố cục Grid 3:3:3 (1fr 1fr 1fr) cố định, sửa lỗi message-panel và cải tiến footer.
 */

/* --- ROOT STYLES (PREMIUM DARK MODE) --- */
:root {
    /* Màu nền & Khung */
    --background-color: #070a0e;     /* Nền tối sâu hơn */
    --container-bg: #111317;         /* Nền Panel chính */
    --text-color: #eceff4;           /* Màu chữ sáng, dịu mắt */
    --panel-border: #282c34;         /* Đường viền tinh tế */
    --display-bg: #0a0c10;           /* Nền input/display (gần với nền body) */
    
    /* Màu hành động & Nhấn */
    --accent-color: #7e92ff;         /* Xanh Indigo mềm mại (Premium Accent) */
    --payment-color: #43a047;        /* Xanh lá cây Corporate (Thành công) */
    --payment-hover: #5cb860;
    --refund-color: #ff7043;         /* Cam Đỏ (Cảnh báo/Hoàn tiền) */
    --refund-hover: #ff8a65;
    --fail-color: #e6a700;           /* Vàng (Thất bại) */
    --fail-hover: #ffc107;
    
    /* Màu Nút & Message */
    --button-bg: #1f2229;            /* Nền nút thường */
    --button-hover: #2d313a;
    --message-bg: #181b21;           /* Nền chat panel */
    --telegram-bubble: #4080ee;      /* Màu tin nhắn Telegram tươi hơn */
    --system-msg-bg: #292d33;        /* Màu tin nhắn hệ thống (xám đậm) */
    
    --export-bg: #9c71f5;            /* Tím cho Export */
    --reset-bg: #7289DA;             /* Xám xanh cho Reset */
}

* {
    box-sizing: border-box;
    font-family: 'Poppins', 'Tahoma', sans-serif;
}

body {
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    /* Tăng padding dưới để footer cố định không che nội dung */
    padding: 20px;
    padding-bottom: 60px; 
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
}

/* --- PANEL HEADERS --- */
h2 {
    color: var(--text-color);
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 15px;
    padding-bottom: 5px; 
    font-size: 1.25em;
    position: relative;
    padding-left: 15px; 
}

h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 10px;
    width: 4px; 
    background-color: var(--accent-color);
    border-radius: 2px;
}


/* ------------------------------------------------------------------ */
/* --- MAIN CONTAINER & BỐ CỤC (FIX LỖI VÀ CỐ ĐỊNH 3:3:3) --- */
/* ------------------------------------------------------------------ */
.container {
    display: grid; 
    /* Thiết lập 3 cột bằng nhau (1fr 1fr 1fr) */
    grid-template-columns: 1fr 1fr 1fr;
    /* Thiết lập hàng: Hàng 1 tự động; Hàng 2 chiếm phần còn lại (1fr) */
    grid-template-rows: auto 1fr; 
    /* Định danh vùng */
    grid-template-areas: 
        "config-area calc-area filler-area" /* 3 ô ở hàng 1 */
        "message-area message-area message-area"; /* Message Panel chiếm toàn bộ 3 cột ở hàng 2 */

    gap: 20px;
    background-color: var(--container-bg);
    padding: 25px; 
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7); 
    width: 100%;
    max-width: 1450px; 
    min-height: 90vh; /* Quan trọng để message-panel có không gian giãn nở */
}

/* --- PANELS CHUNG VÀ ĐỊNH VỊ --- */
.config-panel, .calculator-panel, .message-panel {
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); 
}

/* Định vị và cố định Config/Calculator */
.config-panel {
    grid-area: config-area;
    height: fit-content;
}

.calculator-panel {
    grid-area: calc-area;
    height: fit-content;
}

/* Cố định Message Panel */
.message-panel {
    grid-area: message-area; /* Chiếm toàn bộ hàng dưới */
    display: flex;
    flex-direction: column;
    min-height: 350px; /* Chiều cao tối thiểu */
    overflow-y: hidden; /* Quan trọng: panel cha không cuộn */
}


/* --- INPUT GROUPS & LABELS --- (GIỮ NGUYÊN) */
.config-group {
    margin-bottom: 18px;
}

.config-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 400;
    color: #b0b4ba; 
    font-size: 0.9em;
}

input[type="number"], input[type="text"], select, input[type="date"], input[type="time"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background-color: var(--display-bg);
    color: var(--text-color);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 8px rgba(126, 146, 255, 0.7); 
    outline: none;
    background-color: var(--container-bg); 
}

.datetime-group {
    display: flex;
    gap: 10px;
}

.datetime-group input {
    flex: 1;
}

.half-group {
    display: flex;
    gap: 15px;
}

.half-item {
    flex: 1;
}

/* --- BUTTONS --- (GIỮ NGUYÊN) */
.action-buttons-group {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s;
    color: var(--text-color); 
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

.action-btn:active:not(:disabled) {
    transform: translateY(2px); 
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.payment-btn {
    background-color: var(--payment-color);
    color: #ffffff; 
}
.payment-btn:not(:disabled):hover {
    background-color: var(--payment-hover);
}

.refund-btn {
    background-color: var(--refund-color);
    color: #ffffff;
}
.refund-btn:not(:disabled):hover {
    background-color: var(--refund-hover);
}

.fail-btn {
    background-color: var(--fail-color);
    color: #111; 
}
.fail-btn:not(:disabled):hover {
    background-color: var(--fail-hover);
}

.export-btn {
    background-color: var(--export-bg);
}
.export-btn:not(:disabled):hover {
    background-color: #b388ff;
}

.clear-messages-btn {
    background-color: #555 !important;
    margin-top: 10px;
}
.clear-messages-btn:hover {
    background-color: #777 !important;
}

/* --- AMOUNT INPUT --- (GIỮ NGUYÊN) */
#amount-input {
    font-size: 2em; 
    text-align: right;
    font-weight: 700;
    color: var(--payment-color);
    padding: 18px 15px; 
    margin-bottom: 10px;
    border: 2px solid var(--payment-color); 
}
#amount-input:focus {
    border-color: var(--accent-color);
}


/* --- BALANCE DISPLAY --- (GIỮ NGUYÊN) */
#current-balance-display {
    padding: 18px;
    margin-bottom: 20px;
    background-color: var(--display-bg);
    border-radius: 8px;
    font-size: 1.2em; 
    font-weight: 600;
    text-align: center;
    border: 2px solid var(--accent-color);
    box-shadow: inset 0 0 12px rgba(126, 146, 255, 0.3); 
}


/* --- MESSAGE PANEL (CHAT) - SỬ DỤNG CHUẨN FLEX VÀ CUỘN --- */
.telegram-chat {
    flex-grow: 1; /* Cho phép nó giãn nở để lấp đầy message-panel */
    background-color: var(--message-bg);
    border-radius: 8px;
    padding: 10px;
    overflow-y: auto; /* TẠO THANH CUỘN Ở ĐÂY */
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid var(--panel-border);
}

.bank-message-wrapper {
    display: flex;
    justify-content: flex-end;
}

.bank-message {
    max-width: 85%;
    padding: 14px 18px; 
    border-radius: 20px 20px 0 20px; 
    background-color: var(--telegram-bubble); 
    color: var(--text-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); 
    line-height: 1.5; 
    font-size: 14px; 
    white-space: pre-wrap; 
}

/* Tối ưu nội dung tin nhắn */
.message-content-wrapper {
    display: flex; 
    flex-direction: column;
    gap: 7px; 
}
.message-action-btn {
    padding: 8px 15px; 
    background-color: #3b5998; 
    border: none;
    border-radius: 20px;
    color: white;
    cursor: pointer;
    font-size: 12px; 
    font-weight: 500;
    margin-top: 5px;
    align-self: flex-end;
    transition: background-color 0.1s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.message-action-btn:hover {
    background-color: #4c69a5;
}

.system-message, .transaction-delay {
    max-width: 85%;
    align-self: flex-start;
    padding: 8px 12px;
    border-radius: 18px 18px 18px 0;
    background-color: var(--system-msg-bg); 
    color: #c9d1d9;
    font-style: italic;
    font-size: 13px;
    border: 1px solid #4a4d53;
}

.transaction-delay {
    background-color: #3e4451;
    color: #fff;
    font-style: normal;
}


/* --- TRANSACTION HISTORY --- (GIỮ NGUYÊN) */
#history-container {
    background-color: var(--display-bg);
    border-radius: 6px;
    padding: 5px;
    max-height: 220px; 
    overflow-y: auto;
    border: 1px solid var(--panel-border);
    margin-bottom: 15px;
}

.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.history-item {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #2f343d;
    font-size: 13px;
    align-items: center;
    transition: background-color 0.2s;
    cursor: pointer;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item:hover {
    background-color: #1a1e24; 
}

.tx-info {
    flex: 3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 10px;
}

.tx-id-display {
    flex: 1;
    color: #8892a0;
    font-size: 0.85em;
    text-align: center;
}

.tx-amount {
    flex: 1;
    text-align: right;
    font-weight: 600;
    font-size: 14px; 
}

.positive {
    color: var(--payment-color);
}

.negative {
    color: var(--refund-color);
}

/* --- FOOTER & SEPARATOR (ĐÃ CẢI TIẾN) --- */
.separator {
    border-color: #30363d;
    margin: 15px 0;
}

#main-footer {
    /* Thiết lập vị trí CỐ ĐỊNH (FIXED) ở cuối trang */
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    
    /* Thiết kế nổi bật */
    background-color: var(--container-bg); /* Nền tối của panel */
    color: var(--text-color);
    text-align: center;
    padding: 12px 0; /* Tăng padding để footer trông dày dặn hơn */
    
    /* Đường viền và đổ bóng */
    border-top: 1px solid var(--panel-border);
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.5); /* Đổ bóng lên trên */
    z-index: 999; /* Đảm bảo nó luôn nằm trên các nội dung khác */
    
    font-size: 0.85em;
    line-height: 1.4;
}

#main-footer p {
    margin: 0; 
}

#main-footer strong {
    color: var(--accent-color); /* Sử dụng màu accent cho thông tin quan trọng */
    font-weight: 600;
    margin: 0 5px;
}

/* ------------------------------------------------------------------ */
/* --- MÀN HÌNH KHÓA (LOCK SCREEN) --- (GIỮ NGUYÊN) */
/* ------------------------------------------------------------------ */

#lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s, visibility 0.5s;
}
.lock-card {
    background-color: var(--container-bg);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.7);
    text-align: center;
    width: 350px;
}
.pin-display {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 25px;
    height: 20px; 
}
.dot {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    border: 2px solid var(--text-color);
    background-color: transparent;
    transition: background-color 0.2s, border-color 0.2s;
}
.dot.active {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}
.pin-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}
.pin-buttons button {
    padding: 20px 10px;
    border: none;
    border-radius: 8px;
    background-color: var(--button-bg);
    color: var(--text-color);
    font-size: 1.3em;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.1s;
}
.pin-buttons button:hover {
    background-color: var(--button-hover);
}
.pin-buttons button.delete-btn {
    background-color: var(--refund-color);
    font-size: 1em;
}
.pin-buttons button.delete-btn:hover {
    background-color: var(--refund-hover);
}


/* ------------------------------------------------------------------ */
/* --- MODAL VÀ CHI TIẾT GIAO DỊCH --- (GIỮ NGUYÊN) */
/* ------------------------------------------------------------------ */
.modal {
    display: none;
    position: fixed;
    z-index: 1001; 
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.85);
    padding-top: 60px;
}

.modal-content {
    background-color: var(--container-bg);
    margin: 5% auto;
    padding: 30px; 
    border: 1px solid var(--panel-border);
    width: 80%;
    max-width: 680px; 
    border-radius: 12px;
    position: relative;
    box-shadow: 0 8px 30px rgba(0,0,0,0.9);
    
    display: grid;
    grid-template-columns: 180px 1fr; 
    gap: 30px;
    align-items: flex-start;
}

.modal-details {
    grid-column: 2 / 3;
}

.modal-qr-section {
    grid-column: 1 / 2;
    text-align: center;
}

.close-button {
    color: var(--text-color);
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 20px;
    line-height: 1;
}

.close-button:hover,
.close-button:focus {
    color: var(--refund-color);
}

.detail-item {
    padding: 12px 0;
    border-bottom: 1px dashed #3e4451;
    display: flex;
    justify-content: space-between;
    font-size: 15px; 
    align-items: center;
}
.detail-item:last-child {
    border-bottom: none;
}
.detail-label {
    font-weight: 600;
    color: #b1b5c0;
    flex-basis: 45%;
}
.detail-value {
    max-width: 55%;
    text-align: right;
    word-wrap: break-word;
    font-weight: 500;
}
.qr-code-placeholder {
    width: 160px;
    height: 160px;
    margin: 10px auto 10px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: #333;
    border-radius: 5px;
    text-align: center;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    font-size: 0.9em;
    padding: 5px;
    border: 4px solid var(--payment-color); 
}

.qr-code-placeholder span {
    font-size: 1.1em;
    font-weight: 700;
    color: var(--payment-color);
}


/* ------------------------------------------------------------------ */
/* --- RESPONSIVE DESIGN (ĐÃ CẬP NHẬT GRID AREA) --- */
/* ------------------------------------------------------------------ */
@media (max-width: 1250px) {
    .container {
        /* Bố cục 2 cột (1:1) cho tablet */
        grid-template-columns: 1fr 1fr; 
        grid-template-rows: auto 1fr;
        grid-template-areas: 
            "config-area calc-area" 
            "message-area message-area"; /* Message Panel chiếm 2 cột */
        gap: 15px;
        min-height: 90vh;
    }
    
    .config-panel {
        grid-area: config-area;
    }
    
    .calculator-panel {
        grid-area: calc-area;
    }
    
    .message-panel {
        grid-area: message-area;
        min-height: 450px;
    }

    /* Modal trên tablet/mobile */
    .modal-content {
        grid-template-columns: 1fr; 
        gap: 15px;
    }

    .modal-qr-section {
        grid-column: 1 / 2;
        order: -1; 
    }

    .modal-details {
        grid-column: 1 / 2;
    }

}

@media (max-width: 850px) {
    body {
        padding: 10px;
        padding-bottom: 60px; /* Cập nhật padding body */
    }
    
    .container {
        /* Chuyển sang bố cục 1 cột */
        grid-template-columns: 1fr; 
        grid-template-rows: auto auto 1fr; 
        grid-template-areas: 
            "config-area"
            "calc-area"
            "message-area"; 
        gap: 15px;
        padding: 15px;
        min-height: auto;
    }

    .config-panel, .calculator-panel, .message-panel {
        /* Giữ lại định nghĩa grid-area từ 1250px media query */
        width: auto;
        min-width: auto;
    }
    
    .half-group {
        flex-direction: column;
        gap: 5px;
    }
    
    .datetime-group {
        flex-direction: row; 
    }

    .history-item {
        flex-wrap: wrap;
        font-size: 12px;
        gap: 5px;
    }
    
    .tx-info {
        flex-basis: 100%;
        order: -1;
    }
    
    .modal-content {
        margin: 10% auto;
        width: 95%;
    }
}