/* أساسيات الصفحة */
:root {
    --primary-color: #4a6bff;
    --primary-dark: #3a56d4;
    --secondary-color: #f8f9fa;
    --text-color: #333;
    --light-text: #666;
    --border-color: #ddd;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --border-radius: 10px;
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Tajawal', sans-serif;
}

body {
    background-color: #f5f5f5;
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}

/* Loader */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--primary-color);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.loader p {
    font-size: 1.2rem;
    color: var(--primary-color);
}

/* الهيدر */
header {
    background-color: white;
    padding: 1rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.logo h1 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo p {
    color: var(--light-text);
    font-size: 0.9rem;
}

.last-update {
    background-color: var(--secondary-color);
    padding: 0.5rem;
    border-radius: var(--border-radius);
    font-size: 0.8rem;
    text-align: center;
}

/* المحتوى الرئيسي */
main {
    max-width: 1200px;
    margin: 1rem auto;
    padding: 0 1rem;
}

section {
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

h2 {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary-color);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* قسم التحويل */
.converter-container {
    padding: 1rem;
}

.amount-section, .currency-section, .result-section {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--light-text);
    font-size: 0.9rem;
}

input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
}

input:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 2px rgba(74, 107, 255, 0.2);
}

.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: 50%;
    left: 10px;
    transform: translateY(-50%);
    color: var(--light-text);
    pointer-events: none;
}

select {
    width: 100%;
    padding: 0.8rem 1.5rem 0.8rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    appearance: none;
    background-color: white;
    transition: var(--transition);
}

select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 2px rgba(74, 107, 255, 0.2);
}

.currency-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.currency-from, .currency-to {
    flex: 1;
}

.swap-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    margin: 0 auto;
}

.swap-btn:hover {
    background-color: var(--primary-dark);
    transform: rotate(180deg);
}

.result {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background-color: var(--secondary-color);
    border-radius: var(--border-radius);
}

.rate {
    text-align: center;
    color: var(--light-text);
    font-size: 0.9rem;
}

.convert-btn {
    width: 100%;
    padding: 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.convert-btn:hover {
    background-color: var(--primary-dark);
}

/* البيانات التاريخية */
.time-frames {
    display: flex;
    padding: 0 1rem 1rem;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.time-frames::-webkit-scrollbar {
    display: none;
}

.time-btn {
    padding: 0.5rem 1rem;
    background-color: var(--secondary-color);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    font-size: 0.9rem;
}

.time-btn.active, .time-btn:hover {
    background-color: var(--primary-color);
    color: white;
}

.chart-container {
    padding: 1rem;
    height: 250px;
}

/* العملات الشائعة */
.currencies-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.currency-card {
    background-color: var(--secondary-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: var(--transition);
    cursor: pointer;
    text-align: center;
}

.currency-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.currency-card .flag {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.currency-card .code {
    font-weight: bold;
    margin-bottom: 0.2rem;
}

.currency-card .name {
    color: var(--light-text);
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.currency-card .rate {
    font-size: 1rem;
    color: var(--primary-color);
}

/* الفوتر */
footer {
    text-align: center;
    padding: 1.5rem 1rem;
    background-color: white;
    color: var(--light-text);
    font-size: 0.8rem;
    margin-top: 2rem;
}

footer p:first-child {
    margin-bottom: 0.5rem;
}

#api-source {
    color: var(--primary-color);
    font-weight: bold;
}

/* تحسينات للشاشات الكبيرة */
@media (min-width: 768px) {
    header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 1rem 2rem;
    }
    
    .logo h1 {
        font-size: 1.8rem;
    }
    
    .currency-section {
        flex-direction: row;
        align-items: flex-end;
    }
    
    .swap-btn {
        margin: 0 0.5rem;
    }
    
    .result {
        font-size: 2rem;
    }
    
    .chart-container {
        height: 300px;
    }
    
    .currencies-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* تحسينات للشاشات الصغيرة جداً */
@media (max-width: 400px) {
    .currencies-grid {
        grid-template-columns: 1fr 1fr;
    }
}