/* Chat UI Styles (Welcome, Messages, and Input) */

/* Welcome / Initial Selection */
.chat-initial-selection {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: var(--space-8);
    gap: var(--space-6);
}

.chat-initial-selection.active {
    display: flex;
}

.chat-welcome {
    text-align: center;
    margin-bottom: var(--space-8);
}

.chat-welcome-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
}

.chat-welcome-icon svg {
    width: 32px;
    height: 32px;
    stroke-width: 1.5;
}

.chat-welcome h3 {
    font-size: 24px;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0 0 var(--space-2) 0;
}

.chat-welcome p {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin: 0;
    line-height: 1.5;
}

.chat-start-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: 100%;
    max-width: 600px;
}

.test-loader-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-4);
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    background: transparent;
    border: 1px dashed var(--color-border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.test-loader-btn:hover {
    color: var(--color-text-primary);
    border-color: var(--color-text-secondary);
    background: var(--color-bg-hover);
}

.test-loader-btn svg {
    width: 14px;
    height: 14px;
}

.chat-start-option {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.chat-start-option:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border-light);
}

.chat-start-option .option-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--color-text-secondary);
    transition: color 0.2s ease;
}

.chat-start-option .option-icon svg {
    width: 24px;
    height: 24px;
    stroke-width: 2.5;
}

.chat-start-option:hover .option-icon {
    color: var(--color-text-primary);
}

.chat-start-option .option-content {
    flex: 1;
    min-width: 0;
}

.chat-start-option h4 {
    margin: 0 0 4px 0;
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-text-primary);
    line-height: 1.4;
}

.chat-start-option p {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.chat-start-option .option-arrow {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--color-text-secondary);
    transition: all 0.2s ease;
}

.chat-start-option .option-arrow svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.chat-start-option:hover .option-arrow {
    color: var(--color-text-primary);
    transform: translateX(2px);
}

/* Chat Messages */
.chat-interface {
    display: none;
    flex-direction: column;
    height: 100%;
}

.chat-interface.active {
    display: flex;
}

/* Quick, smooth entrance when a script is selected */
.chat-messages.script-appearing {
    animation: scriptAppear 0.26s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

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

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    /* Allow horizontal scroll for refinement bar on split screen / narrow viewports */
    padding: var(--space-6) var(--space-4);
    scroll-behavior: smooth;
}

.chat-messages-inner {
    max-width: var(--sw-chat-max-width);
    margin: 0 auto;
    transition: max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-interface.refining .chat-messages-inner,
.chat-messages:has(.sources-active) .chat-messages-inner {
    max-width: 1400px;
    /* Expand the whole track so the shift doesn't hit the left edge */
}

.chat-message {
    margin-bottom: var(--space-6);
    max-width: var(--sw-chat-max-width);
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

.chat-message-user {
    display: flex;
    justify-content: flex-end;
}

.chat-message-ai {
    display: flex;
    justify-content: flex-start;
    transition: max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Expand AI message width when sources or refinement sidebars are active */
.chat-message-ai.sources-active,
.chat-interface.refining .chat-message-ai {
    max-width: 1400px;
    width: 100%;
}

/* Shift the block slightly to stay balanced without hitting the left edge */
.chat-message-ai.sources-active {
    transform: translateX(-100px);
    /* Default shift for large screens */
}

.chat-interface.refining .chat-message-ai.sources-active {
    transform: translateX(-200px);
}

@media (max-width: 1366px) {
    .chat-message-ai.sources-active {
        transform: translateX(-50px);
        /* Reduced shift for laptops */
    }

    .chat-interface.refining .chat-message-ai.sources-active {
        transform: translateX(-100px);
    }
}

@media (max-width: 1100px) {

    .chat-message-ai.sources-active,
    .chat-interface.refining .chat-message-ai.sources-active {
        transform: translateX(0);
        /* Center without shifting on small desktops */
    }
}

.message-bubble {
    max-width: 80%;
    padding: var(--space-4) var(--space-5);
    position: relative;
}

.chat-message-user .message-bubble {
    background: var(--color-gray-700);
    color: white;
    border-radius: 18px 18px 4px 18px;
}

.chat-message-ai .message-bubble {
    background: var(--sw-message-ai-bg);
    color: var(--color-text-primary);
    border-bottom-left-radius: 4px;
}

.message-content {
    font-size: var(--font-size-base);
    line-height: 1.6;
    word-wrap: break-word;
}

.message-content p {
    margin: 0 0 var(--space-2) 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-timestamp {
    font-size: 11px;
    opacity: 0.7;
    margin-top: var(--space-2);
}

/* Loading Message */
.chat-message-loading {
    display: flex;
    justify-content: flex-start;
}

.chat-message-loading .message-bubble {
    background: var(--sw-message-ai-bg);
    padding: var(--space-4);
}

.chat-message-loading .loading-bubble {
    padding: var(--space-5) var(--space-5);
    max-width: 420px;
}

.loading-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.loading-status {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Step text: smooth fade when changing */
.loading-step-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    transition: opacity 0.38s cubic-bezier(0.4, 0, 0.2, 1), transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
}

.loading-step-text.loading-step-fade-out {
    opacity: 0;
    transform: translateY(-3px);
}

/* Inline source icons: only on research/sources step. Stacked circles, appear one-by-one like search results. */
.loading-source-icons {
    display: none;
    align-items: center;
    margin-left: var(--space-3);
}

.loading-status.loading-step--web .loading-source-icons {
    display: flex;
}

.loading-source-icons-row {
    display: flex;
    align-items: center;
}

.loading-source-icon-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    margin-left: -10px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--color-bg-secondary);
    box-shadow: 0 0 0 1.5px var(--color-border-light);
    opacity: 0;
    transform: scale(0.82);
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.loading-source-icon-wrap:first-child {
    margin-left: 0;
}

.loading-source-icon-wrap.visible {
    opacity: 1;
    transform: scale(1);
}

.loading-source-icon {
    width: 16px;
    height: 16px;
    object-fit: contain;
}

.typing-indicator {
    display: flex;
    gap: 6px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--color-text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.7;
    }

    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Chat Input Area */
.chat-input-container {
    padding: var(--space-6) var(--space-4);
    max-width: var(--sw-chat-max-width);
    margin: 0 auto;
    width: 100%;
}

.sw-chat-input-box {
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: 32px;
    padding: var(--space-4) var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-base);
}

.sw-chat-input-box:focus-within {
    border-color: var(--color-gray-700);
    box-shadow: var(--shadow-xl);
}

.chat-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-size: var(--font-size-base);
    color: var(--color-text-primary);
    font-family: inherit;
    line-height: var(--line-height-relaxed);
    max-height: 200px;
    padding: 0;
}

.chat-input::placeholder {
    color: var(--color-text-tertiary);
}

.sw-chat-input-bottom {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4);
}

.chat-input-pills {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.chat-option-pill {
    padding: var(--space-2) var(--space-4);
    border-radius: 12px;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    border: 1px solid var(--color-border-light);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.chat-option-pill:hover:not(.active) {
    background: var(--color-bg-hover);
    border-color: var(--color-border-medium);
    color: var(--color-text-primary);
}

.chat-option-pill.active {
    background: var(--color-primary-light);
    color: var(--color-primary-600);
    border-color: var(--color-primary);
}

:root[data-theme='dark'] .chat-option-pill.active {
    color: var(--color-primary-400);
    border-color: var(--color-primary-600);
}

.sw-chat-input-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.chat-send-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--color-border-dark);
}

.chat-send-btn i {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
}

/* Time Selector Dropdown */
.time-selector-wrapper {
    position: relative;
}

.time-dropdown {
    position: absolute;
    bottom: calc(100% + var(--space-2));
    left: 0;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-medium);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--transition-base);
    z-index: var(--z-popover);
    overflow: hidden;
}

.time-selector-wrapper.active .time-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.time-option-item {
    width: 100%;
    padding: var(--space-2) var(--space-4);
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: block;
}

.time-option-item:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
}

.time-option-item.active {
    background: var(--color-primary-light);
    color: var(--color-primary-700);
    font-weight: var(--font-weight-semibold);
}

/* Rules selector (custom instructions) popover */
.rules-selector-wrapper {
    position: relative;
}

.rules-popover {
    position: absolute;
    bottom: calc(100% + var(--space-2));
    right: 0;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-medium);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    max-width: 360px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--transition-base);
    z-index: var(--z-popover);
    overflow: hidden;
    padding: var(--space-3);
}

.rules-selector-wrapper.active .rules-popover {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

@keyframes rules-popover-shake {
    0%, 100% { transform: translateY(0) translateX(0); }
    15% { transform: translateY(0) translateX(-6px); }
    30% { transform: translateY(0) translateX(6px); }
    45% { transform: translateY(0) translateX(-4px); }
    60% { transform: translateY(0) translateX(4px); }
    75% { transform: translateY(0) translateX(-2px); }
}

.rules-popover.rules-popover-shake {
    animation: rules-popover-shake 0.4s ease-in-out;
}

.rules-popover-header {
    margin-bottom: var(--space-2);
}

.rules-popover-title {
    margin: 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.rules-textarea {
    width: 100%;
    height: 88px;
    min-height: 88px;
    max-height: 88px;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-medium);
    border-radius: 8px;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-family: inherit;
    resize: none;
    transition: border-color var(--transition-fast);
    box-sizing: border-box;
}

.rules-textarea::placeholder {
    color: var(--color-text-tertiary);
}

.rules-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-light);
}

.rules-popover-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-top: var(--space-3);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border-light);
}

.rules-toggle-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    user-select: none;
}

.rules-use-toggle {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.rules-toggle-text {
    line-height: 1.3;
}

.rules-save-btn {
    padding: var(--space-1) var(--space-3);
    border-radius: 8px;
    border: 1px solid var(--color-primary);
    background: var(--color-primary);
    color: var(--color-white);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.rules-save-btn:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

.rules-save-btn.saved {
    background: var(--color-success);
    border-color: var(--color-success);
}

.rules-save-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--color-border-dark);
    border-color: var(--color-border-medium);
}

/* Unsaved changes bar */
.rules-unsaved-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-top: var(--space-3);
    padding: var(--space-2) 0 0;
    border-top: 1px solid var(--color-border-light);
}

.rules-unsaved-bar[hidden] {
    display: none;
}

.rules-unsaved-text {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
}

.rules-unsaved-actions {
    display: flex;
    gap: var(--space-2);
}

.rules-discard-btn {
    padding: var(--space-1) var(--space-3);
    border-radius: 8px;
    border: 1px solid var(--color-border-medium);
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.rules-discard-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
}

.rules-save-bar-btn {
    padding: var(--space-1) var(--space-3);
}

/* Pill: active when rules are on and have content */
.rules-option.rules-on {
    background: var(--color-primary-light);
    color: var(--color-primary-600);
    border-color: var(--color-primary);
}

:root[data-theme='dark'] .rules-option.rules-on {
    color: var(--color-primary-400);
    border-color: var(--color-primary-600);
}

/* Responsive ChatUI */
@media (max-width: 768px) {
    .rules-popover {
        min-width: 240px;
        max-width: calc(100vw - var(--space-6));
    }

    .chat-messages {
        padding: var(--space-4) var(--space-3);
    }

    .message-bubble {
        max-width: 90%;
    }

    .chat-start-options {
        padding: 0 var(--space-2);
        gap: var(--space-3);
    }

    .chat-welcome {
        padding: 0 var(--space-2);
        margin-bottom: var(--space-6);
    }

    .chat-initial-selection {
        padding: var(--space-4);
    }
}

.chat-input-container.refining .sw-chat-input-box {
    display: none;
}

/* Script Writer Usage Indicator – wrapper so hover area includes tooltip for clickable Upgrade */
.sw-usage-wrapper {
    position: relative;
    display: inline-flex;
    padding-top: 100px;
    margin-top: -100px;
}

.sw-usage-wrapper:hover .sw-usage-tooltip {
    opacity: 1;
    visibility: visible;
}

.sw-usage-indicator {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    transition: all var(--transition-base);
    flex-shrink: 0;
    cursor: pointer;
    line-height: 1;
    /* Default percentage */
    --usage-percent: 100%;
}

/* The Ring (Background) */
.sw-usage-indicator::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(var(--color-text-secondary) var(--usage-percent),
            var(--color-border-medium) 0);
    transition: background 0.3s ease;
    z-index: 1;
}

/* The Center Cutout (creates the ring effect) */
.sw-usage-indicator::after {
    content: '';
    position: absolute;
    inset: 2px;
    /* Thickness of the border */
    border-radius: 50%;
    background: var(--color-surface-elevated);
    z-index: 2;
}

.sw-usage-indicator:hover {
    color: var(--color-text-primary);
}

.sw-usage-indicator:hover::before {
    background: conic-gradient(var(--color-text-primary) var(--usage-percent),
            var(--color-border-dark) 0);
}

.sw-usage-indicator.unlimited {
    color: var(--color-text-tertiary);
}

.sw-usage-indicator.unlimited::before {
    background: none;
    border: 1px solid var(--color-border-medium);
}

.sw-usage-indicator.unlimited::after {
    display: none;
}

.sw-usage-indicator.low {
    color: var(--color-text-primary);
}

.sw-usage-indicator.low::before {
    background: conic-gradient(var(--color-primary) var(--usage-percent),
            var(--color-border-medium) 0);
}

.sw-usage-indicator.depleted {
    opacity: 0.6;
}

.sw-usage-indicator.depleted::before {
    background: var(--color-border-medium);
}

.sw-usage-indicator span {
    position: relative;
    z-index: 3;
    /* Above the cutout */
}

.sw-usage-indicator i {
    width: 12px;
    height: 12px;
    stroke-width: 2.5;
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Custom Tooltip */
.sw-usage-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-medium);
    border-radius: var(--border-radius-base);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
    z-index: var(--z-tooltip);
    pointer-events: none;
    min-width: 180px;
}

.sw-usage-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--color-surface-elevated);
}

.sw-usage-indicator:hover .sw-usage-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Allow hovering and clicking the tooltip (e.g. Upgrade button) without it disappearing */
.sw-usage-tooltip {
    pointer-events: auto;
}

.sw-usage-tooltip-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    margin-bottom: var(--space-1);
    font-weight: var(--font-weight-medium);
    width: 100%;
}

.sw-usage-tooltip-subtext {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-3);
    font-weight: var(--font-weight-normal);
    width: 100%;
}

.sw-usage-tooltip-upgrade {
    display: inline-block;
    padding: var(--space-1) var(--space-3);
    background: var(--gradient-primary);
    color: var(--color-white);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
    transition: all var(--transition-base);
    margin-top: var(--space-1);
}

.sw-usage-tooltip-upgrade:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

@keyframes pulse-warning {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(245, 158, 11, 0);
    }
}

@keyframes pulse-error {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(239, 68, 68, 0);
    }
}

/* Profile Modal Styles */
.profile-modal-content {
    max-width: 900px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    /* Ensure the modal itself doesn't scroll */
}

.profile-modal-content .modal-header {
    padding: var(--space-5) var(--space-6);
    display: flex;
    align-items: center;
}

.profile-modal-content .modal-header h2 {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--font-size-2xl);
    margin: 0;
    line-height: 1;
    /* Force tight alignment */
}

.profile-modal-content .modal-header h2 span {
    display: flex;
    align-items: center;
    transform: translateY(1px);
    /* micro-adjustment for optical centering */
}

.profile-modal-content .modal-header h2 i,
.profile-modal-content .modal-header h2 svg {
    width: 28px;
    height: 28px;
    color: var(--color-text-primary);
    stroke-width: 2.5px;
    display: block;
    flex-shrink: 0;
}

.profile-modal-content .modal-close-btn {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--space-2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    border-radius: 50%;
}

.profile-modal-content .modal-close-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
    transform: rotate(90deg);
}

.profile-modal-content .modal-body {
    overflow: hidden;
    flex: 1;
    min-height: 0;
    padding-right: var(--space-2);
    display: flex;
    flex-direction: column;
}

.profile-modal-content .form-group {
    margin-bottom: var(--space-4);
    flex-shrink: 0;
}

.profile-modal-content .form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-2);
    color: var(--color-text-primary);
}

.profile-modal-content .form-group input[type="text"] {
    width: 100%;
    color: var(--color-text-primary);
    transition: all var(--transition-base);
}

.profile-modal-content .form-group input[type="text"]:hover {
    border-color: var(--color-border-medium);
}

.profile-modal-content .form-group input[type="text"]:focus {
    outline: none;
    background: var(--color-bg-secondary);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.profile-modal-content .input-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--space-1);
}

.profile-modal-content .char-count {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.profile-modal-content .video-selection-section {
    margin-top: var(--space-6);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.profile-modal-content .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
    flex-shrink: 0;
}

.profile-modal-content .section-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text);
}

.profile-modal-content .selection-count {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    padding: var(--space-1) var(--space-2);
    background: var(--color-bg-secondary);
    border-radius: 4px;
}

.profile-modal-content .selection-count.complete {
    background: var(--color-success-bg);
    color: var(--color-success);
    font-weight: 500;
}

.profile-modal-content .section-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
    flex-shrink: 0;
}

.profile-modal-content .video-selection-section .outlier-search-bar {
    flex-shrink: 0;
}

/* Video List */
.profile-modal-content .video-scroll-area {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: var(--space-4);
    background: transparent;
    border-radius: var(--border-radius-base);
    border: var(--border-width-thin) solid var(--color-border-light);
}

.profile-modal-content .video-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
    border: none;
    min-height: min-content;
}



.profile-modal-content .video-list-loading,
.profile-modal-content .video-list-empty,
.profile-modal-content .video-list-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    gap: var(--space-2);
    color: var(--color-text-secondary);
    grid-column: 1 / -1;
}

.profile-modal-content .video-list-loading i,
.profile-modal-content .video-list-empty i,
.profile-modal-content .video-list-error i {
    font-size: 32px;
}

.profile-modal-content .video-list-error {
    color: var(--color-error);
}

/* Video Card in Modal */
.profile-modal-content .video-card-modal {
    position: relative;
    border: var(--border-width-thin) solid var(--color-border-light);
    border-radius: var(--border-radius-base);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-base);
    background: var(--color-surface-elevated);
}

.profile-modal-content .video-card-modal:hover:not(.disabled) {
    border-color: var(--color-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.profile-modal-content .video-card-modal.selected {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.profile-modal-content .video-card-modal.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.video-card-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
}

.video-card-checkbox input[type="checkbox"] {
    display: none;
}

.video-card-checkbox label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 2px solid white;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: all var(--transition-base);
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
    /* Let clicks pass to the card */
}

.video-card-modal:hover .video-card-checkbox label,
.video-card-modal.selected .video-card-checkbox label {
    opacity: 1;
    transform: scale(1);
}

.video-card-checkbox input[type="checkbox"]:checked+label {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.video-card-checkbox label i {
    color: white;
    font-size: 14px;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.video-card-checkbox input[type="checkbox"]:checked+label i {
    opacity: 1;
}

.video-card-thumbnail {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    /* 16:9 aspect ratio */
    overflow: hidden;
}

.video-card-thumbnail img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-card-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: var(--font-size-xs);
    border-radius: 4px;
}

.video-card-info {
    padding: var(--space-3);
}

.video-card-title {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: var(--space-1);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-card-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    display: flex;
    gap: var(--space-1);
}

/* Load More Button Wrapper */
.profile-modal-content .load-more-btn {
    width: 100%;
    margin: var(--space-6) 0 var(--space-4);
    padding: var(--space-2) var(--space-4);
    background: var(--color-surface-sunken);
    border: var(--border-width-thin) solid var(--color-border-light);
    border-radius: var(--border-radius-sm);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    box-shadow: none;
    flex-shrink: 0;
}

.profile-modal-content .load-more-btn:hover:not(:disabled) {
    background: var(--color-bg-hover);
    border-color: var(--color-primary);
    color: var(--color-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.profile-modal-content .load-more-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Modal Buttons */
.script-writer-modal .modal-footer {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

.script-writer-modal .btn-secondary,
.script-writer-modal .btn-primary {
    padding: var(--space-2) var(--space-6);
    border-radius: 10px;
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    line-height: 1;
}

.script-writer-modal .btn-secondary span,
.script-writer-modal .btn-primary span {
    display: flex;
    align-items: center;
    transform: translateY(1px);
    /* micro-adjustment for optical vertical centering */
}

.script-writer-modal .btn-secondary {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
}

.script-writer-modal .btn-secondary:hover {
    background: var(--color-border-light);
}

.script-writer-modal .btn-primary {
    background: var(--color-primary);
    color: white;
}

.script-writer-modal .btn-primary i,
.script-writer-modal .btn-primary svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}

.script-writer-modal .btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
}

.script-writer-modal .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Toast Animations */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}