/* Tab Navigation Styles */
.tab-navigation {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 10px;
}

.tab-button {
    flex: 1;
    padding: 15px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background: transparent;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tab-button.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tab-button:hover:not(.active) {
    background: rgba(102, 126, 234, 0.1);
}

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============= LAYOUT CẢI THIỆN CHO TÍNH TIỀN ============= */

/* Cài đặt trên cùng - IMPROVED GRID */
.calculation-settings-top {
    margin-bottom: 25px;
}

.settings-grid-improved {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr; /* 4 cột */
    gap: 20px;
    align-items: start;
}

.settings-group {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 2px solid #dee2e6;
    border-radius: 12px;
    padding: 18px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.settings-group:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.settings-group h4 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.settings-row:last-child {
    margin-bottom: 0;
}

.setting-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 85px;
    flex: 1;
}

.setting-item label {
    font-size: 12px;
    font-weight: 600;
    color: #6c757d;
    margin-bottom: 6px;
    text-align: center;
}

/* IMPROVED INPUT STYLING */
.setting-input {
    width: 75px;
    padding: 10px 8px;
    border: 2px solid #ced4da;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    background: white;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.setting-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
    transform: scale(1.02);
}

.setting-input:hover {
    border-color: #adb5bd;
}

/* XIÊN SETTINGS - ĐẶC BIỆT */
.xiên-settings {
    background: linear-gradient(135deg, #fff9e6, #fff3cd);
    border-color: #ffc107;
}

.xiên-settings h4 {
    color: #856404;
    border-bottom-color: #ffc107;
}

.xiên-input {
    background: linear-gradient(135deg, #fff9e6, #ffffff);
    border-color: #ffc107;
    color: #856404;
}

.xiên-input:focus {
    border-color: #e0a800;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.2);
}

.setting-item input[type="date"] {
    width: 140px;
    padding: 10px 8px;
    border: 2px solid #ced4da;
    border-radius: 8px;
    font-size: 13px;
    background: white;
    transition: all 0.3s ease;
}

.setting-item input[type="date"]:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.btn-compact {
    padding: 10px 14px;
    font-size: 12px;
    min-width: 90px;
    font-weight: 600;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.btn-compact:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* VAI TRÒ SELECTOR - CẢI THIỆN */
.role-selector-settings {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
}

.role-option {
    cursor: pointer;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    transition: all 0.3s ease;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

.role-option:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.role-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.role-option input[type="radio"]:checked + .role-content {
    color: #667eea;
    font-weight: 700;
}

.role-option input[type="radio"]:checked {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.role-option:has(input[type="radio"]:checked) {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.05));
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.role-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    color: #4a5568;
    transition: all 0.3s ease;
}

.role-content i {
    font-size: 16px;
}

/* Xiên checkbox styling */
#xienNhayEnabled {
    width: 18px;
    height: 18px;
    accent-color: #ffc107;
    margin-right: 8px;
    transform: scale(1.2);
}

.setting-item:has(#xienNhayEnabled) {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.setting-item:has(#xienNhayEnabled) label {
    margin-bottom: 0;
    font-size: 13px;
    color: #856404;
    font-weight: 700;
}

/* Layout chính 2 cột cân đối */
.calculation-main-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 25px;
}

.calculation-left,
.calculation-right {
    display: flex;
    flex-direction: column;
}

/* Input sections lớn hơn */
.input-section-large {
    margin-bottom: 20px;
    padding: 20px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
}

.input-section-large h4 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 8px;
}

.input-section-large textarea {
    width: 100%;
    padding: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    font-family: 'Courier New', monospace;
}

.input-section-large textarea:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.btn-large {
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    width: 100%;
    margin-top: 10px;
}

/* Lottery results compact */
.lottery-results-compact {
    background: linear-gradient(135deg, #e8f5e8, #d4edda);
    border: 2px solid #28a745;
    border-radius: 12px;
    padding: 15px;
    margin-top: 15px;
}

.lottery-results-compact h4 {
    margin-bottom: 10px;
    color: #155724;
    font-size: 14px;
}

.result-grid-compact {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    font-size: 12px;
}

.result-grid-compact .result-item {
    background: white;
    padding: 8px;
    border-radius: 6px;
    border-left: 3px solid #28a745;
}

/* Kết quả tính toán toàn chiều rộng */
.calculation-results-full {
    grid-column: 1 / -1;
    margin-top: 20px;
}

/* Details grid 3 cột */
.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.detail-column {
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 15px;
}

.detail-column h4 {
    margin: 0 0 15px 0;
    color: #495057;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 8px;
}

.detail-table-container {
    max-height: 400px;
    overflow-y: auto;
    border-radius: 8px;
}

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

.detail-table th {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    position: sticky;
    top: 0;
    z-index: 1;
}

.detail-table td {
    padding: 8px;
    border-bottom: 1px solid #f1f5f9;
    background: white;
}

.detail-table tr:hover td {
    background: #f8f9fa;
}

/* Lottery Results for Calculation */
.lottery-results {
    background: #f8f9fa;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
}

.lottery-results h4 {
    margin-bottom: 15px;
    color: #2d3748;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.result-item {
    background: white;
    padding: 10px;
    border-radius: 6px;
    border-left: 4px solid #667eea;
}

.result-item strong {
    color: #2d3748;
}

/* Calculation Results */
.calculation-results {
    margin-top: 20px;
}

.calc-summary {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.calc-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.calc-row:last-child {
    border-bottom: none;
    font-weight: bold;
    font-size: 16px;
    color: #2d3748;
}

.win-amount {
    color: #38a169;
    font-weight: bold;
}

.lose-amount {
    color: #e53e3e;
    font-weight: bold;
}

.hit-number {
    background: #c6f6d5;
    color: #276749;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

/* Enhanced Input Sections */
.input-section {
    margin-bottom: 25px;
    padding: 15px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8f9fa;
}

.input-section h4 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-section h4::before {
    content: "📝";
    font-size: 1.2em;
}

/* Diễn giải tự động */
#dienGiaiTuDong {
    font-family: 'Courier New', monospace;
    background: #f8f9fa;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px;
    font-size: 13px;
    line-height: 1.5;
    color: #2d3748;
    transition: all 0.3s ease;
}

#dienGiaiTuDong:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Highlight lỗi trong diễn giải */
#dienGiaiTuDong.has-error {
    background: linear-gradient(135deg, #ffe6e6, #fff0f0);
    border-color: #dc3545;
    animation: errorShake 0.5s ease;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Tin nhắn khách input */
#tinNhanKhach {
    border: 2px dashed #cbd5e0;
    background: #ffffff;
    transition: all 0.3s ease;
}

#tinNhanKhach:focus {
    border-color: #667eea;
    border-style: solid;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#tinNhanKhach::placeholder {
    color: #a0aec0;
    font-style: italic;
}

/* Xiên Details Table Specific Styling */
#moneyXienDetails {
    background: linear-gradient(135deg, #f0f8ff, #e6f3ff);
    border: 2px solid #4a90e2;
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
}

#moneyXienDetails h4 {
    color: #2c5aa0;
    margin-bottom: 15px;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 8px;
}

#moneyXienDetails h4::before {
    content: "🎰";
    font-size: 1.2em;
}

#moneyXienDetailsBody tr:hover {
    background: linear-gradient(135deg, #e6f3ff, #f0f8ff);
}

/* Responsive cho calculation layout */
@media (max-width: 1200px) {
    .settings-grid-improved {
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }
    
    .calculation-main-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .details-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .settings-grid-improved {
        grid-template-columns: 1fr;
    }
    
    .settings-row {
        flex-direction: column;
        gap: 8px;
    }
    
    .setting-item {
        width: 100%;
    }
    
    .setting-input,
    .setting-item input[type="date"] {
        width: 100%;
    }
    
    .role-selector-settings {
        flex-direction: column;
    }
    
    .details-grid {
        grid-template-columns: 1fr;
    }
    
    .tab-button {
        padding: 12px 15px;
        font-size: 14px;
    }
    
    .tab-button i {
        display: none;
    }
    
    .calc-row {
        flex-direction: column;
        gap: 5px;
    }
    
    .calc-row span:last-child {
        text-align: right;
        font-weight: bold;
    }
}

/* Loading states */
.calculating {
    opacity: 0.7;
    pointer-events: none;
    position: relative;
}

.calculating::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #667eea;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Success/Error states */
.success-highlight {
    background: rgba(72, 187, 120, 0.1);
    border-color: #48bb78;
    animation: successPulse 0.6s ease;
}

.error-highlight {
    background: rgba(245, 101, 101, 0.1);
    border-color: #f56565;
    animation: errorPulse 0.6s ease;
}

@keyframes successPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes errorPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Advanced typography */
.section h3 {
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
}

/* Custom scrollbar for calculation results */
.calculation-results::-webkit-scrollbar,
.rule-list::-webkit-scrollbar {
    width: 8px;
}

.calculation-results::-webkit-scrollbar-track,
.rule-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.calculation-results::-webkit-scrollbar-thumb,
.rule-list::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 4px;
}

.calculation-results::-webkit-scrollbar-thumb:hover,
.rule-list::-webkit-scrollbar-thumb:hover {
    background: #5a67d8;
}

/* Enhanced focus styles for accessibility */
.tab-button:focus,
.rule-actions button:focus,
.add-rule-section input:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Dark mode compatibility preparations */
@media (prefers-color-scheme: dark) {
    .rule-item {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .add-rule-section {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .rule-examples {
        background: linear-gradient(135deg, #4a5568, #2d3748);
    }
    
    .rule-example {
        background: #1a202c;
        color: #e2e8f0;
    }
    
    #moneyXienDetails {
        background: linear-gradient(135deg, #2d3748, #1a202c);
        border-color: #4a90e2;
    }
}