/* templates/style.css */

/* Локальный Inter */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/lib/fonts/Inter-Regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('/lib/fonts/Inter-Medium.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('/lib/fonts/Inter-SemiBold.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('/lib/fonts/Inter-Bold.woff2') format('woff2');
}

:root {
    --bg: #f8fafc;             /* Прохладный светло-серый */
    --panel: #ffffff;          /* Белый */
    --text: #0f172a;           /* Глубокий темный */
    --muted: #64748b;          /* Серый */
    --border: #e2e8f0;         /* Чуть холоднее границы */
    --accent: #3b82f6;         /* Более яркий синий */
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --radius: 12px;            /* Чуть больше скругления */
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font: 15px/1.6 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 12px 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,0.02);
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); letter-spacing: -.01em; }
.topbar .search { flex: 1; max-width: 480px; }
.topbar .search input {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); font: inherit; color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.topbar .search input:focus {
    outline: none; border-color: var(--accent); background: #fff;
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.topbar .nav { display: flex; gap: 16px; align-items: center; font-size: 14px; }
.topbar .who { color: var(--muted); }

/* ---------- Content ---------- */
.content {
    flex: 1;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 22px 24px;
    min-width: 0; /* <-- ДОБАВИТЬ ВОТ ЭТО */
}

/* ---------- Cards ---------- */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

/* ---------- Typography ---------- */
h1 { margin: 0 0 16px; font-size: 28px; letter-spacing: -.015em; }
h2 { margin: 24px 0 12px; font-size: 20px; letter-spacing: -.01em; }
h3 { margin: 20px 0 10px; font-size: 17px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; padding: 8px 16px;
    border-radius: 8px; border: 1px solid var(--border);
    background: var(--panel); color: var(--text); cursor: pointer;
    font: inherit; font-size: 14px; font-weight: 500;
    transition: all .15s ease;
}
.btn:hover { background: #f1f5f9; border-color: #cbd5e1; text-decoration: none; }
.btn:hover { background: #f2f4f7; border-color: #d0d4da; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: #fff; color: var(--danger); border-color: #f3c1c1; }
.btn-danger:hover { background: #fef2f2; border-color: var(--danger); }

/* ---------- Forms ---------- */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; }
.form-row input[type=text],
.form-row input[type=password],
.form-row input[type=search],
.form-row input[type=email],
.form-row input[type=number],
.form-row select,
.form-row textarea {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: 8px;
    font: inherit; font-size: 14px; background: #fff; color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-row textarea { min-height: 260px; resize: vertical; font-family: inherit; }

/* ---------- Alerts ---------- */
.error {
    background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
    padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px;
}
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 12px 0; }

/* ---------- Spaces list ---------- */
.spaces-list { list-style: none; padding: 0; margin: 0; }
.spaces-list li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.spaces-list li:last-child { border-bottom: 0; }
.spaces-list a { font-weight: 500; }
.spaces-list a:hover { text-decoration: none; color: var(--accent-hover); }
.spaces-list .desc { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* ---------- Wiki links ---------- */
.wiki-link { border-bottom: 1px dashed var(--accent); }
.wiki-link.missing { color: var(--danger); border-bottom-color: var(--danger); }

/* ---------- Comments ---------- */
.comments { margin-top: 24px; }
.comment { padding: 14px 0; border-top: 1px solid var(--border); }
.comment .meta { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.comment .meta strong { color: var(--text); }
.comment .children { margin-left: 22px; border-left: 2px solid var(--border); padding-left: 14px; }

/* ---------- Footer ---------- */
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 32px 0 24px; }

/* ---------- Notif badge ---------- */
.notif-badge {
    display: inline-block; min-width: 18px; padding: 0 6px;
    background: var(--danger); color: #fff; border-radius: 10px;
    font-size: 11px; font-weight: 700; text-align: center; line-height: 18px;
    vertical-align: middle; margin-left: 4px;
}

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
    content: ""; position: absolute; left: 8px; top: 0; bottom: 0;
    width: 2px; background: var(--border);
}
.tl-item { position: relative; padding: 12px 0 12px 12px; }
.tl-marker {
    position: absolute; left: -20px; top: 18px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--accent);
}
.tl-head { display: flex; gap: 8px; align-items: center; font-size: 14px; flex-wrap: wrap; }
.tl-summary { margin-top: 4px; color: var(--text); font-size: 14px; }
.tl-comment {
    margin-top: 6px; background: var(--bg); padding: 8px 10px;
    border-radius: var(--radius); font-size: 14px;
}
.tl-pre {
    margin-top: 6px; padding: 8px 10px; background: var(--bg);
    border-radius: var(--radius); font-size: 12px; max-height: 300px;
    overflow: auto; white-space: pre-wrap; word-break: break-word;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 6px;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
}
.badge-version_create { background: #ede9fe; color: #6d28d9; }
.badge-version_save   { background: #dbeafe; color: #1d4ed8; }
.badge-version_revert { background: #fef3c7; color: #92400e; }
.badge-comment        { background: #dcfce7; color: #15803d; }
.badge-trash          { background: #fee2e2; color: #991b1b; }
.badge-restore        { background: #e0f2fe; color: #0369a1; }

/* ---------- Diff ---------- */
.diff-block {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; padding: 14px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 13px; line-height: 1.6;
    white-space: pre-wrap; word-break: break-word;
    max-height: 600px; overflow: auto;
}
.d-add { background: #dcfce7; color: #166534; padding: 0 2px; border-radius: 3px; }
.d-del { background: #fee2e2; color: #991b1b; padding: 0 2px; border-radius: 3px; text-decoration: line-through; }
.d-chg { background: #dbeafe; color: #1d4ed8; padding: 0 2px; border-radius: 3px; font-weight: 600; }

/* ---------- Markdown content ---------- */
.card h1, .card h2, .card h3, .card h4, .card h5, .card h6 {
    line-height: 1.3; margin: 1.2em 0 .5em; font-weight: 700;
}
.card h1 { font-size: 26px; }
.card h2 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.card h3 { font-size: 18px; }
.card h4 { font-size: 16px; }
.card h5 { font-size: 15px; color: var(--muted); }
.card h6 { font-size: 14px; color: var(--muted); }
.card > *:first-child { margin-top: 0; }

.card p { margin: .8em 0; }
.card ul, .card ol { margin: .8em 0; padding-left: 1.6em; }
.card ul ul, .card ol ol, .card ul ol, .card ol ul { margin: .3em 0; }
.card li { margin: .25em 0; }

.card blockquote {
    margin: 1em 0; padding: 8px 16px;
    border-left: 4px solid var(--accent);
    background: var(--bg); color: var(--muted);
    border-radius: 0 var(--radius) var(--radius) 0;
}
.card code {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; padding: 1px 5px;
    font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em;
}
.card pre {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; padding: 12px 14px; overflow: auto;
    margin: 1em 0; font-size: 13px; line-height: 1.5;
}
.card pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.card a { color: var(--accent); }
.card a:hover { text-decoration: underline; }
.card img { max-width: 100%; height: auto; border-radius: 8px; }
.card hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.card mark { background: #fef08a; color: inherit; padding: 0 2px; border-radius: 3px; }
.card a.wiki-link { color: var(--accent); border-bottom: 1px dashed var(--accent); text-decoration: none; }
.card a.wiki-link.missing { color: var(--danger); border-bottom-color: var(--danger); }

/* ---------- Tables ---------- */
.card table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.card table th, .card table td {
    border: 1px solid var(--border); padding: 8px 12px; text-align: left; vertical-align: top;
}
.card table th { background: var(--bg); font-weight: 600; }
.card table tr:nth-child(even) td { background: #fafbfc; }

/* ---------- Mermaid / BPMN / Swagger ---------- */
.mermaid-container,
.bpmn-container,
.swagger-container,
.mermaid {
    margin: 1em 0; padding: 16px;
    background: #f8fafc; /* Всегда светлый фон */
    border: 1px solid var(--border);
    border-radius: var(--radius); overflow: auto;
    color: #0f172a; /* Темный текст внутри диаграмм */
}

/* В темной теме делаем фон чуть темнее (светло-серый), чтобы не резал глаз */
[data-theme="dark"] .mermaid-container,
[data-theme="dark"] .bpmn-container,
[data-theme="dark"] .swagger-container,
[data-theme="dark"] .mermaid {
    background: #e2e8f0; /* Светло-серый (Slate 200) */
    border-color: #475569;
}

.bpmn-container { min-height: 300px; }

/* Swagger UI принудительно делаем светлым внутри контейнера */
[data-theme="dark"] .swagger-container .swagger-ui,
[data-theme="dark"] .swagger-container .swagger-ui .info .title,
[data-theme="dark"] .swagger-container .swagger-ui .opblock-tag,
[data-theme="dark"] .swagger-container .swagger-ui .opblock-summary-description {
    color: #0f172a !important;
}
[data-theme="dark"] .swagger-container .swagger-ui .scheme-container {
    background: transparent;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
    .topbar .search { order: 3; flex-basis: 100%; max-width: none; }
    .nav { gap: 12px; font-size: 13px; }
    .content { padding: 20px 16px; }
    .card { padding: 16px 18px; }
    h1 { font-size: 24px; }
    .comment .children { margin-left: 12px; padding-left: 12px; }
}

/* ---------- Layout с сайдбаром ---------- */
.layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 24px;
    width: 100%;
    max-width: 100%; /* Растягиваем на весь экран */
    margin: 0;
    padding: 24px 22px 0;
    flex: 1;
    align-items: stretch;
}
.layout > .content {
    max-width: none;
    margin: 0;
    padding: 0 0 24px;
    min-width: 0;
    flex: none;
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 92px);
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}
.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.sidebar-actions .btn {
    width: 100%;
    text-align: center;
}
.sidebar-section { margin-bottom: 14px; }
.sidebar-section:last-child { margin-bottom: 0; }
.sidebar-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: 6px;
    padding: 0 4px;
}
.sidebar-empty { color: var(--muted); font-size: 13px; padding: 4px; }

.sidebar-list,
.sidebar-tree {
    list-style: none;
    padding: 0;
    margin: 0;
}
.sidebar-list li,
.sidebar-tree li { margin: 0; }
.sidebar-list a,
.sidebar-tree a {
    display: block;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.35;
}
.sidebar-list a:hover,
.sidebar-tree a:hover {
    background: var(--bg);
    text-decoration: none;
}
.sidebar-list a.active,
.sidebar-tree a.active {
    background: var(--bg);
    color: var(--accent);
    font-weight: 600;
}
.sidebar-children {
    margin-left: 10px;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}

/* --- Раскрывающееся дерево (Confluence-style) --- */
.sidebar-node {
    display: flex;
    align-items: center;
    border-radius: 6px;
}
.sidebar-node:hover { background: var(--bg); }
.sidebar-node a {
    flex: 1;
    padding: 6px 4px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-node a:hover { background: transparent; text-decoration: none; }

.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    width: 20px;
    height: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 10px;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}
.sidebar-toggle::before { content: "▶"; }
.sidebar-toggle.open { transform: rotate(90deg); }

.sidebar-spacer {
    width: 20px;
    flex-shrink: 0;
}


/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
        padding: 16px 16px 0;
        gap: 16px;
    }
    .sidebar {
        position: static;
        max-height: none;
    }
    .layout > .content { padding-bottom: 20px; }
}

.badge-error { background: #fee2e2; color: #991b1b; }
.badge-warn  { background: #fef3c7; color: #92400e; }
.badge-info  { background: #dbeafe; color: #1d4ed8; }
.badge-debug { background: #e5e7eb; color: #4b5563; }
.badge-critical { background: #dc2626; color: #fff; }

/* ---------- Тёмная тема ---------- */
[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --shadow: 0 1px 3px 0 rgba(0,0,0,0.3);
}

[data-theme="dark"] .card table tr:nth-child(even) td {
    background: #2a3a50;
}
[data-theme="dark"] .btn:hover { background: #334155; border-color: #475569; }
[data-theme="dark"] .json-help { background: #1e293b; }
[data-theme="dark"] .topbar .search input { background: #0f172a; color: var(--text); }
[data-theme="dark"] .sidebar-node:hover { background: #334155; }
[data-theme="dark"] .markdown .card pre { background: #0f172a; }
[data-theme="dark"] .badge-error { background: #7f1d1d; color: #fecaca; }
[data-theme="dark"] .badge-warn  { background: #78350f; color: #fde68a; }
[data-theme="dark"] .badge-info  { background: #1e3a8a; color: #bfdbfe; }
[data-theme="dark"] .badge-debug { background: #334155; color: #cbd5e1; }

[data-theme="dark"] textarea {
    background: #334155; /* Темно-серый фон */
    color: #f1f5f9;      /* Светлый текст */
    border-color: #475569;
}
[data-theme="dark"] textarea:focus {
    border-color: var(--accent);
    background: #334155;
}
[data-theme="dark"] .card mark {
    background: #fef08a; /* Оставляем желтый */
    color: #0f172a;      /* Принудительно темный текст */
}

/* Переключатель */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 16px;
    color: var(--text);
    margin-left: auto;
    margin-right: 16px;
}
.theme-toggle:hover { background: var(--bg); }