:root {
    --bg-main: #0a0b0f;
    --bg-card: #12141a;
    --bg-card-hover: #1a1d25;
    --bg-card-inner: #0e1015;
    --accent: #8b5cf6;
    --accent-light: #a78bfa;
    --accent-glow: rgba(139, 92, 246, 0.35);
    --accent-subtle: rgba(139, 92, 246, 0.08);
    --blue: #3b82f6;
    --green: #10b981;
    --orange: #f59e0b;
    --red: #ef4444;
    --cyan: #06b6d4;
    --pink: #ec4899;
    --yellow: #eab308;
    --text-primary: #f1f5f9;
    --text-secondary: #64748b;
    --text-tertiary: #475569;
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* ═══════════════ Sidebar ═══════════════ */
.sidebar {
    width: 270px;
    min-width: 270px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 28px 20px;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 36px;
    padding: 0 4px;
}

.logo-icon {
    color: var(--accent);
    filter: drop-shadow(0 0 12px var(--accent-glow));
    width: 28px;
    height: 28px;
}

.sidebar-header h2 {
    font-weight: 800;
    letter-spacing: -0.5px;
    font-size: 1.35rem;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.domain-list h3 {
    text-transform: uppercase;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    letter-spacing: 1.5px;
    margin-bottom: 14px;
    padding: 0 4px;
    font-weight: 600;
}

.domain-list ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.domain-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 14px;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.domain-item:hover {
    background: rgba(255, 255, 255, 0.02);
    border-color: var(--border);
}

.domain-item.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.12), rgba(139, 92, 246, 0.03));
    border-color: rgba(139, 92, 246, 0.25);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.08);
}

.domain-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.domain-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.04);
    padding: 2px 10px;
    border-radius: 20px;
    font-weight: 500;
}

/* ═══════════════ Main Content ═══════════════ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: 
        radial-gradient(ellipse at 20% 0%, rgba(139, 92, 246, 0.04), transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(59, 130, 246, 0.03), transparent 50%);
}

.top-nav {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 40px;
    background: rgba(10, 11, 15, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.top-nav h1 {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* ═══════════════ Tabs ═══════════════ */
.tab-nav {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.03);
    padding: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: 'Outfit', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.tab-btn i {
    width: 15px;
    height: 15px;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
    color: var(--text-primary);
    background: var(--accent-subtle);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.1);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ═══════════════ Buttons ═══════════════ */
.refresh-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.refresh-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-hover);
}

.refresh-btn:active {
    transform: scale(0.92);
}

.refresh-btn i {
    width: 18px;
    height: 18px;
}

.refresh-btn.is-loading svg,
.refresh-btn.is-loading i {
    animation: spin 0.8s linear infinite !important;
}

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

.delete-btn {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.15);
    color: #ef4444;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.delete-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
}

.delete-btn:active {
    transform: scale(0.92);
}

.delete-btn i {
    width: 16px;
    height: 16px;
}

/* ═══════════════ Content Body ═══════════════ */
.content-body {
    flex: 1;
    padding: 28px 40px 40px;
}

/* ═══════════════ Stats Grid ═══════════════ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.3), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

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

.stat-card:hover::before {
    opacity: 1;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-subtle);
    color: var(--accent);
    flex-shrink: 0;
}

.stat-icon i {
    width: 20px;
    height: 20px;
}

.stat-icon.icon-blue { background: rgba(59, 130, 246, 0.1); color: var(--blue); }
.stat-icon.icon-green { background: rgba(16, 185, 129, 0.1); color: var(--green); }
.stat-icon.icon-orange { background: rgba(245, 158, 11, 0.1); color: var(--orange); }
.stat-icon.icon-red { background: rgba(239, 68, 68, 0.1); color: var(--red); }
.stat-icon.icon-cyan { background: rgba(6, 182, 212, 0.1); color: var(--cyan); }
.stat-icon.icon-pink { background: rgba(236, 72, 153, 0.1); color: var(--pink); }
.stat-icon.icon-yellow { background: rgba(234, 179, 8, 0.1); color: var(--yellow); }

.stat-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ═══════════════ Charts ═══════════════ */
.charts-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-bottom: 14px;
}

.charts-row:has(.wide:only-child),
.charts-row .wide {
    grid-column: 1 / -1;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: var(--transition);
}

.chart-card:hover {
    border-color: var(--border-hover);
}

.chart-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.chart-card h3 i {
    width: 16px;
    height: 16px;
    color: var(--accent);
}

/* Bar Charts */
.chart-container {
    min-height: 200px;
}

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bar-chart-horizontal {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 180px;
    padding-top: 20px;
}

.hbar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    height: 100%;
    justify-content: flex-end;
}

.hbar-fill {
    width: 100%;
    max-width: 28px;
    border-radius: 4px 4px 0 0;
    background: linear-gradient(180deg, var(--accent), rgba(139, 92, 246, 0.4));
    transition: height 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-height: 2px;
    position: relative;
}

.hbar-fill:hover {
    filter: brightness(1.3);
}

.hbar-fill .tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-hover);
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    font-size: 0.72rem;
    white-space: nowrap;
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10;
}

.hbar-fill:hover .tooltip {
    display: block;
}

.hbar-label {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

/* Line Chart */
.line-chart-wrapper {
    position: relative;
    height: 200px;
    padding-bottom: 26px;
}

.line-chart-svg {
    width: 100%;
    height: 100%;
}

.line-chart-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-tertiary);
    padding-top: 8px;
}

/* List Items */
.list-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 280px;
    overflow-y: auto;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-xs);
    background: var(--bg-card-inner);
    border: 1px solid transparent;
    transition: var(--transition);
}

.list-item:hover {
    border-color: var(--border);
    background: var(--bg-card-hover);
}

.list-item-bar {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 4px;
    overflow: hidden;
}

.list-item-fill {
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    transition: width 0.5s ease;
}

.list-item-name {
    font-size: 0.82rem;
    font-weight: 500;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.list-item-count {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
}

/* Donut Charts */
.donut-chart-container {
    display: flex;
    align-items: center;
    gap: 24px;
    min-height: 160px;
}

.donut-svg {
    width: 140px;
    height: 140px;
    flex-shrink: 0;
}

.donut-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-label {
    flex: 1;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.legend-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* ═══════════════ Tables ═══════════════ */
.table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-tertiary);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    font-size: 0.85rem;
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background 0.15s ease;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* ═══════════════ Badges ═══════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-device {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}

.badge-device i {
    width: 13px;
    height: 13px;
}

.badge-event {
    background: var(--accent-subtle);
    color: var(--accent-light);
}

.badge-event.click {
    background: rgba(59, 130, 246, 0.1);
    color: var(--blue);
}

.badge-event.form_submit {
    background: rgba(16, 185, 129, 0.1);
    color: var(--green);
}

.badge-event.outbound_click {
    background: rgba(245, 158, 11, 0.1);
    color: var(--orange);
}

.badge-event.copy {
    background: rgba(236, 72, 153, 0.1);
    color: var(--pink);
}

.badge-event.rage_click {
    background: rgba(239, 68, 68, 0.2);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-event.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--red);
}

.badge-event.custom {
    background: rgba(6, 182, 212, 0.1);
    color: var(--cyan);
}

.engagement-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.engagement-fill-bg {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 4px;
    overflow: hidden;
    min-width: 50px;
}

.engagement-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.engagement-value {
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    min-width: 30px;
}

.ip-badge {
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    color: var(--text-primary);
    background: rgba(139, 92, 246, 0.08);
    padding: 3px 8px;
    border-radius: var(--radius-xs);
    border: 1px solid rgba(139, 92, 246, 0.15);
}

.visitor-id-badge {
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-bottom: 3px;
}

.url-cell {
    font-size: 0.82rem;
    word-break: break-all;
    max-width: 250px;
    color: var(--text-secondary);
}

.title-cell {
    font-weight: 500;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mono {
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
}

.text-muted {
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.text-truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ═══════════════ Empty State ═══════════════ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    gap: 20px;
    padding: 80px 0;
}

.empty-state i {
    width: 56px;
    height: 56px;
    color: var(--text-tertiary);
    opacity: 0.4;
}

.empty-state p {
    font-size: 1rem;
    max-width: 320px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.empty-table {
    text-align: center;
    padding: 48px 16px !important;
    color: var(--text-tertiary);
    font-size: 0.9rem;
}

/* ═══════════════ Scrollbar ═══════════════ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ═══════════════ Animations ═══════════════ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.tab-content.active {
    animation: fadeIn 0.3s ease;
}

.stat-card {
    animation: fadeIn 0.4s ease backwards;
}

.stat-card:nth-child(1) { animation-delay: 0ms; }
.stat-card:nth-child(2) { animation-delay: 40ms; }
.stat-card:nth-child(3) { animation-delay: 80ms; }
.stat-card:nth-child(4) { animation-delay: 120ms; }
.stat-card:nth-child(5) { animation-delay: 160ms; }
.stat-card:nth-child(6) { animation-delay: 200ms; }
.stat-card:nth-child(7) { animation-delay: 240ms; }
.stat-card:nth-child(8) { animation-delay: 280ms; }

/* ═══════════════ Responsive ═══════════════ */
@media (max-width: 1400px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .charts-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    .content-body {
        padding: 20px;
    }
    .top-nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px 20px;
    }
    .nav-actions {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }
    .tab-nav {
        overflow-x: auto;
        width: 100%;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* --------------- Login Screen --------------- */
.login-screen {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(10, 11, 15, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-icon {
    width: 48px;
    height: 48px;
    color: var(--accent);
    margin: 0 auto 16px;
    filter: drop-shadow(0 0 12px var(--accent-glow));
}

.login-header h2 {
    font-size: 1.6rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 20px;
}

#password-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
}

#password-input:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: white;
    border: none;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(139, 92, 246, 0.25);
}

.btn-primary:active {
    transform: scale(0.98);
}

.login-error {
    color: var(--red);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 16px;
    min-height: 20px;
}

/* --------------- Generic Modals --------------- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(10, 11, 15, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 1;
    animation: fadeIn 0.2s;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-content.large {
    max-width: 1100px;
}

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

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    padding: 4px;
    border-radius: 4px;
}

.modal-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.vm-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 0;
    color: var(--text-secondary);
}

.spin {
    animation: spin 1s linear infinite;
}

