.app-title {
    text-align: center;
    margin: 0;
    padding: 15px 0;
    font-size: 1.6rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    /* Hiệu ứng chữ Gradient đổ màu từ Xanh sang Tím */
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    /* Đổ bóng nhẹ để chữ nổi bật trên nền trắng */
    filter: drop-shadow(0px 2px 4px rgba(0, 0, 0, 0.1));
    border-bottom: 1px solid #f1f1f1;
}

.btn-ac {
    background-color: #ff9f1c !important; /* Dùng !important để đè màu nền trắng mặc định */
    color: white !important; /* Dùng !important để đè màu chữ đen mặc định */
    border-color: #e68a00 !important; /* Đổi màu viền cho nó tiệp màu */
}

.calc-toolbar {
    display: none; /* Mặc định ẩn, chỉ hiện trên mobile/tablet */
    background: #f8f9fa;
    border-top: 1px solid #ddd;
    padding: 10px;
    justify-content: space-around;            
    box-sizing: border-box; /* Để padding không làm quá chiều rộng */
}

/* Chỉ hiện và định dạng thanh công cụ cho các thiết bị di động (Android, iOS) */
.mobile-os .calc-toolbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* Giữ 4 cột */
    gap: 8px; /* Thu hẹp gap xíu cho đỡ chật màn hình */
    padding: 8px;
    box-sizing: border-box;
    background: #f8f9fa;
}

/* Khi toolbar bị thu gọn, ẩn tất cả các nút trừ 4 nút đầu tiên */
.mobile-os .calc-toolbar.collapsed button:nth-child(n+5) {
    display: none;
}

.calc-toolbar button:active {
    background: #e2e6ea;
}

.btn-equal {
    background-color: #28a745 !important;
    color: white !important;
    border-color: #1e7e34 !important;
}

.calc-toolbar button { /* Common button styles */
    padding: 12px;
    font-size: 1.2rem;
    font-weight: bold;
    border: 1px solid #ccc;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    margin: 0;
    min-width: 0;
    padding: 15px 5px; /* Tăng chiều cao nút bấm cho dễ trúng */
}

/* Định dạng các nút trong thanh công cụ chỉ cho thiết bị di động */
.mobile-os .calc-toolbar button {
    margin: 0; /* Remove margin, use gap instead */
    min-width: 0; /* Allow buttons to shrink */
    padding: 15px 5px;
    font-size: 1.2rem;
    font-weight: bold;
    border: 1px solid #ccc;
    border-radius: 8px;
    background: white; /* Phím số mặc định nền trắng */
    cursor: pointer;
}

.mobile-os .btn-zero {
    grid-column: span 1; /* Make '0' button span 2 columns */
}

.mobile-os .btn-del {
    grid-column: span 1; /* Thu hẹp nút DEL lại còn 1 ô */
    background-color: #e57373 !important; /* Đỏ dịu */
    color: white !important;
    border-color: #ef9a9a !important;
}

/* Nút ẩn bàn phím */
.mobile-os .btn-kbd {
    background-color: #cfd8dc !important; /* Xanh xám nhạt */
    color: #37474f !important;
    border-color: #b0bec5 !important;
}

/* Các phím tính toán: +, -, x, /, % */
.mobile-os .btn-op {
    background-color: #bbdefb !important; /* Xanh nhạt */
    color: #1976d2 !important;
    border-color: #90caf9 !important;
}

.mobile-os .btn-ac, .mobile-os .btn-backspace {
    background-color: #ffc107; /* Warning color for AC/DEL */
    border-color: #ffc107;
    color: #343a40;
}

.mobile-os .btn-ac:active, .mobile-os .btn-backspace:active {
    background-color: #e0a800;
}


html, body {
    height: 100dvh; /* Dynamic Viewport Height: Tự thích ứng khi toolbar hiện/ẩn */
    margin: 0;
    padding: 0;
    overflow: hidden; /* Ngăn cuộn trang chính (html/body) */
}
body {
    font-family: 'Segoe UI', Roboto, Arial, 'Helvetica Neue', Helvetica, sans-serif;
    background-color: #e9ecef;
    display: flex;
    justify-content: center;
    /* align-items: center; đã bỏ để ứng dụng bắt đầu từ đầu màn hình, phù hợp hơn cho di động */
    min-height: 100vh; /* Đảm bảo body có chiều cao tối thiểu bằng chiều cao viewport */
}

.app-container {
    width: 100%;
    max-width: 100%; /* Mặc định là full màn hình cho Mobile */
    background: #fff;
    border-radius: 0; /* Mobile không cần bo góc */
    box-shadow: none;
    display: flex;
    flex-direction: column;
    height: 100dvh; /* Sử dụng dvh để luôn khớp với phần diện tích hiển thị thực tế */
    overflow: hidden;
    transition: all 0.3s ease; /* Thêm hiệu ứng chuyển đổi cho mượt */
}

/* Cho Máy tính bảng (Màn hình từ 600px trở lên) */
@media only screen and (min-width: 600px) {
    body {
        align-items: center; /* Căn giữa máy tính khi màn hình to */
    }
    .app-container {
        max-width: 500px;
        height: 85vh;
        border-radius: 12px;
        box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    }
}

/* Cho iPad và các màn hình lớn hơn (ví dụ: từ 768px trở lên) */
@media only screen and (min-width: 768px) {
    .app-container {
        max-width: 1366px; /* Tăng chiều rộng cho iPad ở chế độ dọc */
        height: 90dvh; /* Tăng chiều cao một chút cho màn hình lớn hơn */
        border-radius: 16px; /* Bo góc nhiều hơn cho màn hình lớn */
    }
}

/* Cho màn hình desktop lớn hơn (ví dụ: từ 1024px trở lên) */
@media only screen and (min-width: 1024px) {
    .app-container {
        max-width: 850px; /* Chiều rộng tối đa cho iPad ở chế độ ngang hoặc desktop */
        height: 95vh; /* Chiều cao tối đa cho desktop */
        border-radius: 20px; /* Bo góc nhiều hơn nữa */
    }
}

.tape-container {
    flex: 1;
    background-color: #fffdf2; /* Màu giấy ngả vàng giống hóa đơn */
    min-height: 0; /* Quan trọng: Giúp flexbox co giãn đúng cách và hiển thị thanh cuộn */
    overflow-y: auto;
    padding: 15px;
    font-family: 'Courier New', Courier, monospace;
    cursor: text; /* Đổi trỏ chuột để biểu thị vùng có thể gõ */
}

.tape-row {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px dashed #dcdcdc;
}

.line-input {
    width: 50%;
    box-sizing: border-box; /* Đảm bảo padding không ảnh hưởng đến chiều rộng */
    border: none;
    background: transparent;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.1em;
    outline: none;
    color: #333;
}

.line-input::placeholder {
    color: #aaa;
    font-style: italic;
}

.line-subtotal {
    text-align: right;
    color: #999;
    font-size: 0.9em;
    min-width: 80px;
    padding-left: 10px;
}

.result-row {
    border-top: 1px solid #999;
    border-bottom: 3px double #444;
    margin-top: 4px;
    padding-top: 8px;
    padding-bottom: 8px;
    background: rgba(0,0,0,0.02);
}

.result-row .line-subtotal {
    color: #d9534f;
    font-size: 1.2em;
    font-weight: bold;
}

.total-bar {
    background: #343a40;
    color: #fff;
    padding: 15px;
    font-size: 1.5em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.danger-btn-small {
    background: #dc3545;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: bold;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.5em;
}

.danger-btn-small:hover {
    background: #c82333;
}

.info-btn-small {
    background: #007bff; /* Màu xanh dương thân thiện */
    color: white;
    border: none;
    cursor: pointer;
    font-weight: bold;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.5em;
    transition: background-color 0.2s ease; /* Hiệu ứng chuyển màu */
}

.info-btn-small:hover {
    background: #0056b3;
}

.line-note {
    width: 50%;
    box-sizing: border-box; /* Đảm bảo padding không ảnh hưởng đến chiều rộng */
    padding-left: 15px; /* Tạo một khoảng đệm bên trái cho dễ nhìn */
    /* Các thay đổi để ô ghi chú hòa vào nền */
    border: none; /* Bỏ viền */
    background: transparent; /* Bỏ nền trắng */
    outline: none; /* Bỏ viền xanh khi focus */
    font-family: 'Courier New', Courier, monospace; /* Đồng bộ font chữ */
    font-size: 1.1em; /* Đồng bộ cỡ chữ */
    color: #333; /* Đồng bộ màu chữ */
    /* Bổ sung để có thanh trượt ngang và cố định chữ */
    /* Thay đổi để tự động xuống dòng và điều chỉnh chiều cao */
    resize: none; /* Tắt chức năng thay đổi kích thước của textarea */
    overflow: hidden; /* Ẩn thanh trượt, chiều cao sẽ được JS điều chỉnh */
}

/* Thêm style cho placeholder của ô ghi chú để đồng bộ */
.line-note::placeholder {
    color: #aaa;
    font-style: italic;
}

/* Các màu sắc dùng trong script */
.text-green { color: #28a745 !important; }
.text-red { color: #dc3545 !important; }
.total-green { color: #4ade80 !important; }
.total-red { color: #f87171 !important; }

.total-bar > div {
    display: flex;
    gap: 8px;
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 15px;
    box-sizing: border-box;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-content h2 {
    margin: 0;
    text-align: center;
    font-size: 1.4rem;
    color: #333;
}

.modal-content p {
    margin: 0;
    font-size: 0.9em;
    color: #555;
    text-align: center;
}

#paste-textarea {
    width: 100%;
    box-sizing: border-box;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1em;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    resize: vertical;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-actions button {
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9em;
}

.modal-actions button#process-data-btn { background-color: #007bff; color: white; }
.modal-actions button#process-data-btn:hover { background-color: #0056b3; }
.modal-actions button#cancel-paste-btn { background-color: #6c757d; color: white; }
.modal-actions button#cancel-paste-btn:hover { background-color: #5a6268; }