:root {
    /* Dimensions */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    /* Layout */
    --sidebar-width: 280px;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Animations */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    
    /* Default Colors (Dark Mode) */
    --bg-base: #0f1115;
    --bg-surface: rgba(30, 33, 40, 0.6);
    --bg-surface-hover: rgba(45, 50, 60, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    /* Heatmap neutral */
    --heatmap-bg: rgba(255, 255, 255, 0.05);
    
    /* Active Habit Theme */
    --theme-color: var(--success);
}

body.light-theme {
    --bg-base: #f8fafc;
    --bg-surface: rgba(255, 255, 255, 0.7);
    --bg-surface-hover: rgba(241, 245, 249, 0.9);
    --border-color: rgba(0, 0, 0, 0.1);
    
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    
    --heatmap-bg: #e2e8f0;
}

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

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-normal);
}

.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.glass-header {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    color: var(--success);
    width: 24px;
    height: 24px;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.light-theme .logo h1 {
    background: linear-gradient(135deg, #000 0%, #4f46e5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.theme-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-surface-hover);
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    transform: scale(1.05);
}

body.light-theme .icon-sun { display: none; }
body.dark-theme .icon-moon { display: none; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-surface-hover);
}

.btn-action {
    background: var(--theme-color);
    color: white;
    opacity: 0.9;
}

.btn-action:hover {
    opacity: 1;
    transform: scale(1.02);
    box-shadow: 0 4px 12px var(--theme-color);
}

.btn-action:disabled {
    background: var(--bg-surface-hover);
    color: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.5;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.btn-icon.danger:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

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

.dashboard-content {
    display: flex;
    flex: 1;
    padding: 2rem;
    gap: 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    position: sticky;
    top: 90px;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.habit-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.habit-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.habit-item:hover {
    background: var(--bg-surface-hover);
}

.habit-item.active {
    background: var(--bg-surface-hover);
    border-left: 3px solid var(--item-color, var(--primary-color));
}

.habit-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--item-color, var(--primary-color));
}

.habit-name {
    flex: 1;
    font-weight: 500;
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.habit-streak {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.habit-streak.hot {
    color: #f59e0b;
}

.main-panel {
    flex: 1;
    min-width: 0;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
}

.empty-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.empty-icon svg {
    width: 40px;
    height: 40px;
    color: var(--primary-color);
}

.empty-state h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.empty-state p {
    margin-bottom: 2rem;
    max-width: 400px;
}

.hidden {
    display: none !important;
}

/* Habit Detail */
.habit-detail {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.habit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
}

.habit-title-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.habit-title-wrapper h2 {
    font-size: 1.75rem;
    font-weight: 700;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    padding: 10px;
    border-radius: var(--radius-md);
    background: var(--bg-surface-hover);
}

.focus-icon { color: #f59e0b; background: rgba(245, 158, 11, 0.1); }
.award-icon { color: #8b5cf6; background: rgba(139, 92, 246, 0.1); }
.total-icon { color: #10b981; background: rgba(16, 185, 129, 0.1); }
.rate-icon { color: #3b82f6; background: rgba(59, 130, 246, 0.1); }

.stat-info h3 {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Heatmap */
.heatmap-container {
    padding: 2rem;
}

.heatmap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-cell {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.color-0 { background-color: var(--heatmap-bg); }
.color-1 { background-color: var(--theme-color); }

.scroll-wrapper {
    overflow-x: auto;
    padding-bottom: 1rem;
}

.heatmap-grid {
    display: grid;
    /* 53 weeks = 53 columns. We configure columns via JS inline style, or rely on flex column wrap */
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    height: calc(7 * 16px); /* 7 rows of ~14px + gap */
    gap: 4px;
    align-content: flex-start;
}

.heatmap-cell {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background-color: var(--heatmap-bg);
    transition: transform var(--transition-fast), background-color var(--transition-normal);
    cursor: pointer;
    position: relative;
}

.heatmap-cell:hover {
    transform: scale(1.3);
    z-index: 2;
    border: 1px solid rgba(255,255,255,0.5);
}

.heatmap-cell.active {
    background-color: var(--theme-color);
}

.months-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast);
}

.form-group input:focus {
    border-color: var(--primary-color);
}

.color-picker {
    display: flex;
    gap: 1rem;
}

.color-option {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: var(--opts-color);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.color-option.selected {
    border-color: white;
    transform: scale(1.1);
    box-shadow: 0 0 0 2px var(--opts-color);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
}

.toast i {
    color: var(--success);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Tooltip on cells */
.heatmap-cell[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: #000;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 10;
    pointer-events: none;
}

/* Responsive */
@media (max-width: 1024px) {
    .dashboard-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        min-height: 250px;
    }
}

@media (max-width: 640px) {
    .glass-header {
        padding: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .dashboard-content {
        padding: 1rem;
    }
    
    .habit-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}
