:root {
    --primary: #4f46e5;
    --primary-gradient: linear-gradient(90deg, #4f46e5 0%, #9333ea 100%);
    --bg-gradient: linear-gradient(135deg, #e0e7ff 0%, #f3e8ff 50%, #fce7f3 100%);
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --card-bg: #ffffff;
    --bg-secondary: #f9fafb;
    --radius: 16px;
    --border-color: #e5e7eb;
    --btn-bg-red: #fee2e2;
    --badge-bg: #eef2ff;
    --nav-hover: #f3f4f6;
    --input-bg: #fff;
    --input-border: #f3f4f6;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-gradient: linear-gradient(90deg, #6366f1 0%, #a855f7 100%);
    --bg-gradient: linear-gradient(135deg, #111827 0%, #1f2937 100%);
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --card-bg: #1f2937;
    --bg-secondary: #374151;
    --border-color: #4b5563;
    --btn-bg-red: #7f1d1d;
    --badge-bg: #312e81;
    --nav-hover: #374151;
    --input-bg: #374151;
    --input-border: #4b5563;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s, color 0.3s;
}
.container { max-width: 1200px; margin: 0 auto; }

/* ANIMATIONS */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.animate-slide-down { animation: slideUp 0.6s ease-out forwards; opacity: 0; }
.animate-pop { animation: fadeIn 0.4s ease-out; }

.staggered-anim {
    opacity: 0;
    animation: slideUp 0.5s ease-out forwards;
}

/* LIVE BADGE */
.live-badge {
    font-size: 0.7rem;
    color: #16a34a; /* Green */
    background: #dcfce7;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid #bbf7d0;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    animation: pulse 2s infinite;
}
.live-badge::before {
    content: '';
    display: block;
    width: 6px; height: 6px;
    background: #16a34a;
    border-radius: 50%;
}
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* TIMELINE STYLES (New for Calendar) */
.timeline {
    position: relative;
    padding-left: 20px;
    margin-top: 10px;
}
.timeline::before {
    content: '';
    position: absolute;
    top: 0; bottom: 0; left: 6px;
    width: 2px;
    background: var(--border-color);
}
.timeline-item {
    position: relative;
    margin-bottom: 12px;
}
.timeline-item::before {
    content: '';
    position: absolute;
    top: 15px; left: -19px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    border: 2px solid var(--card-bg);
    z-index: 1;
}
.timeline-item.focus-session::before { background: #3b82f6; } /* Blue for focus */
.timeline-item.break-session::before { background: #10b981; } /* Green for break */
.timeline-item.event-google::before { background: #f59e0b; } /* Yellow for GCal */

.timeline-card {
    background: var(--bg-secondary);
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}
.timeline-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 4px;
}
.timeline-title { font-weight: 600; font-size: 0.95rem; }
.timeline-time { font-size: 0.8rem; color: var(--text-muted); }
.timeline-duration { font-size: 0.8rem; color: var(--primary); font-weight: 500; }

/* AUTH */
.auth-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(10px);
    display: flex; justify-content: center; align-items: center;
    z-index: 9999;
    padding: 20px;
}
.auth-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    width: 100%; max-width: 400px;
    text-align: center;
}
.auth-tabs {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 4px;
    display: flex;
    margin-bottom: 24px;
}
.auth-tab {
    flex: 1; padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.3s;
}
.auth-tab.active { background: var(--card-bg); color: var(--primary); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }

.input-group { margin-bottom: 16px; }
.input-group input {
    width: 100%; padding: 14px;
    border: 2px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-main);
    border-radius: 12px;
    font-size: 1rem;
    outline: none; transition: border-color 0.2s;
}
.input-group input:focus { border-color: var(--primary); }
.auth-submit-btn {
    width: 100%; padding: 14px;
    background: var(--primary);
    color: white; border: none;
    border-radius: 12px;
    font-size: 1rem; font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.auth-submit-btn:hover { opacity: 0.9; }
.error-msg { color: #ef4444; margin-top: 10px; font-size: 0.9rem; }

/* HEADER & NAV */
header { margin-bottom: 32px; }
h1 {
    font-size: 2.5rem;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}
.subtitle { color: var(--text-muted); font-size: 1rem; }
nav {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 8px; margin-bottom: 24px;
    display: flex; gap: 8px; overflow-x: auto;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    scrollbar-width: none; 
}
nav::-webkit-scrollbar { display: none; }

.nav-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 24px; border: none; border-radius: 12px;
    background: transparent; cursor: pointer;
    font-size: 1rem; color: var(--text-muted);
    white-space: nowrap;
    transition: all 0.2s;
}
.nav-btn:hover { background: var(--nav-hover); }
.nav-btn.active { background: var(--primary-gradient); color: white; box-shadow: 0 4px 6px rgba(79, 70, 229, 0.2); }

/* CARDS & DASHBOARD LAYOUT */
.tab-content { display: none; }
.tab-content.active { display: block; }

.card { background: var(--card-bg); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }

/* Dashboard Grids */
.dashboard-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.dashboard-grid-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

/* Updated Stat Card Style */
.stat-card { 
    background: var(--card-bg); 
    border-radius: 20px; 
    padding: 24px; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); 
    border: 1px solid var(--border-color);
    display: flex; 
    flex-direction: column; 
    align-items: flex-start;
}
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: white; font-size: 1.2rem; margin-bottom: 12px; }
.stat-icon-small { 
    width: 36px; height: 36px; 
    border-radius: 10px; 
    display: flex; align-items: center; justify-content: center; 
    color: white; font-size: 1.1rem; 
    margin-bottom: 12px;
}
.stat-icon-small.blue { background: #3b82f6; }
.stat-icon-small.purple { background: #a855f7; }
.stat-icon-small.orange { background: #f97316; }
.stat-icon-small.green { background: #10b981; }

.stat-label { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 6px; font-weight: 500; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text-main); }

.chart-card h3 { font-size: 1rem; margin-bottom: 16px; font-weight: 600; color: var(--text-main); }
.chart-container { position: relative; height: 300px; width: 100%; }
.chart-container.pie-container { display: flex; justify-content: center; }
.chart-container.wide { height: 250px; }


/* TIMER */
.timer-container { max-width: 700px; margin: 0 auto; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; } /* Legacy grid for Timer */
.mode-selector { display: flex; gap: 16px; margin-bottom: 16px; }
.mode-btn {
    flex: 1; padding: 12px; border: none; border-radius: 12px;
    cursor: pointer; background: var(--bg-secondary); color: var(--text-muted);
    font-size: 1rem; display: flex; justify-content: center; align-items: center; gap: 8px;
}
.mode-btn.active { color: white; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.mode-btn.pomodoro.active { background: linear-gradient(90deg, #ef4444, #f97316); }
.mode-btn.stopwatch.active { background: linear-gradient(90deg, #3b82f6, #06b6d4); }
.timer-settings { display: flex; gap: 20px; margin-bottom: 24px; justify-content: center; flex-wrap: wrap; }
.setting-group { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.setting-group label { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.pomodoro-info { background: var(--bg-secondary); border-radius: 12px; padding: 16px; margin-bottom: 30px; }
.pomodoro-header { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--text-muted); font-weight: 500;}
.progress-bar { height: 8px; background: var(--border-color); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; transition: width 1s linear; background: linear-gradient(90deg, #ef4444, #f97316); }
.progress-fill.break { background: linear-gradient(90deg, #10b981, #059669); }
.timer-display { text-align: center; margin: 40px 0; }
.timer-time { font-size: 5rem; font-family: 'Courier New', monospace; font-weight: 700; background: linear-gradient(90deg, #4f46e5, #9333ea); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.timer-controls { display: flex; justify-content: center; gap: 16px; }
.btn-control { padding: 16px 32px; border: none; border-radius: 12px; font-size: 1.1rem; cursor: pointer; color: white; transition: transform 0.1s; }
.btn-control:active { transform: scale(0.98); }
.btn-start { background: linear-gradient(90deg, #10b981, #059669); }
.btn-pause { background: linear-gradient(90deg, #f97316, #ef4444); }
.btn-reset { background: var(--bg-secondary); color: var(--text-main); border: 1px solid var(--border-color); }

.group-input { flex: 1; padding: 10px; border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text-main); border-radius: 8px; outline: none; }
.group-input:focus { border-color: var(--primary); }

/* CALENDAR & EVENTS */
.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.calendar-cell { aspect-ratio: 1; border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 0.9rem; position: relative; cursor: pointer; transition: transform 0.1s; }
.calendar-cell:hover { transform: scale(1.05); background: var(--nav-hover); }
.calendar-cell.header { font-weight: 600; color: var(--text-muted); background: transparent; aspect-ratio: auto; padding-bottom: 8px; cursor: default; }
.calendar-cell.header:hover { transform: none; }
.calendar-cell.today { border: 2px solid var(--primary); }
.calendar-cell.inactive { opacity: 0.3; }
.intensity-0 { background: var(--bg-secondary); }
.intensity-1 { background: #bbf7d0; } 
.intensity-2 { background: #86efac; }
.intensity-3 { background: #4ade80; }
.intensity-4 { background: #22c55e; } 
.intensity-5 { background: #16a34a; }

/* EVENT MARKERS */
.calendar-dots {
    position: absolute; bottom: 4px; left: 0; right: 0;
    display: flex; justify-content: center; gap: 3px;
    padding: 0 2px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; }
.dot.meeting { background: #3b82f6; } 
.dot.holiday { background: #ef4444; } 

.event-item {
    padding: 12px; background: var(--bg-secondary);
    border-radius: 8px; margin-bottom: 8px; border-left: 4px solid var(--primary);
}
.event-item.holiday-item { border-left-color: #ef4444; }
.event-time { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 2px; }

/* DARK MODE OVERRIDES */
[data-theme="dark"] .intensity-0 { background: #374151; }
[data-theme="dark"] .intensity-1 { background: #064e3b; }
[data-theme="dark"] .intensity-2 { background: #065f46; }
[data-theme="dark"] .intensity-3 { background: #047857; }
[data-theme="dark"] .intensity-4 { background: #059669; }
[data-theme="dark"] .intensity-5 { background: #10b981; }

/* GROUPS */
.groups-layout { display: grid; grid-template-columns: 1fr 2fr; gap: 24px; }
.group-item { padding: 16px; background: var(--bg-secondary); border-radius: 12px; margin-bottom: 12px; cursor: pointer; transition: all 0.2s; border: 1px solid transparent; }
.group-item:hover { border-color: var(--primary); }
.group-item.active { background: var(--primary-gradient); color: white; }
.leaderboard-filters { display: flex; gap: 8px; margin-bottom: 16px; border-bottom: 1px solid var(--border-color); padding-bottom: 16px; flex-wrap: wrap; }
.filter-btn { border: none; background: transparent; padding: 6px 12px; border-radius: 20px; cursor: pointer; color: var(--text-muted); font-size: 0.9rem; transition: all 0.2s; }
.filter-btn:hover { background: var(--bg-secondary); }
.filter-btn.active { background: var(--primary); color: white; }
.leaderboard-item { display: flex; align-items: center; padding: 16px; background: var(--bg-secondary); border-radius: 12px; margin-bottom: 12px; gap: 16px; }
.leaderboard-item.me { border: 2px solid var(--primary); background: var(--badge-bg); }

/* ACHIEVEMENTS */
.achievements-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.achievement-card { background: var(--card-bg); border-radius: 16px; padding: 24px; text-align: center; border: 1px solid var(--border-color); transition: transform 0.2s; }
.achievement-card:hover { transform: translateY(-5px); }
.achievement-card.unlocked { border-color: var(--primary); background: linear-gradient(to bottom right, var(--card-bg), var(--badge-bg)); }
.achievement-icon { font-size: 3rem; margin-bottom: 12px; filter: grayscale(1); opacity: 0.5; }
.achievement-card.unlocked .achievement-icon { filter: grayscale(0); opacity: 1; }

/* ==========================================================================
   MOBILE & TABLET RESPONSIVENESS
   ========================================================================== */

@media (max-width: 900px) { 
    .dashboard-grid-row { grid-template-columns: 1fr; } 
    .groups-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    body { padding: 10px; }
    h1 { font-size: 1.8rem; }
    .subtitle { font-size: 0.9rem; }
    
    /* Header & Nav */
    header { flex-direction: row; align-items: center; margin-bottom: 20px; }
    .nav-btn { padding: 10px 16px; font-size: 0.9rem; }
    .icon-only-mobile .desktop-text { display: none; }
    
    /* Timer */
    .timer-time { font-size: 3.5rem; margin: 20px 0; }
    .timer-settings { gap: 10px; }
    .btn-control { padding: 12px 24px; font-size: 1rem; width: 100%; }
    .timer-controls { flex-direction: column; gap: 10px; width: 100%; }
    
    /* Dashboard Mobile Fix: 2x2 Grid */
    .dashboard-stats-grid { 
        grid-template-columns: 1fr 1fr; 
        gap: 10px; 
    }
    .stat-card { padding: 12px; }
    .stat-icon-small { width: 32px; height: 32px; font-size: 1rem; margin-bottom: 8px; }
    .stat-value { font-size: 1.2rem; }
    .stat-label { font-size: 0.8rem; }
    
    .card { padding: 16px; margin-bottom: 12px; }
    .dashboard-grid-row { gap: 12px; }

    /* Charts */
    .chart-container, .chart-container.wide { height: 160px; }
    .chart-container.pie-container { height: 160px; } 
    
    /* Calendar */
    .calendar-cell { font-size: 0.8rem; }
    .calendar-cell span:last-child { display: none; }
    
    /* Groups */
    .groups-layout { grid-template-columns: 1fr; gap: 16px; }
    .group-item { padding: 12px; }
    .leaderboard-filters { gap: 4px; overflow-x: auto; padding-bottom: 8px; }
    .filter-btn { font-size: 0.8rem; padding: 6px 10px; white-space: nowrap; }
    
    /* Auth */
    .auth-card { padding: 24px; }
}

@media (max-width: 480px) {
    .timer-time { font-size: 3rem; }
    .mode-selector { flex-direction: column; gap: 8px; }
}