* { box-sizing: border-box; font-family: Arial, sans-serif; }
body { margin: 0; background: #111; color: #f4f4f4; line-height: 1.45; }
a { color: inherit; }
.hidden { display: none !important; }

header { padding: 18px 20px; background: #1f1f1f; border-bottom: 1px solid #333; }
header h1 { margin: 0 0 4px; }
header p { margin: 0; color: #b9b9b9; }
.header-inner { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-settings { background: none; border: 1px solid #444; color: #f4f4f4; font-size: 22px; width: 42px; height: 42px; border-radius: 8px; cursor: pointer; transition: background .15s; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.btn-settings:hover { background: #2b2b2b; }
.btn-settings-vertical { width: 58px; height: 58px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; line-height: 1; font-size: 18px; }
.btn-settings-label { font-size: 10px; color: #dcdcdc; }
.btn-icon { background: #333; border: 1px solid #555; color: #f4f4f4; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 16px; }
.btn-icon:hover { background: #444; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px; background: #161616; border-bottom: 1px solid #333; }
.tabs button { width: auto; margin: 0; padding: 10px 12px; border: 1px solid #444; background: #222; color: #fff; cursor: pointer; border-radius: 8px; transition: background-color .18s ease, border-color .18s ease, transform .12s ease; }
.tabs button:hover { background: #2b2b2b; }
.tabs button.active { background: #cf0821; border-color: #cf0821; }

main { padding: 16px; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(340px, 1fr); gap: 14px; align-items: start; }
.modules-column { min-width: 0; }
.preview-column { position: sticky; top: 12px; }
.preview-card, .tab-content { background: #1b1b1b; border: 1px solid #333; border-radius: 10px; padding: 16px; }
.tab-content { display: none; }
.tab-content.active { display: block; }
h2, h3, h4, p { margin-top: 0; }

label { display: block; margin: 10px 0; }
input, select, textarea, button { width: 100%; padding: 9px 10px; margin-top: 5px; background: #101010; color: #f4f4f4; border: 1px solid #444; border-radius: 8px; }
textarea { resize: vertical; }
button { width: auto; margin-right: 8px; background: #222; cursor: pointer; }
button:hover { border-color: #666; }
small { color: #b9b9b9; }
code { background: #2a2a2a; padding: 1px 4px; border-radius: 4px; }

canvas { background: #fff; border-radius: 8px; padding: 8px; margin-top: 12px; max-width: 100%; }
table { width: 100%; border-collapse: collapse; margin-top: 12px; background: #fff; color: #000; border-radius: 8px; overflow: hidden; display: block; overflow-x: auto; }
th, td { border: 1px solid #d8d8d8; padding: 8px; text-align: left; }

.form-actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 10px; }
.form-actions-row button { margin-right: 0; }
.muted { color: #bdbdbd; font-size: 13px; }
.notice { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 14px; line-height: 1.5; }
.notice-warn { background: #3a2a00; border: 1px solid #f0a500; color: #ffd166; }
.notice-warn a { color: #ffd166; }
.notice-warn code { background: #4a3500; }
.notice-ok { background: #0d2b1a; border: 1px solid #2ecc71; color: #a8f5c8; }

.preview-html-render, .review-preview-pane {
    margin-top: 6px;
    border: 1px solid #3a3a3a;
    background: #ffffff;
    color: #1d1d1d;
    border-radius: 8px;
    padding: 12px;
    overflow: auto;
}
.preview-html-render { min-height: 220px; }
.review-preview-pane { min-height: 300px; font-size: 0.95rem; line-height: 1.6; }
.preview-html-render h1, .preview-html-render h2, .preview-html-render h3,
.review-preview-pane h1, .review-preview-pane h2, .review-preview-pane h3 { margin: 0 0 8px; line-height: 1.25; }
.preview-html-render p, .review-preview-pane p { margin: 0 0 10px; }
.preview-html-render img, .review-preview-pane img { max-width: 100%; height: auto; border-radius: 6px; margin: 8px 0; }

.articles-list, .folder-structure, .settings-sites-list { margin-top: 8px; display: grid; gap: 8px; }
.article-row, .folder-item, .settings-site-card, .module-b-panel { border: 1px solid #3a3a3a; border-radius: 8px; background: #171717; padding: 10px; }
.article-row.active, .folder-item.active { border-color: #cf0821; box-shadow: 0 0 0 1px rgba(207, 8, 33, 0.35) inset; }
.folder-item { cursor: pointer; }
.folder-item:hover { border-color: #5a5a5a; }
.folder-title, .article-row-title { font-weight: 700; }

.file-browser-grid, .settings-site-grid, .chart-form-grid, .module-b-simple-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.image-gallery, .uploads-photo-grid, .wiki-charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 10px; }
.image-card, .uploads-photo-item, .picker-img-card, .wiki-chart-figure { border: 1px solid #333; border-radius: 8px; padding: 8px; background: #171717; }
.wiki-chart-figure { background: #fafafa; border-color: #e5e5e5; color: #1d1d1d; }
.image-thumb, .picker-img-thumb { width: 100%; height: 140px; object-fit: cover; border-radius: 6px; background: #0d0d0d; }
.image-caption, .picker-img-name, .uploads-photo-name { margin: 6px 0; font-size: 12px; color: #d0d0d0; word-break: break-word; }
.gallery-item { width: 100%; margin: 0; text-align: left; background: #2b2b2b; color: #fff; border: 1px solid #555; border-radius: 8px; }
.gallery-item:hover { background: #333; }

.module-b-panel h3 { margin-bottom: 6px; }
.module-b-panel .muted { margin-bottom: 0; }
.module-b-section-head, .settings-sites-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 14px 0 10px; }
.settings-key-row, .settings-site-actions, .modal-actions, .custom-chart-actions, .postgara-toolbar, .postgara-summary-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.settings-key-row input { flex: 1; }
.settings-site-actions button, .modal-actions button, .custom-chart-actions button, .postgara-toolbar button { margin-right: 0; }
.btn-sm { width: auto; padding: 8px 10px; font-size: 12px; }
.btn-sm-danger { border-color: #8b2a2a; color: #ffb7b7; }
.btn-sm-danger:hover { border-color: #c34b4b; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 1000; }
.modal.hidden { display: none !important; }
.modal-panel { width: min(720px, 100%); max-height: 90vh; overflow: auto; background: #1b1b1b; border: 1px solid #333; border-radius: 12px; padding: 16px; }
.modal-panel-wide { width: min(980px, 100%); }
.modal-panel-settings { width: min(860px, 100%); }

.img-picker-body { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: 12px; }
.img-picker-folders, .img-picker-gallery { min-height: 200px; }

.auto-media-figure, .auto-chart-figure { margin: 0 0 16px; }
.auto-chart-figure figcaption { font-weight: 700; margin-bottom: 6px; color: #1d1d1d; }
.auto-chart-figure .muted { color: #5b5b5b; margin-bottom: 6px; }
.preview-appendix { margin-top: 16px; padding-top: 12px; border-top: 1px solid #e3e3e3; }
.preview-appendix-wiki ul { margin: 0 0 12px 18px; color: #1d1d1d; }
.inline-chart-figure { border: 1px solid #e5e5e5; border-radius: 8px; padding: 10px; background: #fafafa; }
.inline-chart-figure img, .wiki-chart-figure img { width: 100%; height: auto; display: block; border-radius: 6px; margin: 0; }

.h2-image-flex { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid #e5e5e5; }
.h2-image-left { width: 36%; flex: 0 0 36%; }
.h2-image-left img { width: 100%; height: auto; border-radius: 6px; display: block; }
.h2-image-right { width: 64%; flex: 1; }

.postgara-guide-grid, .postgara-summary-grid, .postgara-group-grid { display: grid; gap: 12px; }
.postgara-guide-grid { grid-template-columns: 1fr; margin: 12px 0; }
.postgara-guide-card, .postgara-summary-card, .postgara-group-section, .postgara-group-chart-card, .chart-panel, .chart-card, .bio-card, .result-card, .status-box, .timeline-section { background: #111; border: 1px solid #2e2e2e; border-radius: 12px; padding: 12px; }
.postgara-summary-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.postgara-summary-item { padding: 10px; border: 1px solid #303030; border-radius: 10px; background: #181818; display: flex; flex-direction: column; gap: 4px; }
.postgara-summary-item.accent { border-color: #cf0821; }
.postgara-inline-status { min-height: 20px; margin-bottom: 10px; }
.postgara-boxes-container { display: flex; flex-direction: column; gap: 18px; margin-top: 16px; }
.postgara-group-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.postgara-group-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.postgara-group-chart-title { font-weight: 700; margin-bottom: 8px; }
.postgara-group-chart-wrap { background: #fff; border-radius: 10px; padding: 10px; }
.postgara-group-chart-note { margin-top: 8px; }
.postgara-team-actions.postgara-team-actions-simple { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.postgara-team-actions.postgara-team-actions-simple button { font-size: 12px; padding: 8px; }
.postgara-comment-input { min-height: 84px; }
.postgara-team-chart-container canvas { max-height: 170px; }
.postgara-empty-state, .chart-empty { border: 1px dashed #4a4a4a; border-radius: 10px; padding: 14px; color: #bdbdbd; background: #161616; }

.timeline-list { display: grid; gap: 10px; }
.timeline-item { display: grid; grid-template-columns: 72px 20px minmax(0, 1fr); gap: 10px; align-items: start; }
.timeline-year { font-weight: 700; color: #f4f4f4; }
.timeline-rail { position: relative; min-height: 100%; }
.timeline-rail::before { content: ''; position: absolute; left: 9px; top: 0; bottom: 0; width: 2px; background: #333; }
.timeline-dot { position: relative; width: 20px; height: 20px; border-radius: 999px; background: #cf0821; border: 3px solid #1b1b1b; z-index: 1; }
.timeline-card { border: 1px solid #333; border-radius: 10px; background: #171717; padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.timeline-card span { color: #bdbdbd; }

.suggestions { display: grid; gap: 8px; margin-top: 10px; }
.suggestion-item { text-align: left; margin-right: 0; }
.suggestion-item.active { border-color: #cf0821; }
.suggestion-empty { opacity: .7; }

#mod-chart .chart-builder-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
#mod-chart .chart-meta-pill { background: #151515; border: 1px solid #353535; border-radius: 999px; padding: 6px 10px; font-size: 12px; color: #d6d6d6; }
#mod-chart .chart-builder-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
#mod-chart .chart-builder-saved-panel { grid-column: 1 / -1; }
#mod-chart .chart-type-hint { margin-top: -2px; margin-bottom: 8px; }
#mod-chart .custom-chart-list { display: grid; gap: 12px; }
#mod-chart .custom-chart-card { border: 1px solid #343434; border-radius: 10px; padding: 12px; background: #161616; }
#mod-chart .custom-chart-card-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
#mod-chart .custom-chart-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#mod-chart .custom-chart-actions button { margin-right: 0; }
#mod-chart .custom-chart-preview-wrap { min-height: 260px; border: 1px solid #303030; border-radius: 10px; background: #fff; padding: 10px; }
#mod-chart .custom-chart-preview-wrap canvas { width: 100% !important; height: 100% !important; margin-top: 0; }
#mod-chart .custom-chart-preview-wrap-editor { min-height: 320px; }

@media (max-width: 980px) {
    .workspace-grid { grid-template-columns: 1fr; }
    .preview-column { position: static; }
    .postgara-team-actions.postgara-team-actions-simple { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    #mod-chart .chart-builder-grid,
    .file-browser-grid,
    .settings-site-grid,
    .chart-form-grid,
    .module-b-simple-grid,
    .img-picker-body {
        grid-template-columns: 1fr;
    }

    #mod-chart .custom-chart-card-head,
    .module-b-section-head,
    .settings-sites-head,
    .header-inner {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 768px) {
    main { padding: 12px; }
    .tabs { padding: 10px 12px; }
    .tabs button { width: 100%; }
    .h2-image-flex { flex-direction: column; }
    .h2-image-left, .h2-image-right { width: 100%; flex: 1 1 auto; }
    .timeline-item { grid-template-columns: 1fr; }
    .timeline-rail { display: none; }
    .postgara-team-actions.postgara-team-actions-simple { grid-template-columns: 1fr; }
}
