/**
 * Instagram Pipeline - Main Styles
 */

/* ===========================
   Hero Section (match other tools)
   =========================== */

.tool-hero {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: var(--space-16) 0;
    text-align: center;
}

.tool-hero h1 {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: var(--space-3);
    color: var(--text);
}

.tool-hero p {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

.tool-content {
    padding: var(--space-12) 0;
}

/* ===========================
   Layout
   =========================== */

.pipeline {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 30px;
    margin-top: 30px;
}

.pipeline-main {
    min-height: 600px;
}

/* ===========================
   Progress Bar
   =========================== */

.progress-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1rem 1.25rem;
    background: var(--gray-50);
    border-radius: var(--radius-base);
    position: relative;
}

.progress-bar::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 4.5rem;
    right: 4.5rem;
    height: 2px;
    background: var(--gray-200);
    z-index: 0;
    transform: translateY(-0.375rem);
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    position: relative;
    z-index: 1;
}

.progress-step__number {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--white);
    border: 2px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

.progress-step__label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.progress-step.active .progress-step__number {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.progress-step.active .progress-step__label {
    color: var(--primary);
    font-weight: 600;
}

.progress-step.completed .progress-step__number {
    background: var(--success);
    border-color: var(--success);
    color: var(--white);
}

.progress-step.completed .progress-step__number::after {
    content: '✓';
}

/* ===========================
   Mode Selection
   =========================== */

.mode-selection {
    text-align: center;
    padding: 2.5rem 1.25rem;
}

.mode-selection h2 {
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}

.mode-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
    max-width: 700px;
    margin: 0 auto;
}

.mode-card {
    padding: 1.5rem;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    text-align: left;
}

.mode-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.mode-card__icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.mode-card h3 {
    margin-bottom: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.mode-card p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
}

.mode-card__tag {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: var(--primary);
    color: var(--white);
    padding: 0.25rem 0.625rem;
    border-radius: 10px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* ===========================
   Pipeline Steps
   =========================== */

.pipeline-step {
    animation: fadeIn 0.3s ease;
}

.pipeline-step h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.step-content {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--radius-base);
    border: 1px solid var(--border);
}

.step-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.step-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

/* Form Actions within steps */
.form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.limit-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ===========================
   Source Tabs (styled like Scenarist)
   =========================== */

.source-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem;
    background: var(--gray-100);
    border-radius: var(--radius-base);
    margin-bottom: 1.25rem;
}

.source-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.source-tab:hover {
    color: var(--text);
}

.source-tab--active {
    background: var(--white);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.source-panel {
    display: none;
}

.source-panel--active {
    display: block;
}

/* ===========================
   Form Elements (Scenarist-like)
   =========================== */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-label,
.source-panel label,
.settings-section label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.form-textarea,
.source-panel textarea,
.source-panel input[type="url"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: vertical;
    transition: border-color 0.15s ease;
}

.form-textarea:focus,
.source-panel textarea:focus,
.source-panel input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-textarea[readonly],
.source-panel textarea[readonly] {
    background: var(--gray-50);
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    font-size: 0.875rem;
    transition: border-color 0.15s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    font-size: 0.875rem;
    background: var(--white);
    cursor: pointer;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Form Settings Block */
.form-settings {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius-base);
}

/* YouTube Input */
.youtube-input {
    display: flex;
    gap: 0.5rem;
}

.youtube-input input {
    flex: 1;
}

/* YouTube Preview */
.youtube-preview,
#youtube-preview {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius-base);
    border: 1px solid var(--border);
}

.youtube-preview__header,
.youtube-info {
    margin-bottom: 0.75rem;
}

.youtube-preview__title,
.youtube-info h4 {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.youtube-preview__channel,
.youtube-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* YouTube Loading */
.youtube-loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem;
    color: var(--text-secondary);
}

.youtube-loading:not([hidden]) {
    display: flex;
}

/* ===========================
   Settings Section
   =========================== */

.settings-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.settings-section h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 600;
}

/* ===========================
   Spinner & Loading States
   =========================== */

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.generation-progress {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.5rem;
    background: var(--gray-50);
    border-radius: var(--radius-base);
    color: var(--text-secondary);
}

.generation-progress:not([hidden]) {
    display: flex;
}

/* ===========================
   Result Area (Scenarist-like)
   =========================== */

.result-area {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.result-area[hidden] {
    display: none !important;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.result-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
}

.result-actions {
    display: flex;
    gap: 0.5rem;
}

/* Slides List */
.slides-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.slide-item {
    padding: 1rem;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    transition: border-color 0.15s ease;
}

.slide-item:hover {
    border-color: var(--gray-300);
}

.slide-item__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.slide-item__number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--primary);
    color: var(--white);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 50%;
}

.slide-item__type {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.slide-item__text {
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
}

.slide-item--cover {
    background: linear-gradient(135deg, var(--gray-900), var(--gray-800));
    border-color: var(--gray-700);
}

.slide-item--cover .slide-item__number {
    background: var(--white);
    color: var(--gray-900);
}

.slide-item--cover .slide-item__type {
    color: var(--gray-400);
}

.slide-item--cover .slide-item__text {
    color: var(--white);
    font-size: 1.125rem;
    font-weight: 600;
}

.slide-item--cta {
    background: var(--gray-50);
    border-style: dashed;
}

.slide-item__actions {
    display: flex;
    gap: 0.25rem;
}

.slide-item__btn {
    padding: 0.25rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

.slide-item__btn:hover {
    background: var(--gray-100);
    color: var(--text);
}

.slide-item--cover .slide-item__btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

/* Slide Edit Area */
.slide-item__edit-area {
    margin-top: 0.75rem;
}

.slide-item__textarea {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.6;
    resize: vertical;
}

.slide-item--cover .slide-item__textarea {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--white);
}

.slide-item__edit-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* Caption Area */
.caption-area {
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius-base);
}

.caption-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.caption-actions {
    display: flex;
    gap: 0.5rem;
}

.caption-length {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: right;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state[hidden] {
    display: none !important;
}

.empty-state svg {
    opacity: 0.5;
}

.empty-state p {
    max-width: 300px;
    line-height: 1.5;
}

/* ===========================
   History Sidebar
   =========================== */

.pipeline-history {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    height: fit-content;
    max-height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 1.25rem;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.history-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.history-empty {
    text-align: center;
    padding: 2.5rem 1.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.history-item {
    display: grid;
    grid-template-columns: 80px 1fr auto;
    gap: 0.875rem;
    padding: 0.875rem;
    border-radius: var(--radius-base);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.15s ease;
    position: relative;
    border: 1px solid transparent;
}

.history-item:hover {
    border-color: var(--border);
    background: var(--gray-50);
}

.history-thumbnail {
    width: 80px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius-base);
    background: var(--gray-100);
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.history-info {
    min-width: 0;
}

.history-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0 0 0.25rem 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.history-meta {
    display: flex;
    gap: 0.625rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.history-variant {
    font-size: 0.6875rem;
    color: var(--primary);
    margin-top: 0.25rem;
}

.history-actions {
    display: flex;
    gap: 0.25rem;
    align-items: flex-start;
}

.history-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 100;
    min-width: 220px;
    overflow: hidden;
}

.history-menu button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.15s ease;
    color: var(--text);
    white-space: nowrap;
}

.history-menu button:hover {
    background: var(--gray-50);
}

.history-menu button.danger {
    color: var(--error);
}

.history-menu button.danger:hover {
    background: rgba(220, 38, 38, 0.08);
}

.history-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
}

/* ===========================
   Buttons (Scenarist-like BEM)
   =========================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-base);
    font-size: 0.875rem;
    font-weight: 500;
    background: var(--white);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn:hover {
    background: var(--gray-50);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary,
.btn--primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.btn-primary:hover,
.btn--primary:hover {
    background: var(--primary-hover);
}

.btn-secondary,
.btn--secondary {
    background: var(--gray-100);
    border-color: var(--gray-200);
    color: var(--text);
}

.btn-secondary:hover,
.btn--secondary:hover {
    background: var(--gray-200);
}

.btn-outline,
.btn--outline {
    background: var(--white);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover,
.btn--outline:hover {
    background: var(--gray-50);
    border-color: var(--primary);
}

.btn-ghost,
.btn--ghost {
    border-color: transparent;
    background: transparent;
}

.btn-ghost:hover,
.btn--ghost:hover {
    background: var(--gray-100);
}

.btn-small,
.btn--small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-large,
.btn--large {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
}

.btn--new {
    background: var(--success);
    border-color: var(--success);
    color: var(--white);
}

.btn--new:hover {
    background: #047857;
    border-color: #047857;
}

.btn--telegram {
    background: #0088cc;
    border-color: #0088cc;
    color: var(--white);
}

.btn--telegram:hover {
    background: #006699;
    border-color: #006699;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--white);
    border-radius: var(--radius-base);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 1rem;
}

.btn-icon:hover {
    background: var(--gray-50);
    border-color: var(--primary);
}

/* ===========================
   Toast Notifications
   =========================== */

.toast-container {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.toast {
    background: var(--gray-900);
    color: var(--white);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-base);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
    max-width: 360px;
    font-size: 0.875rem;
}

.toast--show {
    opacity: 1;
    transform: translateX(0);
}

.toast--success {
    background: var(--success);
}

.toast--error {
    background: var(--error);
}

.toast--info {
    background: var(--primary);
}

/* ===========================
   Responsive
   =========================== */

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

    .pipeline-history {
        max-height: 320px;
        position: relative;
        top: 0;
        order: 2;
    }

    .pipeline-main {
        order: 1;
    }

    .progress-bar {
        overflow-x: auto;
    }

    .progress-step__label {
        font-size: 0.75rem;
    }
}

/* ===========================
   Slide Renderer (for html-to-image export)
   Same styles as Insta-Slides
   =========================== */

.slide-canvas {
    position: relative;
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

.slide-bg {
    position: absolute;
    inset: 0;
    background-color: #1a1a2e;
    background-size: cover;
    background-position: center;
}

.slide-content {
    position: absolute;
    top: 60px;
    left: 130px;
    right: 130px;
    bottom: 140px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 24px;
    z-index: 1;
    overflow: hidden;
}

.slide-content[data-align="top"] {
    justify-content: flex-start;
}

.slide-content[data-align="bottom"] {
    justify-content: flex-end;
}

.slide-title {
    font-size: 48px;
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
    word-wrap: break-word;
    word-break: break-word;
    flex-shrink: 0;
}

.slide-body {
    font-size: 24px;
    font-weight: 400;
    line-height: 1.5;
    color: #fff;
    word-wrap: break-word;
    word-break: break-word;
    flex-shrink: 1;
}

.slide-footer {
    position: absolute;
    left: 130px;
    right: 220px;
    bottom: 80px;
    display: flex;
    align-items: center;
    height: 51px;
    font-size: 25px;
    font-weight: 500;
    color: #fff;
    opacity: 0.9;
    z-index: 2;
}

.slide-arrow {
    position: absolute;
    right: 130px;
    bottom: 80px;
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 51px;
    gap: 8px;
    z-index: 3;
}

.slide-arrow__icon {
    opacity: 0.8;
    order: 2;
}

.slide-arrow__text {
    font-size: 25px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    opacity: 0.8;
    order: 1;
}

@media (max-width: 768px) {
    .tool-hero {
        padding: var(--space-12) 0;
    }

    .tool-hero h1 {
        font-size: 1.75rem;
    }
}

@media (max-width: 640px) {
    .step-content {
        padding: 1.25rem;
    }

    .step-actions {
        flex-direction: column;
    }

    .step-actions button {
        width: 100%;
    }

    .mode-cards {
        grid-template-columns: 1fr;
    }

    .source-tabs {
        flex-direction: column;
    }

    .youtube-input {
        flex-direction: column;
    }

    .progress-bar::before {
        display: none;
    }

    .progress-step__number {
        width: 2rem;
        height: 2rem;
        font-size: 0.875rem;
    }

    .toast-container {
        left: 1rem;
        right: 1rem;
    }

    .toast {
        max-width: none;
    }

    .history-item {
        grid-template-columns: 60px 1fr auto;
    }

    .history-thumbnail {
        width: 60px;
        height: 75px;
    }
}
