/* =========================================
   1. CSS Variables & Theming (SaaS Professional)
========================================= */
:root[data-theme="light"] {
    --bg-base: #f4f4f5;         /* Zinc 100 */
    --bg-surface: #ffffff;      /* Zinc 50 */
    --bg-hover: #f4f4f5;

    --text-main: #09090b;       /* Zinc 950 */
    --text-muted: #71717a;      /* Zinc 500 */
    --text-link: #2563eb;       /* Blue 600 */

    --border-color: #e4e4e7;    /* Zinc 200 */
    --border-focus: #18181b;

    --primary: #18181b;         /* Zinc 900 */
    --primary-hover: #27272a;   /* Zinc 800 */
    --primary-text: #ffffff;

    --success: #10b981;
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;

    --danger: #ef4444;
    --danger-bg: #fef2f2;

    --warning: #f59e0b;
    --warning-bg: #fffbeb;

    --label-chapter-text: #2563eb;
    --label-chapter-bg: #eff6ff;
    --label-practice-text: #059669;
    --label-practice-bg: #ecfdf5;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.02);
}

:root[data-theme="dark"] {
    --bg-base: #09090b;         /* Zinc 950 */
    --bg-surface: #18181b;      /* Zinc 900 */
    --bg-hover: #27272a;

    --text-main: #fafafa;       /* Zinc 50 */
    --text-muted: #a1a1aa;      /* Zinc 400 */
    --text-link: #60a5fa;       /* Blue 400 */

    --border-color: #27272a;    /* Zinc 800 */
    --border-focus: #fafafa;

    --primary: #fafafa;         /* Zinc 50 */
    --primary-hover: #e4e4e7;   /* Zinc 200 */
    --primary-text: #09090b;

    --success: #34d399;
    --success-bg: rgba(16, 185, 129, 0.1);
    --success-border: rgba(16, 185, 129, 0.2);

    --danger: #f87171;
    --danger-bg: rgba(239, 68, 68, 0.1);

    --warning: #fbbf24;
    --warning-bg: rgba(245, 158, 11, 0.1);

    --label-chapter-text: #60a5fa;
    --label-chapter-bg: rgba(59, 130, 246, 0.1);
    --label-practice-text: #34d399;
    --label-practice-bg: rgba(16, 185, 129, 0.1);

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

/* =========================================
   2. Global Reset & Layout
========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    transition: background-color 0.2s ease, color 0.2s ease;
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--text-link);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    text-decoration: underline;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Theme Button */
.theme-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.theme-btn:hover {
    color: var(--text-main);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* =========================================
   3. Navbar & Header
========================================= */
.navbar, .sub-navbar {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
}

.sub-navbar { margin-bottom: 2rem; }

.navbar-container, .sub-navbar-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
}

.nav-brand svg, .back-nav { color: var(--text-main); }
.back-nav:hover { color: var(--text-link); text-decoration: none; }

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}
.breadcrumb .separator { color: var(--text-muted); }
.breadcrumb .current { font-weight: 600; }
.repo-page-title { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; }

/* =========================================
   4. Badges, Labels & Forms
========================================= */
.label {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
}

.label-chapter {
    color: var(--label-chapter-text);
    background-color: var(--label-chapter-bg);
    border-color: rgba(59, 130, 246, 0.2);
}

.label-practice {
    color: var(--label-practice-text);
    background-color: var(--label-practice-bg);
    border-color: var(--success-border);
}

.badge {
    background: var(--bg-hover);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 2px 6px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    margin-left: 6px;
}

.search-input {
    width: 100%;
    max-width: 400px;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-base);
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.15s;
}

.search-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 1px var(--border-focus);
    background: var(--bg-surface);
}

/* =========================================
   5. Buttons
========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0.6rem 1.25rem;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: var(--shadow-sm);
}

.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--primary);
    color: var(--primary-text);
    border-color: transparent;
}
.btn-primary:hover { background: var(--primary-hover); }

/* =========================================
   6. Layouts (Hub & Repo)
========================================= */
.layout-hub, .layout-repo {
    display: grid;
    gap: 2rem;
    margin-top: 2rem;
    margin-bottom: 4rem;
}
.layout-hub { grid-template-columns: 280px 1fr; }
.layout-repo { grid-template-columns: minmax(0, 1fr) 300px; }

/* Sidebar Panels (Profile & Details) */
.profile-sidebar, .repo-sidebar {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    height: fit-content;
}

.profile-avatar {
    width: 100%;
    aspect-ratio: 1;
    background-color: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.profile-name { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; letter-spacing: -0.02em; }
.profile-bio { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 1rem; }
.profile-divider { height: 1px; background-color: var(--border-color); margin: 1rem 0; }
.profile-detail { display: flex; align-items: center; gap: 0.5rem; color: var(--text-main); margin-bottom: 0.5rem; font-size: 0.9rem; }
.profile-detail svg { color: var(--text-muted); }

/* Hub Main Area */
.repo-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0.5rem;
    font-size: 0.95rem;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 0.15s;
}

.tab.active {
    border-bottom-color: var(--border-focus);
    color: var(--text-main);
    font-weight: 600;
}

.repo-controls { margin-bottom: 1.5rem; }

/* Repo List Items */
.repo-list {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.repo-list-item {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}
.repo-list-item:hover { background: var(--bg-hover); }
.repo-list-item:last-child { border-bottom: none; }

.repo-info { flex: 1; }
.repo-title-wrapper { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.4rem; }
.repo-title { font-size: 1.15rem; font-weight: 600; color: var(--text-link); }
.repo-description { color: var(--text-muted); margin-bottom: 0.75rem; font-size: 0.9rem; max-width: 90%; }
.repo-meta { display: flex; align-items: center; gap: 1.25rem; color: var(--text-muted); font-size: 0.8rem; }
.meta-item { display: flex; align-items: center; gap: 4px; }
.lang-color { width: 10px; height: 10px; border-radius: 50%; background-color: #b07219; display: inline-block; }

/* =========================================
   7. Repo Detail Page Specifics
========================================= */
.repo-page-desc { font-size: 1.05rem; color: var(--text-muted); margin-bottom: 2rem; }

.readme-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.readme-header {
    background: var(--bg-base);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.readme-body { padding: 1.5rem; }
.readme-body h2 { padding-bottom: 0.5rem; border-bottom: 1px solid var(--border-color); margin-bottom: 1.25rem; font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }

.code-block {
    background-color: #0d1117; /* Keep code block strictly dark for contrast */
    color: #e6edf3;
    border-radius: var(--radius-md);
    padding: 1.25rem;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    overflow-x: auto;
    border: 1px solid var(--border-color);
}
.code-line { margin-bottom: 6px; }
.code-line .comment { color: #8b949e; }
.code-line .prompt { color: #3fb950; margin-right: 8px; user-select: none; }
.code-line .command { color: #e6edf3; }

/* Repo Sidebar Details */
.sidebar-section { border-bottom: 1px solid var(--border-color); padding-bottom: 1.25rem; margin-bottom: 1.25rem; }
.sidebar-section:last-child { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.sidebar-section h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--text-main); }
.sidebar-section p { color: var(--text-muted); font-size: 0.9rem; }
.sidebar-list { list-style: none; font-size: 0.9rem; }
.sidebar-list li { display: flex; align-items: center; gap: 0.5rem; padding: 4px 0; color: var(--text-muted); }
.sidebar-list strong { color: var(--text-main); }
.lang-stats { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; font-size: 0.9rem; }
.authors-list { display: flex; flex-direction: column; gap: 0.75rem; }
.author-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; }
.author-avatar { width: 28px; height: 28px; border-radius: 50%; background-color: var(--bg-hover); border: 1px solid var(--border-color); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600; color: var(--text-main); }

/* =========================================
   8. Responsive Design
========================================= */
@media (max-width: 1024px) {
    .layout-hub { grid-template-columns: 240px 1fr; gap: 1.5rem; }
    .layout-repo { grid-template-columns: minmax(0, 1fr) 240px; gap: 1.5rem; }
}

@media (max-width: 768px) {
    .navbar-container { flex-direction: column; align-items: flex-start; }
    .layout-hub { display: flex; flex-direction: column; gap: 1.5rem; }
    
    .profile-sidebar { display: flex; flex-direction: column; align-items: center; text-align: center; }
    .profile-avatar { width: 120px; border-radius: 50%; font-size: 2.5rem; }
    .profile-detail { justify-content: center; }
    
    .repo-tabs { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    
    .repo-list-item { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .repo-list-item .repo-actions { width: 100%; }
    .repo-list-item .btn { width: 100%; justify-content: center; }

    .sub-navbar-container { flex-direction: column; align-items: flex-start; }
    .sub-navbar-container .btn { width: 100%; justify-content: center; }
    
    .layout-repo { display: flex; flex-direction: column; }
    .repo-sidebar { margin-top: 1rem; }
    
    .theme-btn { bottom: 1rem; right: 1rem; width: 40px; height: 40px; }
}
