/* ============================================================
   DevGrid — Base
   ============================================================ */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.55;
    transition: background var(--transition-base), color var(--transition-base);
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.25;
    margin: 0 0 var(--space-3);
    letter-spacing: -0.01em;
}

h1 { font-size: 28px; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }

p { margin: 0 0 var(--space-3); color: var(--text-primary); }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

code, pre {
    font-family: var(--font-mono);
    font-size: 13px;
}

pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    overflow-x: auto;
    line-height: 1.5;
}

code:not(pre code) {
    background: var(--bg-secondary);
    padding: 1px 5px;
    border-radius: var(--radius-sm);
}

img { max-width: 100%; display: block; }

button { font-family: inherit; }

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

.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 24px; height: 24px; }

/* ============================================================
   Layout shell
   ============================================================ */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-5);
    z-index: 100;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    color: var(--text-primary);
}
.topbar-brand:hover { text-decoration: none; color: var(--text-primary); }
.topbar-brand .dot { color: var(--accent); }

.topbar-search {
    flex: 1;
    max-width: 420px;
    margin: 0 var(--space-6);
}
.topbar-search input {
    width: 100%;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text-primary); }

.badge-dot {
    position: absolute;
    top: 5px; right: 5px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--surface);
}

.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--border);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 84px; height: 84px; font-size: 28px; }
.avatar-sm { width: 24px; height: 24px; font-size: 11px; }

.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: var(--space-5) var(--space-3);
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.sidebar-nav a:hover { background: var(--surface-hover); color: var(--text-primary); text-decoration: none; }
.sidebar-nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-nav a.active .icon { stroke: var(--accent); }

.sidebar-section-label {
    font-family: var(--font-display);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    padding: var(--space-4) var(--space-3) var(--space-1);
}

.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    flex: 1;
    padding: var(--space-6);
    min-height: calc(100vh - var(--header-height));
}

.container-narrow { max-width: var(--max-content); margin: 0 auto; }
.container-tight { max-width: 720px; margin: 0 auto; }

.guest-topbar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--header-height);
    background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 var(--space-6); z-index: 100;
}
.guest-main { margin-top: var(--header-height); padding: var(--space-7) var(--space-5); }

@media (max-width: 900px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: var(--space-4); }
    .topbar-search { display: none; }
}

/* ============================================================
   Buttons & forms
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 9px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
    line-height: 1.2;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.form-group { margin-bottom: var(--space-4); }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: var(--space-2);
    color: var(--text-primary);
}
.form-hint { font-size: 12px; color: var(--text-tertiary); margin-top: var(--space-1); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="url"], textarea, select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition-fast);
}
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    outline: none;
}
textarea { resize: vertical; min-height: 90px; }

.form-row { display: flex; gap: var(--space-4); }
.form-row > * { flex: 1; }

.checkbox-row { display: flex; align-items: center; gap: var(--space-2); font-size: 14px; }

.file-drop {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
}
.file-drop:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   Cards & lists
   ============================================================ */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
}

.card-list { display: flex; flex-direction: column; gap: var(--space-3); }

.item-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    transition: border-color var(--transition-fast);
}
.item-card:hover { border-color: var(--border-strong); }

.item-card-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.item-card-title a { color: var(--text-primary); }
.item-card-title a:hover { color: var(--accent); text-decoration: none; }
.item-card-desc { color: var(--text-secondary); font-size: 13.5px; margin: 0 0 var(--space-3); }

.item-card-meta {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    font-size: 12.5px;
    color: var(--text-tertiary);
}
.item-card-meta span { display: inline-flex; align-items: center; gap: 4px; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
@media (max-width: 900px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.tag-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    font-family: var(--font-display);
}
.pill-public { background: var(--success-soft); color: var(--success); }
.pill-private { background: var(--bg-secondary); color: var(--text-secondary); }
.pill-shared { background: var(--info-soft); color: var(--info); }
.pill-draft { background: var(--bg-secondary); color: var(--text-tertiary); }

.empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-5);
    color: var(--text-secondary);
}
.empty-state h3 { color: var(--text-primary); margin-bottom: var(--space-2); }

/* ============================================================
   Page header, tabs, stats
   ============================================================ */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
    gap: var(--space-3);
}
.page-header p { color: var(--text-secondary); margin: 4px 0 0; }

.stat-row { display: flex; gap: var(--space-5); margin-bottom: var(--space-6); }
.stat-box {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
}
.stat-box .num { font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.stat-box .label { font-size: 12.5px; color: var(--text-secondary); }

.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-5);
}
.tabs a {
    padding: var(--space-3) var(--space-4);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tabs a:hover { text-decoration: none; color: var(--text-primary); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ============================================================
   Alerts / flash messages
   ============================================================ */

.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    font-size: 14px;
    border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* ============================================================
   Auth pages
   ============================================================ */

.auth-wrap {
    max-width: 400px;
    margin: 60px auto;
    padding: 0 var(--space-4);
}
.auth-wrap .card { padding: var(--space-6); }
.auth-logo { text-align: center; margin-bottom: var(--space-5); font-family: var(--font-display); font-size: 22px; font-weight: 700; }
.auth-logo .dot { color: var(--accent); }
.auth-footer-link { text-align: center; margin-top: var(--space-4); font-size: 13.5px; color: var(--text-secondary); }

/* ============================================================
   Feed / posts
   ============================================================ */

.post {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}
.post-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.post-head .name { font-weight: 600; font-size: 14px; }
.post-head .meta { font-size: 12.5px; color: var(--text-tertiary); }
.post-body { font-size: 14.5px; white-space: pre-wrap; margin-bottom: var(--space-3); }
.post-image { border-radius: var(--radius-md); border: 1px solid var(--border); margin-bottom: var(--space-3); max-height: 420px; object-fit: cover; }
.post-actions { display: flex; gap: var(--space-2); border-top: 1px solid var(--border); padding-top: var(--space-3); }

.action-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: var(--radius-md);
    border: 1px solid transparent; background: transparent;
    color: var(--text-secondary); font-size: 13px; cursor: pointer;
}
.action-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.action-btn.active { color: var(--accent); }
.action-btn.active .icon { fill: var(--accent); stroke: var(--accent); }

.composer { margin-bottom: var(--space-5); }
.composer textarea { min-height: 70px; }
.composer-footer { display: flex; justify-content: space-between; align-items: center; margin-top: var(--space-3); }

/* ============================================================
   Comments
   ============================================================ */

.comment-list { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-4); }
.comment { display: flex; gap: var(--space-3); }
.comment-body { flex: 1; }
.comment-bubble { background: var(--bg-secondary); border-radius: var(--radius-md); padding: 10px 12px; }
.comment-bubble .name { font-weight: 600; font-size: 13px; margin-right: 6px; }
.comment-bubble .text { font-size: 13.5px; }
.comment-meta { font-size: 11.5px; color: var(--text-tertiary); margin-top: 3px; display: flex; gap: var(--space-3); }

/* ============================================================
   Code viewer
   ============================================================ */

.file-tree {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.file-tree-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    cursor: pointer;
}
.file-tree-item:last-child { border-bottom: none; }
.file-tree-item:hover { background: var(--surface-hover); }
.file-tree-item.active { background: var(--accent-soft); color: var(--accent); }
.file-tree-name { display: flex; align-items: center; gap: var(--space-2); font-family: var(--font-mono); }
.file-meta { color: var(--text-tertiary); font-size: 12px; }

.code-viewer { display: grid; grid-template-columns: 240px 1fr; gap: var(--space-4); }
@media (max-width: 900px) { .code-viewer { grid-template-columns: 1fr; } }

.code-block-wrap { position: relative; }
.code-block-wrap .copy-btn { position: absolute; top: var(--space-2); right: var(--space-2); }
.code-block-wrap pre { max-height: 600px; overflow: auto; }

/* ============================================================
   Profile
   ============================================================ */

.profile-header { display: flex; gap: var(--space-5); margin-bottom: var(--space-6); flex-wrap: wrap; }
.profile-header .info { flex: 1; min-width: 240px; }
.profile-stats { display: flex; gap: var(--space-5); margin-top: var(--space-3); font-size: 13.5px; }
.profile-stats strong { color: var(--text-primary); }
.profile-stats span { color: var(--text-secondary); }
.skill-list { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }

/* ============================================================
   Tables (admin)
   ============================================================ */

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th, table.data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data-table th { color: var(--text-secondary); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ============================================================
   Pagination
   ============================================================ */

.pagination { display: flex; gap: var(--space-2); justify-content: center; margin-top: var(--space-6); }
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 34px; border-radius: var(--radius-md);
    border: 1px solid var(--border); font-size: 13px; color: var(--text-secondary);
}
.pagination a:hover { background: var(--surface-hover); text-decoration: none; }
.pagination .current { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

/* ============================================================
   Modal
   ============================================================ */

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(10, 10, 10, 0.5);
    display: none; align-items: center; justify-content: center; z-index: 1000;
}
.modal-backdrop.open { display: flex; }
.modal-box {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: var(--space-5); width: 100%; max-width: 420px; box-shadow: var(--shadow-2);
}
.modal-box h3 { margin-bottom: var(--space-4); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }

/* ============================================================
   Theme toggle
   ============================================================ */

.theme-toggle-group { display: flex; gap: 2px; background: var(--bg-secondary); padding: 2px; border-radius: var(--radius-md); }
.theme-toggle-group button {
    border: none; background: transparent; width: 30px; height: 30px; border-radius: calc(var(--radius-md) - 1px);
    display: flex; align-items: center; justify-content: center; color: var(--text-secondary); cursor: pointer;
}
.theme-toggle-group button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-1); }

/* ============================================================
   404 / 403
   ============================================================ */

.error-page {
    text-align: center;
    padding: var(--space-8) var(--space-5);
}
.error-page .code { font-family: var(--font-display); font-size: 64px; font-weight: 700; color: var(--accent); }

/* Utility */
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 13px; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.w-full { width: 100%; }
