/* ============= Stage 4 =============== */
#stage-4 {
    max-width: none;
    margin: 0;
    padding: 20px 0 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    box-sizing: border-box;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.s4-header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 auto 24px;
    padding: 0 16px;
    gap: 12px;
    width: 100%;
    max-width: 1100px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.s4-header-left,
.s4-header-right {
    display: flex;
    align-items: center;
    gap: 7px;
    overflow: visible;
    position: relative;
}

.s4-header-left {
    gap: 10px;
    min-width: 0;
    overflow: visible;
}

.s4-split-btn {
    display: inline-flex;
    align-items: stretch;
    border-radius: 100px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: #000;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.s4-storyboard-split {
    position: relative;
    overflow: visible;
}

.s4-storyboard-split .s4-split-model,
.s4-storyboard-split .s4-split-gen {
    border-radius: 0;
}

.s4-storyboard-split .s4-split-model {
    border-radius: 100px 0 0 100px;
}

.s4-storyboard-split .s4-split-gen {
    border-radius: 0 100px 100px 0;
}

.s4-method-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 180px;
    padding: 6px;
    border-radius: 14px;
    background: rgba(18, 18, 18, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.s4-method-menu[hidden] {
    display: none !important;
}

.s4-method-option {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.84);
    text-align: left;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

.s4-method-option:hover,
.s4-method-option.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.s4-text-btn {
    height: 34px;
    padding: 0 12px;
    border-radius: 100px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #f5f5f7;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.s4-text-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.s4-text-btn:disabled {
    opacity: 0.55;
    cursor: wait;
}

#s4-smart-select-btn[hidden] {
    display: none !important;
}

#s4-multishot-wrap {
    position: relative;
    flex-shrink: 0;
    display: none;
}

#s4-multishot-wrap[hidden] {
    display: none !important;
}

#stage-4.s4-v2 #s4-multishot-wrap,
#stage-4.s4-v2 #s4-multishot-wrap[hidden] {
    display: inline-flex !important;
}

.s4-multishot-split {
    display: inline-flex;
    align-items: stretch;
    border-radius: 100px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
}

.s4-multishot-split .s4-text-btn {
    background: transparent;
    border-radius: 0;
}

.s4-multishot-split .s4-text-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.s4-multishot-split .s4-text-btn.is-active {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.s4-multishot-gear {
    width: 34px;
    padding: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.82);
}

.s4-multishot-gear.is-open {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.s4-multishot-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 228px;
    padding: 12px;
    border-radius: 16px;
    background: rgba(18, 18, 18, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.s4-multishot-menu[hidden] {
    display: none !important;
}

.s4-multishot-duration-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: rgba(255, 255, 255, 0.88);
    font-size: 12px;
    font-weight: 600;
}

.s4-multishot-duration-field {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 4px 8px;
    color: #fff;
}

.s4-multishot-duration-field input {
    width: 42px;
    border: none;
    background: transparent;
    color: #fff;
    font: inherit;
    font-weight: 700;
    text-align: right;
    outline: none;
}

.s4-multishot-duration-field input::-webkit-outer-spin-button,
.s4-multishot-duration-field input::-webkit-inner-spin-button {
    opacity: 1;
}

.s4-multishot-models-label {
    color: rgba(255, 255, 255, 0.45);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.s4-multishot-models {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.s4-multishot-model {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.84);
    text-align: left;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

.s4-multishot-model:hover,
.s4-multishot-model.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.s4-shot-unit {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    min-width: 0;
}

.s4-shot-unit .storyboard-row {
    width: 100%;
    margin: 0;
}

.s4-grid-view .s4-shot-unit.s4-multishot-unit {
    grid-column: 1 / -1;
}

.s4-list-view .s4-shot-unit {
    width: 100%;
}

.s4-shot-unit-label {
    padding: 0 8px 2px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 12px;
    font-weight: 650;
    letter-spacing: 0.04em;
    line-height: 1.2;
    white-space: pre;
    direction: ltr;
    text-align: start;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
    user-select: none;
}

#stage-4:not(.s4-multishot-on) .s4-shot-unit-label {
    display: none;
}

.s4-multishot-group {
    --ms-hue: 168;
    position: relative;
    background: rgba(255, 255, 255, 0.018);
    border: 1px solid hsl(var(--ms-hue) 38% 52% / 0.58);
    border-radius: 28px;
    box-shadow: none;
    padding: 12px;
}

.s4-multishot-group.is-drop-target {
    border-color: hsl(var(--ms-hue) 50% 68% / 0.95);
}

.s4-grid-view .s4-multishot-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}

.s4-list-view .s4-multishot-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.s4-multishot-group-head {
    display: none;
}

.s4-multishot-group .storyboard-text-edit,
.storyboard-row.is-multishot .storyboard-text-edit,
.s4-shot-body .storyboard-text-edit {
    background: transparent !important;
    background-color: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

.s4-sequence-header:first-child {
    margin-top: 0;
}

.s4-sequence-header {
    grid-column: 1 / -1;
    width: 100%;
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 6px 4px 0;
    margin-top: 8px;
    pointer-events: none;
}

.s4-list-view .s4-sequence-header {
    margin-top: 12px;
}

.s4-sequence-label {
    color: rgba(255, 255, 255, 0.92);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.s4-sequence-title {
    color: rgba(255, 255, 255, 0.55);
    font-size: 13px;
    font-weight: 500;
}

.s4-shot-meta {
    position: absolute;
    right: 10px;
    bottom: 7px;
    display: flex;
    align-items: baseline;
    gap: 6px;
    z-index: 6;
    pointer-events: none;
}

.shot-key-badge {
    position: static;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.38);
    padding: 0;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1;
    text-transform: lowercase;
    pointer-events: none;
}

.s4-shot-duration {
    display: inline;
    color: rgba(255, 255, 255, 0.62);
    font-size: 13px;
    font-weight: 650;
    letter-spacing: 0.02em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    pointer-events: auto;
    cursor: text;
    user-select: none;
    white-space: nowrap;
}

.s4-shot-duration-num {
    outline: none;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    caret-color: rgba(255, 255, 255, 0.7);
    min-width: 0.7em;
    user-select: text;
}

.s4-multishot-group .storyboard-row,
.s4-multishot-group .storyboard-row.is-key-shot,
.storyboard-row.is-multishot,
.storyboard-row.is-multishot.is-key-shot {
    border: none;
    box-shadow: none;
    background: transparent;
}

.s4-multishot-group .storyboard-row:hover,
.s4-multishot-group .storyboard-row.is-key-shot:hover,
.storyboard-row.is-multishot:hover,
.storyboard-row.is-multishot.is-key-shot:hover {
    border: none;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.03);
}

.s4-split-model {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.08);
    color: #f5f5f7;
    padding: 0 12px 0 10px;
    max-width: 168px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
}

.s4-split-model.smp-trigger {
    max-width: 168px;
}

.s4-split-model .smp-trigger-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.s4-split-model:hover {
    background: rgba(255, 255, 255, 0.14);
}

.s4-split-gen {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    background: #000;
    color: #fff;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.s4-split-gen:hover {
    background: #fff;
    color: #000;
}

.s4-generate-credits {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 8px;
    background: rgba(255, 215, 120, 0.16);
    color: #f3d48a;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.s4-split-gen:hover .s4-generate-credits {
    background: rgba(0, 0, 0, 0.1);
    color: #6b5310;
}

.s4-header-right .s4-icon-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #f5f5f7;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.s4-header-right .s4-icon-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: none;
}

.s4-header-right .s4-icon-btn.is-active {
    background: rgba(255, 255, 255, 0.16);
    color: #f5f5f7;
}

.s4-header-right .s4-icon-btn.s4-delete-btn:hover {
    background: rgba(220, 70, 70, 0.28);
    color: #ff9b9b;
}

#stage-4 #s4-layout-btn .s4-layout-cols { display: none; }
#stage-4.s4-list #s4-layout-btn .s4-layout-cols { display: block; }
#stage-4.s4-list #s4-layout-btn .s4-layout-rows { display: none; }
#stage-4:not(.s4-list) #s4-layout-btn { background: rgba(255, 255, 255, 0.16); }

.s4-add-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    padding: 10px 20px;
    border-radius: 100px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.s4-add-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

#s4-scroll {
    flex: 1 1 0%;
    min-height: 0;
    height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    box-sizing: border-box;
}

#s4-scroll::-webkit-scrollbar {
    width: 8px;
}

#s4-scroll::-webkit-scrollbar-track {
    background: transparent;
}

#s4-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
    border-radius: 10px;
}

#s4-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.32);
}

#s4-container {
    width: 100%;
    box-sizing: border-box;
    padding: 10px max(16px, calc((100% - 1100px) / 2)) 40px;
    gap: 24px;
}

.s4-grid-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    align-content: start;
}

.s4-list-view {
    display: flex;
    flex-direction: column;
    width: 100%;
}

#s4-container.s4-list-view {
    gap: 12px;
}

.storyboard-row {
    position: relative;
    background: rgba(20, 20, 20, 0.4);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 16px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    cursor: grab;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.storyboard-row:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(40, 40, 40, 0.55);
}

.storyboard-row.approved-card {
        border: 1px solid white !important;
        box-shadow: 0 0 8px rgba(255, 255, 255, 0.6) !important;
        outline: none !important;
}

.s4-list-view .storyboard-row {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 18px;
    padding: 12px;
    border-radius: 18px;
}

.s4-grid-view .storyboard-row {
    display: flex;
    flex-direction: column;
}

.s4-shot-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.s4-shot-body .storyboard-text-edit {
    margin-top: 0;
}

.s4-shot-assets {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 0 2px 2px;
}

.s4-shot-asset {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    overflow: hidden;
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: border-color 0.18s ease, background 0.18s ease;
}

.s4-shot-asset:hover {
    border-color: rgba(255, 255, 255, 0.22);
}

.s4-shot-asset-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 11px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    z-index: 2;
}

.s4-shot-asset:hover .s4-shot-asset-remove,
.s4-shot-asset-remove:focus-visible {
    opacity: 1;
}

.s4-shot-asset-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px dashed rgba(255, 255, 255, 0.28);
    color: rgba(255, 255, 255, 0.58);
    font-size: 18px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
}

.s4-shot-asset-add:hover {
    border-color: rgba(255, 255, 255, 0.45);
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    transform: none;
}

.s4-shot-asset img,
.s4-shot-asset .s4-empty-still {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.s4-shot-asset .s4-empty-still {
    padding: 7px;
    box-sizing: border-box;
    color: #6d6d72;
}

.s4-list-view .s4-shot-assets {
    padding-bottom: 2px;
}

.img-wrapper {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.s4-list-view .img-wrapper {
    flex: 0 0 280px;
    width: 280px;
    height: auto;
    align-self: center;
}

.s4-list-view .empty-img-placeholder {
    font-size: unset;
}

.s4-empty-still {
    width: 38%;
    max-width: 84px;
    color: #6a6a70;
    opacity: 0.92;
    pointer-events: none;
}

.s4-empty-still svg {
    width: 100%;
    height: auto;
    display: block;
}

.image-container {
    width: 100%;
    display: block;
    background: #2a2a2a;
    border-radius: 16px;
    overflow: hidden;
}

.story-img,
.image-container .story-img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    object-position: center;
    border-radius: 16px;
}

/* Badge (P01, P02...) */
.shot-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    z-index: 10;
    pointer-events: none;
    opacity: 0.32;
    transition: opacity 0.3s ease;
}

/* Checkbox */
.s4-approval-checkbox {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    z-index: 20;
    opacity: 0; /* مخفی به صورت پیش‌فرض */
    transition: opacity 0.3s ease;
    /* تیره کردن چک‌باکس */
    filter: grayscale(1) brightness(0.4) contrast(1.2); 
}

/* Hover Controls (Bottom Right) */
.s4-hover-controls {
    position: absolute;
    bottom: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    z-index: 20;
    opacity: 0; /* مخفی به صورت پیش‌فرض */
    transition: opacity 0.3s ease;
}

.s4-hover-controls .s4-icon-btn {
    background: rgba(20, 20, 20, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #aaa;
    border-radius: 8px;
    width: 38px; /* بزرگتر شدن دکمه */
    height: 38px; /* بزرگتر شدن دکمه */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
}

.s4-hover-controls .s4-icon-btn:hover {
    color: #fff;
    background: rgba(40, 40, 40, 0.9);
    transform: scale(1.05);
}

.s4-hover-controls .s4-icon-btn svg {
    width: 22px; /* بزرگتر شدن آیکون */
    height: 22px; /* بزرگتر شدن آیکون */
}
.storyboard-row:hover .shot-badge,
.storyboard-row:hover .s4-approval-checkbox,
.storyboard-row:hover .s4-hover-controls {
    opacity: 1;
}

/* اگر چک‌باکس تیک خورده باشد، همیشه نمایش داده شود */
.s4-approval-checkbox:checked {
    opacity: 1;
}

/* Textarea Redesign (مخفی شدن حاشیه و بک‌گراند) */
.storyboard-text-edit,
textarea.storyboard-text-edit {
    flex: 1;
    background: transparent !important;
    background-color: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    appearance: none;
    -webkit-appearance: none;
    color: rgba(255, 255, 255, 0.9);
    padding: 12px 4px;
    resize: none;
    min-height: 80px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    margin-top: 12px;
    transition: none;
    cursor: text;
    user-select: text;
    -webkit-user-drag: none;
}

.s4-list-view .storyboard-text-edit {
    margin-top: 0;
    margin-left: 0;
    padding: 8px 6px;
    min-height: 120px;
    height: auto;
    flex: 1;
    align-self: stretch;
    overflow-y: auto;
}

.empty-img-placeholder {
    width: 100%;
    height: auto;
    aspect-ratio: var(--s4-shot-aspect, 16 / 9);
    background: #1c1c1f;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    color: #6a6a70;
}

.s4-empty-state {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 300px;
    color: #666;
    font-size: 16px;
}

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

/* افکت ورود کارت‌ها */
.s4-anim-item {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}
.s4-anim-item.visible {
    opacity: 1;
    transform: translateY(0);
}
