:root {
    --bg:           #ffffff;
    --bg-elevated:  #fafafa;
    --surface:      #f5f5f5;
    --surface-hover:#ececec;

    --text:         #0a0a0a;
    --text-muted:   #6b6b6b;
    --text-dim:     #9b9b9b;

    --border:       #e5e5e5;
    --border-strong:#d0d0d0;

    --accent:         #0a0a0a;
    --accent-text:    #ffffff;
    --accent-hover:   #2a2a2a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    --container-max: 1000px;
    --container-pad-desktop: 24px;
    --container-pad-mobile:  10px;

    --t-fast: 0.15s ease;
    --t-mid:  0.25s ease;
}


*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    transition: background var(--t-mid), color var(--t-mid);
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; }


.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding-left: var(--container-pad-desktop);
    padding-right: var(--container-pad-desktop);
}


/* =========================================
   FLASH
   ========================================= */
.messages-container {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.message {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    transition: opacity 0.3s;
}


/* =========================================
   MAIN
   ========================================= */
main {
    padding-top: 40px;
    padding-bottom: 64px;
}


/* =========================================
   HERO
   ========================================= */
.hero { padding: 40px 0; }
.hero-content {
    text-align: center;
    max-width: 720px;
    margin: 0 auto 60px;
}
.hero-title {
    font-size: clamp(32px, 5vw, 52px);
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin-bottom: 20px;
}
.hero-accent { color: var(--text-muted); }
.hero-subtitle {
    font-size: clamp(15px, 1.8vw, 17px);
    color: var(--text-muted);
    margin-bottom: 32px;
}
.hero-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}


/* Кнопки */
.btn-primary, .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 22px;
    border-radius: var(--radius-pill);
    font-size: 14px;
    font-weight: 500;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
    border: 1px solid transparent;
}
.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
    background: transparent;
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface); }


/* Features */
.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.feature-card {
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    transition: border-color var(--t-fast), background var(--t-fast);
}
.feature-card:hover {
    border-color: var(--border-strong);
    background: var(--surface);
}
.feature-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
}
.feature-text {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}


/* =========================================
   FORMS — общие стили
   ========================================= */
.form-group {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="url"],
.form-group input[type="number"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color var(--t-fast), background var(--t-fast);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-elevated);
}
.form-group textarea {
    min-height: 100px;
    resize: vertical;
    line-height: 1.5;
}
.form-group input[type="file"] {
    padding: 8px;
    cursor: pointer;
}
.helptext {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.4;
}
.helptext ul {
    margin: 4px 0 0;
    padding-left: 16px;
}
.errorlist {
    list-style: none;
    margin: 4px 0 0;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text);
}
.errorlist li + li { margin-top: 2px; }


.form-submit {
    width: 100%;
    padding: 12px 20px;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: var(--radius-pill);
    transition: background var(--t-fast);
}
.form-submit:hover { background: var(--accent-hover); }


/* =========================================
   AUTH (login / register / profile_edit)
   ========================================= */
.auth-container {
    max-width: 440px;
    margin: 40px auto;
}
.auth-card {
    padding: 32px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.auth-card-wide { max-width: 550px; }


.auth-title {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 6px;
}
.auth-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0 0 24px;
}
.auth-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
}
.auth-footer a {
    color: var(--text);
    font-weight: 500;
    border-bottom: 1px solid var(--border-strong);
    transition: border-color var(--t-fast);
}
.auth-footer a:hover { border-color: var(--text); }


.avatar-preview {
    text-align: center;
    margin-bottom: 20px;
}
.avatar-preview img {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
    display: inline-block;
}


/* =========================================
   PROFILE
   ========================================= */
.profile-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.profile-header {
    display: flex;
    gap: 24px;
    padding: 28px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.profile-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.profile-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 44px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface);
    text-transform: uppercase;
}
.profile-info { flex: 1; min-width: 0; }
.profile-name {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 4px;
}
.profile-role {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--surface);
    border-radius: var(--radius-pill);
    margin-bottom: 14px;
}
.profile-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 14px;
}
.profile-bio {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    margin: 0 0 18px;
    white-space: pre-wrap;
}
.profile-bio-empty {
    color: var(--text-dim);
    font-style: italic;
}
.profile-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.profile-actions .btn-primary,
.profile-actions .btn-secondary {
    padding: 9px 18px;
    font-size: 14px;
}


.profile-placeholder {
    padding: 32px;
    text-align: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.profile-placeholder h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
}
.profile-placeholder p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}


/* =========================================
   DIRECTORY (people list)
   ========================================= */
.directory-container {
    max-width: 100%;
}
.directory-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 20px;
}


.directory-search {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.directory-search-input,
.directory-search-select {
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color var(--t-fast);
}
.directory-search-input { flex: 1; min-width: 200px; }
.directory-search-input:focus,
.directory-search-select:focus {
    outline: none;
    border-color: var(--accent);
}
.directory-search-btn {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: var(--radius-md);
    transition: background var(--t-fast);
}
.directory-search-btn:hover { background: var(--accent-hover); }
.directory-clear {
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    font-size: 13px;
    color: var(--text-muted);
    border-bottom: 1px dashed var(--border-strong);
}
.directory-clear:hover { color: var(--text); }


.directory-count {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}
.directory-count strong { color: var(--text); font-weight: 600; }


.directory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.directory-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.directory-card:hover {
    border-color: var(--border-strong);
    background: var(--surface);
    transform: translateY(-2px);
}
.directory-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
    margin-bottom: 12px;
}
.directory-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface);
}
.directory-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.directory-role {
    font-size: 12px;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--surface);
    border-radius: var(--radius-pill);
    margin-bottom: 10px;
}
.directory-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.4;
}


.directory-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 28px;
}
.page-link {
    padding: 8px 14px;
    font-size: 14px;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: background var(--t-fast), border-color var(--t-fast);
}
.page-link:hover {
    background: var(--surface);
    border-color: var(--border-strong);
}
.page-current {
    font-size: 14px;
    color: var(--text-muted);
}


.directory-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.directory-empty p { margin: 0; font-size: 15px; }
.directory-empty-sub {
    margin-top: 6px !important;
    font-size: 13px;
    color: var(--text-dim);
}


/* =========================================
   FEED
   ========================================= */
.feed-container {
    max-width: 700px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}


/* ----- Post creation ----- */
.post-create {
    padding: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.post-create-header {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.post-create-input { flex: 1; }
.post-create-input textarea {
    width: 100%;
    min-height: 70px;
    padding: 8px 4px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: transparent;
    border: none;
    resize: vertical;
    line-height: 1.5;
    outline: none;
}
.post-create-input textarea::placeholder {
    color: var(--text-dim);
}
.post-create-input textarea:focus {
    outline: none;
    border: none;
    background: transparent;
}


.post-create-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    flex-wrap: nowrap;
}
.post-image-btn {
    display: inline-flex;
    align-items: center;
    padding: 7px 14px;
    font-size: 13px;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}
.post-image-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}
/* Скрываем нативный file input */
.post-create-footer input[type="file"] {
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0;
    pointer-events: none;
}
.post-image-name {
    font-size: 12px;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.post-submit-btn {
    margin-left: auto;
    flex-shrink: 0;
}
.post-submit-btn:hover { background: var(--bg); }


/* ----- Avatars ----- */
.post-avatar-sm {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.post-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface);
    text-transform: uppercase;
}


/* ----- Posts list ----- */
.posts-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}


.post-card {
    padding: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}


.post-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}
.post-author-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    min-width: 0;
}
.post-author-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.post-author-link:hover .post-author-name {
    text-decoration: underline;
}
.post-date {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 1px;
}


.post-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    font-size: 20px;
    line-height: 1;
    color: var(--text-dim);
    border-radius: var(--radius-sm);
    transition: background var(--t-fast), color var(--t-fast);
}
.post-delete-btn:hover {
    background: var(--surface);
    color: var(--text);
}


.post-body { margin-bottom: 12px; }
.post-text {
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    margin: 0 0 12px;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.post-text:last-child { margin-bottom: 0; }


.post-image {
    width: 100%;
    max-height: 600px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    display: block;
}


.post-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}


.post-like-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.post-like-btn .like-icon {
    font-size: 14px;
    line-height: 1;
    color: var(--text-dim);
    transition: color var(--t-fast), transform var(--t-fast);
}
.post-like-btn.liked {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}
.post-like-btn.liked:hover {
    background: var(--surface);
    border-color: var(--border-strong);
}
.post-like-btn.liked .like-icon {
    color: #e8364f;
    transform: scale(1.1);
}


/* ----- Empty / end ----- */
.empty-feed {
    padding: 60px 20px;
    text-align: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.empty-feed p {
    margin: 0;
    font-size: 15px;
    color: var(--text);
}
.empty-feed-sub {
    margin-top: 6px !important;
    font-size: 13px !important;
    color: var(--text-muted) !important;
}


.feed-end {
    padding: 20px;
    text-align: center;
    font-size: 13px;
    color: var(--text-dim);
}


/* ----- Loader ----- */
.loader {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 24px;
}
.loader-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: loader-bounce 1.2s infinite ease-in-out;
}
.loader-dot:nth-child(2) { animation-delay: 0.15s; }
.loader-dot:nth-child(3) { animation-delay: 0.3s; }


@keyframes loader-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}


/* =========================================
   DARK MODE
   ========================================= */
@media (prefers-color-scheme: dark) {
    :root {
        --bg:           #0a0a0a;
        --bg-elevated:  #141414;
        --surface:      #1a1a1a;
        --surface-hover:#242424;

        --text:         #f5f5f5;
        --text-muted:   #a0a0a0;
        --text-dim:     #6b6b6b;

        --border:       #262626;
        --border-strong:#3a3a3a;

        --accent:         #f5f5f5;
        --accent-text:    #0a0a0a;
        --accent-hover:   #d4d4d4;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    }
}


/* =========================================
   MOBILE
   ========================================= */
@media (max-width: 768px) {
    .container {
        padding-left: var(--container-pad-mobile);
        padding-right: var(--container-pad-mobile);
    }

    /* Hero / features */
    .features { grid-template-columns: 1fr; }
    .hero { padding: 24px 0; }
    .hero-content { margin-bottom: 40px; }
    .btn-primary, .btn-secondary { width: 100%; }

    /* Auth */
    .auth-container { margin: 20px auto; }
    .auth-card { padding: 20px; border-radius: var(--radius-md); }
    .auth-title { font-size: 20px; }

    /* Profile */
    .profile-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 20px;
    }
    .profile-avatar { width: 96px; height: 96px; }
    .profile-meta { align-items: center; }
    .profile-actions { justify-content: center; }
    .profile-bio { text-align: left; }
    .profile-placeholder { padding: 24px; }

    /* Directory */
    .directory-title { font-size: 22px; }
    .directory-search {
        flex-direction: column;
        gap: 8px;
    }
    .directory-search-input,
    .directory-search-select,
    .directory-search-btn {
        width: 100%;
    }
    .directory-clear {
        align-self: center;
        padding: 6px 0;
    }
    .directory-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }