@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #ffffff;
    --bg-secondary: #f7f7f5;
    --bg-hover: #efefef;
    --bg-active: #e8e5e0;
    --border: #e8e5e0;
    --border-light: #f0efed;
    --text: #37352f;
    --text-secondary: #787774;
    --text-light: #a4a4a0;
    --primary: #2383e2;
    --primary-light: #e8f0fe;
    --primary-hover: #1a73d4;
    --danger: #eb5757;
    --danger-light: #fde8e8;
    --success: #4dab6f;
    --success-light: #e6f4ea;
    --warning: #f5a623;
    --warning-light: #fef7e0;
    --sidebar-width: 280px;
    --header-height: 52px;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.05);
    --transition: 150ms ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.65;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.header {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 8px;
    z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.header-sep { color: var(--text-light); font-size: 18px; font-weight: 300; }
.logo {
    font-weight: 700;
    font-size: 15px;
    text-decoration: none;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
}
.logo-icon {
    width: 24px; height: 24px;
    background: var(--primary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 13px;
    font-weight: 700;
}
.header-project {
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.username {
    color: var(--text-secondary);
    font-size: 13px;
    padding: 4px 10px;
    background: var(--bg-secondary);
    border-radius: 20px;
}
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: var(--radius-sm);
}
.menu-toggle:hover { background: var(--bg-hover); }

/* ── Search ── */
.search-form { position: relative; }
.search-form input {
    padding: 6px 12px 6px 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    width: 220px;
    background: var(--bg-secondary);
    transition: all var(--transition);
    color: var(--text);
}
.search-form input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg);
    box-shadow: 0 0 0 3px var(--primary-light);
    width: 280px;
}
.search-form::before {
    content: '⌕';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 14px;
    pointer-events: none;
}

/* ── Layout ── */
.layout {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-light);
    padding: 12px 8px;
    overflow-y: auto;
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-active) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 3px; }

.sidebar hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 8px 12px;
}
.sidebar-section { margin-bottom: 2px; }
.sidebar-heading {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-light);
    padding: 6px 12px 4px;
    margin-top: 4px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-link:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-link.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}
.sidebar-upload {
    color: var(--primary);
    font-weight: 500;
}
.sidebar-upload::before { content: '↑ '; }
.sidebar-link-icon {
    font-size: 15px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

/* ── Content ── */
.content {
    flex: 1;
    padding: 40px 60px;
    margin-left: var(--sidebar-width);
    max-width: 860px;
}

/* ── Prose (markdown) ── */
.prose { font-size: 15px; line-height: 1.75; }
.prose h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
    letter-spacing: -0.02em;
    line-height: 1.3;
}
.prose h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin: 2rem 0 0.6rem;
    letter-spacing: -0.01em;
    line-height: 1.35;
}
.prose h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 1.5rem 0 0.4rem;
}
.prose p { margin-bottom: 0.8rem; }
.prose a {
    color: var(--primary);
    text-decoration: underline;
    text-decoration-color: rgba(35, 131, 226, 0.3);
    text-underline-offset: 2px;
    transition: text-decoration-color var(--transition);
}
.prose a:hover { text-decoration-color: var(--primary); }
.prose strong { font-weight: 600; }
.prose ul, .prose ol { margin-bottom: 0.8rem; padding-left: 1.6rem; }
.prose li { margin-bottom: 0.2rem; }
.prose li::marker { color: var(--text-secondary); }
.prose code {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    color: #c7254e;
}
.prose pre {
    background: #282c34;
    color: #abb2bf;
    padding: 20px 24px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 1rem;
    font-size: 13px;
    line-height: 1.6;
}
.prose pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}
.prose table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 14px;
}
.prose th, .prose td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.prose th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}
.prose blockquote {
    border-left: 3px solid var(--primary);
    padding: 4px 16px;
    margin: 0 0 1rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.prose img { max-width: 100%; border-radius: var(--radius); }
.prose hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    white-space: nowrap;
    font-family: inherit;
}
.btn:hover { background: var(--bg-secondary); border-color: var(--bg-active); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; }
.btn-outline { background: transparent; }
.btn-full { width: 100%; justify-content: center; }
.btn-ghost {
    border: none;
    background: none;
    color: var(--text-secondary);
    padding: 4px 8px;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

/* ── Forms ── */
label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--text-secondary);
}
input[type="text"], input[type="password"], select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 12px;
    font-family: inherit;
    color: var(--text);
    transition: all var(--transition);
}
input[type="text"]:focus, input[type="password"]:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-inline {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.form-inline input, .form-inline select { width: auto; margin-bottom: 0; }
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 400;
    font-size: 13px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.checkbox-label:hover { background: var(--bg-hover); }

/* ── Table ── */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
    font-size: 13px;
}
.table th, .table td {
    border: 1px solid var(--border-light);
    padding: 10px 14px;
    text-align: left;
}
.table th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}
.table tr:hover td { background: var(--bg-secondary); }

/* ── Alerts ── */
.alert {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #f5c6c6;
}
.alert-success {
    background: var(--success-light);
    color: #1e7e34;
    border: 1px solid #b7e4c7;
}

/* ── Upload ── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 48px 32px;
    text-align: center;
    margin-bottom: 32px;
    transition: all var(--transition);
    background: var(--bg-secondary);
}
.upload-zone:hover { border-color: var(--text-light); }
.upload-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}
.upload-zone-content p {
    color: var(--text-secondary);
    margin: 8px 0 16px;
    font-size: 14px;
}
.upload-icon {
    font-size: 48px;
    margin-bottom: 4px;
    opacity: 0.6;
}
.progress-bar {
    height: 6px;
    background: var(--bg-active);
    border-radius: 3px;
    overflow: hidden;
    margin: 16px 0 8px;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.2s;
    width: 0%;
    border-radius: 3px;
}

/* ── Projects grid ── */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 24px;
}
.project-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-decoration: none;
    color: var(--text);
    transition: all var(--transition);
    background: var(--bg);
}
.project-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--bg-active);
    transform: translateY(-1px);
}
.project-card h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}
.project-slug {
    color: var(--text-light);
    font-size: 13px;
    font-family: 'SF Mono', monospace;
}

/* ── Search results ── */
.search-result {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}
.search-result:last-child { border-bottom: none; }
.search-result-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}
.search-result-title:hover { text-decoration: underline; }
.search-result-snippet {
    color: var(--text-secondary);
    margin: 4px 0;
    font-size: 13px;
    line-height: 1.5;
}
.search-result-snippet mark {
    background: #fef08a;
    padding: 1px 3px;
    border-radius: 2px;
}
.search-result-path {
    color: var(--text-light);
    font-size: 12px;
    font-family: 'SF Mono', monospace;
}

/* ── Login ── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-secondary);
}
.login-card {
    background: var(--bg);
    padding: 40px 36px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}
.login-card h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 28px;
    font-size: 14px;
}

/* ── Admin ── */
.admin-section {
    margin-bottom: 36px;
}
.admin-section h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 15px; }

/* ── Badge ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-admin { background: var(--warning-light); color: #9a6700; }
.badge-user { background: var(--bg-secondary); color: var(--text-secondary); }

/* ── Mobile ── */
@media (max-width: 768px) {
    .menu-toggle { display: block; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 99;
        box-shadow: none;
    }
    .sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    .sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 98;
    }
    .content { margin-left: 0; padding: 24px 16px; }
    .search-form input { width: 140px; }
    .search-form input:focus { width: 180px; }
    .header-right { gap: 6px; }
    .username { display: none; }
}

@media (max-width: 480px) {
    .content { padding: 16px 12px; }
    .prose h1 { font-size: 1.5rem; }
    .projects-grid { grid-template-columns: 1fr; }
}
