/* ===== CSS Variables for Light/Dark Mode ===== */
:root {
    /* Light mode */
    --bg: #ffffff;
    --bg-secondary: #f8f9fa;
    --text: #1a1a1a;
    --text-secondary: #6c757d;
    --border: #e1e4e8;
    --accent: #0969da;
    --accent-hover: #0550ae;
    --shadow: rgba(0, 0, 0, 0.05);

    /* Sidebar */
    --sidebar-bg: #f6f8fa;
    --sidebar-border: #d0d7de;
    --sidebar-hover: #e9ecef;
    --sidebar-active: #ddf4ff;
    --sidebar-active-border: #0969da;

    /* Status colors */
    --status-todo-bg: #f6f8fa;
    --status-todo-text: #57606a;
    --status-in-progress-bg: #fff8c5;
    --status-in-progress-text: #9a6700;
    --status-done-bg: #dafbe1;
    --status-done-text: #0969da;
}

[data-theme="dark"] {
    /* Dark mode */
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --border: #30363d;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --shadow: rgba(0, 0, 0, 0.3);

    /* Sidebar */
    --sidebar-bg: #161b22;
    --sidebar-border: #30363d;
    --sidebar-hover: #21262d;
    --sidebar-active: #1c2128;
    --sidebar-active-border: #58a6ff;

    /* Status colors */
    --status-todo-bg: #21262d;
    --status-todo-text: #8b949e;
    --status-in-progress-bg: #3d2b00;
    --status-in-progress-text: #e3b341;
    --status-done-bg: #0d3818;
    --status-done-text: #3fb950;
}

/* ===== Global Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background-color 0.2s ease, color 0.2s ease;
    overflow-x: hidden;
}

/* ===== Header ===== */
.site-header {
    background-color: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}

/* ===== Theme Toggle Button ===== */
.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--accent);
    border-color: var(--accent);
}

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    height: calc(100vh - 60px);
}

/* ===== Permanent Sidebar ===== */
.permanent-sidebar {
    width: 300px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    overflow-y: auto;
    flex-shrink: 0;
}

.permanent-sidebar::-webkit-scrollbar {
    width: 10px;
}

.permanent-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.permanent-sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
}

.sidebar-header {
    padding: 1.5rem 1rem 1rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

/* ===== Sidebar Navigation ===== */
.sidebar-nav {
    padding: 0.5rem 0;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section-title {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
}

.nav-tree {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Project items in sidebar */
.project-item {
    position: relative;
    margin-bottom: 0.5rem;
}

.project-item::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
}

.project-item:last-child::before {
    bottom: 1.5rem;
}

.project-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem 0.5rem 2rem;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s ease;
    position: relative;
}

.project-link::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 50%;
    width: 0.75rem;
    height: 1px;
    background: var(--border);
}

.project-link:hover {
    background: var(--sidebar-hover);
}

.project-item.active .project-link {
    background: var(--sidebar-active);
    border-left: 2px solid var(--sidebar-active-border);
}

.nav-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-progress {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 0.5rem;
    flex-shrink: 0;
}

/* Subtask tree (nested under projects) */
.subtask-tree {
    list-style: none;
    margin: 0;
    padding: 0;
}

.subtask-item {
    position: relative;
    padding: 0.35rem 1rem 0.35rem 3rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.15s ease;
}

.subtask-item::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
}

.subtask-item:last-child::before {
    bottom: 50%;
}

.subtask-item::after {
    content: '';
    position: absolute;
    left: 1rem;
    top: 50%;
    width: 1.5rem;
    height: 1px;
    background: var(--border);
}

.subtask-item:hover {
    background: var(--sidebar-hover);
}

.subtask-item input[type="checkbox"] {
    cursor: pointer;
    flex-shrink: 0;
}

.subtask-item label {
    cursor: pointer;
    flex: 1;
    user-select: none;
}

.subtask-item input[type="checkbox"]:checked + label {
    text-decoration: line-through;
    opacity: 0.6;
}

/* ===== Main Content Area ===== */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 3rem;
    background: var(--bg);
}

.main-content::-webkit-scrollbar {
    width: 10px;
}

.main-content::-webkit-scrollbar-track {
    background: transparent;
}

.main-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
}

/* ===== Hero Section (Homepage) ===== */
.hero {
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.hero h2 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.hero p {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* ===== Projects Grid (Homepage) ===== */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.project-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s ease;
}

.project-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
    border-color: var(--accent);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.75rem;
    gap: 0.75rem;
}

.card-header h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

/* ===== Status Badges ===== */
.status-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}

.status-todo {
    background-color: var(--status-todo-bg);
    color: var(--status-todo-text);
}

.status-in-progress {
    background-color: var(--status-in-progress-bg);
    color: var(--status-in-progress-text);
}

.status-done {
    background-color: var(--status-done-bg);
    color: var(--status-done-text);
}

/* ===== Project Description ===== */
.project-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

/* ===== Progress Bar ===== */
.progress-bar {
    position: relative;
    height: 24px;
    background: var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    transition: width 0.3s ease;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    z-index: 1;
}

/* ===== Project Page (Simplified) ===== */
.project-page {
    max-width: 800px;
}

.project-header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.project-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text);
    line-height: 1.2;
}

.project-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.progress-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ===== Project Content ===== */
.project-content {
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--text);
}

.project-content h2 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--text);
}

.project-content h3 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.project-content p {
    margin-bottom: 1rem;
}

.project-content ul,
.project-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.project-content li {
    margin-bottom: 0.5rem;
}

.project-content a {
    color: var(--accent);
    text-decoration: none;
}

.project-content a:hover {
    text-decoration: underline;
}

.project-content code {
    background: var(--bg-secondary);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-size: 0.9rem;
    font-family: 'Monaco', 'Menlo', monospace;
}

.project-content pre {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1rem 0;
}

.project-content pre code {
    background: none;
    padding: 0;
}

/* ===== Notes Block ===== */
.notes-block {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-left: 3px solid var(--accent);
    border-radius: 6px;
}

.notes-block h2 {
    font-size: 1.25rem;
    margin-top: 0;
    margin-bottom: 0.75rem;
}

.notes-block p {
    color: var(--text-secondary);
    margin: 0;
}

/* ===== Markdown Notes ===== */
.markdown-notes {
    margin-top: 2rem;
}

.markdown-notes h2 {
    font-size: 1.5rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

.markdown-notes h3 {
    font-size: 1.25rem;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}

.markdown-notes ul,
.markdown-notes ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.markdown-notes a {
    color: var(--accent);
    text-decoration: none;
}

.markdown-notes a:hover {
    text-decoration: underline;
}

.markdown-notes code {
    background: var(--bg-secondary);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-size: 0.9rem;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .permanent-sidebar {
        width: 260px;
    }

    .main-content {
        padding: 1.5rem 2rem;
    }
}

@media (max-width: 768px) {
    .app-layout {
        flex-direction: column;
    }

    .permanent-sidebar {
        width: 100%;
        height: auto;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--sidebar-border);
    }

    .main-content {
        padding: 1rem;
    }

    .hero h2 {
        font-size: 1.75rem;
    }

    .projects-grid {
        grid-template-columns: 1fr;
    }

    .project-header h1 {
        font-size: 2rem;
    }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
