:root {
    --primary-color: #3b82f6; /* Blue 500 */
    --primary-color-dark: #2563eb; /* Blue 600 */
    --bg-color: #f9fafb; /* Gray 50 */
    --fg-color: #ffffff;
    --text-color: #1f2937; /* Gray 800 */
    --text-muted: #6b7280; /* Gray 500 */
    --border-color: #e5e7eb; /* Gray 200 */
    --green-color: #10b981; /* Green 500 */
    --red-color: #ef4444; /* Red 500 */
    --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --font-family: 'Cairo', sans-serif;
}

html.dark {
    --primary-color: #60a5fa; /* Blue 400 */
    --primary-color-dark: #3b82f6; /* Blue 500 */
    --bg-color: #111827; /* Gray 900 */
    --fg-color: #1f2937; /* Gray 800 */
    --text-color: #f9fafb; /* Gray 50 */
    --text-muted: #9ca3af; /* Gray 400 */
    --border-color: #374151; /* Gray 700 */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    font-size: 16px;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.card {
    background-color: var(--fg-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    transition: background-color 0.3s, border-color 0.3s;
}

/* Header */
.app-header {
    background-color: var(--fg-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: background-color 0.2s, color 0.2s;
}

.icon-button:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
}

#theme-toggle .moon { display: none; }
#theme-toggle .sun { display: block; }
html.dark #theme-toggle .moon { display: block; }
html.dark #theme-toggle .sun { display: none; }

/* Main Content */
main {
    padding: 2rem 0;
}

section {
    margin-bottom: 2rem;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

/* Converter */
#converter-form { display: flex; flex-direction: column; gap: 1rem; }
.converter-row { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap;}
.form-group { display: flex; flex-direction: column; }
.form-group.from-group { flex-grow: 2; }
.form-group label { margin-bottom: 0.5rem; font-size: 0.9rem; color: var(--text-muted); }
.form-group input, .form-group select {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 1rem;
    width: 100%;
}

input:focus, select:focus { outline: 2px solid var(--primary-color); }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

.custom-select {
    position: relative;
}

.custom-select select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 2.5rem;
}

.select-arrow {
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    pointer-events: none;
    border: solid var(--text-muted);
    border-width: 0 2px 2px 0;
    display: inline-block;
    padding: 3px;
    transform: translateY(-50%) rotate(45deg);
    -webkit-transform: translateY(-50%) rotate(45deg);

}

#swap-currencies { align-self: flex-end; margin-bottom: 0.45rem; }
.converter-result-container { margin-top: 1rem; text-align: center; }
#converter-result { font-size: 2rem; font-weight: 700; color: var(--primary-color); min-height: 40px; }
#single-unit-rate { font-size: 1rem; color: var(--text-muted); min-height: 24px; }

/* Rates Section */
.rates-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.search-tabs-wrapper { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.search-container {
    position: relative;
}

#search-currency {
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background-color: var(--fg-color);
    color: var(--text-color);
    width: 250px;
    transition: width 0.3s;
}

#search-currency:focus { width: 300px; outline: 1px solid var(--primary-color);}
.search-icon { position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

.tabs { display: flex; background: var(--bg-color); border-radius: 8px; padding: 4px; }
.tab-btn { background: none; border: none; padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer; color: var(--text-muted); font-weight: 600; transition: all 0.3s; }
.tab-btn.active { color: var(--primary-color-dark); background: var(--fg-color); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
html.dark .tab-btn.active { color: var(--primary-color); }

/* Currency Grid */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.currency-card {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem; border: 1px solid var(--border-color); border-radius: 10px;
    background-color: var(--fg-color);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.currency-card:hover { transform: translateY(-3px); box-shadow: 0 7px 14px rgba(0,0,0,0.07), 0 3px 6px rgba(0,0,0,0.05); }
.currency-info { display: flex; align-items: center; gap: 1rem; }
.currency-flag { width: 40px; height: 30px; object-fit: cover; border-radius: 4px; background-color: var(--border-color); }
.currency-name-code .code { font-weight: 700; font-size: 1.1rem; }
.currency-name-code .name { font-size: 0.9rem; color: var(--text-muted); }

.currency-rate-change { text-align: left; display: flex; flex-direction: column; align-items: flex-start; }
.currency-rate { font-weight: 600; font-size: 1.1rem; }
.currency-change { font-size: 0.9rem; font-weight: 600;  }
.currency-change.positive { color: var(--green-color); }
.currency-change.negative { color: var(--red-color); }

.favorite-btn {
    background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 5px; 
}
.favorite-btn svg { width: 20px; height: 20px; transition: color 0.2s, transform 0.2s;}
.favorite-btn.is-favorite svg { fill: #facc15; color: #facc15; transform: scale(1.1); }

#last-updated-container { text-align: center; margin-top: 1.5rem; color: var(--text-muted); font-size: 0.9rem;}

/* Spinner */
.spinner-container { display: none; justify-content: center; align-items: center; padding: 2rem; }
.spinner-container.show { display: flex; }
.spinner {
    width: 50px; height: 50px; border: 5px solid var(--border-color);
    border-top-color: var(--primary-color); border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 100; backdrop-filter: blur(5px); }
.modal-content { width: 90%; max-width: 800px; padding: 1rem; position: relative;} 
.close-button { position: absolute; top: 10px; left: 10px; background: none; border: none; font-size: 2rem; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-header { text-align: center; margin-bottom: 1rem; }
#chart-currency-title { font-size: 1.5rem; }
.chart-controls { display: flex; justify-content: center; gap: 0.5rem; margin-bottom: 1rem; }
.chart-range-btn { background: var(--bg-color); border: 1px solid var(--border-color); color: var(--text-muted); padding: 0.4rem 0.8rem; border-radius: 20px; cursor: pointer; }
.chart-range-btn.active { background: var(--primary-color); color: white; border-color: var(--primary-color); }
.chart-container { position: relative; height: 300px; }
.chart-notice { font-size: 0.8rem; color: var(--text-muted); text-align: center; margin-top: 1rem; }

/* Footer */
.app-footer { background-color: var(--fg-color); border-top: 1px solid var(--border-color); padding: 1.5rem 0; text-align: center; margin-top: 2rem; color: var(--text-muted); font-size: 0.9rem; }

/* Responsive */
@media (max-width: 768px) {
    h2 { font-size: 1.25rem; }
    .converter-row { flex-direction: column; align-items: stretch; }
    #swap-currencies { align-self: center; transform: rotate(90deg); margin: 0; }
    .rates-header { flex-direction: column; align-items: stretch; }
    .search-tabs-wrapper { flex-direction: column-reverse; align-items: stretch; }
    .tabs { justify-content: center; }
    #search-currency, #search-currency:focus { width: 100%; }
    .modal-content { width: 95%; padding: 1rem; }
}