html, body {
    height:100%;
    margin:0;
    font-family:Arial, sans-serif;
    background:#f2f2f2;
}
body {
    display:flex;
    flex-direction:column;
}

/* ===== HEADER ===== */
header {
    background:#222;
    color:#eee;
    padding:20px;
}
.header-inner {
    display:flex;
    align-items:center;
    gap:25px;
}
.header-text p {
    margin:0;
    color:#bbb;
}
.topnav {
    margin-top:15px;
}
.topnav a {
    color:#eee;
    margin-right:20px;
    text-decoration:none;
    font-weight:bold;
}

/* ===== LAYOUT ===== */
.wrap {
    flex:1;
    display:flex;
}
.sidenav {
    width:260px;
    background:#ddd;
    padding:15px;
}
.sidenav a {
    display:block;
    padding:6px 8px;
    color:#000;
    text-decoration:none;
}
.sidenav a:hover {
    background:#bbb;
}

main {
    flex:1;
    padding:20px;
    background:#fff;
}

/* ===== CONTROLS ===== */
.controls {
    display:flex;
    gap:20px;
    align-items:center;
    margin-bottom:25px;
    padding:10px;
    background:#f4f4f4;
    border:1px solid #ddd;
}
.controls label {
    font-size:14px;
}

/* ===== GRID ===== */
.grid {
    display:grid;
    gap:15px;
    row-gap:40px;
}
.tile {
    background:#fff;
    padding:5px;
    box-shadow:0 2px 5px rgba(0,0,0,.1);
}
.tile img {
    object-fit:contain;
    background:#eee;
}
.info-row {
    margin-top:6px;
    display:flex;
    justify-content:space-between;
    font-size:14px;
}
.download-btn {
    background:#28a745;
    color:#fff;
    text-decoration:none;
    padding:2px 6px;
    border-radius:3px;
    font-size:12px;
}

/* ===== FOOTER ===== */
footer {
    margin-top:auto;
    background:#222;
    color:#aaa;
    padding:15px;
    font-size:13px;
    text-align:center;
}
footer a { color:#aaa; }


.folder-note {
    margin-bottom: 25px;
    padding: 12px 15px;
    background: #f6f6f6;
    border-left: 4px solid #444;
    font-size: 15px;
    line-height: 1.4;
    color: #333;
    max-width: 1600px;
}

/* =====================================================
   СТРАНИЦА СТАТЕЙ (articles.php)
   ===================================================== */
main.articles-page {
    flex: 1;
    padding: 40px;
    background: #fff;
    max-width: 1100px;
    margin: 0 auto;
    box-sizing: border-box;
    width: 100%;
}
.articles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(375px, 1fr));
    gap: 25px;
}
.article-tile {
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,.1);
    display: flex;
    flex-direction: column;
    border-radius: 4px;
    overflow: hidden;
    transition: box-shadow .15s;
}
.article-tile:hover { box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.article-tile img {
    width: 100%;
    height: 210px;
    object-fit: cover;
    background: #eee;
    display: block;
}
.article-tile .content {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.article-tile h2 {
    margin: 0 0 8px 0;
    font-size: 18px;
    line-height: 1.3;
}
.article-tile .date {
    font-size: 14px;
    color: #666;
    margin-bottom: 6px;
}
.article-tile .excerpt {
    font-size: 16px;
    flex: 1;
    overflow: hidden;
    line-height: 1.4;
    color: #333;
}
.article-tile a.more {
    margin-top: 10px;
    text-decoration: none;
    color: #28a745;
    font-weight: bold;
    align-self: flex-start;
}
.article-tile a.more:hover { text-decoration: underline; }

/* =====================================================
   СТРАНИЦА СТАТЬИ (article.php)
   ===================================================== */
main.article-page {
    flex: 1;
    padding: 40px;
    background: #fff;
    max-width: 1100px;
    margin: 0 auto;
    box-sizing: border-box;
    width: 100%;
}
main.article-page .back-btn {
    display: inline-block;
    margin-bottom: 20px;
    text-decoration: none;
    background: #28a745;
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 14px;
}
main.article-page .back-btn:hover { background: #218838; }

main.article-page article img {
    width: 100%;
    max-height: 450px;
    object-fit: cover;
    margin: 20px 0;
    display: block;
}
main.article-page article h2 {
    margin-top: 0;
    font-size: 26px;
}
main.article-page article p,
main.article-page article {
    font-size: 18px;
    line-height: 1.6;
    color: #222;
}

/* Адаптив */
@media (max-width: 800px) {
    main.articles-page,
    main.article-page { padding: 20px; }
    .articles-grid { grid-template-columns: 1fr; }
    main.article-page article { font-size: 16px; }
}



/* =====================================================
   РЕДАКТОР (editor.php, editor-edit.php, editor-images.php)
   ===================================================== */
.editor-page {
    flex: 1;
    padding: 30px;
    background: #fff;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.editor-header h2 { margin: 0; }

.editor-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: bold;
    text-decoration: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #fff;
    line-height: 1.2;
    font-family: inherit;
}
.btn:hover { filter: brightness(0.95); }
.btn-green { background: #28a745; }
.btn-blue  { background: #2f7ed8; }
.btn-red   { background: #c0392b; }
.btn-gray  { background: #666; }
.btn-small { padding: 5px 10px; font-size: 13px; }

.notice {
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 15px;
}
.notice-ok  { background: #d4edda; color: #155724; border-left: 4px solid #28a745; }
.notice-err { background: #f8d7da; color: #721c24; border-left: 4px solid #c0392b; }

/* Таблица списка */
.editor-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.editor-table th,
.editor-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
    font-size: 14px;
    vertical-align: top;
}
.editor-table th { background: #f4f4f4; font-weight: bold; }
.editor-table tr:hover { background: #fafafa; }
.editor-table .id-cell { font-family: monospace; color: #666; }
.editor-table .row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.editor-table .row-actions form { margin: 0; }

/* Форма редактирования */
.edit-form {
    background: #fff;
    padding: 22px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.edit-form label {
    display: block;
    margin: 15px 0 5px;
    font-weight: bold;
    font-size: 14px;
}
.edit-form input[type=text],
.edit-form input[type=date],
.edit-form select,
.edit-form textarea {
    width: 100%;
    padding: 9px 11px;
    font-size: 15px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
}
.edit-form textarea {
    min-height: 420px;
    resize: vertical;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 14px;
    line-height: 1.55;
}
.edit-form .row {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}
.edit-form .row > div { flex: 1; min-width: 200px; }
.edit-form .col-narrow { max-width: 220px; }

.edit-actions {
    margin-top: 22px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.hint {
    font-size: 13px;
    color: #666;
    margin: 4px 0 10px;
    line-height: 1.5;
}
.hint code {
    background: #f2f2f2;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}

.editor-toolbar-inline {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
    padding: 8px;
    background: #f4f4f4;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.img-field-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.img-field-row input[type=text] { flex: 1; min-width: 200px; }

.img-preview {
    max-width: 180px;
    max-height: 130px;
    border-radius: 4px;
    border: 1px solid #ddd;
    display: block;
}

.preview-box {
    margin-top: 15px;
    padding: 18px 22px;
    background: #fafafa;
    border: 1px dashed #bbb;
    border-radius: 4px;
    line-height: 1.6;
    font-size: 16px;
}
.preview-box .article-figure { margin: 15px 0; }

/* Модалка */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal.open { display: flex; }
.modal-inner {
    background: #fff;
    padding: 22px;
    border-radius: 6px;
    max-width: 900px;
    max-height: 82vh;
    overflow-y: auto;
    width: 92%;
    box-sizing: border-box;
}
.modal-inner h3 { margin-top: 0; }
.modal-inner input[type=text] {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 15px;
    box-sizing: border-box;
}
.modal-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.img-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    margin: 15px 0;
}
.img-grid .item {
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    overflow: hidden;
    background: #eee;
    transition: border-color .15s;
}
.img-grid .item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
}
.img-grid .item.selected { border-color: #28a745; }
.img-grid .item:hover { border-color: #2f7ed8; }
.img-grid .item .label {
    padding: 4px 6px;
    font-size: 11px;
    background: #fff;
    word-break: break-all;
    line-height: 1.3;
}

/* Страница картинок */
.upload-form {
    background: #f4f4f4;
    padding: 18px;
    border-radius: 6px;
    border: 1px solid #ddd;
    margin-bottom: 25px;
}
.upload-form label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 14px;
}
.upload-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.upload-row input[type=file] { flex: 1; min-width: 200px; }

.img-admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
}
.img-admin-item {
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,.08);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.img-admin-thumb {
    display: block;
    background: #eee;
    border-radius: 4px;
    overflow: hidden;
    aspect-ratio: 1 / 1;
}
.img-admin-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.img-admin-name {
    font-size: 12px;
    word-break: break-all;
    font-family: monospace;
    color: #333;
}
.img-admin-meta { font-size: 12px; color: #777; }

/* Фигуры в тексте статьи (article.php) */
main.article-page .article-figure {
    margin: 25px 0;
    text-align: center;
}
main.article-page .article-figure img {
    max-width: 100%;
    height: auto;
    max-height: none;
    object-fit: contain;
    margin: 0;
    border-radius: 4px;
    display: block;
    margin: 0 auto;
}
main.article-page .article-figure figcaption {
    font-size: 14px;
    color: #666;
    margin-top: 6px;
    font-style: italic;
}
main.article-page .article-cover {
    width: 100%;
    max-height: 450px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 25px;
    display: block;
}

/* Адаптив */
@media (max-width: 800px) {
    .editor-page { padding: 15px; }
    .editor-table th:nth-child(1),
    .editor-table td:nth-child(1) { display: none; }
    .edit-form textarea { min-height: 300px; }
}


/* =====================================================
   ВИЗУАЛЬНЫЙ РЕДАКТОР (RTE)
   ===================================================== */
.rte {
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-top: 5px;
    background: #fff;
}

.rte-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    background: #f4f4f4;
    border-bottom: 1px solid #ddd;
    border-radius: 4px 4px 0 0;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 5;
}
.rte-group {
    display: flex;
    gap: 2px;
    padding-right: 8px;
    border-right: 1px solid #ddd;
}
.rte-group:last-child { border-right: none; padding-right: 0; }
.rte-group.rte-right { margin-left: auto; }

.rte-btn {
    padding: 5px 10px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
    line-height: 1;
    min-width: 32px;
    color: #333;
}
.rte-btn:hover { background: #e8e8e8; }
.rte-btn.active { background: #2f7ed8; color: #fff; border-color: #2f7ed8; }
.rte-btn.rte-accent { background: #28a745; color: #fff; border-color: #28a745; }
.rte-btn.rte-accent:hover { background: #218838; }

.rte-editor {
    min-height: 480px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 22px 26px;
    font-size: 17px;
    line-height: 1.65;
    outline: none;
    color: #222;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
.rte-editor:focus { background: #fefefe; }

.rte-editor h2 { font-size: 24px; margin: 20px 0 10px; line-height: 1.3; }
.rte-editor h3 { font-size: 20px; margin: 18px 0 8px; line-height: 1.3; }
.rte-editor h4 { font-size: 17px; margin: 15px 0 6px; }
.rte-editor p { margin: 0 0 12px; }
.rte-editor blockquote {
    margin: 15px 0;
    padding: 8px 18px;
    border-left: 4px solid #888;
    background: #f8f8f8;
    color: #444;
    font-style: italic;
}
.rte-editor ul, .rte-editor ol { margin: 10px 0 15px; padding-left: 28px; }
.rte-editor li { margin: 4px 0; }
.rte-editor a { color: #2f7ed8; text-decoration: underline; }
.rte-editor hr { border: none; border-top: 1px solid #ccc; margin: 20px 0; }
.rte-editor code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 14px;
}
.rte-editor pre {
    background: #f0f0f0;
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    font-family: monospace;
    font-size: 14px;
}
.rte-editor figure {
    margin: 20px 0;
    text-align: center;
}
.rte-editor figure img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    display: block;
    margin: 0 auto;
}
.rte-editor figure figcaption {
    font-size: 14px;
    color: #666;
    margin-top: 6px;
    font-style: italic;
}
.rte-editor img { max-width: 100%; height: auto; }

.rte-html {
    width: 100%;
    min-height: 480px;
    padding: 15px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
    border: none;
    outline: none;
    box-sizing: border-box;
    resize: vertical;
}

/* Табы в модалке выбора картинки */
.picker-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #ddd;
}
.picker-tab {
    padding: 8px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    color: #666;
    font-family: inherit;
}
.picker-tab:hover { color: #222; }
.picker-tab.active { color: #28a745; border-bottom-color: #28a745; }

#uploadFile {
    display: block;
    margin: 10px 0;
    padding: 8px;
    border: 1px dashed #ccc;
    border-radius: 4px;
    width: 100%;
    box-sizing: border-box;
}

.modal-inner select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 15px;
    box-sizing: border-box;
}

/* Мобильная адаптация тулбара */
@media (max-width: 800px) {
    .rte-toolbar { position: static; }
    .rte-group { border-right: none; }
    .rte-group.rte-right { margin-left: 0; }
    .rte-editor { padding: 15px; font-size: 16px; min-height: 350px; }
}



/* =====================================================
   АДМИНКА — дашборд
   ===================================================== */
.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}
.dash-card {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 22px 20px;
    border-radius: 8px;
    border-left: 4px solid #28a745;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.dash-value {
    font-size: 32px;
    font-weight: bold;
    color: #222;
    line-height: 1.1;
}
.dash-label {
    font-size: 14px;
    color: #555;
    margin-top: 6px;
}
.dash-label code {
    background: rgba(0,0,0,.06);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}
.dash-sub {
    font-size: 12px;
    color: #888;
    margin-top: 8px;
}
.dash-sub a { color: #2f7ed8; }

.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 15px;
}
.qa-card {
    display: block;
    padding: 20px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    text-decoration: none;
    color: #222;
    transition: transform .15s, box-shadow .15s;
    border: 1px solid #eee;
}
.qa-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,.12);
    border-color: #28a745;
}
.qa-icon { font-size: 32px; margin-bottom: 8px; }
.qa-title { font-weight: bold; font-size: 16px; margin-bottom: 4px; }
.qa-desc { font-size: 13px; color: #666; }
.qa-desc code {
    background: #f0f0f0;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}

.upload-target-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.upload-target-row select,
.upload-target-row input {
    padding: 9px 11px;
    font-size: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
    flex: 1;
    min-width: 220px;
}

/* Красная «Выйти» в навигации */
.topnav a[href*="logout"] {
    font-weight: normal;
}


/* =====================================================
   СТАТИСТИКА
   ===================================================== */
.spark {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 120px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #eee;
    margin-bottom: 6px;
}
.spark-bar {
    flex: 1;
    min-width: 4px;
    background: linear-gradient(to top, #28a745, #4fd06b);
    border-radius: 2px 2px 0 0;
    transition: opacity .15s;
}
.spark-bar:hover { opacity: .75; }
.spark-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #888;
    padding: 0 4px;
    margin-bottom: 30px;
}

.stats-cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 25px;
    margin-top: 25px;
}
.stats-col h3 {
    margin: 0 0 12px;
    font-size: 16px;
    color: #333;
}
.stats-col .editor-table {
    font-size: 13px;
}
.stats-col .editor-table td,
.stats-col .editor-table th {
    padding: 6px 10px;
}
.stats-col .editor-table a {
    color: #2f7ed8;
    text-decoration: none;
    word-break: break-all;
}
.stats-col .editor-table a:hover { text-decoration: underline; }

.log-tail {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 15px;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.5;
    max-height: 500px;
    overflow: auto;
    white-space: pre;
    font-family: ui-monospace, Menlo, Consolas, monospace;
}

@media (max-width: 800px) {
    .stats-cols { grid-template-columns: 1fr; }
    .spark { height: 80px; }
}