/* assets/css/loan-calculator.css */

/* فونت‌ها */
@font-face {
    font-family: 'Vazir';
    font-style: normal;
    font-weight: 400;
    src: url('../fonts/Vazirmatn-Regular.woff2') format('woff2');
    font-display: swap;
}

@font-face {
    font-family: 'Vazir';
    font-style: normal;
    font-weight: 500;
    src: url('../fonts/Vazirmatn-Medium.woff2') format('woff2');
    font-display: swap;
}

@font-face {
    font-family: 'Vazir';
    font-style: normal;
    font-weight: 700;
    src: url('../fonts/Vazirmatn-Bold.woff2') format('woff2');
    font-display: swap;
}

/* متغیرهای CSS */
:root {
    --primary-blue: #007AFF;
    --primary-purple: #AF52DE;
    --success-green: #34C759;
    --warning-orange: #FF9500;
    --error-red: #FF3B30;
    --pink: #FF2D92;
    --cyan: #32D74B;
    
    --text-primary: #000000;
    --text-secondary: rgba(0, 0, 0, 0.7);
    --text-tertiary: rgba(0, 0, 0, 0.5);
    
    --bg-primary: #F2F2F7;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: rgba(0, 0, 0, 0.05);
    
    --shadow-light: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.15);
    
    --radius: 16px;
    --radius-small: 12px;
    --radius-large: 20px;
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* تم تاریک */
[data-theme="dark"] {
    --text-primary: #FFFFFF;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-tertiary: rgba(255, 255, 255, 0.5);
    
    --bg-primary: #000000;
    --bg-secondary: rgba(255, 255, 255, 0.1);
    --bg-tertiary: rgba(255, 255, 255, 0.05);
}

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

body {
    font-family: 'Vazir', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Container */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

/* ===== HEADER / BACK BUTTON ===== */
        .top-nav {
            position: sticky;
            top: 0;
            z-index: 100;
            background: var(--bg);
            border-bottom: 1px solid rgba(128,128,128,0.15);
            padding: 12px 16px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .back-btn {
            display: flex;
            align-items: center;
            gap: 5px;
            color: var(--orange);
            text-decoration: none;
            font-size: 15px;
            font-weight: 600;
            padding: 6px 10px;
            border-radius: 8px;
            transition: background 0.2s;
        }

        .back-btn:hover {
            background: rgba(255,149,0,0.12);
        }

        .back-btn svg {
            width: 18px;
            height: 18px;
        }

        .top-nav-title {
            font-size: 16px;
            font-weight: 700;
            color: var(--text-primary);
            flex: 1;
            text-align: center;
        }
        
/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-blue), var(--primary-purple));
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-medium);
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cdefs%3E%3Cpattern id='grain' width='100' height='100' patternUnits='userSpaceOnUse'%3E%3Ccircle cx='25' cy='25' r='1' fill='white' opacity='0.1'/%3E%3Ccircle cx='75' cy='75' r='1' fill='white' opacity='0.1'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='100' height='100' fill='url(%23grain)'/%3E%3C/svg%3E");
}

.header-content {
    position: relative;
    z-index: 2;
}

.header h1 {
    color: white;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.header p {
    color: rgba(255,255,255,0.9);
    font-size: 1rem;
    font-weight: 400;
}

.help-btn {
    position: absolute;
    top: 24px;
    left: 24px;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.2rem;
    z-index: 3;
}

.help-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.05);
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Section */
.calculation-type-section,
.input-section {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-light);
    /* backdrop-filter: blur(10px); */
}

.section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.section-label .icon {
    font-size: 1.2rem;
}

/* Dropdown */
.dropdown {
    position: relative;
    width: 100%;
}

.dropdown-button {
    width: 100%;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: var(--radius-small);
    padding: 16px;
    font-family: 'Vazirmatn', sans-serif;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: var(--transition);
}

.dropdown-button:hover {
    border-color: var(--primary-blue);
}

.dropdown-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dropdown-content .icon {
    font-size: 1.5rem;
}

.dropdown-content span {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chevron {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: var(--transition);
}

.dropdown.open .chevron {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow-medium);
    z-index: 100;
    max-height: 0;
    overflow: hidden;
    transition: var(--transition);
    border: 2px solid var(--bg-tertiary);
    z-index: 10001;
}

.dropdown.open .dropdown-menu {
    max-height: 500px;
    margin-top: 8px;
    z-index: 10002;
}

.dropdown-item {
    padding: 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--bg-tertiary);
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
}

.dropdown-item .icon {
    font-size: 1.5rem;
    margin-top: 2px;
}

.item-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.item-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Input Fields */
.input-field {
    margin-bottom: 20px;
}

.input-field label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.input-field label .icon {
    font-size: 1rem;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper input,
.input-wrapper select {
    flex: 1;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: var(--radius-small);
    padding: 16px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: var(--transition);
    font-family: inherit;
}

.input-wrapper input:focus,
.input-wrapper select:focus {
    outline: none;
    border-color: var(--primary-blue);
    background: var(--bg-secondary);
}

.input-wrapper input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

.input-suffix {
    position: absolute;
    left: 16px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--primary-blue);
    pointer-events: none;
}

/* Grid Layout for Installments */
.installments-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    font-family: 'Vazirmatn', sans-serif;
}

@media (max-width: 600px) {
    .installments-grid {
        grid-template-columns: 1fr;
    }
}

/* Calculate Button */
.calculate-btn {
    background: linear-gradient(135deg, var(--primary-blue), var(--primary-purple));
    color: white;
    border: none;
    border-radius: var(--radius-small);
    padding: 18px 24px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Vazirmatn', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 8px 20px rgba(0, 122, 255, 0.3);
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(0, 122, 255, 0.4);
}

.calculate-btn:active {
    transform: translateY(0);
}

.calculate-btn .icon {
    font-size: 1.2rem;
}

/* Results Section */
.results-section {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-light);
    border: 2px solid var(--success-green);
    animation: slideInUp 0.5s ease-out;
}

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

.results-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.results-header .icon {
    font-size: 1.5rem;
    color: var(--success-green);
}

.results-header h3 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Result Item */
.result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    margin-bottom: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-small);
    transition: var(--transition);
}

.result-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-light);
}

.result-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.result-item-info .icon {
    font-size: 1.3rem;
}

.result-item-info span {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.result-item-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-blue);
}

/* Stepped Schedule */
.stepped-schedule {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--bg-tertiary);
}

.stepped-schedule h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.schedule-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: var(--primary-purple);
    background: linear-gradient(135deg, rgba(175, 82, 222, 0.1), rgba(175, 82, 222, 0.05));
    border-radius: var(--radius-small);
}

.schedule-item span:first-child {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.schedule-item span:last-child {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-purple);
}

/* Share Button */
.share-btn {
    background: transparent;
    color: var(--cyan);
    border: 2px solid var(--cyan);
    border-radius: var(--radius-small);
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 500;
    font-family: 'Vazirmatn', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 16px;
    width: 100%;
}

.share-btn:hover {
    background: var(--cyan);
    color: white;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-medium);
    animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    border-bottom: 1px solid var(--bg-tertiary);
}

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(80vh - 100px);
}

.help-section {
    margin-bottom: 32px;
}

.help-section h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.help-section p {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 16px;
}

.help-section ul {
    list-style: none;
    padding: 0;
}

.help-section li {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 8px;
    padding-right: 20px;
    position: relative;
}

.help-section code {
    background: var(--bg-tertiary);
    color: var(--cyan);
    padding: 8px 12px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    display: block;
    margin: 12px 0;
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 56px;
    height: 56px;
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-medium);
    transition: var(--transition);
    z-index: 999;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.loading.show {
    display: flex;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(0, 122, 255, 0.3);
    border-top: 4px solid var(--primary-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    
    .header {
        padding: 20px;
    }
    
    .header h1 {
        font-size: 1.6rem;
    }
    
    .header p {
        font-size: 0.9rem;
    }
    
    .help-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .calculation-type-section,
    .input-section,
    .results-section {
        padding: 20px;
    }
    
    .dropdown-button {
        padding: 14px;
    }
    
    .dropdown-item {
        padding: 14px;
    }
    
    .input-wrapper input,
    .input-wrapper select {
        padding: 14px;
    }
    
    .calculate-btn {
        padding: 16px 20px;
        font-size: 1rem;
    }
    
    .theme-toggle {
        width: 48px;
        height: 48px;
        bottom: 20px;
        left: 20px;
        font-size: 1.3rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .modal-header,
    .modal-body {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 12px;
    }
    
    .header {
        padding: 16px;
        margin-bottom: 20px;
    }
    
    .header h1 {
        font-size: 1.4rem;
    }
    
    .main-content {
        gap: 20px;
    }
    
    .calculation-type-section,
    .input-section,
    .results-section {
        padding: 16px;
    }
    
    .result-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .result-item-value {
        align-self: flex-end;
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-error {
    color: var(--error-red);
}

.text-success {
    color: var(--success-green);
}

.text-warning {
    color: var(--warning-orange);
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

.slide-up {
    animation: slideInUp 0.5s ease-out;
}

/* Error States */
.input-wrapper.error input,
.input-wrapper.error select {
    border-color: var(--error-red);
    background: rgba(255, 59, 48, 0.1);
}

.error-message {
    color: var(--error-red);
    font-size: 0.85rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.error-message .icon {
    font-size: 0.9rem;
}

/* Success States */
.input-wrapper.success input,
.input-wrapper.success select {
    border-color: var(--success-green);
}

/* Focus States */
.dropdown-button:focus,
.input-wrapper input:focus,
.input-wrapper select:focus,
.calculate-btn:focus,
.help-btn:focus,
.theme-toggle:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .theme-toggle,
    .help-btn,
    .modal {
        display: none !important;
    }
    
    .container {
        max-width: 100%;
        padding: 0;
    }
    
    .header {
        background: none !important;
        color: black !important;
    }
    
    .results-section {
        border: 1px solid #ccc;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --shadow-light: 0 2px 10px rgba(0, 0, 0, 0.3);
        --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.4);
    }
    
    .dropdown-button,
    .input-wrapper input,
    .input-wrapper select {
        border: 2px solid var(--text-secondary);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* گرادینت‌های SwiftUI */
.input-wrapper input:focus,
.input-wrapper select:focus {
    background: linear-gradient(135deg, var(--surface-color) 0%, rgba(0, 122, 255, 0.05) 100%);
    border: 2px solid var(--primary-blue);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

.result-item {
    background: linear-gradient(135deg, var(--surface-color) 0%, rgba(0, 122, 255, 0.02) 100%);
    border: 1px solid rgba(0, 122, 255, 0.1);
}

.result-item:nth-child(even) {
    background: linear-gradient(135deg, var(--surface-color) 0%, rgba(52, 199, 89, 0.02) 100%);
    border: 1px solid rgba(52, 199, 89, 0.1);
}

.result-item:nth-child(3n) {
    background: linear-gradient(135deg, var(--surface-color) 0%, rgba(255, 149, 0, 0.02) 100%);
    border: 1px solid rgba(255, 149, 0, 0.1);
}

.dropdown-item:hover {
    background: linear-gradient(135deg, rgba(0, 122, 255, 0.1) 0%, rgba(0, 122, 255, 0.05) 100%);
}

.input-wrapper input,
.input-wrapper select {
    font-family: 'Vazirmatn', sans-serif;
}

.result-item,
.results-section h3 {
    font-family: 'Vazirmatn', sans-serif;
}