/* ========================================
   Ad Studio — AI-powered ad creation
   ======================================== */

@keyframes ad-fade-up {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes ad-scale-in {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes ad-popover-in {
    from { opacity: 0; transform: translateY(-4px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Page layout */
.ad-page {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ── Header ───────────────────────────── */

.ad-creation-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: ad-fade-up 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.ad-centered-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    padding: 2rem 0 1rem;
}

.ad-centered-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 2rem;
    animation: ad-fade-up 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.05s both;
}

.ad-centered-icon {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: hsl(var(--foreground) / 0.05);
    color: hsl(var(--muted-foreground));
    margin-bottom: 1.25rem;
}

.ad-centered-title {
    font-family: 'Geist', system-ui, -apple-system, sans-serif;
    font-size: 1.65rem;
    font-weight: 700;
    color: hsl(var(--foreground));
    margin: 0 0 0.5rem 0;
    letter-spacing: -0.025em;
}

.ad-centered-subtitle {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin: 0;
    line-height: 1.65;
    max-width: 440px;
}

/* ── Preset Buttons (inside popover) ───── */

.ad-preset-options {
    display: flex;
    background: hsl(var(--secondary));
    border-radius: 0.5rem;
    padding: 3px;
    gap: 2px;
}

.ad-preset-btn {
    flex: 1;
    padding: 0.4rem 0.5rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    font-weight: 550;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.ad-preset-btn:hover:not(.active) {
    color: hsl(var(--foreground));
    background: hsl(var(--foreground) / 0.04);
}

.ad-preset-btn.active {
    background: hsl(var(--foreground));
    color: hsl(var(--background));
    box-shadow: 0 1px 4px hsl(0 0% 0% / 0.12);
}

/* ── Duration Toggle (inline in footer) ── */

.ad-input-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ad-duration-toggle {
    display: inline-flex;
    background: hsl(var(--secondary));
    border-radius: 0.4rem;
    padding: 2px;
    gap: 1px;
}

.ad-dur-btn {
    padding: 0.3rem 0.55rem;
    background: transparent;
    border: none;
    border-radius: 0.3rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ad-dur-btn:hover:not(.active) {
    color: hsl(var(--foreground));
}

.ad-dur-btn.active {
    background: hsl(var(--foreground));
    color: hsl(var(--background));
    box-shadow: 0 1px 3px hsl(0 0% 0% / 0.1);
}

/* ── Main Input ───────────────────────── */

.ad-input-wrapper {
    width: 100%;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 1.25rem;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
    box-shadow: 0 1px 3px hsl(0 0% 0% / 0.04), 0 4px 16px -4px hsl(0 0% 0% / 0.04);
    animation: ad-scale-in 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.15s both;
}

.ad-input-wrapper:focus-within {
    border-color: hsl(var(--foreground) / 0.2);
    box-shadow: 0 1px 3px hsl(0 0% 0% / 0.04), 0 8px 32px -8px hsl(0 0% 0% / 0.08);
}

.ad-main-input {
    width: 100%;
    padding: 1.25rem 1.25rem 0.5rem;
    background: transparent;
    border: none;
    color: hsl(var(--foreground));
    font-size: 0.925rem;
    font-family: inherit;
    line-height: 1.65;
    resize: none;
    min-height: 88px;
    box-sizing: border-box;
}

.ad-main-input:focus { outline: none; }

.ad-main-input::placeholder {
    color: hsl(var(--muted-foreground) / 0.45);
}

/* Footer row */
.ad-input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.625rem 0.625rem 1rem;
}

.ad-input-left {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
}

.ad-input-hint {
    font-size: 0.7rem;
    color: hsl(var(--muted-foreground) / 0.6);
    white-space: nowrap;
}

/* ── Settings Dropdown ────────────────── */

.ad-settings-dropdown { position: relative; }

.ad-settings-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.6rem;
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.725rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ad-settings-toggle:hover {
    color: hsl(var(--foreground));
    border-color: hsl(var(--foreground) / 0.15);
    background: hsl(var(--secondary));
}

.ad-settings-toggle svg:first-child { opacity: 0.5; }
.ad-settings-label { font-size: 0.725rem; }

/* Backdrop + Popover */
.ad-settings-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9998;
}

.ad-settings-backdrop.open { display: block; }

.ad-settings-popover {
    position: fixed;
    min-width: 250px;
    border-radius: 1rem;
    padding: 0.875rem;
    z-index: 9999;
    display: none;
    flex-direction: column;
    gap: 0.875rem;
    background-color: #fff;
    border: 1px solid #ddd;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

.ad-settings-popover[data-theme="dark"] {
    background-color: #1c1c1c;
    border-color: #333;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

.ad-settings-popover.open {
    display: flex;
    animation: ad-popover-in 0.18s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.ad-settings-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.ad-settings-group-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding-left: 0.1rem;
}

.ad-model-options,
.ad-format-options {
    display: flex;
    background: hsl(var(--secondary));
    border-radius: 0.5rem;
    padding: 3px;
    gap: 2px;
}

.ad-model-opt,
.ad-format-opt {
    flex: 1;
    padding: 0.4rem 0.5rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    font-weight: 550;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.ad-model-opt:hover:not(.active),
.ad-format-opt:hover:not(.active) {
    color: hsl(var(--foreground));
    background: hsl(var(--foreground) / 0.04);
}

.ad-model-opt.active,
.ad-format-opt.active {
    background: hsl(var(--foreground));
    color: hsl(var(--background));
    box-shadow: 0 1px 4px hsl(0 0% 0% / 0.12);
}

/* ── Generate Button ──────────────────── */

.ad-generate-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    background: hsl(var(--foreground));
    color: hsl(var(--background));
    border: none;
    border-radius: 0.625rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
}

.ad-generate-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px hsl(0 0% 0% / 0.12);
}

.ad-generate-btn:active:not(:disabled) {
    transform: scale(0.97);
    box-shadow: none;
}

.ad-generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ad-gen-text,
.ad-gen-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.ad-gen-loading .spinner {
    animation: spin 1s linear infinite;
}

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

/* ── Status Message ───────────────────── */

.ad-status-message {
    width: 100%;
    max-width: 680px;
    margin: 0.75rem auto 0;
    padding: 0.7rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.8rem;
    text-align: center;
    animation: ad-fade-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.ad-status-message.success {
    background: hsl(142 71% 45% / 0.08);
    color: hsl(142 71% 40%);
    border: 1px solid hsl(142 71% 45% / 0.15);
}

.ad-status-message.error {
    background: hsl(0 72% 51% / 0.08);
    color: hsl(0 72% 51%);
    border: 1px solid hsl(0 72% 51% / 0.15);
}

/* ── Script Preview ───────────────────── */

.ad-script-preview {
    width: 100%;
    margin-top: 1rem;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 1rem;
    overflow: hidden;
    animation: ad-fade-up 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

.ad-script-title {
    font-family: 'Geist', system-ui, sans-serif;
    font-size: 0.95rem;
    font-weight: 650;
    color: hsl(var(--foreground));
    margin: 0;
    letter-spacing: -0.01em;
}

.ad-script-meta {
    font-size: 0.7rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    flex-shrink: 0;
}

.ad-script-lines {
    display: flex;
    flex-direction: column;
    max-height: 360px;
    overflow-y: auto;
}

.ad-script-line {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    transition: background 0.15s ease;
}

.ad-script-line:last-child {
    border-bottom: none;
}

.ad-script-line:hover {
    background: hsl(var(--foreground) / 0.02);
}

.ad-script-speaker {
    font-size: 0.725rem;
    font-weight: 650;
    min-width: 70px;
    padding-top: 0.45rem;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.ad-script-text {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    color: hsl(var(--foreground));
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.55;
    padding: 0.35rem 0.5rem;
    resize: none;
    transition: all 0.2s ease;
}

.ad-script-text:focus {
    outline: none;
    border-color: hsl(var(--border));
    background: hsl(var(--secondary) / 0.5);
}

.ad-script-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-top: 0.25rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    color: hsl(var(--muted-foreground) / 0.4);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.ad-script-remove:hover {
    color: hsl(0 72% 51%);
    background: hsl(0 72% 51% / 0.08);
}

.ad-script-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid hsl(var(--border));
}

.ad-script-discard {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ad-script-discard:hover {
    color: hsl(var(--foreground));
    border-color: hsl(var(--foreground) / 0.2);
}

.ad-script-submit {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.15rem;
    background: hsl(var(--foreground));
    color: hsl(var(--background));
    border: none;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.ad-script-submit:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px hsl(0 0% 0% / 0.12);
}

.ad-script-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Suggestion Chips ─────────────────── */

.ad-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
    margin-top: 1.5rem;
    animation: ad-fade-up 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.2s both;
}

.ad-suggestion-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: 2rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.775rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ad-suggestion-chip:hover {
    color: hsl(var(--foreground));
    border-color: hsl(var(--foreground) / 0.2);
    background: hsl(var(--foreground) / 0.03);
}

.ad-suggestion-chip:active { transform: scale(0.97); }

/* ── History Section ──────────────────── */

.ad-history {
    margin-top: 3rem;
    animation: ad-fade-up 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.3s both;
}

.ad-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.ad-history-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: hsl(var(--foreground));
}

.ad-history-header .view-all-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: hsl(var(--primary));
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.ad-history-header .view-all-link:hover { opacity: 0.8; }

.ad-history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ad-history-empty {
    text-align: center;
    padding: 2rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
}

.ad-history-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 1rem;
    transition: all 0.25s ease;
}

.ad-history-item:hover {
    border-color: hsl(var(--foreground) / 0.15);
}

.ad-history-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.75rem;
    background: hsl(var(--secondary));
    color: hsl(var(--muted-foreground));
    flex-shrink: 0;
}

.ad-history-info {
    flex: 1;
    min-width: 0;
}

.ad-history-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ad-history-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.ad-status-badge {
    display: inline-flex;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ad-status-badge.completed {
    background: hsl(142 71% 45% / 0.12);
    color: hsl(142 71% 40%);
}

.ad-status-badge.processing {
    background: hsl(45 100% 51% / 0.12);
    color: hsl(45 100% 40%);
}

.ad-status-badge.failed {
    background: hsl(0 72% 51% / 0.12);
    color: hsl(0 72% 51%);
}

.ad-status-badge.cancelled {
    background: hsl(var(--muted-foreground) / 0.12);
    color: hsl(var(--muted-foreground));
}

.ad-history-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}

.ad-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 0.5rem;
    background: hsl(var(--secondary));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.ad-action-btn:hover {
    color: hsl(var(--foreground));
    border-color: hsl(var(--foreground) / 0.2);
}

/* ── Responsive ───────────────────────── */

@media (max-width: 640px) {
    .ad-presets {
        gap: 1rem;
    }

    .ad-suggestions {
        gap: 0.3rem;
    }

    .ad-suggestion-chip {
        font-size: 0.7rem;
        padding: 0.4rem 0.75rem;
    }

    .ad-input-hint { display: none; }

    .ad-input-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}
