/* ===== CSS Variables ===== */
:root {
    /* Colors - Soft Blue Theme */
    --primary: #5B93FF;
    --primary-light: #E8F0FF;
    --primary-dark: #4A7FE7;
    --success: #34D399;
    --danger: #EF4444;
    --warning: #FBBF24;
    --text-primary: #1F2937;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --border: #E5E7EB;
    --bg-gray: #F9FAFB;
    --bg-white: #FFFFFF;
    
    /* Shadows */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    /* Transitions */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Vazirmatn', sans-serif !important;
    background: var(--bg-gray);
    color: var(--text-primary);
    line-height: 1.6;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: 80px;
}

/* ===== Top Navigation ===== */
.top-nav {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-icon {
    font-size: 1.75rem;
}

.brand-text {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.company-credit {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    background: var(--bg-gray);
    border-radius: var(--radius-sm);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    overflow: hidden;
    border: 2px solid var(--border);
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===== Main Content ===== */
.main-wrapper {
    min-height: calc(100vh - 73px - 60px);
    padding: 2rem 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.step-container {
    animation: fadeIn 0.3s ease;
}

/* ===== Breadcrumb ===== */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.breadcrumb-back {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-white);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.breadcrumb-back:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.breadcrumb-item {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.breadcrumb-item.active {
    color: var(--text-primary);
    font-weight: 600;
}

.breadcrumb svg {
    color: var(--text-muted);
}

/* ===== Card ===== */
.card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.btn-icon:hover {
    background: var(--bg-gray);
    color: var(--primary);
}

.card-body {
    padding: 1.5rem;
}

.card-body.no-padding {
    padding: 0;
}

/* ===== Filters ===== */
.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.25rem;
}

.filter-full {
    grid-column: 1 / -1;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* فلش‌ها در سمت چپ */
.filter-select {
    width: 100%;
    padding: 0.625rem 2.5rem 0.625rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: 'Vazirmatn', sans-serif;
    color: var(--text-primary);
    background: var(--bg-white);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 0.75rem center;
    background-size: 12px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    transition: var(--transition);
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-select:hover {
    border-color: var(--primary);
}

/* ===== Select2 Customization ===== */
.select2-container--default .select2-selection--single {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    height: auto;
    padding: 0.5rem 2.5rem 0.5rem 1rem;
    transition: var(--transition);
    font-family: 'Vazirmatn', sans-serif;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 100%;
    left: 0.75rem;
    right: auto;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary);
    line-height: 1.5;
    padding: 0;
    font-family: 'Vazirmatn', sans-serif;
}

.select2-dropdown {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-family: 'Vazirmatn', sans-serif;
}

.select2-search--dropdown .select2-search__field {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.625rem 1rem;
    font-family: 'Vazirmatn', sans-serif;
}

.select2-results__option--highlighted[aria-selected] {
    background: var(--primary-light);
    color: var(--primary);
}

.select2-results__option[aria-selected=true] {
    background: var(--primary);
    color: white;
}

/* ===== Table - Clickable Rows ===== */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--bg-gray);
    border-bottom: 1px solid var(--border);
}

.data-table th {
    padding: 0.875rem 1rem;
    text-align: right;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-primary);
}

.data-table tbody tr {
    transition: var(--transition);
    cursor: pointer;
}

.data-table tbody tr:hover {
    background: var(--bg-gray);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.btn-select {
    padding: 0.5rem 1rem;
    border: none;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: 'Vazirmatn', sans-serif;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-select:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ===== Job Info Card - Single Line ===== */
.job-info-card-single {
    background: linear-gradient(135deg, var(--primary-light) 0%, #F0F7FF 100%);
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1.5rem;
    display: grid;
    grid-template-columns: 55% 45%;
    align-items: center;
}

.job-main-info {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.job-icon {
    width: 36px;
    height: 36px;
    background: var(--bg-white);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    flex-shrink: 0;
}

.job-title-wrap {
    flex: 1;
    min-width: 0;
}

.job-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.job-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.job-badges-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    direction: ltr;
}

.info-badge {
    background: var(--bg-white);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-xs);
    text-align: center;
}

/* بج اینتاکد بزرگتر */
.info-badge-primary {
    padding: 0.625rem;
}

.info-badge-primary .badge-value {
    font-size: 0.9375rem;
    font-weight: 800;
}

.badge-label {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-bottom: 0.125rem;
}

.badge-value {
    display: block;
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--primary);
}

/* ===== Form - دکمه کنار نرخ کاهش + conditional ===== */
.form-grid-with-button {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 1rem;
    align-items: end;
}

/* وقتی نرخ کاهش نمایش داده می‌شود */
.form-grid-with-button.has-reduction {
    grid-template-columns: 2fr 1fr 1fr 1fr;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-label svg {
    color: var(--primary);
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: 'Vazirmatn', sans-serif;
    color: var(--text-primary);
    background: var(--bg-white);
    transition: var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input::placeholder {
    color: var(--text-muted);
}

/* ===== Buttons ===== */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: 'Vazirmatn', sans-serif;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-white);
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-secondary:hover {
    background: var(--primary-light);
}

.btn-large {
    padding: 1rem 1.75rem;
    font-size: 1rem;
}

.btn-calculate {
    height: 46px;
    margin-top: auto;
}

/* ===== Modal - Compact ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    animation: fadeIn 0.3s ease;
}

.modal-container {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-compact {
    max-width: 520px;
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: relative;
}

.modal-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary-light) 0%, #E0F0FF 100%);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.modal-close:hover {
    background: var(--bg-gray);
    color: var(--danger);
}

.modal-body {
    padding: 1.25rem;
}

/* مبلغ کل - Inline */
.result-amount-inline {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 0.875rem 1.125rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: white;
    margin-bottom: 1rem;
}

.result-amount-inline .amount-label {
    font-size: 0.8125rem;
    font-weight: 500;
    opacity: 0.9;
}

.result-amount-inline .amount-value {
    font-size: 1.625rem;
    font-weight: 800;
}

.result-amount-inline .amount-currency {
    font-size: 0.875rem;
    font-weight: 600;
    opacity: 0.9;
}

/* جزئیات - فشرده */
.result-details-compact {
    background: var(--bg-gray);
    border-radius: var(--radius-md);
    padding: 0.75rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.375rem 0;
    border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
    border-bottom: none;
    padding-top: 0.625rem;
    margin-top: 0.25rem;
    border-top: 2px solid var(--primary);
}

.detail-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-value {
    font-size: 0.8125rem;
    color: var(--text-primary);
    font-weight: 700;
}

.detail-row:last-child .detail-label {
    color: var(--primary);
    font-weight: 600;
    font-size: 0.8125rem;
}

.detail-row:last-child .detail-value {
    color: var(--primary);
    font-size: 0.9375rem;
}

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.875rem;
}

.modal-footer .btn-primary,
.modal-footer .btn-secondary {
    flex: 1;
}

/* ===== Footer - Sticky ===== */
.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 1.25rem 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    background: var(--bg-white);
    border-top: 1px solid var(--border);
    z-index: 9999;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 5rem;
    left: 2rem;
    background: var(--text-primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    transform: translateY(150%);
    transition: transform 0.3s ease;
    z-index: 1000;
    max-width: 400px;
}

.toast.show {
    transform: translateY(0);
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

.toast.warning {
    background: var(--warning);
}

/* ===== Loading ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .job-info-card-single {
        grid-template-columns: 1fr;
    }
    
    .job-badges-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .nav-container {
        padding: 1rem;
    }

    .company-credit {
        display: none;
    }

    .container {
        padding: 0 1rem;
    }

    body {
        padding-bottom: 70px;
    }

    .filters-grid {
        grid-template-columns: 1fr;
    }

    .form-grid-with-button,
    .form-grid-with-button.has-reduction {
        grid-template-columns: 1fr;
    }

    .table-wrapper {
        overflow-x: scroll;
    }

    .data-table th,
    .data-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.75rem;
    }

    .job-badges-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-container {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
    }

    .result-amount-inline .amount-value {
        font-size: 1.375rem;
    }

    .modal-footer {
        flex-direction: column;
    }

    .toast {
        left: 1rem;
        right: 1rem;
        bottom: 4rem;
    }

    .app-footer {
        font-size: 0.75rem;
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .brand-text {
        display: none;
    }

    .card-title {
        font-size: 1rem;
    }

    .job-badges-row {
        grid-template-columns: 1fr;
    }

    .result-amount-inline {
        flex-direction: column;
        gap: 0.25rem;
    }

    .result-amount-inline .amount-value {
        font-size: 1.25rem;
    }
}