/* ============================================================
   Elusive Analytics Dashboard — Design System
   Tokens from Section 4 of the build spec.
   ============================================================ */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

/* --- CSS Variables (Design Tokens) --- */
:root {
    --bg:          #F7F5F1;
    --surface:     #FFFFFF;
    --charcoal:    #1C1C1C;
    --gold:        #C9A84C;
    --gold-light:  #D4B96A;
    --gold-subtle: rgba(201, 168, 76, 0.08);
    --mid-gray:    #6B6B6B;
    --light-gray:  #EBEBEB;
    --success:     #2ECC71;
    --warning:     #E67E22;
    --danger:      #E74C3C;

    --font-primary: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono:    'IBM Plex Mono', 'SF Mono', monospace;

    --sidebar-width: 240px;
    --sidebar-collapsed: 64px;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-elevated: 0 8px 24px rgba(0,0,0,0.10);
    --transition: 0.2s ease;
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-primary);
    background: var(--bg);
    color: var(--charcoal);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--gold); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--gold-light); }

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

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--charcoal);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: width var(--transition);
}

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

.sidebar-logo img {
    height: 28px;
    width: auto;
}

.sidebar-logo h1 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--gold);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.nav-section {
    padding: 0 12px;
    margin-bottom: 8px;
}

.nav-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.35);
    padding: 8px 12px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.65);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
}

.nav-item:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.nav-item.active {
    background: rgba(201, 168, 76, 0.12);
    color: var(--gold);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-item.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.8);
}

.user-role {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
}

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 32px 40px;
    min-height: 100vh;
}

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

.page-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--charcoal);
}

.page-subtitle {
    font-size: 13px;
    color: var(--mid-gray);
    margin-top: 4px;
}

/* --- Metric Cards --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.metric-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-card);
    transition: box-shadow var(--transition), transform var(--transition);
    position: relative;
    overflow: hidden;
}

.metric-card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--light-gray);
    border-radius: var(--radius) var(--radius) 0 0;
}

.metric-card.gold::before { background: var(--gold); }
.metric-card.success::before { background: var(--success); }
.metric-card.warning::before { background: var(--warning); }
.metric-card.danger::before { background: var(--danger); }

.metric-label {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--mid-gray);
    margin-bottom: 8px;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 600;
    color: var(--charcoal);
    line-height: 1.2;
}

.metric-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    margin-top: 8px;
    padding: 2px 8px;
    border-radius: 20px;
}

.metric-change.up {
    color: var(--success);
    background: rgba(46, 204, 113, 0.08);
}

.metric-change.down {
    color: var(--danger);
    background: rgba(231, 76, 60, 0.08);
}

.metric-change.flat {
    color: var(--mid-gray);
    background: rgba(107, 107, 107, 0.08);
}

.metric-sparkline {
    margin-top: 12px;
    height: 40px;
}

/* --- Creator Grid (Agency View) --- */
.creators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.creator-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-card);
    transition: all var(--transition);
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

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

.creator-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.creator-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--light-gray);
}

.creator-name {
    font-size: 16px;
    font-weight: 600;
}

.creator-channel {
    font-size: 12px;
    color: var(--mid-gray);
    margin-top: 2px;
}

.creator-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}

.creator-stat {
    text-align: center;
}

.creator-stat-value {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 600;
    color: var(--charcoal);
}

.creator-stat-label {
    font-size: 11px;
    color: var(--mid-gray);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.creator-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    border-top: 1px solid var(--light-gray);
}

.creator-sparkline {
    flex: 1;
    height: 32px;
    margin-right: 12px;
}

.trend-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.trend-badge.growing {
    color: var(--success);
    background: rgba(46, 204, 113, 0.08);
}

.trend-badge.stable {
    color: var(--mid-gray);
    background: rgba(107, 107, 107, 0.08);
}

.trend-badge.declining {
    color: var(--danger);
    background: rgba(231, 76, 60, 0.08);
}

/* --- Platform Icons --- */
.platform-icons {
    display: flex;
    gap: 6px;
}

.platform-icon {
    width: 20px;
    height: 20px;
    opacity: 0.5;
}

.platform-icon.connected {
    opacity: 1;
}

/* --- Video List --- */
.video-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.video-item {
    display: flex;
    gap: 16px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-card);
    transition: box-shadow var(--transition);
}

.video-item:hover {
    box-shadow: var(--shadow-card-hover);
}

.video-thumbnail {
    width: 160px;
    height: 90px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
}

.video-info {
    flex: 1;
    min-width: 0;
}

.video-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.video-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--mid-gray);
}

.video-stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- Charts container --- */
.chart-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-card);
    margin-bottom: 24px;
}

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

.chart-title {
    font-size: 16px;
    font-weight: 600;
}

.chart-canvas {
    width: 100%;
    height: 200px;
}

/* --- Demographics --- */
.demo-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.demo-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.demo-bar-label {
    width: 80px;
    font-size: 12px;
    color: var(--mid-gray);
    text-align: right;
    flex-shrink: 0;
}

.demo-bar-track {
    flex: 1;
    height: 24px;
    background: var(--light-gray);
    border-radius: 4px;
    overflow: hidden;
}

.demo-bar-fill {
    height: 100%;
    background: var(--gold);
    border-radius: 4px;
    transition: width 0.6s ease;
    min-width: 2px;
}

.demo-bar-value {
    width: 48px;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--charcoal);
    flex-shrink: 0;
}

/* --- Section Headers --- */
.section-header {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-header svg {
    width: 20px;
    height: 20px;
    color: var(--gold);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font-primary);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary {
    background: var(--gold);
    color: #fff;
}

.btn-primary:hover {
    background: var(--gold-light);
    color: #fff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--light-gray);
    color: var(--charcoal);
}

.btn-outline:hover {
    border-color: var(--gold);
    color: var(--gold);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

/* --- Login Page --- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--charcoal);
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 48px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-elevated);
    text-align: center;
}

.login-logo {
    margin-bottom: 32px;
}

.login-logo img {
    height: 40px;
}

.login-title {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--mid-gray);
    margin-bottom: 32px;
}

.google-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 32px;
    background: var(--surface);
    border: 1px solid var(--light-gray);
    border-radius: var(--radius-sm);
    font-family: var(--font-primary);
    font-size: 14px;
    font-weight: 500;
    color: var(--charcoal);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    width: 100%;
    justify-content: center;
}

.google-btn:hover {
    border-color: var(--gold);
    box-shadow: var(--shadow-card);
    color: var(--charcoal);
}

.google-btn svg {
    width: 20px;
    height: 20px;
}

/* --- Utilities --- */
.text-gold { color: var(--gold); }
.text-muted { color: var(--mid-gray); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-mono { font-family: var(--font-mono); }
.mt-24 { margin-top: 24px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }

/* --- Last Sync --- */
.sync-info {
    font-size: 12px;
    color: var(--mid-gray);
    display: flex;
    align-items: center;
    gap: 6px;
}

.sync-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 64px 32px;
    color: var(--mid-gray);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--charcoal);
}

/* --- Tab Bar (Phase 1.5) --- */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--light-gray);
    margin-bottom: 24px;
    margin-top: 32px;
}

.tab-btn {
    font-family: var(--font-primary);
    font-size: 14px;
    font-weight: 500;
    color: var(--mid-gray);
    background: none;
    border: none;
    padding: 12px 20px;
    cursor: pointer;
    position: relative;
    transition: color var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.tab-btn:hover { color: var(--charcoal); }

.tab-btn.active {
    color: var(--charcoal);
    font-weight: 600;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gold);
}

.tab-count {
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--gold-subtle);
    color: var(--gold);
    padding: 1px 6px;
    border-radius: 10px;
}

/* --- Duration Badge --- */
.video-thumb-wrap {
    position: relative;
    flex-shrink: 0;
}

.duration-badge {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0,0,0,0.8);
    color: #fff;
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
}

/* --- Shorts Grid --- */
.shorts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.short-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition);
}

.short-card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

.short-card .video-thumb-wrap {
    aspect-ratio: 9/16;
    overflow: hidden;
}

.short-card .video-thumb-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.short-card-info { padding: 12px; }

.short-card-title {
    font-size: 13px;
    font-weight: 500;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 6px;
}

.short-card-meta {
    font-size: 11px;
    color: var(--mid-gray);
    display: flex;
    justify-content: space-between;
}

/* --- Audience Grid --- */
.audience-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.audience-panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 20px;
}

.audience-panel h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--charcoal);
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .sidebar {
        width: var(--sidebar-collapsed);
    }
    .sidebar-logo h1,
    .nav-item span,
    .nav-section-title,
    .user-name,
    .user-role { display: none; }
    .sidebar-logo { justify-content: center; padding: 24px 12px; }
    .nav-item { justify-content: center; padding: 12px; }
    .main-content { margin-left: var(--sidebar-collapsed); padding: 24px; }
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        align-items: center;
    }
    .sidebar-nav { display: flex; gap: 4px; padding: 8px; overflow-x: auto; }
    .nav-section { display: flex; gap: 4px; padding: 0; margin: 0; }
    .nav-section-title { display: none; }
    .sidebar-footer { display: none; }
    .main-content { margin-left: 0; padding: 16px; }
    .layout { flex-direction: column; }
    .creators-grid { grid-template-columns: 1fr; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .video-item { flex-direction: column; }
    .video-thumbnail { width: 100%; height: auto; aspect-ratio: 16/9; }
    .shorts-grid { grid-template-columns: repeat(2, 1fr); }
    .audience-grid { grid-template-columns: 1fr; }
    .tab-btn { padding: 10px 14px; font-size: 13px; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--light-gray); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--mid-gray); }
