/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: "Inter", system-ui, sans-serif;
    font-size: 16px;
    color: #020817;
    background: #f8fafc;
    -webkit-font-smoothing: antialiased;
}

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 16rem;
    min-width: 16rem;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #e2e8f0;
}

.brand-icon {
    font-size: 20px;
    color: #7525f9;
}

.brand-text {
    font-size: 18px;
    font-weight: 700;
    color: #020817;
    letter-spacing: 0.3px;
}

.sidebar-nav {
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: #3f3f46;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    color: #020817;
    background: #f1f5f9;
}

.nav-link.active {
    color: #7525f9;
    background: #ebe5fd;
    border-left-color: #7525f9;
    font-weight: 600;
}

.nav-icon {
    font-size: 8px;
    color: #64748b;
    opacity: 0.7;
}

.nav-link.active .nav-icon {
    opacity: 1;
    color: #7525f9;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
}

/* Hamburger button - hidden on desktop */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: #020817;
}

.hamburger-btn svg {
    width: 24px;
    height: 24px;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    min-height: 64px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    color: #6b21a8;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-name {
    font-size: 14px;
    color: #64748b;
    font-weight: 500;
}

.logout-btn {
    font-size: 14px;
    color: #64748b;
    text-decoration: none;
    padding: 6px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.15s ease;
    background: #ffffff;
}

.logout-btn:hover {
    color: #dc2626;
    border-color: #dc2626;
    background: #fef2f2;
}

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

/* ===== Date Picker ===== */
.date-picker {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
    background: #ffffff;
    padding: 14px 20px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.date-picker-top {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.date-presets {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.preset-btn {
    padding: 6px 12px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: "Inter", system-ui, sans-serif;
}

.preset-btn:hover {
    background: #f1f5f9;
    color: #020817;
    border-color: #cbd5e1;
}

.preset-btn.active {
    background: #8000ff;
    color: #ffffff;
    border-color: #8000ff;
    font-weight: 600;
}

.preset-btn.active:hover {
    background: #5b1cc7;
    border-color: #5b1cc7;
}

/* Date range display text */
.date-range-display {
    margin-left: auto;
    font-size: 13px;
    font-weight: 600;
    color: #7525f9;
    white-space: nowrap;
    letter-spacing: 0.2px;
}

/* Custom date range row */
.date-custom {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 6px;
    border-top: 1px solid #f1f5f9;
    flex-wrap: wrap;
}

.date-custom label {
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 6px;
}

.date-custom input[type="date"] {
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-family: "Inter", system-ui, sans-serif;
    color: #020817;
    background: #ffffff;
    transition: border-color 0.15s ease;
}

.date-custom input[type="date"]:focus {
    outline: none;
    border-color: #8000ff;
    box-shadow: 0 0 0 3px rgba(128, 0, 255, 0.1);
}

.apply-btn {
    padding: 6px 18px;
    background: #8000ff;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    font-family: "Inter", system-ui, sans-serif;
    white-space: nowrap;
}

.apply-btn:hover {
    background: #5b1cc7;
}

/* ===== Metric Cards ===== */
.metric-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px 24px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.metric-label {
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.metric-value {
    font-size: 24px;
    font-weight: 700;
    color: #020817;
}

/* ===== Chart ===== */
.chart-container {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.chart-box {
    width: 100%;
    height: 350px;
    min-height: 250px;
}

/* ===== Data Table ===== */
.table-wrapper,
.data-table-container {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: auto;
    max-height: 600px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table thead th {
    background: #6b21a8;
    color: #ffffff;
    padding: 10px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    cursor: pointer;
    white-space: normal;
    min-width: 60px;
    max-width: 110px;
    line-height: 1.3;
    user-select: none;
    border-bottom: 2px solid #7525f9;
}

.data-table thead th:first-child {
    text-align: center;
}

.data-table thead th:hover {
    background: #7525f9;
}

.sort-arrow {
    font-size: 10px;
    margin-left: 4px;
    opacity: 0.6;
}

.sort-arrow.asc::after { content: " \25B2"; }
.sort-arrow.desc::after { content: " \25BC"; }

.data-table tbody td {
    padding: 8px 8px;
    text-align: center;
    border-bottom: 1px solid #f1f5f9;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    color: #020817;
}

.data-table tbody td:first-child {
    text-align: center;
    font-weight: 500;
    color: #020817;
}

.data-table tbody tr:hover td {
    background: #f8fafc;
}

.data-table tfoot {
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.data-table tfoot td {
    background: #f1f5f9;
    padding: 10px 8px;
    text-align: center;
    font-weight: 700;
    font-size: 14px;
    border-top: 2px solid #e2e8f0;
    white-space: nowrap;
    color: #020817;
}

.data-table tfoot td:first-child {
    text-align: center;
}



/* ===== Preset More Dropdown ===== */
.preset-more-wrapper {
    position: relative;
    display: inline-block;
}

.preset-more-trigger {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.preset-more-trigger svg {
    opacity: 0.6;
    transition: transform 0.15s;
}

.preset-more-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 30;
    min-width: 150px;
    overflow: hidden;
}

.preset-more-menu.open {
    display: block;
}

.preset-more-item {
    display: block;
    width: 100%;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 500;
    color: #334155;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    font-family: "Inter", system-ui, sans-serif;
}

.preset-more-item:hover {
    background: #f1f5f9;
    color: #7525f9;
}

.preset-more-item.active {
    color: #7525f9;
    font-weight: 600;
    background: #f5f0ff;
}

/* ===== Client Switcher ===== */
.client-switcher {
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.client-switcher-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    margin-bottom: 8px;
    font-weight: 600;
}

.client-switcher-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.client-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    cursor: pointer;
    transition: all 0.15s;
    padding: 0;
    flex-shrink: 0;
}

.client-arrow:hover {
    background: #7525f9;
    border-color: #7525f9;
    color: #fff;
}

.client-dropdown-wrapper {
    flex: 1;
    position: relative;
    min-width: 0;
}

.client-dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 4px 8px;
    font-size: 13px;
    font-weight: 600;
    color: #020817;
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 4px;
    transition: background 0.15s;
}

.client-dropdown-trigger:hover {
    background: #f1f5f9;
}

.client-dropdown-trigger svg {
    flex-shrink: 0;
    opacity: 0.5;
}

.client-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 30;
    overflow: hidden;
}

.client-dropdown-menu.open {
    display: block;
}

.client-dropdown-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.client-dropdown-item:hover {
    background: #f1f5f9;
    color: #7525f9;
}

.client-dropdown-item.active {
    color: #7525f9;
    font-weight: 600;
    background: #f5f0ff;
}

.client-switcher-name-only {
    font-size: 14px;
    font-weight: 600;
    color: #020817;
    margin-top: 2px;
}


/* ===== User Menu Dropdown ===== */
.user-menu-wrapper {
    position: relative;
}

.user-avatar-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #7525f9;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    font-family: Inter, system-ui, sans-serif;
}

.user-avatar-btn:hover {
    background: #5b1cc7;
}

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    min-width: 220px;
    z-index: 30;
    overflow: hidden;
}

.user-dropdown.open {
    display: block;
}

.user-dropdown-header {
    padding: 14px 16px;
}

.user-dropdown-name {
    font-size: 14px;
    font-weight: 600;
    color: #020817;
}

.user-dropdown-email {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
}

.user-dropdown-divider {
    height: 1px;
    background: #e2e8f0;
}

.user-dropdown-item {
    display: block;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    text-decoration: none;
    transition: background 0.15s;
}

.user-dropdown-item:hover {
    background: #f1f5f9;
    color: #7525f9;
}

.user-dropdown-logout {
    color: #dc2626;
}

.user-dropdown-logout:hover {
    background: #fef2f2;
    color: #dc2626;
}

/* ===== Account Settings Page ===== */
.account-card {
    max-width: 640px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 32px;
}

.account-card h1 {
    font-size: 24px;
    font-weight: 700;
    color: #020817;
    margin: 0 0 4px 0;
}

.account-card .subtitle {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 20px;
}

.account-card .member-badge {
    display: inline-block;
    padding: 4px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 9999px;
    font-size: 12px;
    color: #64748b;
    margin-bottom: 24px;
}

.account-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #f1f5f9;
    border: 2px solid #ebe5fd;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px auto;
    color: #94a3b8;
}

.account-form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.account-form-group {
    flex: 1;
}

.account-form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #7525f9;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.account-form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
    color: #020817;
    background: #f8fafc;
    font-family: Inter, system-ui, sans-serif;
    box-sizing: border-box;
}

.account-form-group input:focus {
    outline: none;
    border-color: #7525f9;
    box-shadow: 0 0 0 3px rgba(117, 37, 249, 0.1);
}

.account-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

.account-actions .btn-save {
    margin-left: auto;
    padding: 10px 24px;
    background: #7525f9;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    font-family: Inter, system-ui, sans-serif;
}

.account-actions .btn-save:hover {
    background: #5b1cc7;
}

.account-actions .btn-outline {
    padding: 10px 18px;
    background: #fff;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    font-family: Inter, system-ui, sans-serif;
}

.account-actions .btn-outline:hover {
    border-color: #7525f9;
    color: #7525f9;
}

.account-message {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}

.account-message.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.account-message.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ===== Login Page ===== */
.login-page {
    background: #f1f5f9;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: Inter, system-ui, sans-serif;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 40px 36px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

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

.login-logo {
    height: 40px;
    margin-bottom: 4px;
}

.login-brand-sub {
    font-size: 14px;
    font-weight: 500;
    color: #64748b;
    margin-bottom: 20px;
    letter-spacing: 1px;
}

.login-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: #020817;
    margin: 0 0 6px 0;
}

.login-header p {
    font-size: 13px;
    color: #64748b;
    margin: 0;
}

.login-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}

.login-field {
    margin-bottom: 18px;
}

.login-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #020817;
    margin-bottom: 6px;
}

.login-field input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    color: #020817;
    background: #f8fafc;
    font-family: Inter, system-ui, sans-serif;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.login-field input:focus {
    outline: none;
    border-color: #7525f9;
    box-shadow: 0 0 0 3px rgba(117, 37, 249, 0.1);
    background: #fff;
}

.login-field input::placeholder {
    color: #94a3b8;
}

.login-btn {
    width: 100%;
    padding: 12px;
    background: #7525f9;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    font-family: Inter, system-ui, sans-serif;
    margin-top: 4px;
}

.login-btn:hover {
    background: #5b1cc7;
}

/* ===== Responsive: Tablet ===== */
@media (max-width: 1024px) {
    .content-body {
        padding: 20px;
    }

    .metric-cards {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }

    .metric-value {
        font-size: 20px;
    }
}

/* ===== Responsive: Mobile ===== */
@media (max-width: 768px) {
    /* Sidebar: slide-in drawer on mobile */
    .sidebar {
        position: fixed;
        top: 0;
        left: -16rem;
        height: 100vh;
        transition: left 0.3s ease;
        box-shadow: none;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
    }

    /* Overlay behind sidebar */
    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.open {
        opacity: 1;
        pointer-events: auto;
    }

    /* Show hamburger button */
    .hamburger-btn {
        display: block;
    }

    .top-header {
        padding: 12px 16px;
    }

    .page-title {
        font-size: 16px;
    }

    .user-name {
        display: none;
    }

    .content-body {
        padding: 16px;
    }

    /* Date picker: stack on mobile */
    .date-picker {
        padding: 12px 14px;
        gap: 8px;
    }

    .date-picker-top {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .date-range-display {
        margin-left: 0;
        font-size: 12px;
    }

    .date-presets {
        flex-wrap: wrap;
        gap: 4px;
    }

    .preset-btn {
        padding: 6px 10px;
        font-size: 11px;
        flex: 1 1 auto;
        text-align: center;
    }

    .date-custom {
        margin-left: 0;
        flex-wrap: wrap;
        gap: 8px;
    }

    .date-custom label {
        flex: 1 1 auto;
    }

    .date-custom input[type="date"] {
        width: 100%;
        font-size: 13px;
    }

    .apply-btn {
        width: 100%;
    }

    /* Metric cards: stack vertically */
    .metric-cards {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .metric-card {
        padding: 14px 16px;
    }

    .metric-value {
        font-size: 20px;
    }

    /* Chart: smaller on mobile */
    .chart-container {
        padding: 12px;
        margin-bottom: 16px;
    }

    .chart-box {
        height: 260px;
        min-height: 200px;
    }

    /* Table: horizontal scroll with sticky first column */
    .table-wrapper,
    .data-table-container {
        max-height: 450px;
        border-radius: 6px;
    }

    .data-table {
        font-size: 12px;
    }

    .data-table thead th {
        padding: 8px 10px;
        font-size: 10px;
    }

    .data-table tbody td {
        padding: 8px 10px;
    }

    .data-table tfoot td {
        padding: 8px 10px;
        font-size: 12px;
    }

    /* Sticky first column on mobile */
    .data-table thead th:first-child,
    .data-table tbody td:first-child,
    .data-table tfoot td:first-child {
        position: sticky;
        left: 0;
        z-index: 5;
    }

    .data-table thead th:first-child {
        z-index: 15;
        background: #6b21a8;
    }

    .data-table tbody td:first-child {
        background: #ffffff;
        border-right: 1px solid #e2e8f0;
    }

    .data-table tbody tr:hover td:first-child {
        background: #f8fafc;
    }

    .data-table tfoot td:first-child {
        z-index: 15;
        background: #f1f5f9;
        border-right: 1px solid #e2e8f0;
    }
}

/* ===== Responsive: Small Mobile ===== */
@media (max-width: 480px) {
    .top-header {
        padding: 10px 12px;
    }

    .page-title {
        font-size: 14px;
    }

    .content-body {
        padding: 12px;
    }

    .logout-btn {
        font-size: 12px;
        padding: 4px 10px;
    }

    .chart-box {
        height: 220px;
        min-height: 180px;
    }

    .metric-card {
        padding: 12px 14px;
    }

    .metric-value {
        font-size: 18px;
    }

    .metric-label {
        font-size: 11px;
    }
}

/* ===== SaaS Stats Row ===== */
.saas-stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.saas-stat-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px 20px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border-top: 3px solid #9333ea;
}

.saas-stat-label {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.saas-stat-value {
    font-size: 22px;
    font-weight: 700;
    color: #020817;
    margin-bottom: 4px;
}

.saas-stat-change {
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.saas-stat-change.positive {
    color: #16a34a;
}

.saas-stat-change.negative {
    color: #dc2626;
}

.saas-stat-change.neutral {
    color: #64748b;
}

.saas-stat-change .change-period {
    font-weight: 400;
    color: #94a3b8;
    font-size: 11px;
}

/* ===== Funnel Stats Row ===== */
.funnel-stats-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.funnel-stat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 20px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    flex: 1;
    min-width: 150px;
    max-width: 240px;
}

.funnel-stat-icon {
    font-size: 10px;
}

.funnel-stat-body {
    display: flex;
    flex-direction: column;
}

.funnel-stat-value {
    font-size: 22px;
    font-weight: 700;
    color: #020817;
    line-height: 1.2;
}

.funnel-stat-label {
    font-size: 11px;
    font-weight: 500;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.funnel-qual-split {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.qual-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 9999px;
    white-space: nowrap;
}

.qual-tag.qualified {
    background: #dcfce7;
    color: #166534;
}

.qual-tag.unqualified {
    background: #fef2f2;
    color: #991b1b;
}

.qual-inline {
    font-weight: 600;
}

.qual-inline.qualified {
    color: #166534;
}

.qual-inline.unqualified {
    color: #991b1b;
}

.funnel-stat-arrow {
    font-size: 20px;
    color: #94a3b8;
    font-weight: 300;
}

/* ===== Collapsible Funnel Visualization ===== */
.funnel-details {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.funnel-summary {
    padding: 12px 20px;
    font-size: 13px;
    font-weight: 600;
    color: #6b21a8;
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.funnel-summary::before {
    content: "\25B6";
    font-size: 10px;
    transition: transform 0.2s;
}

.funnel-details[open] .funnel-summary::before {
    transform: rotate(90deg);
}

.funnel-summary::-webkit-details-marker {
    display: none;
}

.funnel-viz {
    padding: 16px 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.funnel-stage {
    width: max(var(--stage-width), 200px);
    transition: width 0.3s ease;
}

.funnel-stage-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-radius: 6px;
    color: #ffffff;
    font-weight: 600;
    min-height: 42px;
    gap: 12px;
}

.funnel-stage-label {
    font-size: 13px;
}

.funnel-stage-num {
    font-size: 16px;
    font-weight: 700;
}

.funnel-conversion-rate {
    font-size: 12px;
    color: #64748b;
    padding: 2px 0 2px 16px;
    font-weight: 500;
}

/* ===== Cohort Breakdown Card (Saisify /funnel/) =====
   Editorial finance aesthetic: column-rule accents (no pills), heavy tabular
   numbers, refined monochrome with deep brand accents. No gradients.
*/
.cohort-card {
    --ink-primary: #111018;
    --ink-body:    #2b2a37;
    --ink-muted:   #6b6776;
    --ink-subtle:  #9d99a8;
    --ink-faint:   #c9c6d2;
    --rule:        #eae6f0;
    --surface:     #ffffff;
    --surface-alt: #f8f6fb;
    --accent-new:  #4a148c;
    --accent-old:  #8a5a00;
    --accent-non:  #455168;
    --accent-tot:  #0e0d14;
    --pos:         #0a6b36;
    --neg:         #8b1e2b;

    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 12px;
    box-shadow: 0 1px 1px rgba(17,16,24,.03), 0 16px 40px -20px rgba(17,16,24,.10);
    margin-bottom: 28px;
    overflow: hidden;
    font-family: 'Inter', system-ui, sans-serif;
}
.cohort-card-header {
    padding: 24px 28px 22px;
    border-bottom: 1px solid var(--rule);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 32px;
    flex-wrap: wrap;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: background-color 120ms ease;
}
.cohort-card-header::-webkit-details-marker { display: none; }
.cohort-card-header:hover { background-color: #fbfafd; }

/* Collapsed: compact single-line header, title only, tight to the arrow */
details.cohort-card:not([open]) .cohort-card-header {
    border-bottom-color: transparent;
    padding: 10px 20px;
    gap: 0;
    justify-content: flex-start;
    flex-wrap: nowrap;
}
details.cohort-card:not([open]) .cohort-card-title {
    flex-direction: row;
    align-items: center;
    gap: 0;
}
details.cohort-card:not([open]) .cohort-card-eyebrow { display: none; }
details.cohort-card:not([open]) .cohort-card-meta    { display: none; }
details.cohort-card:not([open]) .cohort-card-title h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0;
}
details.cohort-card:not([open]) .cohort-disclose { margin-top: 3px; margin-right: 10px; }

/* Custom disclosure triangle sibling of the title block */
.cohort-disclose {
    display: inline-block;
    width: 10px; height: 10px;
    margin-top: 6px;
    margin-right: -14px; /* pull title cluster closer */
    position: relative;
    flex-shrink: 0;
    align-self: flex-start;
    transition: transform 180ms ease;
}
.cohort-disclose::before {
    content: "";
    position: absolute;
    left: 0; top: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 6px solid var(--ink-muted);
}
details.cohort-card[open] .cohort-disclose { transform: rotate(90deg); }
.cohort-card-header { align-items: flex-start; }
.cohort-card-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cohort-card-eyebrow {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-muted);
}
.cohort-card-title h3 {
    margin: 4px 0 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--ink-primary);
    letter-spacing: -0.015em;
    line-height: 1.1;
}
.cohort-card-meta {
    margin: 6px 0 0;
    max-width: 440px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--ink-muted);
}
.cohort-card-meta strong { color: var(--ink-primary); font-weight: 600; }

.cohort-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.cohort-v2 {
    width: 100%;
    min-width: 760px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
    color: var(--ink-body);
}

.cohort-v2 colgroup .col-metric { width: 32%; }
.cohort-v2 colgroup .col-cohort { width: 17%; }
.cohort-v2 colgroup .col-total  { width: 17%; }

/* Column rule row — a thin colored stroke at the top of each cohort column */
.cohort-v2 thead tr.rule-row th { padding: 0; border: none; height: 3px; }
.cohort-v2 thead tr.rule-row th .rule {
    display: block; height: 3px; width: 100%;
}
.cohort-v2 thead tr.rule-row th .rule.rule-new { background: var(--accent-new); }
.cohort-v2 thead tr.rule-row th .rule.rule-old { background: var(--accent-old); }
.cohort-v2 thead tr.rule-row th .rule.rule-non { background: var(--accent-non); }
.cohort-v2 thead tr.rule-row th .rule.rule-tot { background: var(--accent-tot); }

.cohort-v2 thead th {
    padding: 20px 20px 22px;
    text-align: center;
    vertical-align: top;
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
    font-weight: 500;
}
.cohort-v2 thead th.th-metric { background: transparent; }

/* Cohort label — plain strong text, NO pill */
.cohort-label {
    display: inline-block;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.005em;
    line-height: 1.2;
}
.label-new { color: var(--accent-new); }
.label-old { color: var(--accent-old); }
.label-non { color: var(--accent-non); }
.label-tot { color: var(--accent-tot); font-weight: 700; }

.cohort-caption {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--ink-subtle);
    letter-spacing: 0.005em;
    line-height: 1.35;
}

/* Rows */
.cohort-v2 tbody tr { transition: background-color 120ms ease; }
.cohort-v2 tbody tr:hover td,
.cohort-v2 tbody tr:hover th { background-color: var(--surface-alt); }
.cohort-v2 tbody tr:hover td.num-total { background-color: #f2efec; }

.cohort-v2 th[scope="row"] {
    text-align: left;
    font-weight: 500;
    padding: 16px 24px 16px 28px;
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 1;
    white-space: nowrap;
    color: var(--ink-body);
}
.cohort-v2 td {
    padding: 16px 20px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    font-feature-settings: "tnum" 1, "ss01" 1;
}

/* Primary (big number) rows */
.cohort-v2 tr.r-primary th[scope="row"] {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink-primary);
}
.cohort-v2 tr.r-primary td.num {
    font-size: 19px;
    font-weight: 600;
    color: var(--ink-primary);
    letter-spacing: -0.005em;
}
.cohort-v2 tr.r-primary td.muted { color: var(--ink-faint); font-weight: 400; }

.cohort-v2 tr.r-section-start th,
.cohort-v2 tr.r-section-start td { border-top: 1px solid var(--rule); }
.cohort-v2 tr:first-child.r-section-start th,
.cohort-v2 tr:first-child.r-section-start td { border-top: none; }

/* Sub rows (Qualified / Unqualified) — smaller, with colored pip + inline % */
.cohort-v2 tr.r-sub th[scope="row"] {
    padding: 10px 24px 10px 52px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-muted);
}
.cohort-v2 tr.r-sub td {
    padding-top: 10px;
    padding-bottom: 10px;
}
.cohort-v2 tr.r-sub td.num {
    font-size: 15px;
    font-weight: 500;
}
.sub-pip {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    margin-right: 10px;
    vertical-align: middle;
    transform: translateY(-1px);
}
.sub-pip.pip-q { background: var(--pos); }
.sub-pip.pip-u { background: var(--neg); }
.num-q { color: var(--pos); }
.num-u { color: var(--neg); }

.pct {
    display: inline-block;
    margin-left: 10px;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--ink-subtle);
    font-feature-settings: "tnum" 1;
    font-variant-numeric: tabular-nums;
}

/* Rate rows — italic caption style */
.cohort-v2 tr.r-rate th[scope="row"] {
    padding: 8px 24px 18px 28px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-muted);
    letter-spacing: 0.005em;
    font-style: italic;
}
.cohort-v2 tr.r-rate .rate-note {
    display: inline-block;
    margin-left: 8px;
    font-size: 10px;
    color: var(--ink-subtle);
    font-style: normal;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 500;
}
.cohort-v2 tr.r-rate td.num {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-muted);
    padding-top: 8px;
    padding-bottom: 18px;
}
.cohort-v2 tr.r-rate td.muted { color: var(--ink-faint); }

/* Total column — subtle left divider + warmer paper tint, no gradients */
.cohort-v2 .th-tot,
.cohort-v2 .num-total {
    border-left: 1px solid var(--rule);
    background: #fdfcfa;
    color: var(--ink-primary);
}
.cohort-v2 tr.r-primary td.num-total { font-weight: 700; }
.cohort-v2 tr.r-rate td.num-total { color: var(--ink-body); font-weight: 600; }
.cohort-v2 tr.r-sub td.num-total { font-weight: 600; }

/* Right-edge fade hint on horizontal scroll */
.cohort-scroll::after {
    content: "";
    position: sticky;
    top: 0; right: 0;
    display: block;
    pointer-events: none;
}

/* Footnote under the cohort table */
.cohort-footnote {
    margin: 0;
    padding: 14px 28px 20px;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--ink-subtle);
    border-top: 1px solid var(--rule);
    background: #fdfcfa;
    letter-spacing: 0.005em;
}
.cohort-footnote strong { color: var(--ink-muted); font-weight: 600; }

/* Mobile stacked cards — hidden on desktop, shown under 640px */
.cohort-mobile { display: none; }

@media (max-width: 900px) {
    .cohort-card-header { padding: 20px 22px 18px; gap: 14px; }
    .cohort-card-meta { max-width: none; }
}
@media (max-width: 768px) {
    .cohort-card { border-radius: 10px; }
    .cohort-card-header { flex-direction: column; gap: 10px; padding: 18px 20px 16px; }
    .cohort-card-title h3 { font-size: 18px; }
    .cohort-card-eyebrow { font-size: 10px; }
    .cohort-card-meta { font-size: 12.5px; }
    .cohort-v2 { font-size: 13px; min-width: 680px; }
    .cohort-v2 thead th { padding: 14px 12px 16px; }
    .cohort-v2 th[scope="row"] {
        padding: 14px 14px 14px 20px;
        box-shadow: 6px 0 10px -8px rgba(17,16,24,.16);
    }
    .cohort-v2 td { padding: 14px 12px; }
    .cohort-v2 tr.r-primary td.num { font-size: 17px; }
    .cohort-v2 tr.r-sub th[scope="row"] { padding-left: 36px; }
    .cohort-v2 tr.r-sub td.num { font-size: 14px; }
    .cohort-caption { display: none; }
    .pct { margin-left: 6px; }
    .cohort-footnote { padding: 12px 20px 16px; font-size: 11px; }
}

/* Below 640px: ditch the table and show per-cohort cards */
@media (max-width: 640px) {
    .cohort-scroll { display: none; }
    .cohort-mobile { display: block; padding: 14px 16px 8px; }
    .cohort-footnote { padding: 10px 16px 16px; }

    .cmc {
        position: relative;
        background: var(--surface);
        border: 1px solid var(--rule);
        border-radius: 10px;
        padding: 18px 18px 6px;
        margin-bottom: 14px;
        overflow: hidden;
    }
    .cmc-rule { position: absolute; top: 0; left: 0; right: 0; height: 3px; }
    .cmc-new .cmc-rule { background: var(--accent-new); }
    .cmc-old .cmc-rule { background: var(--accent-old); }
    .cmc-non .cmc-rule { background: var(--accent-non); }
    .cmc-tot .cmc-rule { background: var(--accent-tot); }
    .cmc-tot { background: #fdfcfa; }

    .cmc-head {
        display: flex;
        flex-direction: column;
        gap: 4px;
        margin-bottom: 12px;
        padding-bottom: 10px;
        border-bottom: 1px solid var(--rule);
    }
    .cmc-head .cohort-label { display: inline-block; font-size: 15px; }
    .cmc-head .cohort-caption { display: block; font-size: 11px; }

    .cmc-list { margin: 0; }
    .cmc-row {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 12px;
        padding: 10px 0;
        border-bottom: 1px solid #f4f1ea;
        min-height: 26px;
    }
    .cmc-row:last-child { border-bottom: none; }
    .cmc-row dt {
        margin: 0;
        font-size: 13px;
        font-weight: 600;
        color: var(--ink-primary);
        letter-spacing: -0.005em;
    }
    .cmc-row dd {
        margin: 0;
        text-align: right;
        font-size: 16px;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
        color: var(--ink-primary);
        white-space: nowrap;
    }
    .cmc-row.cmc-sub { padding: 6px 0 6px 14px; }
    .cmc-row.cmc-sub dt {
        font-weight: 500;
        font-size: 12.5px;
        color: var(--ink-muted);
    }
    .cmc-row.cmc-sub dd { font-size: 14px; font-weight: 500; }
    .cmc-row.cmc-rate {
        padding: 6px 0;
        min-height: 22px;
        border-bottom-color: transparent;
    }
    .cmc-row.cmc-rate dt {
        font-size: 11px;
        font-weight: 500;
        color: var(--ink-muted);
        letter-spacing: 0.005em;
    }
    .cmc-row.cmc-rate dt em {
        font-style: italic;
        font-weight: 500;
        margin-right: 4px;
    }
    .cmc-row.cmc-rate dt .rate-note {
        display: inline;
        margin-left: 2px;
        font-size: 9.5px;
        letter-spacing: 0.06em;
        color: var(--ink-subtle);
        text-transform: uppercase;
    }
    .cmc-row.cmc-rate dd { font-size: 13px; font-weight: 500; color: var(--ink-body); }
}
@media (max-width: 420px) {
    .cohort-mobile { padding: 12px 12px 4px; }
    .cohort-footnote { padding: 10px 12px 14px; }
    .cmc { padding: 16px 14px 4px; border-radius: 8px; }
    .cmc-row dt { font-size: 12.5px; }
    .cmc-row dd { font-size: 15px; }
}

/* ===== Analytics Tables (Saisify Analytics) ===== */
.section-title {
    font-size: 16px;
    font-weight: 700;
    color: #6b21a8;
    margin: 28px 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #ebe5fd;
}

.analytics-table-wrapper {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.analytics-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.analytics-table thead {
    background: #E2E6FF;
}

.analytics-table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: #334155;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.analytics-table td {
    padding: 9px 14px;
    border-top: 1px solid #f1f5f9;
    color: #020817;
}

.analytics-table tbody tr:hover {
    background: #f8fafc;
}

.analytics-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.analytics-table .label-cell {
    font-weight: 500;
    white-space: nowrap;
}

.positive-text { color: #16a34a; }
.negative-text { color: #dc2626; }
.warning-text { color: #d97706; }

/* ===== Country Filter Section ===== */
.filter-section {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.filter-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-select {
    padding: 7px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-family: 'Inter', system-ui, sans-serif;
    color: #020817;
    background: #ffffff;
    cursor: pointer;
    transition: border-color 0.15s ease;
    min-width: 140px;
}

.filter-select:focus {
    outline: none;
    border-color: #8000ff;
    box-shadow: 0 0 0 3px rgba(128, 0, 255, 0.1);
}

.filter-input {
    padding: 7px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-family: 'Inter', system-ui, sans-serif;
    color: #020817;
    background: #ffffff;
    width: 120px;
    transition: border-color 0.15s ease;
}

.filter-input:focus {
    outline: none;
    border-color: #8000ff;
    box-shadow: 0 0 0 3px rgba(128, 0, 255, 0.1);
}

.filter-add-btn {
    padding: 7px 18px;
    background: #8000ff;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', system-ui, sans-serif;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.filter-add-btn:hover {
    background: #5b1cc7;
}

.filter-clear-link {
    font-size: 12px;
    color: #64748b;
    text-decoration: underline;
    cursor: pointer;
    white-space: nowrap;
    margin-left: 4px;
    transition: color 0.15s ease;
}

.filter-clear-link:hover {
    color: #dc2626;
}

/* Active filter pills */
.filter-active {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.filter-active:empty {
    margin-top: 0;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ebe5fd;
    border: 1px solid #c4b5fd;
    border-radius: 999px;
    padding: 4px 10px 4px 12px;
    font-size: 12px;
    font-weight: 500;
    color: #6b21a8;
    white-space: nowrap;
}

.filter-pill-text {
    line-height: 1;
}

.filter-pill-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: #7525f9;
    font-size: 15px;
    line-height: 1;
    padding: 0 2px;
    font-family: 'Inter', system-ui, sans-serif;
    transition: color 0.15s ease;
    display: flex;
    align-items: center;
}

.filter-pill-remove:hover {
    color: #dc2626;
}

/* ===== Responsive: filter section on mobile ===== */
@media (max-width: 768px) {
    .filter-section {
        padding: 12px 14px;
    }

    .filter-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-select,
    .filter-input {
        width: 100%;
        min-width: unset;
    }

    .filter-add-btn {
        width: 100%;
    }

    .filter-clear-link {
        text-align: center;
        display: block;
    }

    .saas-stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .saas-stat-value {
        font-size: 18px;
    }
}

.refresh-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 18px;
    padding: 4px 10px;
    cursor: pointer;
    color: #7525f9;
    transition: all 0.2s;
    margin-right: 8px;
}
.refresh-btn:hover {
    background: #f8fafc;
    border-color: #7525f9;
}
.refresh-btn.spinning {
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.date-picker-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.date-picker-top { display: none; }
.date-custom {
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}
.date-separator {
    color: #64748b;
    font-size: 14px;
}
@media (max-width: 768px) {
    .date-picker-row {
        flex-direction: column;
        align-items: stretch;
    }
    .date-custom {
        flex-wrap: wrap;
    }
}

.refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 12px;
    cursor: pointer;
    color: #64748b;
    transition: all 0.2s;
    font-family: 'Inter', system-ui, sans-serif;
}
.refresh-btn:hover {
    background: #f1f5f9;
    color: #7525f9;
    border-color: #7525f9;
}
.refresh-btn.spinning svg {
    animation: spin 0.8s linear infinite;
}

/* ===== Creative Toggle Buttons ===== */
.creative-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.toggle-btn {
    padding: 10px 24px;
    border: none;
    background: #ffffff;
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: "Inter", system-ui, sans-serif;
    transition: all 0.15s ease;
    border-right: 1px solid #e2e8f0;
}

.toggle-btn:last-child {
    border-right: none;
}

.toggle-btn:hover {
    background: #f1f5f9;
    color: #020817;
}

.toggle-btn.active {
    background: #8000ff;
    color: #ffffff;
}

.toggle-btn.active:hover {
    background: #5b1cc7;
}

@media (max-width: 768px) {
    .creative-toggle {
        width: 100%;
    }
    .toggle-btn {
        flex: 1;
        text-align: center;
        padding: 10px 16px;
    }
}

.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    z-index: 10;
}
.col-resize-handle:hover {
    background: rgba(117, 37, 249, 0.3);
}
.data-table th {
    position: relative;
}
.data-table {
    table-layout: auto;
}

.sidebar-logo {
    max-width: 140px;
    height: auto;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Chrome-style Tabs ===== */
.chrome-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    padding: 0 4px;
    align-items: flex-end;
}

.chrome-tab {
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    font-family: "Inter", system-ui, sans-serif;
    border: 1px solid #d1d5db;
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    background: #e5e7eb;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    z-index: 1;
    margin-right: -1px;
}

.chrome-tab:hover {
    background: #f3f4f6;
    color: #374151;
}

.chrome-tab.active {
    background: #ffffff;
    color: #7525f9;
    font-weight: 600;
    z-index: 2;
    border-color: #e2e8f0;
}

.chrome-tab.active + .chrome-tab {
    border-left-color: transparent;
}

/* Make table wrapper connect to tabs */
.chrome-tabs + .filter-section {
    border-top: 1px solid #e2e8f0;
    margin-top: -1px;
    background: #ffffff;
    padding-top: 16px;
}

.chrome-tabs ~ .table-wrapper {
    border-top: none;
    margin-top: 0;
}

/* Text truncation with ellipsis and hover tooltip */
.data-table td.text-cell,
.data-table td:first-child {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
    position: relative;
}
.data-table td.text-cell:hover,
.data-table td:first-child:hover {
    overflow: visible;
    white-space: normal;
    word-break: break-word;
    z-index: 5;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-width: none;
    position: relative;
}

/* Left align text columns */
.data-table th:first-child,
.data-table td:first-child {
    text-align: center;
}

.data-table td.text-cell,
.data-table th.text-cell,
.data-table tbody td.text-cell,
.data-table thead th.text-cell,
.data-table tbody td:first-child.text-cell,
.data-table thead th:first-child.text-cell {
    text-align: left !important;
}


/* ID column truncation */
.data-table td.id-cell {
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: monospace;
    font-size: 12px;
}

/* ===== Home Gallery Page ===== */
.home-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.home-title {
    font-size: 22px;
    font-weight: 700;
    color: #020817;
}

.home-subtitle {
    font-size: 14px;
    color: #64748b;
    margin-top: 2px;
}

.view-toggle {
    display: flex;
    gap: 0;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.view-toggle-btn {
    background: #ffffff;
    border: none;
    padding: 8px 14px;
    cursor: pointer;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    border-right: 1px solid #e2e8f0;
}

.view-toggle-btn:last-child {
    border-right: none;
}

.view-toggle-btn:hover {
    background: #f1f5f9;
    color: #020817;
}

.view-toggle-btn.active {
    background: #8000ff;
    color: #ffffff;
}

.view-toggle-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== Gallery Grid ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.dashboard-grid.hidden,
.dashboard-list.hidden {
    display: none;
}

.dashboard-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px 20px 20px;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: all 0.2s ease;
    cursor: pointer;
}

.dashboard-card:hover {
    border-color: #7525f9;
    box-shadow: 0 4px 16px rgba(117,37,249,0.12);
    transform: translateY(-2px);
}

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

.card-icon.purple { background: #ebe5fd; }
.card-icon.blue   { background: #dbeafe; }
.card-icon.green  { background: #dcfce7; }
.card-icon.orange { background: #ffedd5; }
.card-icon.pink   { background: #fce7f3; }
.card-icon.teal   { background: #ccfbf1; }
.card-icon.indigo { background: #e0e7ff; }

.card-body {
    flex: 1;
}

.card-name {
    font-size: 15px;
    font-weight: 700;
    color: #020817;
    margin-bottom: 4px;
    line-height: 1.3;
}

.card-desc {
    font-size: 13px;
    color: #64748b;
    line-height: 1.4;
}

.card-category {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: #7525f9;
    background: #ebe5fd;
    padding: 3px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 4px;
}

/* ===== List View ===== */
.dashboard-list {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.list-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s ease;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background: #f8fafc;
}

.list-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.list-name {
    font-size: 14px;
    font-weight: 600;
    color: #020817;
    min-width: 200px;
}

.list-desc {
    font-size: 13px;
    color: #64748b;
    flex: 1;
}

.list-category {
    font-size: 11px;
    font-weight: 600;
    color: #7525f9;
    background: #ebe5fd;
    padding: 3px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

/* ===== Responsive: Home ===== */
@media (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }

    .home-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .list-name {
        min-width: 120px;
    }

    .list-desc {
        display: none;
    }
}

@media (max-width: 480px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Mobile: Funnel Stats ===== */
@media (max-width: 768px) {
    .funnel-stats-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .funnel-stat-card {
        max-width: none;
        min-width: unset;
        width: 100%;
    }

    .funnel-arrow,
    .funnel-stat-arrow {
        display: none;
    }

    /* Date custom inputs: flexible sizing */
    .date-custom input[type="date"] {
        flex: 1;
        min-width: 0;
    }

    /* Refresh button: full width */
    .refresh-btn {
        width: 100%;
        justify-content: center;
    }

    /* Analytics tables: mobile-friendly */
    .analytics-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .analytics-table {
        font-size: 12px;
    }

    .analytics-table th,
    .analytics-table td {
        padding: 8px 10px;
        white-space: nowrap;
    }

    /* Chrome tabs: full width, equal sizing */
    .chrome-tabs {
        width: 100%;
    }

    .chrome-tab {
        flex: 1;
        text-align: center;
        padding: 8px 12px;
        font-size: 12px;
    }
}

/* ===== Small Mobile: SaaS Stats ===== */
@media (max-width: 480px) {
    .saas-stats-row {
        grid-template-columns: 1fr;
    }

    .saas-stat-value {
        font-size: 16px;
    }
}

/* ===== Mobile Fix: 5-column metric cards ===== */
.metric-cards-5 {
    grid-template-columns: repeat(5, 1fr);
}

@media (max-width: 1024px) {
    .metric-cards-5 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .metric-cards-5 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 480px) {
    .metric-cards-5 {
        grid-template-columns: 1fr !important;
    }
}

/* ===== Mobile Fix: ensure all card grids stack properly ===== */
@media (max-width: 480px) {
    .metric-cards {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================================
   Attribution segment (/campaigns/, Saisify only)
   Placed inside .filter-controls, pushed to the right via margin-left: auto.
   Matches the visual language of .filter-select / .filter-add-btn.
   ============================================================ */

.attribution-segment {
    display: inline-flex;
    margin-left: auto;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
    background: #ffffff;
    font-family: 'Inter', system-ui, sans-serif;
}

.attribution-segment-btn {
    padding: 7px 14px;
    background: #ffffff;
    color: #334155;
    border: 0;
    border-right: 1px solid #e2e8f0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.attribution-segment-btn:last-child { border-right: 0; }

.attribution-segment-btn:hover:not(.active) {
    background: #f8fafc;
}

.attribution-segment-btn.active {
    background: #8000ff;
    color: #ffffff;
}

/* Column visibility driven by table mode class.
   .mode-both shows everything — no rules needed. */
.data-table.mode-first [data-col-group="last-touch"] { display: none; }
.data-table.mode-last  [data-col-group="first-touch"] { display: none; }
