@import url("https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap");

:root {
    --ss-bg: #f4f6fb;
    --ss-surface: #ffffff;
    --ss-surface-soft: #f9faff;
    --ss-primary: #5b5bd6;
    --ss-primary-dark: #4444b8;
    --ss-primary-soft: rgba(91, 91, 214, 0.11);
    --ss-text: #20283a;
    --ss-muted: #70798c;
    --ss-border: #e5e8f0;
    --ss-danger: #dc3545;
    --ss-success: #198754;
    --ss-card-radius: 1.25rem;
    --ss-shadow: 0 0.9rem 2.8rem rgba(35, 43, 72, 0.08);
}

html,
body {
    min-height: 100%;
}

html {
    scroll-behavior: smooth;
}

body,
button,
input,
select,
textarea {
    font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
}

body {
    font-size: 0.95rem;
    font-weight: 400;
    color: var(--ss-text);
    background:
        radial-gradient(circle at 100% 0, rgba(91, 91, 214, 0.12), transparent 34rem),
        radial-gradient(circle at 0 18%, rgba(38, 167, 154, 0.07), transparent 30rem),
        var(--ss-bg);
}

h1,
h2,
h3,
h4,
h5,
h6,
.navbar-brand,
.fw-bold {
    font-weight: 700 !important;
    letter-spacing: -0.025em;
}

a {
    text-underline-offset: 0.18em;
}

::selection {
    background: rgba(91, 91, 214, 0.22);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-card {
    width: min(100%, 440px);
    border: 0;
    border-radius: var(--ss-card-radius);
    box-shadow: 0 1.25rem 4rem rgba(24, 30, 42, 0.12);
}

.brand-mark {
    width: 3.25rem;
    height: 3.25rem;
    display: inline-grid;
    place-items: center;
    border-radius: 1rem;
    background: linear-gradient(145deg, var(--ss-primary), var(--ss-primary-dark));
    color: #fff;
    font-weight: 800;
    box-shadow: 0 0.65rem 1.6rem rgba(91, 91, 214, 0.24);
    letter-spacing: -0.04em;
}

.form-control,
.form-select {
    min-height: 3rem;
    border-radius: 0.85rem;
    border-color: var(--ss-border);
    background-color: rgba(255, 255, 255, 0.92);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--ss-primary);
    background-color: #fff;
    box-shadow: 0 0 0 .22rem var(--ss-primary-soft);
}

.form-label {
    color: #374158;
    font-weight: 600;
}

textarea.form-control {
    min-height: 18rem;
    line-height: 2;
}

.btn {
    border-radius: 0.85rem;
    min-height: 2.75rem;
    font-weight: 600;
    transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease, border-color .15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

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

.btn-dark,
.btn-primary {
    background-color: var(--ss-primary);
    border-color: var(--ss-primary);
    box-shadow: 0 .45rem 1.1rem rgba(91, 91, 214, .16);
}

.btn-dark:hover,
.btn-primary:hover,
.btn-dark:focus,
.btn-primary:focus {
    background-color: var(--ss-primary-dark);
    border-color: var(--ss-primary-dark);
}

.btn-outline-dark {
    color: var(--ss-primary);
    border-color: rgba(91, 91, 214, .38);
}

.btn-outline-dark:hover,
.btn-outline-dark:focus {
    color: #fff;
    background-color: var(--ss-primary);
    border-color: var(--ss-primary);
}

.dashboard-card,
.content-card {
    border: 1px solid var(--ss-border);
    border-radius: var(--ss-card-radius);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--ss-shadow);
}

.status-dot {
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 999px;
    background: #198754;
    margin-left: 0.4rem;
}

.brand-color-swatch {
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid rgba(0, 0, 0, 0.08);
    vertical-align: middle;
}

.project-row {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.project-row:hover {
    transform: translateY(-2px);
}

.slide-card {
    border: 1px solid rgba(17, 24, 39, 0.08);
    border-radius: 1rem;
    background: #fff;
}

.slide-number {
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 2.5rem;
    display: inline-grid;
    place-items: center;
    border-radius: 0.8rem;
    background: #111827;
    color: #fff;
    font-weight: 700;
}

.slide-text {
    white-space: pre-wrap;
    line-height: 2;
    overflow-wrap: anywhere;
}

.customer-logo {
    width: 5rem;
    height: 5rem;
    object-fit: contain;
    border-radius: 1rem;
    border: 1px solid rgba(17, 24, 39, 0.08);
    background: #fff;
    padding: 0.5rem;
}

.scenario-help {
    border: 1px dashed rgba(17, 24, 39, 0.2);
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.55);
}


/* -------------------------------------------------------------------------
   Phase 3: Template engine and scaled 1080x1920 preview
   ------------------------------------------------------------------------- */

.template-workspace {
    display: grid;
    grid-template-columns: minmax(300px, 420px) minmax(360px, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.template-sidebar {
    max-height: calc(100vh - 8rem);
    overflow: auto;
}

.template-preview-panel {
    position: sticky;
    top: 1.5rem;
}

.story-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 9 / 16;
    overflow: hidden;
    border-radius: 1.25rem;
    background: #e5e7eb;
    box-shadow: 0 1.5rem 4rem rgba(17, 24, 39, 0.18);
}

.story-canvas {
    position: absolute;
    inset: 0 auto auto 0;
    width: 1080px;
    height: 1920px;
    overflow: hidden;
    transform-origin: top left;
    direction: rtl;
    isolation: isolate;
    background: #fff;
}

.story-canvas *,
.story-canvas *::before,
.story-canvas *::after {
    box-sizing: border-box;
}

.story-slide-body {
    position: absolute;
    z-index: 5;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.story-text-fit {
    overflow: hidden;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.65;
}

.text-overflow-warning {
    outline: 5px dashed rgba(220, 53, 69, 0.75);
    outline-offset: 12px;
}

.story-logo {
    display: block;
    max-width: 210px;
    max-height: 120px;
    object-fit: contain;
}

.story-meta {
    font-size: 30px;
    line-height: 1.4;
}

.template-slide-item {
    cursor: pointer;
    border: 1px solid rgba(17, 24, 39, 0.09);
    border-radius: 1rem;
    background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.template-slide-item:hover,
.template-slide-item.is-active {
    border-color: #111827;
    box-shadow: 0 .75rem 2rem rgba(17, 24, 39, .08);
    transform: translateY(-1px);
}

.template-preview-loading {
    min-height: 24rem;
    display: grid;
    place-items: center;
    color: #6b7280;
}

.template-swatch {
    width: 2.1rem;
    height: 2.1rem;
    border-radius: .75rem;
    flex: 0 0 2.1rem;
    border: 1px solid rgba(17, 24, 39, .1);
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
}

.preview-grid .story-frame {
    border-radius: 1rem;
}

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

    .template-sidebar {
        max-height: none;
        overflow: visible;
    }

    .template-preview-panel {
        position: static;
        order: -1;
    }
}


/* -------------------------------------------------------------------------
   Phase 4: Browser rendering and PNG export
   ------------------------------------------------------------------------- */

.story-canvas .d-flex {
    display: flex !important;
}

.story-canvas .align-items-end {
    align-items: flex-end !important;
}

.story-canvas .gap-4 {
    gap: 1.5rem !important;
}

.story-canvas .mb-4 {
    margin-bottom: 1.5rem !important;
}

.story-canvas .mb-3 {
    margin-bottom: 1rem !important;
}

.render-stage {
    position: fixed;
    z-index: -1000;
    top: 0;
    left: -12000px;
    width: 1080px;
    height: 1920px;
    overflow: hidden;
    pointer-events: none;
    opacity: 1;
}

.render-stage .story-canvas {
    position: relative !important;
    inset: auto !important;
    transform: none !important;
    transform-origin: top left !important;
}

.render-progress-card {
    border: 0;
    border-radius: 1.25rem;
    box-shadow: 0 1rem 3rem rgba(17, 24, 39, .09);
}

.render-slide-row {
    border: 1px solid rgba(17, 24, 39, .09);
    border-radius: 1rem;
    background: #fff;
}

.render-status-badge {
    min-width: 6.5rem;
    text-align: center;
}

.render-log {
    max-height: 15rem;
    overflow: auto;
    white-space: pre-wrap;
    font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
    line-height: 1.8;
    border-radius: 1rem;
    background: #111827;
    color: #d1fae5;
    padding: 1rem;
}

.render-preview-small {
    width: 110px;
    flex: 0 0 110px;
}

@media (max-width: 575.98px) {
    .render-preview-small {
        width: 78px;
        flex-basis: 78px;
    }
}


/* -------------------------------------------------------------------------
   Phase 6: AI backgrounds
   ------------------------------------------------------------------------- */

.ai-background-layer {
    position: absolute;
    z-index: 0;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

.ai-background-overlay {
    position: absolute;
    z-index: 1;
    inset: 0;
    background: var(--ai-background-overlay, linear-gradient(rgba(0,0,0,.25), rgba(0,0,0,.50)));
    pointer-events: none;
}

.story-canvas::before,
.story-canvas::after {
    z-index: 3;
    pointer-events: none;
}

.background-card {
    border: 1px solid rgba(17, 24, 39, .09);
    border-radius: 1.25rem;
    background: #fff;
    overflow: hidden;
}

.background-preview {
    position: relative;
    width: 180px;
    flex: 0 0 180px;
    aspect-ratio: 9 / 16;
    overflow: hidden;
    border-radius: 1rem;
    background: linear-gradient(145deg, #e5e7eb, #f8fafc);
    border: 1px solid rgba(17,24,39,.08);
}

.background-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.background-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    text-align: center;
    color: #6b7280;
    font-size: .85rem;
}

.background-prompt {
    min-height: 13rem !important;
    direction: ltr;
    text-align: left;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: .86rem;
    line-height: 1.65;
}

.background-toolbar {
    position: sticky;
    top: 1rem;
    z-index: 20;
}

.background-log {
    max-height: 14rem;
    overflow: auto;
    white-space: pre-wrap;
    border-radius: 1rem;
    background: #111827;
    color: #d1fae5;
    padding: 1rem;
    line-height: 1.8;
}

@media (max-width: 767.98px) {
    .background-preview {
        width: 110px;
        flex-basis: 110px;
    }
}


/* -------------------------------------------------------------------------
   Phase 8: Story art direction and sequence rhythm
   ------------------------------------------------------------------------- */

.ai-background-layer {
    object-position: var(--ss-bg-position, center center);
}

.ai-background-overlay {
    opacity: var(--ss-overlay-opacity, .35);
}

.story-canvas.ss-layout-cover .story-slide-body {
    inset: 285px 105px 335px !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
}

.story-canvas.ss-layout-cover .story-text-fit {
    width: 100% !important;
    max-width: 900px !important;
    height: 900px !important;
    text-align: center !important;
    line-height: 1.48 !important;
}

.story-canvas.ss-layout-cover::after {
    content: "";
    position: absolute;
    z-index: 4;
    width: 175px;
    height: 10px;
    right: 50%;
    bottom: 315px;
    transform: translateX(50%);
    border-radius: 999px;
    background: var(--brand-color);
}

.story-canvas.ss-layout-statement .story-slide-body {
    inset: 330px 120px 330px !important;
}

.story-canvas.ss-layout-split_right .story-slide-body {
    inset: 340px 90px 320px 500px !important;
    align-items: stretch !important;
    justify-content: center !important;
    text-align: right !important;
}

.story-canvas.ss-layout-split_right .story-text-fit {
    width: 100% !important;
    height: 910px !important;
    text-align: right !important;
}

.story-canvas.ss-layout-split_left .story-slide-body {
    inset: 340px 500px 320px 90px !important;
    align-items: stretch !important;
    justify-content: center !important;
    text-align: right !important;
}

.story-canvas.ss-layout-split_left .story-text-fit {
    width: 100% !important;
    height: 910px !important;
    text-align: right !important;
}

.story-canvas.ss-layout-bottom .story-slide-body {
    inset: 875px 105px 270px !important;
    align-items: stretch !important;
    justify-content: flex-end !important;
    text-align: right !important;
}

.story-canvas.ss-layout-bottom .story-text-fit {
    width: 100% !important;
    height: 610px !important;
    text-align: right !important;
}

.story-canvas.ss-layout-compact .story-slide-body {
    inset: 250px 100px 275px !important;
    align-items: stretch !important;
    justify-content: center !important;
    text-align: right !important;
}

.story-canvas.ss-layout-compact .story-text-fit {
    width: 100% !important;
    height: 1120px !important;
    line-height: 1.76 !important;
    text-align: right !important;
}

.story-canvas.ss-layout-compact .story-slide-body > :not(.story-text-fit) {
    margin-bottom: 32px !important;
}

.story-canvas.ss-layout-cta .story-slide-body {
    inset: 430px 115px 400px !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    border-top: 5px solid var(--brand-color);
    border-bottom: 5px solid var(--brand-color);
    padding: 75px 35px !important;
}

.story-canvas.ss-layout-cta .story-text-fit {
    width: 100% !important;
    height: 720px !important;
    text-align: center !important;
    line-height: 1.55 !important;
}

.story-canvas.ss-layout-cta::before {
    content: "✦";
    position: absolute;
    z-index: 7;
    top: 285px;
    right: 50%;
    transform: translateX(50%);
    color: var(--brand-color);
    font-size: 88px;
    line-height: 1;
}

.story-canvas.ss-layout-cover .story-slide-body > :not(.story-text-fit),
.story-canvas.ss-layout-bottom .story-slide-body > :not(.story-text-fit),
.story-canvas.ss-layout-split_right .story-slide-body > :not(.story-text-fit),
.story-canvas.ss-layout-split_left .story-slide-body > :not(.story-text-fit),
.story-canvas.ss-layout-cta .story-slide-body > :not(.story-text-fit) {
    margin-bottom: 42px !important;
}

.story-canvas.ss-text-scale-85 .story-text-fit {
    letter-spacing: -.02em !important;
}

.story-canvas.ss-text-scale-110 .story-text-fit,
.story-canvas.ss-text-scale-120 .story-text-fit {
    letter-spacing: -.05em !important;
}

.art-direction-sidebar {
    padding-bottom: 1rem;
}

.art-direction-item .form-label {
    margin-bottom: .35rem;
    color: #6b7280;
}

.art-direction-item .form-select {
    min-height: 2.45rem;
    border-radius: .7rem;
}

.art-direction-item.is-active {
    border-width: 2px;
}

@media (max-width: 991.98px) {
    .art-direction-workspace {
        display: flex;
        flex-direction: column;
    }
}

/* -------------------------------------------------------------------------
   UI refresh: Vazirmatn, modern colors, and mobile polish
   ------------------------------------------------------------------------- */

.navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: rgba(255, 255, 255, 0.88) !important;
    border-color: rgba(229, 232, 240, 0.92) !important;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 .35rem 1.4rem rgba(35, 43, 72, .045);
}

.navbar .container {
    gap: .8rem;
}

.navbar-brand {
    color: var(--ss-primary) !important;
    white-space: nowrap;
}

.navbar .d-flex {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.text-secondary,
.text-muted {
    color: var(--ss-muted) !important;
}

.badge {
    border-radius: 999px;
    padding: .48em .72em;
    font-weight: 600;
}

.alert {
    border-radius: 1rem;
    border-width: 1px;
}

code {
    color: #4a4ac2;
    background: rgba(91, 91, 214, .08);
    border: 1px solid rgba(91, 91, 214, .12);
    border-radius: .45rem;
    padding: .12rem .4rem;
    overflow-wrap: anywhere;
}

.table {
    --bs-table-bg: transparent;
    color: var(--ss-text);
}

.table > :not(caption) > * > * {
    padding-block: .9rem;
    border-bottom-color: var(--ss-border);
    vertical-align: middle;
}

.card-header,
.card-footer {
    border-color: var(--ss-border);
    background: rgba(249, 250, 255, .78);
}

.dropdown-menu {
    border-color: var(--ss-border);
    border-radius: 1rem;
    box-shadow: var(--ss-shadow);
}

.slide-card,
.template-slide-item,
.render-slide-row,
.background-card {
    border-color: var(--ss-border);
    box-shadow: 0 .4rem 1.4rem rgba(35, 43, 72, .045);
}

.slide-number {
    background: linear-gradient(145deg, var(--ss-primary), var(--ss-primary-dark));
    box-shadow: 0 .4rem 1rem rgba(91, 91, 214, .18);
}

.template-slide-item:hover,
.template-slide-item.is-active {
    border-color: var(--ss-primary);
    box-shadow: 0 .75rem 2rem rgba(91, 91, 214, .10);
}

.story-canvas,
.story-canvas * {
    font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
}

.auth-card {
    border: 1px solid var(--ss-border);
    background: rgba(255, 255, 255, .95);
}

.auth-shell::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(circle at 18% 18%, rgba(91, 91, 214, .09), transparent 25rem),
        radial-gradient(circle at 85% 82%, rgba(38, 167, 154, .08), transparent 25rem);
}

@media (max-width: 991.98px) {
    .template-workspace,
    .art-direction-workspace {
        gap: 1rem;
    }

    .template-preview-panel {
        width: 100%;
    }

    .story-frame {
        width: min(100%, 430px);
        margin-inline: auto;
    }
}

@media (max-width: 767.98px) {
    body {
        font-size: .91rem;
    }

    main.container,
    main.container-fluid {
        padding-top: 1.4rem !important;
        padding-bottom: 2rem !important;
    }

    .navbar .container {
        padding-block: .65rem !important;
    }

    .navbar-brand {
        font-size: 1rem;
    }

    .navbar .d-flex {
        gap: .45rem !important;
    }

    .navbar .btn {
        min-height: 2.35rem;
        padding: .42rem .68rem;
        font-size: .78rem;
    }

    .card-body {
        padding: 1.05rem !important;
    }

    .dashboard-card,
    .content-card,
    .auth-card,
    .render-progress-card,
    .background-card {
        border-radius: 1rem;
    }

    h1,
    .h1 {
        font-size: 1.55rem;
    }

    h2,
    .h2 {
        font-size: 1.3rem;
    }

    .h3 {
        font-size: 1.2rem;
    }

    .form-control,
    .form-select {
        min-height: 2.8rem;
        font-size: 16px;
    }

    textarea.form-control {
        min-height: 12rem;
    }

    .template-sidebar {
        width: 100%;
    }

    .preview-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .background-card > .d-flex,
    .render-slide-row > .d-flex,
    .slide-card > .d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }

    .background-preview,
    .render-preview-small {
        width: min(100%, 210px);
        flex-basis: auto;
        margin-inline: auto;
    }

    .background-toolbar {
        position: static;
    }

    .table-responsive {
        border: 1px solid var(--ss-border);
        border-radius: 1rem;
        background: rgba(255, 255, 255, .88);
    }

    .table-responsive .table {
        min-width: 680px;
        margin-bottom: 0;
        font-size: .82rem;
    }

    .auth-shell {
        padding: 1rem;
    }

    .auth-card .card-body {
        padding: 1.35rem !important;
    }
}

@media (max-width: 575.98px) {
    .navbar .container {
        flex-wrap: wrap;
    }

    .navbar-brand {
        width: 100%;
        margin: 0;
        text-align: center;
    }

    .navbar .d-flex {
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .navbar .btn {
        width: 100%;
        white-space: normal;
    }

    .story-frame {
        border-radius: .9rem;
    }

    .row.g-4,
    .row.g-3 {
        --bs-gutter-y: .85rem;
    }
}

@media (max-width: 390px) {
    .navbar .d-flex {
        grid-template-columns: 1fr;
    }
}

