:root {
    --bg: rgba(255,255,255,0.6);
    --text: #0a0a0a;
    --text-secondary: #555;
    --text-muted: #888;
    --border: rgba(0,0,0,0.06);
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --prompt-bg: rgba(0,0,0,0.02);
    --code-bg: rgba(0,0,0,0.03);
    --max-width: 680px;
    --radius: 10px;
    --glass-border: rgba(255,255,255,0.8);
    --glass-shadow: 0 8px 40px rgba(0,0,0,0.04), inset 0 1px 0 rgba(255,255,255,0.6);
    --glass-bg: rgba(255,255,255,0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 17px;
    line-height: 1.6;
    color: var(--text);
    background: linear-gradient(135deg, #f8fafc 0%, #e8edf5 100%);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    -webkit-font-smoothing: antialiased;
}

/* === TYPOGRAPHY === */
h1, h2, h3, h4 { line-height: 1.3; font-weight: 700; margin: 1.5em 0 0.5em; }
h1 { font-size: 1.7em; }
h2 { font-size: 1.35em; }
h3 { font-size: 1.15em; }
p { margin: 0.8em 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: var(--max-width); margin: 0 auto; padding: 0 20px; }

/* === HEADER — Сафари-фикс: min-width: 0 на контейнере === */
.site-header {
    padding: 16px 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    margin-bottom: 28px;
    background: rgba(255,255,255,0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
.header-inner {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: row;
    flex-direction: row;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    -webkit-align-items: center;
    align-items: center;
    min-width: 0; /* КРИТИЧНО ДЛЯ САФАРИ 17.6 */
}
.site-logo {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}
.site-logo:hover { color: var(--accent); text-decoration: none; }
.nav-link {
    font-size: 14px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
    -webkit-flex-shrink: 0;
    flex-shrink: 0;
}
.nav-link:hover { color: var(--accent); text-decoration: none; }

/* === FORMS === */
.create-form { margin: 20px 0 32px; }
.form-section { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 4px;
}
.label-optional { color: var(--text-muted); font-weight: 400; font-size: 12px; }
.form-input, .form-textarea {
    width: 100%; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-family: inherit; font-size: 14px; line-height: 1.5;
    color: var(--text); background: var(--bg);
    transition: border-color 0.15s; resize: vertical;
}
.form-input:focus, .form-textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.1);
}
.form-input { height: 40px; }
.form-textarea { min-height: 120px; }

.checkbox-row {
    display: block;
    padding: 8px 14px; background: #fafafa;
    border-radius: var(--radius); border: 1px solid var(--border);
    cursor: pointer; font-size: 13px; color: var(--text-secondary);
}
.checkbox-row:hover { background: #f5f5f5; }
.checkbox-row input[type="checkbox"] {
    width: 16px; height: 16px; accent-color: var(--accent);
    margin-right: 6px;
    vertical-align: middle;
}
.checkbox-hint { color: var(--text-muted); font-size: 12px; }

.btn {
    display: inline-block;
    padding: 9px 18px; border: none; border-radius: var(--radius);
    font-family: inherit; font-size: 14px; font-weight: 500;
    cursor: pointer; transition: background 0.15s;
    text-align: center;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
    background: transparent; color: var(--text-secondary);
    border: 1px solid var(--border); text-decoration: none; font-size: 13px; padding: 6px 12px;
}
.btn-ghost:hover { background: #f5f5f5; color: var(--text); text-decoration: none; }
.btn-danger { background: transparent; color: #e53e3e; border: 1px solid #fed7d7; }
.btn-danger:hover { background: #fff5f5; }

/* === FLASH === */
.flash {
    padding: 10px 14px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 13px; line-height: 1.4;
}
.flash-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

.section-title { font-size: 18px; font-weight: 600; margin: 0 0 4px; color: var(--text); }
.section-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* === FEED (Хабр-стиль) — Сафари-фикс === */
.my-header {
    margin-bottom: 4px;
}

.posts-feed {
    margin: 0 0 32px;
}

.feed-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.feed-item:last-child {
    border-bottom: none;
}

.feed-meta-top {
    margin-bottom: 4px;
    font-size: 14px;
    color: var(--text-muted);
    min-width: 0; /* Сафари-фикс */
}

.action-icon {
    display: inline-block;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    color: var(--text-muted);
    text-decoration: none;
    line-height: 1;
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}
.action-icon:hover {
    color: var(--text);
    text-decoration: none;
}

.action-form {
    display: inline;
}

.feed-visibility {
    display: inline-block;
    margin-left: 10px;
    font-size: 13px;
    cursor: help;
}

.feed-title {
    font-size: 17px;
    font-weight: 400;
    margin: 0 0 4px;
    line-height: 1.35;
}

.feed-title a {
    color: var(--text);
    text-decoration: none;
}

.feed-title a:hover {
    color: var(--accent);
    text-decoration: none;
}

.feed-meta-bottom {
    font-size: 12px;
    color: var(--text-muted);
}

.feed-meta-bottom span {
    display: inline-block;
    margin-right: 6px;
}

.meta-sep {
    color: var(--border);
    margin: 0 2px;
}

/* === PROMPT BLOCK === */
.prompt-block {
    background: var(--prompt-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
}

.prompt-header {
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    color: var(--text-secondary);
    font-size: 13px;
}

.prompt-header:hover {
    background: #f0f0f0;
}

.prompt-header span {
    display: inline-block;
    vertical-align: middle;
}

.prompt-icon { font-size: 15px; margin-right: 6px; }
.prompt-label { font-weight: 600; color: var(--text-secondary); margin-right: 8px; }
.prompt-preview {
    color: var(--text-muted);
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
    font-size: 12px;
}
.prompt-arrow { font-size: 10px; color: var(--text-muted); margin-left: 8px; }
.prompt-content {
    border-top: 1px solid var(--border);
    padding: 14px;
    font-style: italic;
    color: var(--text-secondary);
    font-size: 14px;
}
.prompt-content p:first-child { margin-top: 0; }
.prompt-content p:last-child { margin-bottom: 0; }

/* === POST VIEW === */
.post-hero { margin-bottom: 20px; }
.post-title {
    font-size: 1.65em;
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 8px;
    word-break: break-word;
}
.post-byline {
    font-size: 13px;
    color: var(--text-muted);
}
.post-article {
    word-wrap: break-word;
    overflow-wrap: break-word;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--glass-shadow);
    position: relative;
    overflow: visible;
}
.post-article > * { position: relative; z-index: 1; }
.post-body {
    font-size: 17px;
    line-height: 1.7;
    /* без рамок, без отступов — внутри post-article */
}
.post-byline span {
    display: inline-block;
    margin-right: 6px;
}
.byline-sep { color: var(--border); }


.post-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 13px;
    overflow-x: auto;
    display: block;
}
.post-body table th,
.post-body table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}
.post-body table th {
    background: #fafafa;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
}

.post-body code {
    background: var(--code-bg);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: "SF Mono", "Fira Code", Consolas, monospace;
    font-size: 0.85em;
    word-break: break-all;
}
.post-body pre {
    background: var(--code-bg);
    padding: 14px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.8em 0;
    font-size: 13px;
    line-height: 1.45;
}
.post-body pre code {
    background: none;
    padding: 0;
    font-size: inherit;
    word-break: normal;
}

.post-body blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 14px;
    color: var(--text-secondary);
    margin: 0.8em 0;
    font-style: italic;
}
.post-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
}
.post-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5em 0;
}

/* === BADGES === */
.badge-public {
    background: #f0fdf4;
    color: #166534;
    padding: 1px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}
.badge-private {
    background: #fef2f2;
    color: #991b1b;
    padding: 1px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.owner-bar {
    margin-top: 28px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.owner-bar .btn,
.owner-bar button {
    display: inline-block;
    margin-right: 6px;
    margin-bottom: 6px;
}

.back-link {
    display: inline-block;
    margin-top: 24px;
    font-size: 14px;
    color: var(--text-secondary);
}
.back-link a { color: var(--text-secondary); }
.back-link a:hover { color: var(--text); }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state p { margin: 6px 0; font-size: 15px; }

/* === FOOTER === */
.site-footer {
    margin-top: 48px;
    padding: 16px 0;
    border-top: 1px solid rgba(0,0,0,0.04);
    background: rgba(255,255,255,0.3);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

/* === RESPONSIVE === */
@media (max-width: 600px) {
    body { font-size: 16px; }
    .container { padding: 0 12px; }

    .site-logo { font-size: 16px; }
    .nav-link { font-size: 13px; }

    .post-article { padding: 20px 16px; }
    .post-body { font-size: 16px; }
    .post-body pre { font-size: 12px; }
    .post-body table { font-size: 11px; }

    .feed-title { font-size: 16px; }
    
    /* Убираем лишние отступы у редактора */
    .editor-outer { padding: 16px 0 200px; }
    .title-input { padding: 8px 0 4px; }
}

/* Stats page */
.stats-cards {
    display: -webkit-flex;
    display: flex;
    gap: 16px;
    margin: 20px 0 32px;
    flex-wrap: wrap;
}

.stat-card {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 28px;
    text-align: center;
    min-width: 150px;
    flex: 1;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.1;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Charts */
.chart-container {
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 20px 12px;
    margin-bottom: 28px;
    overflow-x: auto;
}

.chart-bars {
    display: -webkit-flex;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 200px;
    min-width: 620px;
}

.chart-bar-wrapper {
    flex: 1;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    align-items: center;
    height: 100%;
    -webkit-justify-content: flex-end;
    justify-content: flex-end;
}

.chart-bar {
    width: 100%;
    max-width: 18px;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    position: relative;
    transition: background 0.15s;
}

.chart-bar:hover {
    background: var(--accent-hover);
}

.chart-bar-green {
    background: #10b981;
}

.chart-bar-green:hover {
    background: #059669;
}

.chart-value {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

.chart-label {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 6px;
    white-space: nowrap;
    transform: rotate(-45deg);
    transform-origin: top left;
}

@media (max-width: 600px) {
    .stats-cards {
        gap: 8px;
    }
    .stat-card {
        padding: 14px 16px;
        min-width: 120px;
    }
    .stat-value {
        font-size: 28px;
    }
    .chart-bars {
        height: 140px;
        min-width: 400px;
    }
    .chart-bar {
        max-width: 12px;
    }
    .chart-label {
        font-size: 7px;
    }
}

.form-agreement {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

.form-agreement a {
    color: var(--accent);
    text-decoration: none;
}

.form-agreement a:hover {
    text-decoration: underline;
}

.site-footer a {
    color: var(--text-muted);
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.footer-sep {
    color: var(--border);
    margin: 0 6px;
}

.post-body h1 { font-size: 1.7em; font-weight: 700; margin: 1.5em 0 0.5em; line-height: 1.3; }
.post-body h2 { font-size: 1.35em; font-weight: 700; margin: 1.2em 0 0.4em; line-height: 1.3; }
.post-body h3 { font-size: 1.15em; font-weight: 700; margin: 1em 0 0.3em; line-height: 1.3; }

/* Блок Поделиться */
.share-block {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.share-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 4px;
}
.share-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.share-icon:hover { opacity: 0.8; }
.share-icon svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}
.share-icon.tg  { background: #2AABEE; }
.share-icon.wa  { background: #25D366; }
.share-icon.vk  { background: #0077FF; }
.share-icon.x   { background: #000; }
.share-icon.copy-btn {
    width: auto;
    padding: 0 14px;
    border-radius: 18px;
    background: #f0f0f0;
    color: #333;
    font-size: 13px;
    font-weight: 500;
    gap: 4px;
    font-family: inherit;
}
.share-icon.copy-btn:hover { background: #e0e0e0; opacity: 1; }

@media (max-width: 600px) {
    .share-icon { width: 32px; height: 32px; }
    .share-icon svg { width: 16px; height: 16px; }
    .share-icon.copy-btn { font-size: 12px; padding: 0 10px; }
}

/* Переопределяем блок Поделиться */
.share-block {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 48px;
    padding-top: 0;
    border-top: none;
    flex-wrap: wrap;
}
.share-label {
    font-size: 12px;
    color: #bbb;
    font-weight: 400;
    letter-spacing: 0.3px;
}
.share-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
    flex-shrink: 0;
    opacity: 0.7;
}
.share-icon:hover { opacity: 1; }
.share-icon svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}
.share-icon.tg  { background: #2AABEE; }
.share-icon.wa  { background: #25D366; }
.share-icon.vk  { background: #0077FF; }
.share-icon.x   { background: #000; }
.share-icon.copy-btn {
    width: auto;
    height: 32px;
    padding: 0 14px;
    border-radius: 16px;
    background: transparent;
    color: #bbb;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.3px;
    border: 1px solid #e5e5e5;
    gap: 4px;
    font-family: inherit;
    opacity: 1;
}
.share-icon.copy-btn:hover {
    background: #f5f5f5;
    color: #888;
    opacity: 1;
}

@media (max-width: 600px) {
    .share-icon { width: 30px; height: 30px; }
    .share-icon svg { width: 15px; height: 15px; }
    .share-icon.copy-btn { font-size: 11px; padding: 0 10px; }
}

/* Переопределяем — стиль как у back-link */
.share-block {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    padding: 0;
    border: none;
    flex-wrap: wrap;
}
.share-label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
    border: none;
    letter-spacing: 0;
}
.share-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    flex-shrink: 0;
    opacity: 0.65;
    transition: opacity 0.15s;
}
.share-icon:hover { opacity: 1; }
.share-icon svg { width: 15px; height: 15px; fill: #fff; }
.share-icon.tg  { background: #2AABEE; }
.share-icon.wa  { background: #25D366; }
.share-icon.vk  { background: #0077FF; }
.share-icon.x   { background: #000; }
.share-icon.copy-btn {
    width: auto;
    height: 30px;
    padding: 0 14px;
    border-radius: 15px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 400;
    border: 1px solid var(--border);
    gap: 4px;
    font-family: inherit;
    opacity: 1;
}
.share-icon.copy-btn:hover {
    background: #f5f5f5;
    color: var(--text);
}

@media (max-width: 600px) {
    .share-icon { width: 28px; height: 28px; }
    .share-icon svg { width: 14px; height: 14px; }
    .share-icon.copy-btn { font-size: 13px; padding: 0 10px; }
}
.post-article::before {
    content: '';
    position: absolute;
    top: -100px; right: -100px;
    width: 300px; height: 300px;
    background: radial-gradient(circle, rgba(100,150,255,0.15) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}
.post-article::after {
    content: '';
    position: absolute;
    bottom: -60px; left: -60px;
    width: 200px; height: 200px;
    background: radial-gradient(circle, rgba(255,150,100,0.1) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.post-article > * {
    position: relative;
    z-index: 1;
}