body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
    --header-height: 60px; /* CSS variable cho chiều cao header desktop */
    --mobile-header-height: 120px; /* CSS variable cho mobile */
}
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height); /* Sử dụng CSS variable */
    background: #81c408;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
    padding: 0 20px;
    box-sizing: border-box;
}
.header-left {
    flex: 1;
    display: flex;
    align-items: center;
}
.site-name {
    cursor: pointer;
    font-size: 2em;
    font-weight: bold;
}
.header-center {
    flex: 2;
    display: flex;
    justify-content: center;
    gap: 10px;
}
.nav-btn {
    background: transparent;
    color: #fff;
    border: 2px solid transparent;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s, color 0.2s;
}
.nav-btn:hover {
    background: #fff;
    color: #007bff;
}
.header-right {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}
.icon-btn {
    background: transparent;
    color: inherit;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-weight: bold;
    transition: background 0.2s;
}
.icon-btn img {
    margin-right: 4px;
}
.icon-btn:hover {
    background: rgba(255,255,255,0.2);
}
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100px;
    background: #45595b;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    font-family: Arial, sans-serif;
}
.footer-main {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 100px;
}
.footer-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.footer-brand {
    font-size: 1.5em;
    font-weight: bold;
    color: #81c408;
}
.footer-sub {
    font-size: 1em;
    color: #ffb300;
    margin-top: 4px;
}
.footer-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}
.payment-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.payment-email {
    color: #ccc;
    font-size: 1em;
    min-width: 180px;
}
.content {
    margin-top: var(--header-height); /* Sử dụng CSS variable */
    margin-bottom: 50px;
    padding: 20px;
}
.form-login {
    max-width: 350px;
    margin: 24px auto;
    padding: 24px 28px;
    background: #f7f7f7;
    border-radius: 10px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.form-login label {
    font-weight: bold;
    color: #45595b;
    margin-bottom: 6px;
    display: block;
}
.form-login input[type="text"],
.form-login input[type="password"],
.form-login input[type="email"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #b6b64a;
    border-radius: 5px;
    font-size: 1em;
    margin-bottom: 8px;
    background: #fff;
    color: #333;
    box-sizing: border-box;
}
.form-login input[type="password"] {
    padding-right: 36px;
}
.form-login input[type="text"].error,
.form-login input[type="password"].error {
    border-color: #d32f2f !important;
}
.form-login input:focus {
    border-color: #81c408;
    outline: none;
}
.form-login .nav-btn {
    background: #81c408;
    color: #fff;
    border: none;
    padding: 10px 0;
    border-radius: 5px;
    font-weight: bold;
    font-size: 1em;
    cursor: pointer;
    transition: background 0.2s;
}
.form-login .nav-btn:hover {
    background: #6ca007;
}
#login-section h2 {
    color: #81c408;
    text-align: center;
}
.forgot-btn {
    background: none;
    border: none;
    color: #81c408;
    font-size: 1em;
    cursor: pointer;
    margin-top: 8px;
    text-align: center;
    text-decoration: underline;
    transition: color 0.2s;
}
.forgot-btn:hover {
    color: #6ca007;
}
.form-error {
    color: #d32f2f;
    background: #fff3f3;
    border: 1px solid #d32f2f;
    border-radius: 4px;
    padding: 8px;
    margin-bottom: 8px;
    text-align: center;
    display: none;
}
.global-error {
    position: fixed;
    /* top sẽ được set bằng JavaScript */
    right: 10px; /* Hiển thị ở bên phải */
    min-width: 260px;
    max-width: 350px;
    background: #fff3f3;
    color: #d32f2f;
    border: 1px solid #d32f2f;
    border-radius: 8px;
    padding: 12px 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    font-size: 1em;
    z-index: 9999; /* Z-index cao nhất */
    display: none;
    text-align: left;
    /* Fallback nếu JavaScript fail */
    top: 70px;
}
#username-display {
    display: inline-block;
    vertical-align: middle;
    font-weight: bold;
    color: #333;
}
#btn-logout img {
    vertical-align: middle;
}
.toggle-password {
    position: absolute;
    right: 8px;
    top: 50px;
    background: none;
    border: none;
    padding: 0;
    display: flex;
    justify-content: center;
    height: 24px;
    width: 24px;
    cursor: pointer;
}
.toggle-password i {
    color: #81c408;
}
#device-key-form {
    margin: 24px auto;
    max-width: 700px;
    background: #f9fff3;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(129,196,8,0.08);
    padding: 24px 16px;
}

#device-key-form table {
    width: 100%;
    border-collapse: collapse;
}

#device-key-form td {
    align-items: center;
    vertical-align: middle;
    padding: 8px 6px;
}

#device-key-form input[type="text"]{
    display: block;
    margin: 0 auto;
    width: 100%;
      padding: 6px 10px;
    border: 1px solid #cde7b0;
    border-radius: 6px;
    font-size: 1em;
    background: #fff;
    transition: border-color 0.2s;
}
#device-key-form input[type="number"] {
    text-align: center;
    display: block;
    margin: 0 auto;
    max-width: 80px;
    padding: 6px 10px;
    border: 1px solid #cde7b0;
    border-radius: 6px;
    font-size: 1em;
    background: #fff;
    transition: border-color 0.2s;
}

#device-key-form input[type="text"]:focus,
#device-key-form input[type="number"]:focus {
    border-color: #81c408;
    outline: none;
}

#device-key-form .nav-btn {
    display: block;
    margin: 18px auto 0 auto;
    background: #81c408;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 32px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

#device-key-form .nav-btn:hover {
    background: #6ca007;
}
#autoreroll-count {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-weight: bold;
    color: #333;
    gap: 20px;
}

#autoreroll-left {
    padding-left: 50px;
}
#autoreroll-right {
    padding-right: 50px;
}

/* Tablet responsive */
@media (max-width: 768px) and (min-width: 601px) {
    .global-error {
        right: 15px;
        max-width: 300px;
        min-width: 240px;
    }
}

@media (max-width: 600px) {
    header {
        flex-direction: column;
        height: auto;
        padding: 10px;
    }
    .header-center {
        margin: 10px 0;
    }
    .content {
        margin-top: 140px;
        padding: 10px;
    }
    
    /* Global error responsive */
    .global-error {
        /* top sẽ được tính toán bằng JavaScript */
        right: 5px;
        max-width: calc(100vw - 20px); /* Không vượt quá màn hình */
        min-width: 250px;
        font-size: 0.9em;
        padding: 10px 15px;
    }
    
    footer {
        height: auto;
        font-size: 16px;
        padding-bottom: 10px;
    }
    .content {
        padding: 10px;
    }
    .footer-main {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 20px;
    }
    .footer-right {
        margin-top: 10px;
    }
}
#changepass-section h2 {
    color: #81c408;
    text-align: center;
}

#admin-section,
#key-section,
#home-section,
#login-section,
#changepass-section,
#register-section {
    padding-bottom: 100px;
}
body, html {
    scrollbar-width: none;
}
body::-webkit-scrollbar, html::-webkit-scrollbar {
    display: none;
}
.download-btn {
    background: #81c408;
    color: #fff;
    font-size: 1.2em;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    padding: 10px 30px;
    cursor: pointer;
    margin: 0 auto;
    display: block;
}
.download-btn:hover {
    background: #6ca007;
}
.tutorial-switch {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
}
.tutorial-toggle-btn {
    background: linear-gradient(135deg, #81c408, #6ca007);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(129, 196, 8, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.tutorial-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(129, 196, 8, 0.36);
    filter: brightness(1.02);
}
.tutorial-toggle-btn.active {
    background: #45595b;
    box-shadow: 0 8px 20px rgba(69, 89, 91, 0.35);
}
.tutorial-panel {
    display: none;
    margin-top: 18px;
}
@media (max-width: 600px) {
    .tutorial-toggle-btn {
        width: 100%;
        max-width: 320px;
    }
}

/* Admin Panel Styles */
.admin-content {
    display: block;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

.admin-users-table {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
}

.admin-users-table h3 {
    color: #81c408;
    margin-bottom: 15px;
    text-align: center;
}

.admin-controls {
    display: flex;
    justify-content: flex-end; /* Căn phải search container */
    align-items: center;
    margin-bottom: 20px;
}

.search-container {
    display: flex;
    align-items: center;
    position: relative;
}

.search-input {
    padding: 8px 35px 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    width: 400px;
    transition: border-color 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: #81c408;
    box-shadow: 0 0 5px rgba(129, 196, 8, 0.3);
}

.search-btn {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: #999;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-btn:hover {
    color: #666;
}

#users-table-container {
    overflow-x: auto;
    margin-top: 20px;
}

#users-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 5px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#users-table th {
    background: #81c408;
    color: white;
    padding: 12px 8px;
    text-align: center;
    font-weight: bold;
    border-bottom: 2px solid #6ca007;
}

#users-table td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid #dee2e6;
    vertical-align: middle;
}

/* Căn lề trái cho các cột Username và Expire */
#users-table td:nth-child(1) {
    text-align: left;
}

#users-table tr:nth-child(even) {
    background-color: #f8f9fa;
}

#users-table tr:hover {
    background-color: #e8f5e8;
}

.action-btn {
    padding: 5px 10px;
    margin: 2px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: background 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.action-btn img {
    width: 18px;
    height: 18px;
    display: block;
}

.edit-btn {
    background: transparent;
    color: #007bff;
    border: 1px solid #007bff;
}

.edit-btn:hover {
    background: rgba(0, 123, 255, 0.1);
    color: #0056b3;
}

.delete-btn {
    background: transparent;
    color: #dc3545;
    border: 1px solid #dc3545;
}

.delete-btn:hover {
    background: rgba(220, 53, 69, 0.1);
    color: #c82333;
}

.admin-btn {
    background: #81c408;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s ease;
    font-size: 1em;
    margin-bottom: 0px;
}

.admin-btn:hover {
    background: #6ca007;
}

#admin-section {
    display: none !important;
}

#admin-section.admin-allowed {
    display: block !important;
}

@media (max-width: 768px) {
    .admin-content {
        padding: 10px;
    }
    
    .admin-users-table {
        padding: 15px;
    }
    
    .admin-controls {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
    
    .search-container {
        justify-content: center;
    }
    
    .search-input {
        width: 100%;
        max-width: 250px;
    }
    
    #users-table th,
    #users-table td {
        padding: 8px 4px;
        font-size: 12px;
    }
    
    .action-btn {
        padding: 4px 8px;
        font-size: 10px;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
    animation: slideIn 0.3s ease;
    box-sizing: border-box;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid #81c408;
    padding-bottom: 10px;
}

.modal-header h3 {
    margin: 0;
    color: #81c408;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #333;
}

.modal-form-group {
    margin-bottom: 15px;
}

.modal-form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

.modal-form-group input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}

.modal-form-group input:focus {
    outline: none;
    border-color: #81c408;
    box-shadow: 0 0 5px rgba(129, 196, 8, 0.3);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s ease;
}

.modal-btn-primary {
    background: #81c408;
    color: white;
}

.modal-btn-primary:hover {
    background: #6ca007;
}

.modal-btn-secondary {
    background: #6c757d;
    color: white;
}

.modal-btn-secondary:hover {
    background: #545b62;
}

.modal-btn-danger {
    background: #dc3545;
    color: white;
}

.modal-btn-danger:hover {
    background: #c82333;
}

.confirm-text {
    margin-bottom: 20px;
    color: #333;
    line-height: 1.5;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Modal responsive */
@media (max-width: 600px) {
    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 15px;
    }
    
    .modal-form-group input {
        padding: 10px 12px;
        font-size: 16px;
    }
}
