﻿/* ═══════════════════════════════════════════════════
   FEATURE / ArticleForm — فرم ثبت و ویرایش کالا
   ═══════════════════════════════════════════════════ */

.af-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px;
    max-height: calc(90vh - 80px); /* ⭐ ارتفاع محدود */
    overflow-y: auto; /* ⭐ اسکرول داخلی */
}

.af-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding: 12px 4px;
    margin: 0 -4px -4px -4px;
    border-top: 2px solid var(--border);
    box-shadow: 0 -4px 8px rgba(0,0,0,0.04);
}

.modal-box:has(.af-form) {
    max-width: 1000px !important;
}

/* ═══ Sections ═══ */
.af-section {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}

.af-section-top {
    background: linear-gradient(135deg, #EEF2FF, #F5F3FF) !important;
    border: 2px solid #C7D2FE !important;
}

    .af-section-top .af-section-title {
        color: #4338CA !important;
        border-bottom-color: #C7D2FE !important;
    }

.af-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

/* ═══ Grid Layouts ═══ */
.af-grid {
    display: grid;
    gap: 10px;
}

.af-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.af-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.af-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.af-col-2 {
    grid-column: span 2;
}

.af-col-3 {
    grid-column: 1 / -1;
}

/* ═══ Fields ═══ */
.af-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

    .af-field label {
        font-size: 11.5px;
        color: #6B7280;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .af-field .req {
        color: var(--danger);
    }

    .af-field input,
    .af-field select {
        width: 100%;
        padding: 7px 10px;
        border: 1px solid var(--border);
        border-radius: 6px;
        font-family: inherit;
        font-size: 13px;
        background: #fff;
        min-height: 36px;
        box-sizing: border-box;
        transition: all 0.15s;
    }

        .af-field input:focus,
        .af-field select:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px var(--primary-light);
        }

.af-readonly {
    background: #F3F4F6 !important;
    color: var(--text-muted) !important;
    cursor: not-allowed;
}

/* ═══ Input with pick button ═══ */
.af-input-with-btn {
    display: flex;
    gap: 4px;
    align-items: stretch;
}

    .af-input-with-btn input {
        flex: 1;
    }

.af-pick-btn {
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
    transition: all 0.15s;
}

    .af-pick-btn:hover {
        background: var(--primary-light);
        border-color: var(--primary);
    }

/* ═══ Code name hint ═══ */
.af-code-name {
    font-size: 11px;
    color: var(--primary);
    min-height: 14px;
    padding: 2px 4px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ═══ Unlock button (ویرایش دستی کد) ═══ */
.af-unlock-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    margin-right: 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 12px;
    vertical-align: middle;
    transition: all 0.15s;
}

    .af-unlock-btn:hover {
        background: var(--primary-light);
        border-color: var(--primary);
        transform: scale(1.1);
    }

/* ═══ Code editing state ═══ */
.af-code-editing {
    background: #FEF3C7 !important;
    border: 2px solid #F59E0B !important;
    color: #92400E !important;
    cursor: text;
    font-weight: 700;
}

    .af-code-editing:focus {
        box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2) !important;
    }

/* ═══ Picker overlay (معین / تفصیلی) ═══ */
.af-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 20px;
}

.af-picker-box {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    overflow: hidden;
}

.af-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 14px;
    background: #F9FAFB;
}

.af-picker-close {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 8px;
    border-radius: 6px;
}

    .af-picker-close:hover {
        background: var(--bg);
    }

.af-picker-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

    .af-picker-search input {
        width: 100%;
        padding: 8px 12px;
        border: 1px solid var(--border);
        border-radius: 8px;
        font-family: inherit;
        font-size: 13px;
    }

        .af-picker-search input:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px var(--primary-light);
        }

.af-picker-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
}

.af-picker-item {
    display: flex;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.1s;
    align-items: center;
}

    .af-picker-item:hover {
        background: var(--primary-light);
    }

.af-picker-code {
    font-family: 'Consolas', monospace;
    font-weight: 700;
    color: var(--primary);
    min-width: 70px;
    direction: ltr;
}

.af-picker-name {
    flex: 1;
}

.af-picker-parent {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.af-picker-empty {
    padding: 30px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ═══ Footer (sticky) ═══ */
.af-footer {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-top: 12px;
    border-top: 2px solid var(--border);
    position: sticky;
    bottom: 0;
    background: #fff;
    z-index: 5;
    margin-top: 8px;
}

/* ═══ Responsive ═══ */
@media (max-width: 900px) {
    .af-grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .af-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .af-col-2 {
        grid-column: span 2;
    }
}

@media (max-width: 600px) {
    .af-grid-2,
    .af-grid-3,
    .af-grid-4 {
        grid-template-columns: 1fr;
    }

    .af-col-2,
    .af-col-3 {
        grid-column: auto;
    }
}
