body {
    background: #1a1a1a;
    color: #ccc;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
}
.header {
    background: linear-gradient(135deg, #2a2a2a 0%, #111 100%);
    border-bottom: 2px solid #444;
}
.banner img {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    display: block;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: #222;
    border-bottom: 1px solid #333;
}
.logo {
    display: flex;
    align-items: center;
    gap: 15px;
}
.logo img {
    width: 64px !important;
    height: 64px !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
}
.sitename {
    font-size: 28px;
    font-weight: bold;
    color: white;
    letter-spacing: 2px;
}
.time {
    color: #aaa;
    font-size: 14px;
    margin-left: 15px;
    font-family: 'Courier New', monospace;
    min-width: 70px;
}
.nav a {
    color: white;
    text-decoration: underline;
    margin: 0 12px;
    font-size: 16px;
}
.nav a:hover {
    color: #ffcc00;
}
.container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
    background: #2a2a2a;
    border-radius: 8px;
    border: 1px solid #444;
    box-shadow: 0 0 15px rgba(0,0,0,0.7);
}
a {
    color: white;
    text-decoration: underline;
}
a:hover {
    color: #ffcc00;
}
.card {
    background: #333;
    padding: 15px;
    border-radius: 6px;
    border: 1px solid #555;
    margin-bottom: 15px;
}
.flashes {
    list-style: none;
    padding: 0;
    color: #ffaa00;
}
input, textarea, select {
    background: #222;
    color: #ddd;
    border: 1px solid #555;
    padding: 8px;
    border-radius: 4px;
    width: 100%;
    margin-bottom: 10px;
}
input[type="file"] {
    padding: 5px;
}
button, .btn {
    background: #444;
    color: white;
    border: 1px solid #666;
    padding: 8px 20px;
    border-radius: 4px;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
}
button:hover, .btn:hover {
    background: #555;
    color: #ffcc00;
}

/* ==========================================================================
   СЕТКА ДЛЯ СТРАНИЦЫ СТАТЕЙ (То, что пропадало)
   ========================================================================== */
.articles-page {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    width: 100%;
}
.articles-main {
    flex: 1 1 auto;
    min-width: 0;
}
.articles-sidebar {
    width: 320px;
    flex: 0 0 320px;
}
@media (max-width: 992px) {
    .articles-page { flex-direction: column; }
    .articles-sidebar { width: 100%; }
}

/* Профиль */
.profile-avatar { max-width: 200px; border-radius: 8px; border: 2px solid #666; }
.profile-container { max-width: 900px; margin: 0 auto; }
.profile-header { display: flex; gap: 30px; align-items: flex-start; background: #333; padding: 25px; border-radius: 8px; border: 1px solid #555; margin-bottom: 30px; }
.profile-avatar-large { width: 256px; height: 256px; object-fit: cover; border-radius: 8px; border: 2px solid #666; flex-shrink: 0; }
.profile-info { flex: 1; }
.profile-info h1 { color: white; margin-top: 0; }
.profile-info p { color: #ccc; }
.profile-articles h2 { color: white; border-bottom: 1px solid #444; padding-bottom: 10px; }
@media (max-width: 768px) { .profile-header { flex-direction: column; align-items: center; text-align: center; } .profile-avatar-large { width: 150px; height: 150px; } }

/* Карточки статей */
.article-card { background: #2a2a2a; border: 1px solid #444; border-radius: 8px; overflow: hidden; margin-bottom: 25px; cursor: pointer; transition: all 0.3s ease; }
.article-card:hover { border-color: #666; transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
.article-banner { width: 100%; aspect-ratio: 2/1; overflow: hidden; background: #1a1a1a; }
.article-banner img { width: 100%; height: 100%; object-fit: cover; }
.article-content { padding: 20px; }
.article-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; margin-bottom: 10px; }
.article-title { color: white; font-size: 24px; margin: 0; font-weight: 600; }
.article-category { background: #444; color: #aaa; padding: 4px 12px; border-radius: 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; flex-shrink: 0; }
.article-short { color: #bbb; font-size: 15px; line-height: 1.6; margin: 10px 0; }
.article-meta { display: flex; gap: 20px; color: #888; font-size: 13px; }

/* Боковая панель (Сайдбар) */
.sidebar-block { background: #2a2a2a; border: 1px solid #444; border-radius: 8px; padding: 20px; margin-bottom: 20px; }
.sidebar-block h3 { color: white; font-size: 16px; margin: 0 0 15px 0; border-bottom: 1px solid #444; padding-bottom: 10px; }
.sidebar-block input[type="text"] { width: 100%; padding: 8px 12px; border: 1px solid #555; border-radius: 4px; background: #222; color: #ddd; box-sizing: border-box; }
.sidebar-block button { width: 100%; margin-top: 8px; padding: 8px; background: #444; color: white; border: 1px solid #666; border-radius: 4px; cursor: pointer; }
.sidebar-block button:hover { background: #555; }
.category-list { list-style: none; padding: 0; margin: 0; }
.category-list li { margin-bottom: 6px; }
.category-list a { color: #ccc; text-decoration: none; display: block; padding: 6px 10px; border-radius: 4px; transition: all 0.2s; }
.category-list a:hover { background: #444; color: white; }
.category-list a.active { background: #555; color: white; }

.btn-create { display: block; text-align: center; background: #555; color: white; padding: 12px; border-radius: 6px; text-decoration: none; font-weight: bold; border: 1px solid #777; transition: all 0.3s; }
.btn-create:hover { background: #666; border-color: #888; color: white; }

/* Просмотр статьи */
.article-view-header { margin-bottom: 30px; }
.article-view-banner { width: 100%; aspect-ratio: 2/1; object-fit: cover; border-radius: 8px; }
.article-view-title { padding: 20px 0; }
.article-view-title h1 { color: white; font-size: 32px; margin: 0 0 10px 0; }
.article-view-meta { display: flex; gap: 20px; color: #888; font-size: 14px; align-items: center; }
.category-tag { background: #444; color: #aaa; padding: 4px 14px; border-radius: 4px; font-size: 12px; text-transform: uppercase; }
.article-view-content { color: #ddd; font-size: 16px; line-height: 1.8; padding: 20px 0; }
.article-actions { display: flex; gap: 15px; margin-top: 30px; padding-top: 20px; border-top: 1px solid #444; }
.btn-edit, .btn-delete { padding: 8px 20px; border-radius: 4px; text-decoration: none; }
.btn-edit { background: #444; color: white; }
.btn-delete { background: #5a2222; color: #ff6666; }

/* Редактирование статьи */
.article-edit { max-width: 800px; margin: 0 auto; }
.article-edit h2 { color: white; border-bottom: 1px solid #444; padding-bottom: 15px; margin-bottom: 25px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; color: #ccc; font-weight: bold; margin-bottom: 6px; font-size: 14px; }
.form-group textarea { resize: vertical; font-family: inherit; }
.btn-cancel { display: inline-block; padding: 10px 24px; background: #333; color: #ccc; text-decoration: none; border-radius: 4px; margin-left: 10px; }
.empty-state { text-align: center; padding: 60px 20px; color: #888; }

/* ==========================================================================
   СЕТКА ДЛЯ ДЕРЕВА КВЕСТОВ (БЕЗОПАСНАЯ ВЕРСИЯ С ИСПОЛЬЗОВАНИЕМ :has)
   ========================================================================== */

body:has(.quest-grid-master) .container.articles-page,
body:has(.quest-grid-master) .articles-page,
body:has(.quest-grid-master) .container {
    max-width: 96% !important;
    width: 96% !important;
    display: block !important; 
}

body:has(.quest-grid-master) .articles-main {
    width: 100% !important;
    max-width: none !important;
    float: none !important;
}

body:has(.quest-grid-master) .articles-sidebar, 
body:has(.quest-grid-master) .sidebar,
.articles-sidebar:empty, 
.sidebar:empty {
    display: none !important;
    width: 0 !important;
}

.quest-grid-master {
    display: flex;
    gap: 25px;
    align-items: flex-start;
    width: 100%;
}

.quest-master-left {
    flex: 1 1 auto;
    min-width: 0;
    width: calc(100% - 345px);
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 0 20px rgba(0,0,0,0.8);
}

.quest-master-right {
    width: 320px;
    flex: 0 0 320px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media (max-width: 1200px) {
    .quest-grid-master { flex-direction: column; }
    .quest-master-left { width: 100%; }
    .quest-master-right { width: 100%; flex: 1 1 auto; }
}

/* Окно с деревом */
.graph-wrapper {
    position: relative;
    width: 100%;
    height: 600px; /* fallback до первого рендера; далее высоту подстраивает JS под содержимое */
    min-height: 220px;
    background: #161616;
    border: 1px solid #333;
    border-radius: 6px;
    overflow: hidden;
}

.note-editor.note-frame .note-editing-area .note-editable {
    color: #ffffff !important;
    background-color: #1a1a1a !important;
}

.note-editor.note-frame .note-statusbar {
    background-color: #222 !important;
}

.note-toolbar {
    background: #2a2a2a !important;
    border-bottom: 1px solid #444 !important;
}

.note-toolbar .note-btn {
    background: #333 !important;
    color: #ccc !important;
    border-color: #555 !important;
}

.note-toolbar .note-btn:hover {
    background: #444 !important;
    color: #fff !important;
}

.note-toolbar .note-btn-group .note-btn {
    border-color: #555 !important;
}

.note-toolbar .note-btn-group .note-btn.active {
    background: #555 !important;
    color: #fff !important;
}

.admin-panel {
    max-width: 1000px;
    margin: 0 auto;
}
.admin-panel h1 {
    color: white;
    border-bottom: 2px solid #444;
    padding-bottom: 15px;
    margin-bottom: 30px;
}
.admin-section {
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 25px;
}
.admin-section h2 {
    color: white;
    margin-top: 0;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
}
.admin-table th {
    color: #aaa;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid #444;
    font-weight: normal;
    font-size: 13px;
    text-transform: uppercase;
}
.admin-table td {
    color: #ddd;
    padding: 10px 12px;
    border-bottom: 1px solid #333;
}
.admin-table tr:hover td {
    background: #333;
}
.btn-approve {
    background: #2a5a2a;
    color: #8f8;
    padding: 4px 12px;
    border-radius: 4px;
    text-decoration: none;
    border: 1px solid #3a7a3a;
}
.btn-approve:hover {
    background: #3a7a3a;
}
.btn-deny {
    background: #5a2a2a;
    color: #f88;
    padding: 4px 12px;
    border-radius: 4px;
    text-decoration: none;
    border: 1px solid #7a3a3a;
}
.btn-deny:hover {
    background: #7a3a3a;
}

.nav a.admin-link {
    color: #ffcc00 !important;
    font-weight: bold;
}
.nav a.admin-link:hover {
    color: #ffdd44 !important;
}


#treeView { position: absolute; inset: 0; width: 100%; height: 100%; }
.tree-scroll { width: 100%; height: 100%; overflow: auto; background: #161616; cursor: grab; user-select: none; }
.tree-scroll.is-dragging { cursor: grabbing !important; }
.tree-canvas { position: relative; min-height: 100%; min-width: max-content; }

/* Полосы торговцев */
.tree-lane { position: relative; display: flex; align-items: stretch; border-bottom: 1px solid #262626; z-index: 2; }
.tree-lane-label { position: sticky; left: 0; top: auto; z-index: 6; flex: 0 0 140px; width: 140px; display: flex; align-items: center; padding: 0 14px; font-size: 13px; font-weight: bold; color: #111; box-shadow: 3px 0 8px rgba(0,0,0,0.6); letter-spacing: 0.5px; }
.tree-lane-content { position: relative; flex: 0 0 auto; }
.tree-svg { position: absolute; top: 0; left: 140px; z-index: 1; pointer-events: none; }

/* Плашки квестов */
.quest-node { position: absolute; box-sizing: border-box; border-radius: 4px; border: 1px solid #555; padding: 8px 10px; font-size: 12px; line-height: 1.3; color: #fff; cursor: pointer; overflow: hidden; display: flex; align-items: center; transition: transform .1s, box-shadow .1s, border-color .15s; box-shadow: 0 2px 5px rgba(0,0,0,0.5); user-select: none; }
.quest-node:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.7); border-color: #fff; z-index: 5; }
.quest-node.dimmed { opacity: 0.22; filter: grayscale(60%); }
.quest-node.flash { outline: 2px solid #ffcc00; outline-offset: 2px; z-index: 10; }
.quest-node .qn-name { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; pointer-events: none; }

/* Подсветка пути: выбранный узел / его зависимости (prev) / разблокировки (next) / остальное затемнено */
.quest-node.path-active { border: 2px solid #ffcc00 !important; box-shadow: 0 0 16px rgba(255, 204, 0, 0.55), 0 4px 12px rgba(0,0,0,0.7) !important; z-index: 8; transform: translateY(-2px); }
.quest-node.path-prev { border: 2px solid #4aa3ff !important; box-shadow: 0 0 12px rgba(74, 163, 255, 0.45) !important; z-index: 6; }
.quest-node.path-next { border: 2px solid #ff9d3b !important; box-shadow: 0 0 12px rgba(255, 157, 59, 0.45) !important; z-index: 6; }
.quest-node.path-dim { opacity: 0.18; filter: grayscale(70%); }

.tree-edge { transition: stroke .15s, stroke-width .15s, stroke-opacity .15s; }
.tree-edge.edge-active { filter: drop-shadow(0 0 3px rgba(0,0,0,0.6)); }

.reward-chip-row { position: absolute; display: flex; gap: 3px; flex-wrap: wrap; max-width: 190px; pointer-events: none; }
.reward-chip { background: #222; border: 1px solid #3a3a3a; color: #bbb; font-size: 9.5px; padding: 1px 5px; border-radius: 3px; white-space: nowrap; }
.reward-chip.more { color: #888; border: none; background: transparent; }

/* Выполненные квесты */
.quest-node.completed { border: 2px solid #5cb85c !important; background-blend-mode: multiply; box-shadow: 0 0 10px rgba(92, 184, 92, 0.3), inset 0 0 15px rgba(0,0,0,0.4) !important; }
.quest-node.completed .qn-name::before { content: '✓ '; color: #71d171; font-weight: 900; font-size: 13px; }

/* Кнопка статуса */
.btn-toggle-status { background: #333; border: 1px solid #555; color: #ccc; padding: 7px 16px; border-radius: 4px; cursor: pointer; font-size: 13px; font-weight: bold; transition: 0.2s; }
.btn-toggle-status:hover { background: #444; color: #fff; }
.btn-toggle-status.is-completed { background: #1b351b; border-color: #5cb85c; color: #5cb85c; }
.btn-toggle-status.is-completed:hover { background: #254725; color: #fff; }

/* Карточка внизу */
.quest-detail-bottom { margin-top: 20px; background: #1e1e1e; border: 1px solid #333; border-radius: 6px; display: none; box-shadow: 0 4px 20px rgba(0,0,0,0.6); overflow: hidden; }
.quest-detail-bottom.open { display: block; animation: slideDownCard 0.2s ease-out; }
.quest-detail-bottom .detail-head { background: #111; padding: 14px 20px; border-bottom: 1px solid #262626; display: flex; align-items: center; justify-content: space-between; }
.quest-detail-bottom .detail-head h3 { margin: 0; color: #fff; font-size: 18px; }

#dBadges { display: flex; gap: 8px; align-items: center; }
.badge { font-size: 11px; padding: 3px 8px; border: 1px solid #444; border-radius: 4px; font-weight: 600; background: #222; color: #ccc; }

.close-btn { background: none; border: none; color: #888; font-size: 24px; cursor: pointer; padding: 0 5px; }
.close-btn:hover { color: #fff; }

.quest-detail-bottom .detail-body { padding: 20px; display: flex; flex-wrap: wrap; gap: 25px; }
.detail-section { flex: 1; min-width: 200px; }
.detail-section h4 { margin: 0 0 10px 0; color: #888; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #2c2c2c; padding-bottom: 6px; }
.detail-section ul { margin: 0; padding-left: 20px; color: #ddd; font-size: 13.5px; line-height: 1.6; }

.chip-link { display: inline-block; background: #262626; color: #ccc; padding: 5px 10px; border-radius: 4px; font-size: 12px; margin: 0 6px 6px 0; cursor: pointer; border: 1px solid #3c3c3c; transition: 0.15s; }
.chip-link:hover { border-color: #ffcc00; color: #fff; background: #333; }

.reward-row { display: flex; justify-content: space-between; font-size: 13px; padding: 5px 0; border-bottom: 1px dashed #2c2c2c; color: #ccc; }
.reward-row .v { color: #a1c970; font-weight: bold; }

@keyframes slideDownCard { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ==========================================================================
   СТИЛИ ДЛЯ УБЕЖИЩА (используют ту же систему, что и дерево квестов)
   ========================================================================== */

/* Мини-полоска прогресса внутри плашки мастерской */
.station-frac { position: absolute; top: 6px; right: 8px; font-family: 'Courier New', monospace; font-size: 10px; opacity: 0.85; pointer-events: none; }
.station-bar { position: absolute; left: 0; bottom: 0; width: 100%; height: 3px; background: rgba(0,0,0,0.35); pointer-events: none; }
.station-bar-fill { height: 100%; transition: width 0.2s; }

/* Степпер уровня в шапке детальной панели */
.stepper-controls { display: flex; align-items: center; gap: 8px; }
.stepper-label { font-family: 'Courier New', monospace; font-size: 13px; color: #ccc; min-width: 48px; text-align: center; }
.btn-toggle-status.btn-step { padding: 7px 14px; font-size: 15px; line-height: 1; }
.btn-toggle-status:disabled { opacity: 0.35; cursor: default; }
.btn-toggle-status:disabled:hover { background: #333; color: #ccc; }

/* Блоки уровней мастерской в детальной панели */
.lvl-block { border: 1px solid #2c2c2c; border-radius: 4px; padding: 10px 12px; margin-bottom: 10px; background: #181818; }
.lvl-block.current { border-color: #ffcc00; }
.lvl-block.done { opacity: 0.55; }
.lvl-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 12.5px; }
.lvl-head b { color: #fff; letter-spacing: 0.3px; }
.lvl-head .time { font-family: 'Courier New', monospace; font-size: 10.5px; color: #888; }
.lock-line { color: #d9695a; font-size: 11.5px; margin-top: 6px; font-family: 'Courier New', monospace; line-height: 1.5; }

/* Категории-статусы (переиспользуют .category-list) */
.category-list .status-not-started { color: #888; }
.category-list .status-in-progress { color: #ffcc00; }
.category-list .status-done { color: #5cb85c; }