/* ============================================
   MKTAI Funnel Dashboard — Premium Dark Theme
   ============================================ */

:root {
    --bg-body: #0f0f1a;
    --bg-sidebar: #12122a;
    --bg-card: #1a1a2e;
    --bg-card-hover: #222240;
    --bg-input: #16163a;
    --border: #2a2a4a;
    --border-light: #333366;
    --text-primary: #e6e6f0;
    --text-secondary: #8888aa;
    --text-muted: #555577;
    --accent: #a78bfa;
    --accent-glow: rgba(167, 139, 250, 0.15);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --trial-bg: rgba(245, 158, 11, 0.12);
    --trial-color: #fbbf24;
    --member-bg: rgba(16, 185, 129, 0.12);
    --member-color: #34d399;
    --block-bg: rgba(239, 68, 68, 0.12);
    --block-color: #f87171;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
    width: 220px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
}

.brand-icon {
    font-size: 1.6rem;
    filter: drop-shadow(0 0 8px var(--accent));
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
}

.nav-item:hover {
    background: var(--accent-glow);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 600;
}

.nav-icon {
    font-size: 1.1rem;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}

.api-status {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.api-status.online {
    color: var(--success);
}

.api-status.offline {
    color: var(--danger);
}

/* ── MAIN ── */
.main {
    flex: 1;
    margin-left: 220px;
    min-height: 100vh;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-sidebar);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
}

.header h1 {
    font-size: 1.3rem;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.last-update {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.btn-refresh {
    background: var(--accent-glow);
    color: var(--accent);
    border: 1px solid rgba(167, 139, 250, 0.2);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.btn-refresh:hover {
    background: rgba(167, 139, 250, 0.25);
    border-color: var(--accent);
}

.content {
    padding: 1.5rem 2rem 3rem;
}

/* ── VIEWS ── */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── STATS GRID ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius) var(--radius) 0 0;
}

.stat-total::before {
    background: var(--accent);
}

.stat-trial::before {
    background: var(--warning);
}

.stat-member::before {
    background: var(--success);
}

.stat-conversion::before {
    background: var(--info);
}

.stat-ltv::before {
    background: linear-gradient(90deg, var(--warning), var(--success));
}

.stat-churn::before {
    background: var(--danger);
}

.stat-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    margin: 0.5rem 0 0.25rem;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ── SECTION CARDS ── */
.section-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.section-card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* ── TABLES ── */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(42, 42, 74, 0.5);
    color: var(--text-secondary);
}

tbody tr {
    transition: background var(--transition);
}

tbody tr:hover {
    background: var(--bg-card-hover);
}

/* ── STATUS BADGES ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-trial {
    background: var(--trial-bg);
    color: var(--trial-color);
}

.badge-member {
    background: var(--member-bg);
    color: var(--member-color);
}

.badge-block {
    background: var(--block-bg);
    color: var(--block-color);
}

.badge-guest {
    background: rgba(6, 182, 212, 0.12);
    color: #22d3ee;
}

/* ── FILTER BAR ── */
.leads-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-bar {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.4rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.filter-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.search-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    width: 280px;
    outline: none;
    transition: border-color var(--transition);
}

.search-input:focus {
    border-color: var(--accent);
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* ── PAGINATION ── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.page-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.page-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.page-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ── MODAL ── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.open {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 700px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: color var(--transition);
}

.modal-close:hover {
    color: var(--danger);
}

/* ── LEAD DETAIL ── */
.lead-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.lead-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

.lead-info h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.lead-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.journey-timeline {
    position: relative;
    padding-left: 2rem;
}

.journey-timeline::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.journey-item {
    position: relative;
    padding: 0.75rem 0;
    padding-left: 1rem;
}

.journey-item::before {
    content: '';
    position: absolute;
    left: -1.75rem;
    top: 1.1rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-card);
}

.journey-event {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.journey-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* ── CONVERSION STATS ── */
.conversion-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.conv-stat {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.conv-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.conv-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.conv-value.accent {
    color: var(--accent);
}

.chart-container {
    width: 100%;
    overflow-x: auto;
}

/* ── REVENUE ── */
.revenue-total {
    font-size: 2rem;
    font-weight: 700;
    color: var(--success);
    margin-bottom: 1.5rem;
}

.revenue-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.revenue-card {
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.revenue-card h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.revenue-amount {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--success);
}

.revenue-detail {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ── EMPTY STATE ── */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

.empty-state p {
    font-size: 0.9rem;
}

/* ── VIEW DETAIL BUTTON ── */
.btn-view {
    background: none;
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.btn-view:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
}

/* ── TRACK VIEW (always white text, high contrast) ── */
#view-track .section-card { background: #12122a; }
#view-track .section-card h2 { color: #ffffff !important; }

.track-tabs {
    display: flex; gap: 0.5rem; margin-bottom: 1rem;
    padding-bottom: 0.75rem; border-bottom: 1px solid rgba(255,255,255,0.1);
}

.track-hint {
    font-size: 0.75rem; color: #ffffff; opacity: 0.7;
    margin-bottom: 1rem;
}

.track-table { font-size: 0.8rem; }
.track-table thead th { color: #ffffff; opacity: 0.85; }
.track-table tbody td { color: #ffffff !important; vertical-align: top; }

.track-name { color: #ffffff; font-weight: 600; font-size: 0.85rem; }
.track-email { color: #c4b5fd; font-size: 0.75rem; word-break: break-all; }
.track-sub { color: #ffffff; opacity: 0.75; font-size: 0.7rem; margin-top: 2px; }
.track-mono { color: #ffffff; font-family: ui-monospace, monospace; font-size: 0.75rem; }

.track-badge {
    display: inline-block; padding: 2px 8px; border-radius: 99px;
    font-size: 0.65rem; font-weight: 600; text-transform: uppercase;
    margin-left: 4px;
}
.track-badge-critical { background: rgba(239,68,68,0.2); color: #fecaca; }
.track-badge-warning  { background: rgba(245,158,11,0.2); color: #fde68a; }
.track-badge-moderate { background: rgba(59,130,246,0.2); color: #bfdbfe; }
.track-badge-advanced { background: rgba(16,185,129,0.2); color: #bbf7d0; }

.track-chip {
    display: inline-block; background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15); border-radius: 4px;
    padding: 2px 6px; font-size: 0.65rem; color: #ffffff;
    margin-right: 3px; margin-bottom: 2px; font-family: ui-monospace, monospace;
}

.track-raw { color: #ffffff; font-size: 0.75rem; }
.track-raw summary { cursor: pointer; color: #a78bfa; }
.track-raw pre {
    max-height: 280px; overflow: auto; background: rgba(0,0,0,0.35);
    padding: 8px; margin-top: 6px; border-radius: 6px;
    color: #ffffff; font-size: 0.7rem; white-space: pre-wrap; word-break: break-all;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }

    .sidebar-brand span,
    .nav-item span:not(.nav-icon) {
        display: none;
    }

    .sidebar-brand {
        justify-content: center;
    }

    .nav-item {
        justify-content: center;
        padding: 0.75rem;
    }

    .main {
        margin-left: 60px;
    }

    .header {
        padding: 1rem;
    }

    .content {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .leads-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-input {
        width: 100%;
    }
}

/* ── LOGIN SCREEN ── */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.4s ease;
}

.login-overlay.hidden {
    display: none;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5), 0 0 80px var(--accent-glow);
    position: relative;
    overflow: hidden;
}

.login-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), #6366f1, var(--accent));
    background-size: 200% 100%;
    animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 1.5rem;
    justify-content: center;
}

.login-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-field {
    margin-bottom: 1rem;
}

.login-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.4rem;
}

.login-field input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.login-field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-error {
    color: var(--danger);
    font-size: 0.8rem;
    text-align: center;
    min-height: 1.2rem;
    margin-bottom: 0.5rem;
}

.login-btn {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.3px;
}

.login-btn:hover {
    background: #9072e8;
    box-shadow: 0 4px 20px rgba(167, 139, 250, 0.3);
    transform: translateY(-1px);
}

.login-btn:active {
    transform: translateY(0);
}

.login-footer {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 1.5rem;
}

/* appContainer layout fix */
#appContainer {
    display: none;
    width: 100%;
    min-height: 100vh;
}

#appContainer.authenticated {
    display: flex !important;
}