/* ========================================
   استایل‌های گرید استوری‌ها
   ======================================== */

.alijm-story-grid {
    display: grid;
    grid-template-columns: repeat(var(--alijm-story-mobile-cols, 6), minmax(0, 1fr));
    gap: 14px 10px;
    margin: 20px 0;
}

@media (min-width: 768px) {
    .alijm-story-grid {
        grid-template-columns: repeat(var(--alijm-story-desktop-cols, 10), minmax(0, 1fr));
        gap: 18px 12px;
    }
}

.alijm-story-grid.is-hide-name .alijm-story-circle-name {
    display: none;
}

.alijm-story-circle {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 0;
    margin: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.alijm-story-circle-ring {
    width: var(--alijm-story-logo-size, 72px);
    height: var(--alijm-story-logo-size, 72px);
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(135deg, #ff7a18, #ff3d81, #6c5ce7);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease;
}

.alijm-story-circle:hover .alijm-story-circle-ring {
    transform: scale(1.04);
}

.alijm-story-circle-inner {
    width: 100%;
    height: 100%;
    background: #fff;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.alijm-story-circle-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.alijm-story-circle-fallback {
    font-size: 20px;
    font-weight: 700;
    color: #222;
}

.alijm-story-circle-name {
    font-size: 12px;
    line-height: 1.5;
    color: #333;
    text-align: center;
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.alijm-story-empty {
    padding: 14px 16px;
    background: #f7f7f7;
    border-radius: 10px;
    color: #666;
    margin: 20px 0;
}

/* ========================================
   ویوور استوری
   ======================================== */

.alijm-story-viewer {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: none;
}

.alijm-story-viewer.is-open {
    display: block;
}

.alijm-story-viewer-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
}

.alijm-story-viewer-dialog {
    position: relative;
    width: min(100vw, 520px);
    height: 110vh;
    margin: 0 auto;
    background: #000;
    overflow: hidden;
}

.alijm-story-viewer-close {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 10;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.alijm-story-viewer-close:hover {
    background: rgba(0, 0, 0, 0.85);
    transform: scale(1.05);
}

.alijm-story-viewer-progress {
    position: absolute;
    top: 12px;
    right: 12px;
    left: 60px;
    z-index: 10;
    display: flex;
    gap: 6px;
    height: 3px;
}

.alijm-story-progress-segment {
    flex: 1;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 99px;
    overflow: hidden;
}

.alijm-story-progress-segment.is-active .alijm-story-progress-bar {
    background: linear-gradient(90deg, #ffffff, #363636);
}

.alijm-story-progress-bar {
    display: block;
    width: 0%;
    height: 100%;
    background: #ffffff;
    transition: width 0ms linear;
}

.alijm-story-viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 48px;
    height: 80px;
    border: 0;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 8px;
}

.alijm-story-viewer-nav:hover {
    background: rgba(0, 0, 0, 0.7);
    width: 56px;
}

.alijm-story-viewer-prev {
    right: 10px;
}

.alijm-story-viewer-next {
    left: 10px;
}

.alijm-story-viewer-stage {
    position: relative;
    height: 100%;
}

.alijm-story-viewer-content-wrap {
    height: 100%;
}

.alijm-story-viewer-content {
    height: 100%;
}

.alijm-story-slide {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: #111;
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
}

.alijm-story-slide-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,.45), rgba(0,0,0,.15), rgba(0,0,0,.35));
    pointer-events: none;
}

.alijm-story-slide-header,
.alijm-story-slide-body,
.alijm-story-slide-footer {
    position: relative;
    z-index: 3;
}

.alijm-story-slide-header {
    padding: 56px 16px 12px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.alijm-story-viewer-business {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-decoration: none;
    min-width: 0;
}

.alijm-story-viewer-business-logo,
.alijm-story-viewer-business-fallback {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    color: #111;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex: 0 0 42px;
}

.alijm-story-viewer-business-name {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.6;
    word-break: break-word;
}

.alijm-story-viewer-manage {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.alijm-story-viewer-manage-btn {
    border: 0;
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    background: rgba(17, 24, 39, 0.72);
    backdrop-filter: blur(6px);
    transition: .2s ease;
}

.alijm-story-viewer-manage-btn:hover {
    background: rgba(17, 24, 39, 0.9);
    transform: translateY(-1px);
}

.alijm-story-viewer-manage-btn.is-delete {
    background: rgba(220, 38, 38, 0.82);
}

.alijm-story-viewer-manage-btn.is-delete:hover {
    background: rgba(185, 28, 28, 0.95);
}

.alijm-story-slide-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
}

.alijm-story-slide-text {
    font-size: clamp(22px, 4vw, 34px);
    font-weight: 800;
    line-height: 1.9;
    white-space: pre-line;
    max-width: 92%;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.alijm-story-slide-footer {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    z-index: 3;
    padding: 12px;
    text-align: center;
}

.alijm-story-views-info {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    padding: 6px 14px;
    border-radius: 40px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
}

.alijm-story-views-icon {
    font-size: 14px;
}

.alijm-story-views-count {
    font-weight: 700;
    font-size: 14px;
    direction: ltr;
}

.alijm-story-views-label {
    font-size: 12px;
    opacity: 0.9;
}

/* ========================================
   مودال داشبورد
   ======================================== */

.alijm-story-dashboard-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: none;
}

.alijm-story-dashboard-modal.is-open {
    display: block;
}

.alijm-story-dashboard-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.alijm-story-dashboard-dialog {
    position: relative;
    z-index: 2;
    width: min(92vw, 860px);
    max-height: 90vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 24px;
    margin: 5vh auto;
    padding: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.alijm-story-dashboard-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid #e5e7eb;
}

.alijm-story-dashboard-header h3 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: #1f2937;
    text-align: right;
}

.alijm-story-dashboard-close {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 36px;
    height: 36px;
    border: none;
    background: #f3f4f6;
    border-radius: 50%;
    font-size: 22px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.alijm-story-dashboard-close:hover {
    background: #e5e7eb;
    transform: scale(1.05);
}

/* ========================================
   ردیف‌های فرم - حالت دسکتاپ
   ======================================== */

.alijm-story-dashboard-row {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.alijm-story-dashboard-row .full-width {
    flex: 1;
    min-width: 100%;
}

.alijm-story-dashboard-field {
    flex: 1;
    min-width: 160px;
}

.alijm-story-dashboard-field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #374151;
    font-size: 14px;
}

.alijm-story-dashboard-field.full-width textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    font-size: 15px;
    font-family: inherit;
    resize: vertical;
    transition: all 0.2s ease;
    background: #f9fafb;
}

.alijm-story-dashboard-field.full-width textarea:focus {
    outline: none;
    border-color: #10b981;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.alijm-story-dashboard-field.full-width textarea::placeholder {
    color: #9ca3af;
    font-size: 14px;
}

.color-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-input-wrapper input[type="color"] {
    width: 52px;
    height: 52px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    cursor: pointer;
    padding: 3px;
}

.color-input-wrapper input[type="color"]:hover {
    transform: scale(1.02);
}

.color-value {
    flex: 1;
    padding: 10px 14px;
    background: #f9fafb;
    border-radius: 10px;
    font-size: 13px;
    font-family: monospace;
    text-align: center;
    direction: ltr;
    font-weight: 600;
}

.image-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.image-input-wrapper input[type="file"] {
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #f9fafb;
    cursor: pointer;
}

.image-preview-thumb {
    position: relative;
    display: inline-block;
    width: 80px;
    height: 80px;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid #e5e7eb;
    background: #f9fafb;
}

.image-preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ef4444;
    color: white;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.remove-image-btn:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.field-note {
    display: block;
    font-size: 11px;
    color: #6b7280;
    margin-top: 6px;
}

.alijm-story-upload-progress {
    margin: 15px 0;
    background: #f3f4f6;
    border-radius: 12px;
    padding: 12px 16px;
    direction: ltr;
}

.alijm-story-upload-progress .progress-bar-container {
    background: #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    height: 8px;
}

.alijm-story-upload-progress .progress-bar-fill {
    background: linear-gradient(90deg, #10b981, #059669);
    width: 0%;
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 10px;
}

.alijm-story-upload-progress .progress-text {
    text-align: center;
    margin-top: 8px;
    font-size: 12px;
    color: #374151;
    font-weight: 500;
}

/* ========================================
   دکمه‌ها - حالت دسکتاپ
   ======================================== */

.alijm-story-dashboard-actions-row {
    display: flex;
    gap: 16px;
    margin: 25px 0 0;
    flex-wrap: wrap;
    align-items: center;
}

.alijm-story-dashboard-buttons-wrapper {
    display: flex;
    gap: 16px;
    flex: 1;
}

.alijm-story-dashboard-submit,
.alijm-story-dashboard-delete {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.alijm-story-dashboard-submit {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.alijm-story-dashboard-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.alijm-story-dashboard-delete {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.alijm-story-dashboard-delete:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.alijm-story-dashboard-submit:disabled,
.alijm-story-dashboard-delete:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.alijm-story-dashboard-message {
    flex: 1;
    margin: 0;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
    min-width: 150px;
}

.alijm-story-dashboard-message.is-success {
    background: #d1fae5;
    color: #065f46;
    border-right: 4px solid #10b981;
}

.alijm-story-dashboard-message.is-error {
    background: #fee2e2;
    color: #991b1b;
    border-right: 4px solid #ef4444;
}

.alijm-story-dashboard-message.is-loading {
    background: #fef3c7;
    color: #92400e;
    border-right: 4px solid #f59e0b;
}

.alijm-story-dashboard-message.is-loading .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f59e0b;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-left: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-icon {
    font-size: 16px;
}

.btn-text {
    font-size: 14px;
}

/* ========================================
   پیش‌نمایش استوری با نسبت 9:16
   ======================================== */

.alijm-story-dashboard-preview {
    margin-top: 24px;
    position: relative;
}

.alijm-story-dashboard-preview-inner {
    position: relative;
    width: 100%;
    aspect-ratio: 9 / 17;
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111;
    background-size: cover;
    background-position: center;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.02);
}

/* اضافه کردن یک افکت مرزی زیبا */
.alijm-story-dashboard-preview-inner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    pointer-events: none;
    z-index: 1;
}

.alijm-story-dashboard-preview-text {
    font-size: 26px;
    font-weight: 800;
    line-height: 1.8;
    font-weight: 700;
    white-space: pre-line;
    max-width: 90%;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    position: relative;
    z-index: 2;
    word-break: break-word;
}

/* اگر تصویر پس‌زمینه وجود دارد، متن را کمی شفاف‌تر کن */
/*.alijm-story-dashboard-preview-inner[style*="background-image"] .alijm-story-dashboard-preview-text {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px 24px;
    border-radius: 16px;
    backdrop-filter: blur(4px);
}*/

body.alijm-story-modal-open,
body.alijm-story-viewer-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

.alijm-story-manage-btn {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    color: #fff;
    border: none;
    border-radius: 30px;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(109, 40, 217, 0.3);
}

.alijm-story-manage-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(109, 40, 217, 0.4);
}
/* ========================================
   حالت موبایل (کمتر از 768px)
   ======================================== */

@media (max-width: 768px) {
    /* ویوور موبایل */
    .alijm-story-viewer-dialog {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    
    .alijm-story-slide-header {
        padding: 56px 12px 12px;
        flex-direction: column;
        align-items: stretch;
    }
    
    .alijm-story-viewer-manage {
        justify-content: flex-start;
    }
    
    .alijm-story-viewer-manage-btn {
        padding: 8px 12px;
        font-size: 11px;
    }
    
    .alijm-story-slide-text {
        max-width: 96%;
        font-size: clamp(20px, 5vw, 28px);
    }
    
    .alijm-story-slide-footer {
        bottom: 15px;
        padding: 8px;
    }
    
    .alijm-story-views-info {
        padding: 4px 12px;
        font-size: 11px;
    }
    
    .alijm-story-views-count {
        font-size: 12px;
    }
    
    .alijm-story-views-label {
        font-size: 10px;
    }
    
    .alijm-story-viewer-nav {
        width: 40px;
        height: 60px;
        font-size: 24px;
    }
    
    .alijm-story-viewer-nav:hover {
        width: 44px;
    }
    
    .alijm-story-viewer-prev {
        right: 5px;
    }
    
    .alijm-story-viewer-next {
        left: 5px;
    }
    
    /* ========================================
       مودال موبایل - اصلاح شده
       ======================================== */
    
    .alijm-story-dashboard-dialog {
        width: 95vw;
        margin: 2vh auto;
        padding: 18px;
    }
    
    /* ردیف فرم در موبایل - 2 ستون */
    .alijm-story-dashboard-row {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
    
    /* فیلد متن (textarea) در ردیف اول - عرض کامل */
    .alijm-story-dashboard-row .full-width {
        grid-column: span 2 !important;
    }
    
    /* اصلاح: اطمینان از اینکه textarea داخل full-width عرض کامل دارد */
    .alijm-story-dashboard-row .full-width textarea {
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* فیلدهای رنگ متن و رنگ زمینه - هر کدام 1 ستون */
    .alijm-story-dashboard-row .alijm-story-dashboard-field:first-child,
    .alijm-story-dashboard-row .alijm-story-dashboard-field:nth-child(2) {
        grid-column: span 1 !important;
        width: 100% !important;
        min-width: auto !important;
    }
    
    /* فیلد تصویر - 2 ستون کامل */
    .alijm-story-dashboard-row .alijm-story-dashboard-field:last-child {
        grid-column: span 2 !important;
        margin-top: 0 !important;
    }
    
    /* ورودی رنگ در موبایل */
    .color-input-wrapper {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 8px !important;
    }
    
    .color-input-wrapper input[type="color"] {
        width: 45px !important;
        height: 45px !important;
        flex-shrink: 0 !important;
    }
    
    .color-value {
        font-size: 11px !important;
        padding: 8px 10px !important;
    }
    
    /* ========================================
       دکمه‌های مودال موبایل
       ======================================== */
    
    .alijm-story-dashboard-actions-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    /* پیام در بالای دکمه‌ها */
    .alijm-story-dashboard-message {
        order: -1 !important;
        width: 100% !important;
        margin-bottom: 0 !important;
    }
    
    /* دکمه‌ها در یک ردیف کنار هم */
    .alijm-story-dashboard-buttons-wrapper {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        width: 100% !important;
    }
    
    .alijm-story-dashboard-submit,
    .alijm-story-dashboard-delete {
        width: 100% !important;
        padding: 12px 16px !important;
        margin: 0 !important;
    }
    
    /* پیش‌نمایش موبایل */
    .alijm-story-dashboard-preview-inner {
        aspect-ratio: 9 / 17;
        border-radius: 16px;
    }
    
    .alijm-story-dashboard-preview-text {
        font-size: 18px;
        padding: 10px 20px;
    }
    
    .alijm-story-dashboard-preview-inner::before {
        border-radius: 16px;
    }
}

/* ========================================
   موبایل خیلی کوچک (کمتر از 480px)
   ======================================== */

@media (max-width: 480px) {
    .alijm-story-dashboard-row {
        gap: 10px !important;
    }
    
    .color-input-wrapper {
        flex-wrap: wrap !important;
    }
    
    .color-value {
        width: 100% !important;
        text-align: center !important;
    }
    
    .alijm-story-dashboard-buttons-wrapper {
        gap: 10px !important;
    }
}

/* ========================================
   تبلت
   ======================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .alijm-story-dashboard-row {
        gap: 15px;
    }
    
    .alijm-story-dashboard-field {
        min-width: 140px;
    }
    
    .alijm-story-dashboard-preview-inner {
        aspect-ratio: 9 / 17;
        border-radius: 18px;
    }
    
    .alijm-story-dashboard-preview-text {
        font-size: 22px;
    }
    
    .alijm-story-dashboard-preview-inner::before {
        border-radius: 18px;
    }
}