:root {
    /* Semantic colors — mapped to shared theme tokens with hardcoded fallbacks */
    --primary: var(--sidebar-active, #6366f1);
    --primary-dark: var(--sidebar-active, #4f46e5);
    --success: var(--success-color, #10b981);
    --warning: var(--warning-color, #f59e0b);
    --danger: var(--danger-color, #ef4444);
    --info: var(--info-color, #3b82f6);
    /* Gray scale — no shared equivalents, keep hardcoded */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    /* Spacing & sizing tokens (needed by shared buttons.css) */
    --space-sm: 8px;
    --space-md: 14px;
    --space-lg: 20px;
    --font-size-sm: 13px;
    --radius-xs: 6px;
    /* Layout */
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg:
        0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family:
        "Inter",
        -apple-system,
        BlinkMacSystemFont,
        sans-serif;
    background: var(--content-bg, var(--gray-50));
    color: var(--text-primary, var(--gray-800));
    min-height: 100vh;
    line-height: 1.5;
}

/* Layout */
.analytics-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.analytics-header {
    background: var(--toolbar-bg, white);
    border-bottom: 1px solid var(--toolbar-border, var(--gray-200));
    padding: 12px 24px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

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

.header-title h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--toolbar-text, var(--gray-900));
}

.header-title .badge {
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 500;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Fix double-spacing: shared buttons.css sets both gap:8px AND
   margin-right:8px on .btn i:first-child — remove the margin so
   only flexbox gap controls the spacing. */
.analytics-header .btn i:first-child {
    margin-right: 0;
}

.analytics-header .btn i:last-child {
    margin-left: 0;
}

/* ── Analytics-specific nav-switcher-pill overrides ─────────────────
   The shared pill assumes a dark toolbar. Analytics has a light header
   by default, so we re-theme the pill to match the analytics header. */
.analytics-header .nav-switcher-pill {
    border-color: var(--gray-200);
    background: var(--panel-bg, white);
    border-radius: 8px;
    height: 36px;
}

.analytics-header .nav-switcher-pill .shared-project-selector-btn,
.analytics-header .nav-switcher-pill .app-switcher-btn {
    background: transparent;
    color: var(--toolbar-text, var(--gray-700));
    border: none;
    font-size: 13px;
}

.analytics-header .nav-switcher-pill .shared-project-selector-btn:hover,
.analytics-header .nav-switcher-pill .app-switcher-btn:hover {
    background: var(--gray-100);
}

.analytics-header
    .nav-switcher-pill
    > #projectSelectorContainer
    + #appSwitcherContainer {
    border-left-color: var(--gray-200);
}

/* When a dark theme is active, let the shared pill styles win */
body.theme-dark-modern .analytics-header .nav-switcher-pill,
body.theme-dark-professional .analytics-header .nav-switcher-pill {
    border-color: var(--toolbar-border);
    background: var(--toolbar-button-bg);
}

body.theme-dark-modern
    .analytics-header
    .nav-switcher-pill
    .shared-project-selector-btn,
body.theme-dark-modern .analytics-header .nav-switcher-pill .app-switcher-btn,
body.theme-dark-professional
    .analytics-header
    .nav-switcher-pill
    .shared-project-selector-btn,
body.theme-dark-professional
    .analytics-header
    .nav-switcher-pill
    .app-switcher-btn {
    color: var(--toolbar-text);
}

body.theme-dark-modern
    .analytics-header
    .nav-switcher-pill
    .shared-project-selector-btn:hover,
body.theme-dark-modern
    .analytics-header
    .nav-switcher-pill
    .app-switcher-btn:hover,
body.theme-dark-professional
    .analytics-header
    .nav-switcher-pill
    .shared-project-selector-btn:hover,
body.theme-dark-professional
    .analytics-header
    .nav-switcher-pill
    .app-switcher-btn:hover {
    background: var(--toolbar-button-hover);
}

body.theme-dark-modern
    .analytics-header
    .nav-switcher-pill
    > #projectSelectorContainer
    + #appSwitcherContainer,
body.theme-dark-professional
    .analytics-header
    .nav-switcher-pill
    > #projectSelectorContainer
    + #appSwitcherContainer {
    border-left-color: var(--toolbar-border);
}

/* ── Filter-bar project selector: match filter-select look ───────── */
.filter-bar .shared-project-selector-btn {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    height: 36px;
    font-size: 13px;
    padding: 0 12px;
    transition: border-color 0.15s;
}

.filter-bar .shared-project-selector-btn:hover {
    border-color: var(--gray-300);
    background: white;
}

.filter-bar .shared-project-selector-chevron {
    color: var(--gray-500);
}

.filter-bar .shared-project-selector-name {
    color: var(--gray-700);
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    padding-bottom: 12px;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-select {
    appearance: none;
    background: white
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
        no-repeat right 10px center;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 8px 32px 8px 12px;
    font-size: 13px;
    color: var(--gray-700);
    min-width: 160px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.filter-select:hover {
    border-color: var(--gray-300);
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Date Range Picker */
.date-range-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.date-preset-select {
    appearance: none;
    background: white
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
        no-repeat right 10px center;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 8px 32px 8px 12px;
    font-size: 13px;
    color: var(--gray-700);
    min-width: 140px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.date-preset-select:hover {
    border-color: var(--gray-300);
}

.date-preset-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.date-custom-inputs {
    display: none;
    align-items: center;
    gap: 6px;
}

.date-custom-inputs.visible {
    display: flex;
}

.date-input {
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
    font-family: "Inter", sans-serif;
    color: var(--gray-700);
    background: white;
    cursor: pointer;
    transition: border-color 0.15s;
    width: 130px;
}

.date-input:hover {
    border-color: var(--gray-300);
}

.date-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.date-range-badge {
    display: none;
    align-items: center;
    gap: 6px;
    background: var(--primary);
    color: white;
    padding: 4px 10px 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.date-range-badge.visible {
    display: inline-flex;
}

.date-range-badge .clear-date {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    opacity: 0.8;
    transition: opacity 0.15s;
    line-height: 1;
}

.date-range-badge .clear-date:hover {
    opacity: 1;
}

.date-sep {
    color: var(--gray-400);
    font-size: 12px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    background: var(--gray-100);
    padding: 4px;
    border-radius: 10px;
    margin: 8px 0 0;
    /* Give the tabs row some bottom breathing room inside the sticky header */
    padding-bottom: 4px;
    margin-bottom: 0;
}

.tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.tab:hover {
    color: var(--gray-800);
}

.tab.active {
    background: white;
    color: var(--gray-900);
    box-shadow: var(--shadow);
}

/* Content */
.analytics-content {
    flex: 1;
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.tab-panel {
    display: none;
}

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

/* Summary Cards */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--panel-bg, white);
    border: 1px solid var(--panel-border, transparent);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.summary-card.total::before {
    background: var(--primary);
}
.summary-card.completed::before {
    background: var(--success);
}
.summary-card.in-progress::before {
    background: var(--info);
}
.summary-card.open::before {
    background: var(--warning);
}

.summary-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    font-size: 18px;
}

.summary-card.total .summary-icon {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}
.summary-card.completed .summary-icon {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}
.summary-card.in-progress .summary-icon {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
}
.summary-card.open .summary-icon {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.summary-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.summary-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
}

.summary-sub {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 4px;
}

.summary-sub .trend-up {
    color: var(--success);
}
