/* ── FlexiFunnels Pro - Master Stylesheet ──────────────────────────────────── */
:root {
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --bg-sidebar: #0f172a;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --radius: 0.75rem;
    --radius-sm: 0.5rem;
}

[data-bs-theme="dark"] {
    --bg-sidebar: #020617;
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    margin: 0;
    overflow-x: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform 0.3s ease;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: -0.02em;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
}

.sidebar-section-title {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: #475569;
    padding: 16px 12px 6px;
    text-transform: uppercase;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: #94a3b8;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 2px;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.06);
    color: #e2e8f0;
}

.sidebar-link.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,0.4);
}

.sidebar-link i {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: auto;
}

.avatar-sm {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
    font-weight: 600;
}

/* ── Main Content ────────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.content-wrapper {
    padding: 24px;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* ── Stat Cards ──────────────────────────────────────────────────────────── */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table {
    --bs-table-bg: transparent;
}

.table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom-width: 1px;
    padding: 12px 16px;
}

.table td {
    padding: 12px 16px;
    vertical-align: middle;
    font-size: 0.875rem;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

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

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-ghost:hover {
    background: var(--bg-body);
}

/* ── Page Header ──────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
}

.page-header .breadcrumb {
    font-size: 0.8rem;
    margin: 0;
}

/* ── AI Tools Grid ────────────────────────────────────────────────────────── */
.ai-tool-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
    display: block;
}

.ai-tool-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-4px);
    border-color: var(--primary);
    color: inherit;
}

.ai-tool-card .tool-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin: 0 auto 16px;
}

.ai-tool-card h5 {
    font-weight: 600;
    margin-bottom: 8px;
}

.ai-tool-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
}

/* ── Funnel Card ──────────────────────────────────────────────────────────── */
.funnel-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-card);
    overflow: hidden;
    transition: all 0.2s ease;
}

.funnel-card:hover {
    box-shadow: var(--shadow-md);
}

.funnel-card .funnel-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.funnel-card .funnel-stats {
    display: flex;
    padding: 12px 20px;
    gap: 20px;
}

.funnel-card .funnel-stat {
    text-align: center;
}

.funnel-card .funnel-stat .value {
    font-size: 1.1rem;
    font-weight: 700;
}

.funnel-card .funnel-stat .label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* ── Badge ────────────────────────────────────────────────────────────────── */
.badge-status {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}

.badge-draft { background: #fef3c7; color: #92400e; }
.badge-active, .badge-published { background: #d1fae5; color: #065f46; }
.badge-paused { background: #fee2e2; color: #991b1b; }
.badge-completed { background: #dbeafe; color: #1e40af; }

/* ── Builder ──────────────────────────────────────────────────────────────── */
.builder-toolbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.builder-canvas {
    background: #e2e8f0;
    min-height: calc(100vh - 120px);
    padding: 30px;
    display: flex;
    justify-content: center;
}

.builder-frame {
    background: white;
    width: 100%;
    max-width: 1200px;
    min-height: 600px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h4 {
    color: var(--text-primary);
    font-weight: 600;
}

/* ── Loading Spinner ──────────────────────────────────────────────────────── */
.ai-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--primary);
}

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

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

/* ── AI Generating Overlay ───────────────────────────────────────────────── */
.ai-generating-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.5);
    backdrop-filter: blur(4px);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ai-generating-overlay.show { opacity: 1; }

.ai-generating-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 40px 48px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
}

.ai-generating-card h5 {
    font-weight: 700;
    margin-bottom: 4px;
}

.ai-generating-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

/* ── Button Loading State ────────────────────────────────────────────────── */
.btn-loading {
    pointer-events: none;
    opacity: 0.85;
}

/* ── Toast Notifications ─────────────────────────────────────────────────── */
.toast-container-custom {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast-notification {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 280px;
    max-width: 400px;
}

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

.toast-success { background: #059669; color: white; }
.toast-danger { background: #dc2626; color: white; }
.toast-warning { background: #d97706; color: white; }
.toast-info { background: var(--primary); color: white; }

/* ── AI Result Sections ──────────────────────────────────────────────────── */
.ai-result-section {
    position: relative;
}

.ai-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.copy-btn-float {
    position: absolute;
    top: 12px;
    right: 12px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.card:hover .copy-btn-float { opacity: 1; }

/* ── Form Validation ─────────────────────────────────────────────────────── */
.form-control.is-invalid, .form-select.is-invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.15);
}

/* ── Score Badges ────────────────────────────────────────────────────────── */
.score-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 1.1rem;
}

.score-high { background: #d1fae5; color: #065f46; }
.score-medium { background: #fef3c7; color: #92400e; }
.score-low { background: #fee2e2; color: #991b1b; }

/* ── Auth Pages ───────────────────────────────────────────────────────────── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    padding: 20px;
}

.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    padding: 40px;
}

.auth-brand {
    text-align: center;
    margin-bottom: 32px;
}

.auth-brand i {
    font-size: 2.5rem;
    color: var(--primary);
}

.auth-brand h2 {
    font-weight: 800;
    font-size: 1.5rem;
    margin-top: 8px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Chat Widget ──────────────────────────────────────────────────────────── */
.chat-container {
    height: 400px;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-body);
    border-radius: var(--radius-sm);
}

.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    margin-bottom: 8px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.chat-bubble.user {
    background: var(--primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-bubble.bot {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.min-w-0 { min-width: 0; }
.gap-1 { gap: 4px; }
.cursor-pointer { cursor: pointer; }

.gradient-text {
    background: linear-gradient(135deg, var(--primary), #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hover-lift { transition: transform 0.2s ease; }
.hover-lift:hover { transform: translateY(-2px); }

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(99,102,241,0.15);
}

.code-block {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    overflow-x: auto;
}

.template-card {
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}
.template-card:hover, .template-card.selected {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}
