:root {
    --primary-color: #0d6efd;
    --primary-dark: #0a58ca;
    --secondary-color: #6c757d;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --font-color: #212529;
    --border-color: #dee2e6;
    --success-bg: #d1e7dd;
    --success-border: #a3cfbb;
    --success-color: #0f5132;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --border-radius: 12px;
}

body {
    font-family: 'Tajawal', sans-serif;
    background-color: var(--bg-color);
    color: var(--font-color);
    margin: 0;
    padding: 20px;
    direction: rtl;
    line-height: 1.7;
}

.main-container {
    max-width: 1100px;
    margin: 20px auto;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

header .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    font-size: 1.8rem;
    color: var(--primary-color);
}

header .logo .fas {
    font-size: 2.5rem;
}

header h1 {
    margin: 0;
    font-weight: 700;
}

header p {
    font-size: 1.1rem;
    color: var(--secondary-color);
    margin-top: 5px;
}

.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 25px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: all 0.3s ease;
}

.card-header {
    background-color: #f7f9fc;
    padding: 15px 25px;
    margin: 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.3rem;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-body {
    padding: 25px;
}

.form-grid, .filters-grid, .results-grid, .details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

label {
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.95rem;
}

input, select {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: 'Tajawal', sans-serif;
    transition: all 0.2s ease-in-out;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.reference {
    font-size: 0.8rem;
    color: var(--secondary-color);
    margin-top: 5px;
}

.reference sup {
    cursor: help;
    color: var(--primary-color);
    font-weight: bold;
}

.filter-option {
    border: 1px solid var(--border-color);
    padding: 20px;
    border-radius: var(--border-radius);
    background-color: #fdfdff;
}

.filter-option h3 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--primary-dark);
}

.filter-info {
    font-size: 0.9rem;
    color: #555;
    margin-top: 15px;
    background: #f8f9fa;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #eee;
}

#calculate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 16px;
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    background-image: linear-gradient(45deg, var(--primary-dark), var(--primary-color));
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    margin: 20px 0;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(13, 110, 253, 0.3);
}

#calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.4);
}

.hidden {
    display: none;
}

#results-section .results-grid {
    margin-bottom: 20px;
}

.result-card {
    border: 2px solid var(--border-color);
    padding: 20px;
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.result-card h4 {
    text-align: center;
    font-size: 1.2rem;
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--primary-dark);
}

.result-card p {
    margin: 5px 0 15px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.result-card p .fas {
    color: var(--secondary-color);
}

.tco-box {
    margin-top: auto;
    background-color: var(--secondary-color);
    color: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.tco-label {
    font-size: 0.9rem;
    opacity: 0.9;
}

.tco-value {
    font-size: 1.8rem;
    font-weight: 700;
}

.result-card.best-option {
    border-color: var(--success-border);
    background-color: var(--success-bg);
}

.result-card.best-option h4, .result-card.best-option p .fas {
    color: var(--success-color);
}

.result-card.best-option .tco-box {
    background-color: var(--success-color);
}

#toggle-details-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto;
    margin: 20px auto 0 auto;
    padding: 10px 20px;
    font-size: 1rem;
    background-color: transparent;
    color: var(--secondary-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

#toggle-details-btn:hover {
    background-color: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
}

#calculation-details ul {
    list-style-type: none;
    padding: 0;
}

#calculation-details li {
    background-color: var(--card-bg);
    padding: 12px 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    border-left: 5px solid var(--primary-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

#calculation-details .formula {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: #e83e8c;
    display: block;
    margin-top: 5px;
    direction: ltr;
    text-align: left;
    background-color: #f8f9fa;
    padding: 5px;
    border-radius: 4px;
}

#calculation-details .ref-note {
    font-size: 0.8em;
    color: var(--secondary-color);
    display: block;
    text-align: left;
}

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

#results-section.fade-in, #calculation-details.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

.secondary-btn {
    background-color: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    padding: 8px 16px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 700;
    transition: all 0.3s ease;
    margin-top: 15px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.secondary-btn:hover {
    background-color: var(--primary-color);
    color: white;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--border-radius);
    max-width: 90%;
    width: 1200px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transform: scale(1);
    transition: transform 0.3s ease;
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.95);
}

.modal-close {
    position: absolute;
    top: 15px;
    left: 20px;
    background: transparent;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--secondary-color);
}

.table-container {
    width: 100%;
    overflow-x: auto;
    margin: 20px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1100px;
}

table th, table td {
    padding: 12px 15px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

table thead th {
    background-color: #f7f9fc;
    font-weight: 700;
    color: var(--primary-dark);
    position: sticky;
    top: 0;
    z-index: 1;
}

table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

table tbody tr:hover {
    background-color: #e9ecef;
}

.modal-content h2, .modal-content h3 {
    color: var(--primary-dark);
}