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

:root {
    --bg:        #0A0A0A;
    --surface:   #111111;
    --surface2:  #1A1A1A;
    --surface3:  #222222;
    --border:    #1F1F1F;
    --border-2:  #2A2A2A;
    --accent:    #FFFFFF;
    --accent-dim:#A0A0A0;
    --green:     #22C55E;
    --green-dim: rgba(34,197,94,0.1);
    --red:       #EF4444;
    --red-dim:   rgba(239,68,68,0.1);
    --yellow:    #EAB308;
    --yellow-dim:rgba(234,179,8,0.1);
    --indigo:    #6366F1;
    --indigo-dim:rgba(99,102,241,0.12);
    --text:      #EDEDED;
    --text-2:    #6B6B6B;
    --text-3:    #3A3A3A;
    --font:      'Geist', 'Inter', system-ui, sans-serif;
    --mono:      'Geist Mono', 'Cascadia Code', 'Consolas', monospace;
    --radius:    6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --sidebar-w: 220px;
    --topbar-h:  48px;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

/* ─── Light ──────────────────────────────────────────────────── */
body.light {
    --bg:        #FAFAFA;
    --surface:   #FFFFFF;
    --surface2:  #F5F5F5;
    --surface3:  #EBEBEB;
    --border:    #E5E5E5;
    --border-2:  #D4D4D4;
    --accent:    #0A0A0A;
    --accent-dim:#404040;
    --text:      #0A0A0A;
    --text-2:    #737373;
    --text-3:    #A3A3A3;
    --green:     #16A34A;
    --red:       #DC2626;
    --yellow:    #CA8A04;
    --indigo:    #4F46E5;
}

html, body { height: 100%; }

html, body {
    /* На мобильных длинные значения и фиксированные ширины элементов
       часто провоцируют горизонтальный скролл всего документа. */
    overflow-x: hidden;
    overscroll-behavior-x: none;
    -webkit-text-size-adjust: 100%;
    /* Запрет pinch-zoom через touch-action (Safari частично игнорирует
       maximum-scale в meta). pan-x/y оставляем чтобы скролл работал. */
    touch-action: pan-x pan-y;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ─── Auth ───────────────────────────────────────────────────── */
.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-box {
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-logo {
    margin-bottom: 20px;
}

.auth-logo h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.4px;
}

.auth-logo p {
    color: var(--text-2);
    font-size: 13px;
    margin-top: 4px;
}

.auth-error {
    color: var(--red);
    font-size: 12px;
    min-height: 16px;
}

/* ─── Layout ─────────────────────────────────────────────────── */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    height: 100vh;
    overflow: hidden;
}

/* ─── Topbar ─────────────────────────────────────────────────── */
.topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    padding: 0 16px 0 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    gap: 0;
}

.topbar-logo {
    width: var(--sidebar-w);
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 16px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    height: 100%;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.2px;
    text-decoration: none;
    cursor: default;
    user-select: none;
}

.topbar-logo-icon {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
    color: var(--bg);
}

.topbar-actions {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 12px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
}

.topbar-btn {
    height: 28px;
    padding: 0 10px;
    background: none;
    border: none;
    color: var(--text-2);
    font-size: 12px;
    font-family: var(--font);
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.1s, color 0.1s;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    flex-shrink: 0;
}
.topbar-btn:hover { background: var(--surface2); color: var(--text); }
.topbar-btn svg  { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    border-right: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 1px;
    overflow-y: auto;
    overflow-x: hidden;
}
/* «Ещё» — только для мобильной bottom-nav */
.sidebar .nav-more { display: none; }

.sidebar-section {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 14px 8px 4px;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    color: var(--text-2);
    text-decoration: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.08s, color 0.08s;
    user-select: none;
    position: relative;
    font-size: 13px;
    font-weight: 500;
}

.sidebar a svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.sidebar a .label { flex: 1; }

.sidebar a .sidebar-badge {
    margin-left: auto;
}

.sidebar a:hover { background: var(--surface2); color: var(--text); }
.sidebar a.active { background: var(--surface2); color: var(--text); }
.sidebar a.active svg { color: var(--text); }

body.light .sidebar a:hover  { background: var(--surface2); }
body.light .sidebar a.active { background: var(--surface2); }

/* ─── Sidebar bottom ─────────────────────────────────────────── */
.sidebar-spacer { flex: 1; }

.sidebar-footer {
    padding-top: 8px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 1px;
}

/* ─── Main ───────────────────────────────────────────────────── */
.main {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--bg);
    min-height: 0;
}

.main--fullscreen {
    padding: 0 !important;
    overflow: hidden !important;
    gap: 0 !important;
}

/* ─── Page header ────────────────────────────────────────────── */
.page-header {
    margin-bottom: 4px;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.4px;
}

.page-desc {
    font-size: 13px;
    color: var(--text-2);
    margin-top: 3px;
}

/* ─── Section ────────────────────────────────────────────────── */
.section {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.section-header {
    padding: 0 0 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px 24px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ─── Inputs ─────────────────────────────────────────────────── */
input[type=text],
input[type=password],
input[type=search] {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    color: var(--text);
    padding: 7px 11px;
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.12s;
}

input:focus { border-color: var(--text-2); }
input::placeholder { color: var(--text-3); }

.totp-input {
    letter-spacing: 0.35em;
    font-size: 22px !important;
    text-align: center;
    font-family: var(--mono) !important;
    padding: 10px 14px !important;
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 12px;
    font-family: var(--font);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.1s, opacity 0.1s, border-color 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: -0.1px;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:active:not(:disabled) { opacity: 0.8; }

.btn-primary  { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-success  { background: var(--green-dim); color: var(--green); border-color: rgba(34,197,94,0.2); }
.btn-success:hover:not(:disabled) { background: rgba(34,197,94,0.16); }

.btn-danger   { background: var(--red-dim); color: var(--red); border-color: rgba(239,68,68,0.2); }
.btn-danger:hover:not(:disabled)  { background: rgba(239,68,68,0.16); }

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    border-color: var(--border-2);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); border-color: var(--border-2); }

.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-full { width: 100%; }

/* ─── Badge ──────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 500;
}

.badge::before {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge-on  { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.2); }
.badge-on::before  { background: var(--green); animation: pulse 2s infinite; }

.badge-off { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }
.badge-off::before { background: var(--red); }

.badge-busy { background: var(--yellow-dim); color: var(--yellow); border: 1px solid rgba(234,179,8,0.2); }
.badge-busy::before { background: var(--yellow); animation: pulse 1.4s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ─── Server glow ────────────────────────────────────────────── */
.server-glow {
    position: absolute;
    top: 0; right: 0;
    width: 60%;
    height: 100%;
    pointer-events: none;
    transition: background 1.5s ease;
}
.server-glow-on  { background: radial-gradient(ellipse at 100% 50%, rgba(34,197,94,0.07) 0%, transparent 70%); }
.server-glow-off { background: radial-gradient(ellipse at 100% 50%, rgba(239,68,68,0.05) 0%, transparent 70%); }

/* ─── Stat rows ──────────────────────────────────────────────── */
.stat-rows { display: flex; flex-direction: column; }

.stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.stat-row:last-child  { border-bottom: none; padding-bottom: 0; }
.stat-row:first-child { padding-top: 0; }

.stat-label { color: var(--text-2); font-size: 12px; }
.stat-value { font-size: 12px; font-weight: 500; }

/* ─── Button row ─────────────────────────────────────────────── */
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ─── Settings rows ──────────────────────────────────────────── */
.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border);
}
.settings-row:last-child  { border-bottom: none; }
.settings-row:first-child { padding-top: 0; }

.settings-row-body { flex: 1; min-width: 0; }

.settings-row-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.settings-row-desc {
    font-size: 12px;
    color: var(--text-2);
    margin-top: 1px;
}

.settings-row-action { flex-shrink: 0; }

/* Toggle */
.toggle {
    display: inline-block;
    position: relative;
    width: 36px;
    height: 20px;
    min-width: 36px;
    flex-shrink: 0;
    cursor: pointer;
    vertical-align: middle;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
    position: absolute;
    inset: 0;
    background: #333;
    border-radius: 99px;
    border: 1px solid #444;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
[data-theme="light"] .toggle-track {
    background: #DCDCDC;
    border-color: #BFBFBF;
}
.toggle input:checked + .toggle-track {
    background: var(--text);
    border-color: var(--text);
}
.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #B0B0B0;
    transition: transform 0.15s, background 0.15s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
[data-theme="light"] .toggle-track::after { background: #FFFFFF; }
.toggle input:checked + .toggle-track::after {
    transform: translateX(16px);
    background: var(--bg);
}

/* Compile spinner */
.compile-spinner {
    display: inline-block;
    width: 10px; height: 10px;
    border: 1.5px solid var(--text-3);
    border-top-color: var(--text);
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: -1px;
    animation: compile-spin 0.7s linear infinite;
}
@keyframes compile-spin { to { transform: rotate(360deg); } }

/* ─── Console ────────────────────────────────────────────────── */
.console-wrap {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.console {
    background: #080808;
    padding: 12px 14px;
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1.8;
    height: 420px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-2);
}

.console-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.console-count {
    font-size: 11px;
    color: var(--text-3);
    margin-left: auto;
    font-family: var(--mono);
}

/* Перенос строк выкл — горизонтальный скролл, ровные логи */
.console.nowrap { white-space: pre; word-break: normal; overflow-x: auto; }

/* Подсветка совпадений фильтра */
.con-hl { background: rgba(234,179,8,0.28); color: inherit; border-radius: 2px; }

/* Чипы фильтра по уровням */
.console-levels { display: flex; align-items: center; gap: 4px; }
.console-chip {
    font-family: var(--mono);
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 99px;
    border: 1px solid var(--border-2);
    background: var(--surface2);
    color: var(--text-2);
    cursor: pointer;
    transition: opacity .12s, background .12s, color .12s;
    user-select: none;
}
.console-chip:hover { color: var(--text); }
.console-chip.off { opacity: 0.4; text-decoration: line-through; }

/* Кнопка «вниз» */
.console-jump {
    position: absolute;
    right: 16px;
    bottom: 14px;
    background: var(--surface2);
    border: 1px solid var(--border-2);
    color: var(--text);
    border-radius: 99px;
    font-size: 11px;
    padding: 5px 12px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    transition: opacity .15s, transform .15s;
}
.console-jump:hover { background: var(--surface3); }
.console-jump.hidden { display: none; }

/* ─── Compile output ─────────────────────────────────────────── */
.compile-out {
    background: #080808;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.7;
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-2);
}
.compile-out .line-err  { color: var(--red); }
.compile-out .line-warn { color: var(--text-2); }
.compile-out .line-ok   { color: var(--green); }

@keyframes highlight-in {
    0%   { background: rgba(255,255,255,0.06); }
    100% { background: transparent; }
}

/* ─── File tree ──────────────────────────────────────────────── */
.files-layout {
    display: grid;
    grid-template-columns: var(--files-tree-w, 220px) 6px 1fr;
    height: 100%;
    overflow: hidden;
    border-top: 1px solid var(--border);
}
/* Drag-handle между sidebar'ом и редактором */
.files-resize {
    background: transparent;
    cursor: col-resize;
    position: relative;
    user-select: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    margin: 0 -1px;
    transition: background 0.1s;
}
.files-resize:hover,
.files-resize.dragging {
    background: var(--accent);
    opacity: 0.4;
}
body.files-resizing,
body.files-resizing * {
    cursor: col-resize !important;
    user-select: none !important;
}

.file-tree {
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 6px 0;
    background: var(--bg);
}

.file-tree-search {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 1;
}

.file-tree-search input {
    background: var(--surface2);
    font-size: 12px;
    padding: 5px 9px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.06s, color 0.06s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-item:hover,
.file-item.kbd-hover    { background: var(--surface2); color: var(--text); }
.file-item.active       { background: var(--surface2); color: var(--text); }
.tree-row.file.kbd-hover { background: var(--surface2); color: var(--text); }

.file-item .file-icon { flex-shrink: 0; font-size: 12px; }

.file-editor {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.editor-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: 38px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg);
}

.editor-filename {
    font-size: 12px;
    color: var(--text-2);
    flex: 1;
    font-family: var(--mono);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-filename.modified::after {
    content: '●';
    color: var(--yellow);
    margin-left: 6px;
    font-size: 8px;
}

.editor-area {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#monaco-editor { width: 100%; height: 100%; }

.editor-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-3);
    font-size: 13px;
    flex-direction: column;
    gap: 8px;
}
.editor-empty .big { font-size: 24px; }

/* ─── Search results ─────────────────────────────────────────── */
.sq-file-group { border-bottom: 1px solid var(--border); }
.sq-file-group:last-child { border-bottom: none; }

.sq-file-header {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 12px; background: rgba(255,255,255,0.01);
    border-bottom: 1px solid var(--border); font-size: 12px; user-select: none;
}
.sq-file-icon  { font-size: 11px; flex-shrink: 0; }
.sq-file-dir   { color: var(--text-3); font-family: var(--mono); font-size: 11px; }
.sq-file-name  { color: var(--text); font-weight: 600; font-family: var(--mono); font-size: 12px; }
.sq-file-count { margin-left: 8px; color: var(--text-3); font-size: 10px; background: var(--surface2); padding: 1px 6px; border-radius: 99px; }
.sq-file-actions { margin-left: auto; display: flex; gap: 4px; }
.sq-header-btn { background: none; border: none; color: var(--text-3); cursor: pointer; font-size: 12px; padding: 2px 5px; border-radius: var(--radius); transition: color .1s, background .1s; }
.sq-header-btn:hover { color: var(--text); background: var(--surface2); }

.sq-file-blocks { padding: 2px 0; }

.sq-block-row {
    display: flex; align-items: center; gap: 8px;
    padding: 3px 12px; font-size: 12px; font-family: var(--mono);
    transition: background .06s; min-height: 26px;
}
.sq-block-row:hover { background: rgba(255,255,255,0.02); }
.sq-block-parent > .sq-block-row { cursor: pointer; }

.sq-toggle-icon { color: var(--text-3); font-size: 9px; flex-shrink: 0; width: 12px; text-align: center; }
.sq-line-num { color: var(--text-3); font-size: 10px; flex-shrink: 0; min-width: 44px; text-align: right; }
.sq-block-label { flex: 1; display: flex; align-items: center; gap: 5px; overflow: hidden; min-width: 0; }
.sq-type-tag { font-size: 9px; color: var(--indigo); border: 1px solid rgba(99,102,241,0.25); border-radius: 3px; padding: 1px 4px; flex-shrink: 0; font-family: var(--font); }
.sq-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sq-lines-badge { font-size: 10px; flex-shrink: 0; font-family: var(--font); }

.sq-row-actions { display: flex; gap: 2px; margin-left: auto; flex-shrink: 0; opacity: 0; transition: opacity .1s; }
.sq-block-row:hover .sq-row-actions { opacity: 1; }

.sq-act-btn {
    background: none; border: none; color: var(--text-2); cursor: pointer;
    font-size: 10px; padding: 2px 6px; border-radius: var(--radius);
    font-family: var(--font); white-space: nowrap; transition: color .1s, background .1s; line-height: 1.4;
}
.sq-act-btn:hover { color: var(--text); background: var(--surface2); }
.sq-act-btn:disabled { opacity: .4; cursor: not-allowed; }

.sq-preview-code { color: var(--green); white-space: pre-wrap; word-break: break-all; }
.sq-has-preview { background: rgba(34,197,94,0.03) !important; }

.sq-block-children { padding-left: 20px; border-left: 1px solid var(--border); margin-left: 18px; }
.sq-hidden { display: none !important; }
.sq-gap { padding: 2px 12px 2px 68px; color: var(--text-3); font-size: 10px; font-family: var(--mono); }
mark.sq-hl { background: rgba(234,179,8,0.15); color: var(--yellow); border-radius: 2px; padding: 0 1px; }

.sq-hist-drop {
    /* fixed — чтобы не блюрился внутри .card с backdrop-filter (v2) */
    position: fixed;
    z-index: 50000;
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    /* top/left/width выставляет _sqShowHist */
}

.sq-hist-item {
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text-2);
    cursor: pointer;
    transition: background .06s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sq-hist-item:hover { background: var(--surface2); color: var(--text); }

.sr-block-children { padding-left: 18px; border-left: 1px solid var(--border); margin: 2px 0 2px 8px; }
.sr-brace { font-family: var(--mono); color: var(--text-3); font-size: 12px; padding: 2px 6px; }
.sr-gap   { color: var(--text-3); font-size: 11px; padding: 2px 6px; font-family: var(--mono); }

#tab-search {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 18px 20px;
    box-sizing: border-box;
    flex-shrink: 0;
}

#search-root { display: flex; flex-direction: column; gap: 18px; }

/* ─── Editor tabs ────────────────────────────────────────────── */
.editor-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.etab {
    padding: 8px 16px;
    background: none;
    border: none;
    border-bottom: 1px solid transparent;
    color: var(--text-2);
    font-size: 12px;
    font-family: var(--font);
    font-weight: 500;
    cursor: pointer;
    transition: color 0.1s, border-color 0.1s;
}
.etab:hover  { color: var(--text); }
.etab.active { color: var(--text); border-bottom-color: var(--text); }

.editor-tab-content { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.editor-tab-content.hidden { display: none !important; }

/* ─── File tree extras ───────────────────────────────────────── */
.file-tree-section {
    font-size: 10px; font-weight: 600; color: var(--text-3);
    text-transform: uppercase; letter-spacing: .08em;
    padding: 10px 12px 4px;
}
.file-tree-sep { height: 1px; background: var(--border); margin: 4px 0; }
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.fav-btn {
    flex-shrink: 0; opacity: 0; font-size: 11px;
    color: var(--yellow); transition: opacity 0.1s;
    padding: 0 2px; cursor: pointer;
}
.file-item:hover .fav-btn { opacity: 0.5; }
.file-item:hover .fav-btn:hover { opacity: 1; }

/* ─── File tree toolbar ─────────────────────────────────────── */
.file-tree-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-3);
    flex-wrap: wrap;
}
.file-count {
    margin-right: auto;
    font-family: var(--mono);
}
.file-count-dim {
    color: var(--text-3);
    font-style: italic;
    margin-left: 4px;
}
.file-toggle {
    background: none;
    border: none;
    color: var(--text-2);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}
.file-toggle:hover { color: var(--text); background: var(--surface2); }

/* ─── Бадж кол-ва выданных part'ов ──────────────────────────── */
.file-badge {
    flex-shrink: 0;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-3);
    background: var(--surface3);
    border-radius: 10px;
    padding: 1px 7px;
    line-height: 14px;
}
.file-item-dim { opacity: 0.42; }
.file-item-dim .file-icon,
.file-item-dim .file-name { color: var(--text-3); }

/* ─── Tree view ─────────────────────────────────────────────── */
.tree-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 12px 3px 6px;
    cursor: pointer;
    color: var(--text-2);
    font-size: 12.5px;
    line-height: 1.4;
    user-select: none;
}
.tree-row:hover { background: var(--surface2); color: var(--text); }
.tree-row.active { background: var(--surface2); color: var(--text); }
.tree-row.dir {
    color: var(--text);
    font-weight: 500;
}
.tree-row-dim { opacity: 0.42; }
.tree-row-dim .tree-name,
.tree-row-dim .tree-icon { color: var(--text-3); }
.tree-caret {
    flex-shrink: 0;
    width: 12px;
    text-align: center;
    color: var(--text-3);
    font-size: 9px;
}
.tree-row.file .tree-caret { visibility: hidden; }
.tree-icon { flex-shrink: 0; font-size: 12px; }
.tree-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.fav-btn-dir {
    flex-shrink: 0;
    opacity: 0;
    font-size: 11px;
    color: var(--yellow);
    transition: opacity 0.1s;
    padding: 0 2px;
    cursor: pointer;
}
.tree-row:hover .fav-btn-dir { opacity: 0.5; }
.tree-row:hover .fav-btn-dir:hover { opacity: 1; }
/* Если папка уже в избранном — звезда жёлтая и всегда видна */
.fav-btn-dir:where([data-dir]) { /* плейсхолдер если нужно расширить */ }
.tree-row.dir .fav-btn-dir,
.file-fav-dir .fav-btn-dir {
    opacity: 0;
}
.tree-row.dir:hover .fav-btn-dir { opacity: 0.5; }
.tree-row.dir:hover .fav-btn-dir:hover { opacity: 1; }
/* Если уже в избранном — звёздочку показываем всегда */
.fav-btn-dir.is-fav { opacity: 1 !important; }

.file-fav-dir {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 12px 3px 6px;
    color: var(--text-2);
    font-size: 12.5px;
}
.file-fav-dir-name { flex: 1; }

#delete-access-bar:not(.hidden) { display: flex; }

.del-access-bar {
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    font-size: 12px;
}

.del-bar-label { color: var(--text-2); font-size: 11px; flex-shrink: 0; }

.del-access-bar input[type=number] {
    width: 64px; padding: 3px 7px; font-size: 12px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); outline: none;
    -moz-appearance: textfield;
}
.del-access-bar input[type=number]::-webkit-inner-spin-button { display: none; }
.del-access-bar input[type=number]:focus { border-color: var(--text-2); }
.del-bar-sep    { color: var(--text-3); font-size: 11px; }
.del-bar-divider { width: 1px; height: 12px; background: var(--border); flex-shrink: 0; margin: 0 2px; }
.del-bar-danger { color: var(--red) !important; }
.del-bar-danger:hover { background: var(--red-dim) !important; }

/* ─── Part tabs ──────────────────────────────────────────────── */
.part-tabs-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-width: 0;
}
.part-tabs-wrap::before,
.part-tabs-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 1px;
    width: 24px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s;
    z-index: 1;
}
.part-tabs-wrap::before {
    left: 28px;
    background: linear-gradient(to right, var(--bg), transparent);
}
.part-tabs-wrap::after {
    right: 28px;
    background: linear-gradient(to left, var(--bg), transparent);
}
.part-tabs-wrap.part-tabs-fade-left::before  { opacity: 1; }
.part-tabs-wrap.part-tabs-fade-right::after  { opacity: 1; }
/* Если оверфлоу нет — стрелки скрыты через .hidden, маски тоже не нужны */
.part-tabs-wrap:not(.part-tabs-overflow)::before,
.part-tabs-wrap:not(.part-tabs-overflow)::after { display: none; }

.part-tabs-arrow {
    flex: 0 0 auto;
    width: 28px;
    background: var(--bg);
    border: none;
    border-right: 1px solid var(--border);
    color: var(--text-2);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    font-weight: 600;
    padding: 0;
    user-select: none;
    z-index: 2;
}
.part-tabs-arrow.part-tabs-arrow-right { border-right: none; border-left: 1px solid var(--border); }
.part-tabs-arrow:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.part-tabs-arrow:disabled { opacity: 0.3; cursor: default; }
.part-tabs-arrow.hidden { display: none; }

.part-tabs-horizontal {
    display: flex;
    gap: 0;
    background: var(--bg);
    overflow-x: auto;
    flex: 1 1 auto;
    min-width: 0;
    scrollbar-width: none;
    scroll-behavior: smooth;
}
.part-tabs-horizontal::-webkit-scrollbar { display: none; }

.ptab {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    cursor: pointer;
    border-bottom: 1px solid transparent;
    transition: background .06s, border-color .06s;
    user-select: none;
    flex-shrink: 0;
    max-width: 200px;
    background: var(--bg);
    font-size: 11px;
}
.ptab:hover { background: var(--surface2); }
.ptab.active { border-bottom-color: var(--text); }

.ptab-line {
    font-family: var(--mono);
    font-size: 9px;
    color: var(--text-3);
    font-weight: 600;
    background: var(--surface2);
    padding: 1px 4px;
    border-radius: 3px;
    flex-shrink: 0;
}
.ptab.active .ptab-line { background: rgba(255,255,255,0.08); color: var(--text-2); }

.ptab-label {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}
.ptab.active .ptab-label { color: var(--text); }

/* ─── Вкладки частей: переключатель вида + вертикальный список ──── */
.part-tabs-view-toggle {
    flex: 0 0 auto;
    width: 28px;
    background: var(--bg);
    color: var(--text-3);
    border: none;
    border-right: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    transition: background .1s, color .1s;
}
.part-tabs-view-toggle:hover { background: var(--surface2); color: var(--text); }

.part-tabs-vertical {
    flex: 0 0 auto;
    width: 250px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg);
    overflow: hidden;
}
.part-vtabs-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.part-vtabs-title {
    font-size: 10px; font-weight: 600; color: var(--text-3);
    text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
}
.part-vtabs-filter {
    flex: 1; min-width: 0;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text);
    font-size: 11px; padding: 3px 8px; outline: none;
}
.part-vtabs-filter:focus { border-color: var(--text-2); }
.part-vtabs-head .part-tabs-view-toggle { width: 24px; border: none; border-radius: var(--radius-sm); }
.part-vtabs { flex: 1; overflow-y: auto; }
.pvtab {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 10px; cursor: pointer;
    border-left: 2px solid transparent;
    transition: background .06s;
}
.pvtab:hover { background: var(--surface2); }
.pvtab.active { background: var(--surface2); border-left-color: var(--text); }
.pvtab .ptab-label { flex: 1; }

/* ─── History modal ──────────────────────────────────────────── */
.hist-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .06s;
    border-left: 2px solid transparent;
}
.hist-item:hover  { background: var(--surface2); }
.hist-item.active { background: var(--surface2); border-left-color: var(--text); }
.hist-item-ts   { font-size: 12px; font-weight: 500; color: var(--text); }
.hist-item-line { font-size: 10px; color: var(--text-3); margin-top: 2px; font-family: var(--mono); }

.part-tab-active {
    background: var(--surface2) !important;
    color: var(--text) !important;
}

/* ─── Console colorize ───────────────────────────────────────── */
.con-fatal  { color: #FF3B30; font-weight: 600; }
.con-error  { color: var(--red); }
.con-warn   { color: var(--yellow); }
.con-debug  { color: var(--text-3); }
.con-info   { color: #818CF8; }
.con-default{ color: var(--text-2); }

/* ─── Editor statusbar ───────────────────────────────────────── */
.editor-statusbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 12px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    font-size: 10px;
    color: var(--text-3);
    font-family: var(--mono);
    flex-shrink: 0;
    order: 10;
}
.sb-sep { color: var(--border-2); }

/* ─── Monaco suggest ─────────────────────────────────────────── */
.monaco-editor {
    --vscode-editorSuggestWidget-background: #111111;
    --vscode-editorSuggestWidget-border: #1F1F1F;
    --vscode-editorSuggestWidget-foreground: #EDEDED;
    --vscode-editorSuggestWidget-selectedBackground: rgba(255,255,255,0.06);
    --vscode-editorSuggestWidget-selectedForeground: #ffffff;
    --vscode-editorSuggestWidget-highlightForeground: #EDEDED;
    --vscode-editorSuggestWidget-focusHighlightForeground: #EDEDED;
    --vscode-editorHoverWidget-background: #111111;
    --vscode-editorHoverWidget-foreground: #EDEDED;
    --vscode-editorHoverWidget-border: #1F1F1F;
    --vscode-list-hoverBackground: rgba(255,255,255,0.04);
    --vscode-list-activeSelectionBackground: rgba(255,255,255,0.08);
    --vscode-list-activeSelectionForeground: #ffffff;
    --vscode-foreground: #EDEDED;
}
.monaco-editor .suggest-widget { background: #111111 !important; border: 1px solid #1F1F1F !important; }
.monaco-editor .suggest-widget .suggest-status-bar { background: #0A0A0A !important; }

/* ─── WS status ──────────────────────────────────────────────── */
.ws-status {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.3s;
}
.ws-online  { background: var(--green); }
.ws-offline { background: var(--red); animation: pulse-red 1.5s infinite; }

@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.25; }
}

/* ─── Toast ──────────────────────────────────────────────────── */
.toast-wrap { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 9999; pointer-events: none; }
.toast {
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text);
    min-width: 180px; max-width: 300px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    animation: toast-in 0.15s ease;
    transition: opacity 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.toast::before {
    content: '';
    width: 4px;
    height: 4px;
    border-radius: 50%;
    flex-shrink: 0;
}
.toast.success::before { background: var(--green); }
.toast.error::before   { background: var(--red); }
.toast.info::before    { background: var(--text-2); }
@keyframes toast-in { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:translateY(0); } }

/* ─── Queries ────────────────────────────────────────────────── */
.q-item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.q-item:last-child { border-bottom: none; }
.q-item-main { flex: 1; min-width: 0; }
.q-item-header { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.q-item-user { font-size: 12px; color: var(--text-2); flex-shrink: 0; }
.q-item-file { font-size: 12px; color: var(--indigo); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-item-lines { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.q-item-code { font-family: var(--mono); font-size: 12px; color: var(--text); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Command Palette ────────────────────────────────────────── */
#palette-overlay {
    position: fixed;
    inset: 0;
    z-index: 99000;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 80px;
}

#palette {
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.7);
    overflow: hidden;
    animation: palette-in 0.1s ease;
}
@keyframes palette-in {
    from { opacity: 0; transform: translateY(-6px) scale(0.99); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.palette-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.palette-icon { font-size: 13px; color: var(--text-3); flex-shrink: 0; }

#palette-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    padding: 0;
    width: 100%;
}
#palette-input::placeholder { color: var(--text-3); }

.palette-hint { font-size: 10px; color: var(--text-3); flex-shrink: 0; font-family: var(--mono); }

#palette-list { max-height: 360px; overflow-y: auto; padding: 4px 0; }

.palette-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    transition: background 0.06s;
}
.palette-item:hover, .palette-item.active { background: var(--surface2); }

.palette-item-icon  { font-size: 12px; flex-shrink: 0; width: 18px; text-align: center; color: var(--text-3); }
.palette-item-title { flex: 1; font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item-group { font-size: 9px; color: var(--text-3); background: var(--surface2); padding: 1px 6px; border-radius: 99px; flex-shrink: 0; }
.palette-item-hint  { font-size: 10px; color: var(--text-3); font-family: var(--mono); flex-shrink: 0; }
mark.palette-hl { background: rgba(234,179,8,0.15); color: var(--yellow); border-radius: 2px; padding: 0 1px; }
.palette-empty { padding: 20px; text-align: center; color: var(--text-3); font-size: 12px; }

/* ─── Workspace manager ──────────────────────────────────────── */
.ws-item {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 18px; border-bottom: 1px solid var(--border);
    cursor: default; transition: background 0.06s;
}
.ws-item:last-child { border-bottom: none; }
.ws-item:hover  { background: var(--surface2); }
.ws-item.active { background: var(--surface2); }
.ws-name { font-size: 12px; font-weight: 500; color: var(--text); }
.ws-meta { font-size: 10px; color: var(--text-3); font-family: var(--mono); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ws-restore-btn, .ws-del-btn {
    background: none; border: 1px solid var(--border-2);
    color: var(--text-2); cursor: pointer; font-size: 11px;
    padding: 2px 7px; border-radius: var(--radius);
    transition: background 0.08s, color 0.08s; flex-shrink: 0;
}
.ws-restore-btn:hover { background: var(--surface2); color: var(--text); }
.ws-del-btn:hover { background: var(--red-dim); color: var(--red); border-color: var(--red); }

/* ─── Sidebar badge ──────────────────────────────────────────── */
.sidebar-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 99px;
    font-size: 9px;
    font-weight: 700;
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(239,68,68,0.15);
    flex-shrink: 0;
}

/* ─── TODO tracker ───────────────────────────────────────────── */
.todo-wrap { display: flex; flex-direction: column; gap: 0; }
.todo-filters { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }

.todo-tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 99px;
    font-size: 11px; font-weight: 600;
    cursor: pointer; border: 1px solid transparent;
    transition: opacity 0.1s, border-color 0.1s; user-select: none;
}
.todo-tag.todo-todo  { background: var(--indigo-dim); color: #818CF8; }
.todo-tag.todo-fixme { background: var(--red-dim); color: var(--red); }
.todo-tag.todo-hack  { background: var(--yellow-dim); color: var(--yellow); }
.todo-tag.todo-note  { background: var(--green-dim); color: var(--green); }
.todo-tag.active   { border-color: currentColor; }
.todo-tag.inactive { opacity: 0.3; }

.todo-item {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 9px 0; border-bottom: 1px solid var(--border);
    cursor: pointer; transition: background 0.06s;
}
.todo-item:last-child { border-bottom: none; }
.todo-item:hover { background: rgba(255,255,255,0.01); }

.todo-badge {
    font-size: 9px; font-weight: 700;
    padding: 2px 5px; border-radius: 99px;
    flex-shrink: 0; margin-top: 2px; letter-spacing: .04em;
}
.todo-badge.todo-todo  { background: var(--indigo-dim); color: #818CF8; }
.todo-badge.todo-fixme { background: var(--red-dim); color: var(--red); }
.todo-badge.todo-hack  { background: var(--yellow-dim); color: var(--yellow); }
.todo-badge.todo-note  { background: var(--green-dim); color: var(--green); }

.todo-body { flex: 1; overflow: hidden; }
.todo-text { font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.todo-loc  { font-size: 10px; color: var(--text-3); font-family: var(--mono); margin-top: 2px; }

/* ─── DB interface ───────────────────────────────────────────── */
.db-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 0;
    height: calc(100vh - var(--topbar-h));
    margin: -32px -40px;
    overflow: hidden;
}

.db-sidebar {
    border-right: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.db-sidebar-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .08em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.db-table-list { flex: 1; overflow-y: auto; padding: 4px 0; }

.db-table-item {
    display: flex; align-items: center; gap: 7px;
    padding: 5px 12px; font-size: 11px; color: var(--text-2);
    cursor: pointer; transition: background 0.06s, color 0.06s;
    font-family: var(--mono);
}
.db-table-item:hover  { background: var(--surface2); color: var(--text); }
.db-table-item.active { background: var(--surface2); color: var(--text); }

.db-toolbar .btn.active {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--border-2);
}

.db-main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

#db-query-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }

.db-toolbar {
    display: flex; align-items: center; gap: 5px;
    padding: 7px 12px; border-bottom: 1px solid var(--border);
    background: var(--bg); flex-shrink: 0;
}

.db-query-wrap {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.db-query-input {
    width: 100%; min-height: 72px; max-height: 180px;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    padding: 8px 12px;
    resize: vertical;
    outline: none;
    transition: border-color 0.12s;
}
.db-query-input:focus { border-color: var(--text-2); }

/* min-height:0 обязателен: без него flex-элемент не сжимается ниже
   размера контента, и высокая таблица «выталкивает» контейнер за
   пределы экрана вместо появления вертикального скролла. */
.db-result-wrap  { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.db-result-inner { flex: 1; min-height: 0; overflow: auto; }

/* Несколько результатов (пакет запросов, как в HeidiSQL) — каждый
   блок скроллится независимо, между блоками скроллится контейнер. */
.db-multi-results { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.db-result-block { display: flex; flex-direction: column; min-height: 0; }
.db-result-block-head {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 10px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 3;
}
.db-result-block-body { overflow: auto; max-height: 55vh; }
/* Единственный результат занимает всё доступное место и скроллится сам. */
.db-multi-results > .db-result-block:only-child { flex: 1; min-height: 0; }
.db-multi-results > .db-result-block:only-child > .db-result-block-body { flex: 1; min-height: 0; max-height: none; }

.db-table-result {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
    font-family: var(--mono);
}
.db-table-result th {
    background: var(--surface);
    color: var(--text-3);
    font-weight: 600;
    padding: 6px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1;
    white-space: nowrap;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.db-table-result td {
    padding: 4px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.02);
    color: var(--text);
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
}
.db-table-result td.db-null { color: var(--text-3); font-style: italic; }
.db-table-result td.db-num  { color: #818CF8; text-align: right; }
.db-table-result td.db-str  { color: var(--green); }
.db-table-result tr:hover td { background: rgba(255,255,255,0.015); }

/* Резайзер колонок */
.db-table-result th { position: relative; }
.db-th-label { display: inline-block; }
.db-col-resizer {
    position: absolute; top: 0; right: 0; width: 6px; height: 100%;
    cursor: col-resize; user-select: none; z-index: 2;
}
.db-col-resizer:hover { background: var(--accent, #3b82f6); opacity: 0.5; }

/* Гуттер с номером строки — закреплён слева, открывает карточку строки */
.db-table-result th.db-gut,
.db-table-result td.db-gut {
    position: sticky; left: 0; z-index: 2;
    width: 40px; min-width: 40px; max-width: 40px;
    text-align: right; padding: 4px 8px;
    color: var(--text-3); font-size: 10px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    user-select: none;
}
.db-table-result th.db-gut { z-index: 4; }
.db-table-result td.db-gut { cursor: pointer; }
.db-table-result tr:hover td.db-gut { color: var(--accent, #3b82f6); background: var(--surface2); }

/* Карточный просмотр строки */
.db-card-box {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); width: 100%; max-width: 620px;
    max-height: 76vh; display: flex; flex-direction: column;
    overflow: hidden; box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}
.db-card-head {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.db-card-body { overflow-y: auto; padding: 4px 0; }
.db-card-row {
    display: grid; grid-template-columns: 180px 1fr auto; gap: 12px;
    align-items: start; padding: 7px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.db-card-row:hover { background: rgba(255,255,255,0.02); }
.db-card-key {
    font-size: 11px; color: var(--text-3); font-family: var(--mono);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    padding-top: 1px;
}
.db-card-val {
    font-size: 12px; color: var(--text); font-family: var(--mono);
    white-space: pre-wrap; word-break: break-word; min-width: 0;
}
.db-card-val.db-null { color: var(--text-3); font-style: italic; }
.db-card-copy {
    background: none; border: 1px solid var(--border); border-radius: var(--radius-xs);
    color: var(--text-3); cursor: pointer; font-size: 11px; padding: 1px 6px;
    height: 22px; flex-shrink: 0;
}
.db-card-copy:hover { color: var(--text); border-color: var(--border-2); }

.db-status {
    padding: 5px 12px; font-size: 10px; font-family: var(--mono);
    border-top: 1px solid var(--border); background: var(--bg);
    flex-shrink: 0; color: var(--text-3);
}
.db-status.ok  { color: var(--green); }
.db-status.err { color: var(--red); }

.db-cell-edit {
    position: fixed; z-index: 50000;
    background: var(--surface); border: 1px solid var(--border-2);
    border-radius: var(--radius); padding: 4px 9px;
    font-family: var(--mono); font-size: 12px; color: var(--text);
    outline: none; box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    min-width: 140px;
}

/* ─── Widget ─────────────────────────────────────────────────── */
.widget {
    position: fixed; z-index: 9000; display: flex; flex-direction: column;
    background: rgba(10,10,10,0.92);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-md);
    backdrop-filter: blur(20px);
    box-shadow: 0 16px 48px rgba(0,0,0,0.7);
    overflow: hidden;
    min-width: 220px; min-height: 140px;
}

.widget-header {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; border-bottom: 1px solid var(--border);
    flex-shrink: 0; cursor: grab; user-select: none;
}
.widget-header:active { cursor: grabbing; }

.widget-title { font-size: 10px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .08em; flex: 1; }
.widget-controls { display: flex; align-items: center; gap: 5px; }
.widget-opacity { width: 54px; height: 2px; cursor: pointer; accent-color: var(--text-2); }
.widget-close { background: none; border: none; color: var(--text-3); cursor: pointer; font-size: 11px; padding: 2px 4px; line-height: 1; border-radius: 3px; transition: background .1s; }
.widget-close:hover { background: var(--surface2); color: var(--text); }
.widget-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.widget-resize { position: absolute; bottom: 0; right: 0; width: 12px; height: 12px; cursor: se-resize; background: linear-gradient(135deg, transparent 50%, var(--border-2) 50%); }

/* ─── AI Assistant (widget + page) ───────────────────────────── */
.ai { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ai-page { padding: 0 4px; height: calc(100vh - 90px); }
.ai-page-header { display: flex; align-items: center; justify-content: space-between; padding: 0 0 10px; flex-shrink: 0; }

.ai-status { display: flex; align-items: center; gap: 6px; padding: 8px 12px; font-size: 11px; color: var(--text-2); border-bottom: 1px solid var(--border); }
.ai-status-inline { padding: 4px 0 0; border: none; font-size: 11px; }
.ai-status a { color: var(--text); text-decoration: underline; }
.ai-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.ai-dot-ok   { background: var(--green); }
.ai-dot-warn { background: #F59E0B; }

.ai-ctx { padding: 8px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.ai-ctx-page { flex-direction: row; align-items: flex-end; flex-wrap: wrap; gap: 14px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; }
.ai-ctx-row { display: flex; gap: 10px; align-items: center; flex-wrap: nowrap; }
.ai-field { display: flex; flex-direction: column; gap: 4px; font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; min-width: 0; }
.ai-field > span { font-weight: 500; }
.ai-select { background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 8px; font-size: 12px; font-family: inherit; outline: none; cursor: pointer; min-width: 0; width: 100%; appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='%236B6B6B' d='M5 7L1 3h8z'/></svg>"); background-repeat: no-repeat; background-position: right 8px center; padding-right: 24px; }
.ai-select:focus { border-color: var(--border-2); }
.ai-num { background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 8px; font-size: 12px; width: 64px; outline: none; font-family: var(--mono); text-align: center; }
.ai-num:focus { border-color: var(--border-2); }
/* Обёртка для toggle с подписью — сам .toggle остаётся 36x20px */
.ai-toggle-row { display: inline-flex; align-items: center; gap: 8px; user-select: none; padding: 2px 0; }
.ai-toggle-row .toggle { flex-shrink: 0; }
.ai-toggle-label { font-size: 12px; color: var(--text-2); cursor: pointer; }

.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; background: var(--bg); }
.ai-chips-page { background: transparent; border: none; padding: 0; }
.ai-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; background: var(--surface2); border: 1px solid var(--border-2); border-radius: 99px; font-size: 11px; color: var(--text); max-width: 240px; }
.ai-chip-name { font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-chip-x { background: none; border: none; color: var(--text-3); cursor: pointer; padding: 0 4px; font-size: 11px; line-height: 1; border-radius: 99px; }
.ai-chip-x:hover { background: var(--surface3); color: var(--text); }

.ai-page-attached { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; flex-shrink: 0; }
.ai-attached-header { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }

.ai-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px; min-height: 0; }
.ai-messages-page { padding: 14px 0; }
.ai-empty { margin: auto; color: var(--text-3); font-size: 12px; text-align: center; padding: 24px 12px; line-height: 1.6; }
.ai-hint { font-size: 10px; color: var(--text-3); }
.ai-suggestions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.ai-suggest { background: var(--surface); border: 1px solid var(--border-2); color: var(--text-2); padding: 6px 12px; border-radius: var(--radius); font-size: 12px; cursor: pointer; transition: background .15s, color .15s; }
.ai-suggest:hover { background: var(--surface2); color: var(--text); }

.ai-msg { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.ai-msg-user   { align-items: flex-end; }
.ai-msg-claude { align-items: flex-start; }
.ai-msg-label { font-size: 9px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; padding: 0 4px; }
.ai-msg-body { font-size: 13px; line-height: 1.6; padding: 9px 13px; border-radius: var(--radius-md); max-width: 92%; word-wrap: break-word; }
.ai-msg-user .ai-msg-body   { background: var(--surface3); color: var(--text); border: 1px solid var(--border-2); }
.ai-msg-claude .ai-msg-body { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.ai-page .ai-msg-body { max-width: min(800px, 92%); }
.ai-typing { opacity: .4; }

.ai-code { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 11px; overflow-x: auto; font-family: var(--mono); font-size: 12px; line-height: 1.55; margin: 6px 0; }
.ai-inline-code { background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; font-family: var(--mono); font-size: 11px; }

/* Markdown tables */
.ai-table-wrap { overflow-x: auto; margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius); }
.ai-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ai-table thead th { background: var(--surface2); color: var(--text); text-align: left; padding: 7px 12px; font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ai-table tbody td { padding: 6px 12px; color: var(--text); border-bottom: 1px solid var(--border); vertical-align: top; }
.ai-table tbody tr:last-child td { border-bottom: none; }
.ai-table tbody tr:hover { background: var(--surface2); }
.ai-table code.ai-inline-code { font-size: 11px; }

/* Tool-use timeline (что Claude делал по дороге) */
.ai-tools { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; max-width: 92%; }
.ai-tool { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: 10.5px; color: var(--text-2); font-family: var(--mono); }
.ai-tool-icon { font-size: 10px; opacity: .85; }
.ai-tool-path { background: transparent; border: none; padding: 0; font-size: 10.5px; color: var(--text); }

/* Edits — карточка с кнопками */
.ai-edits { margin-top: 8px; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-md); overflow: hidden; max-width: 92%; }
.ai-page .ai-edits { max-width: min(800px, 92%); }
.ai-edits-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--surface2); border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: .04em; }
.ai-edits-list { display: flex; flex-direction: column; }
.ai-edit { display: flex; justify-content: space-between; align-items: center; padding: 7px 12px; gap: 10px; border-top: 1px solid var(--border); }
.ai-edit:first-child { border-top: none; }
.ai-edit-done { opacity: .6; }
.ai-edit-info { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.ai-edit-icon { font-size: 12px; color: var(--text-2); width: 16px; text-align: center; }
.ai-edit-path { font-family: var(--mono); font-size: 12px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 1px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ai-edit-stats { display: inline-flex; gap: 6px; font-family: var(--mono); font-size: 11px; flex-shrink: 0; }
.ai-edit-plus  { color: var(--green); }
.ai-edit-minus { color: var(--red); }
.ai-edit-actions { display: flex; gap: 4px; flex-shrink: 0; }
.ai-edit-badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.ai-edit-badge-ok    { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.25); }
.ai-edit-badge-err   { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.25); cursor: help; }
.ai-edit-badge-muted { background: var(--surface2); color: var(--text-3); border: 1px solid var(--border); }

/* Usage badge + modal */
.ai-statusbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.ai-statusbar .ai-status { border: none; padding: 0; flex: 1; }
.ai-usage-btn { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 10px; font-size: 11px; color: var(--text-2); cursor: pointer; font-family: var(--mono); transition: background .15s, color .15s; }
.ai-usage-btn:hover { background: var(--surface3); color: var(--text); }
.ai-usage { display: inline-flex; gap: 4px; align-items: center; }
.ai-usage-warn { color: #F59E0B; }
.ai-usage-over { color: var(--red); background: var(--red-dim); padding: 1px 6px; border-radius: 4px; border: 1px solid rgba(239,68,68,0.3); }
.ai-usage-budget { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); margin-top: 4px; }
.ai-usage-budget span { font-size: 12px; color: var(--text-2); flex: 1; }
.ai-usage-budget input { width: 80px; padding: 5px 8px; font-family: var(--mono); font-size: 12px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); outline: none; text-align: right; }
.ai-usage-budget input:focus { border-color: var(--border-2); }
.ai-usage b { color: var(--text); font-weight: 600; }

.ai-usage-window { width: 100%; max-width: 720px; max-height: 80vh; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-lg); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,0.7); }
.ai-usage-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.ai-usage-title { font-size: 13px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: .04em; }
.ai-usage-close { background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.ai-usage-body { padding: 16px; overflow-y: auto; }
.ai-usage-section-title { font-size: 10px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; margin: 10px 0 8px; }
.ai-usage-section-title:first-child { margin-top: 0; }
.ai-usage-empty { padding: 14px; color: var(--text-3); font-size: 12px; text-align: center; background: var(--surface2); border-radius: var(--radius); }
.ai-usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-bottom: 12px; }
.ai-usage-stat { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); }
.ai-usage-stat span { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.ai-usage-stat b { font-size: 16px; color: var(--text); font-weight: 600; font-family: var(--mono); }
.ai-usage-stat-accent { border-color: var(--border-2); background: var(--bg); }
.ai-usage-models { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.ai-usage-model { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; }
.ai-usage-model-name { color: var(--text); font-weight: 600; text-transform: uppercase; font-family: var(--mono); }
.ai-usage-model-stats { color: var(--text-2); flex: 1; text-align: right; font-family: var(--mono); font-size: 11px; }
.ai-usage-model-cost { color: var(--text); font-weight: 600; font-family: var(--mono); }
.ai-usage-history { display: flex; flex-direction: column; gap: 2px; }
.ai-usage-day { display: grid; grid-template-columns: 100px 70px 80px 70px; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 11px; }
.ai-usage-day-date { color: var(--text); }
.ai-usage-day-req,
.ai-usage-day-tok { color: var(--text-2); }
.ai-usage-day-cost { color: var(--text); text-align: right; }
.ai-usage-note { margin-top: 16px; padding: 10px 12px; background: var(--surface2); border-radius: var(--radius); font-size: 11px; color: var(--text-3); line-height: 1.5; }

/* Active task picker button */
.ai-active-task-bar { padding: 6px 12px; border-bottom: 1px solid var(--border); display: flex; }
.ai-active-task { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 11.5px; color: var(--text-2); cursor: pointer; max-width: 100%; transition: background .15s, color .15s, border-color .15s; }
.ai-active-task:hover { background: var(--surface3); color: var(--text); }
.ai-active-task-on { color: var(--text); border-color: var(--border-2); background: var(--bg); }
.ai-active-task-icon { font-size: 11px; opacity: .8; }
.ai-active-task-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; font-family: var(--mono); }

/* Thread pill */
.ai-thread-pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 11.5px; color: var(--text); cursor: pointer; max-width: 100%; transition: background .15s, border-color .15s; }
.ai-thread-pill:hover { background: var(--surface3); border-color: var(--border-2); }
.ai-thread-pill-task { border-color: var(--border-2); background: var(--bg); }
.ai-thread-icon { font-size: 11px; opacity: .85; }
.ai-thread-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; font-family: var(--mono); }

/* Thread picker modal */
.ai-thread-picker { max-width: 540px; height: 70vh; }
.ai-thread-section { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; padding: 10px 14px 4px; font-weight: 600; }
.ai-thread-row { padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer; border-bottom: 1px solid transparent; transition: background .12s; }
.ai-thread-row:hover { background: var(--surface2); }
.ai-thread-row.attached { background: var(--surface3); }
.ai-thread-row-body { flex: 1; min-width: 0; }
.ai-thread-row-title { color: var(--text); font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-thread-row-sub { color: var(--text-3); font-size: 10.5px; margin-top: 2px; font-family: var(--mono); }
.ai-thread-row-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.ai-thread-mini { background: none; border: 1px solid var(--border); color: var(--text-3); border-radius: var(--radius); padding: 2px 7px; font-size: 11px; cursor: pointer; transition: all .12s; }
.ai-thread-mini:hover { color: var(--text); border-color: var(--border-2); background: var(--surface2); }

/* ─── Tasks page ─────────────────────────────────────────────── */
.tasks-page { display: flex; flex-direction: column; height: calc(100vh - 90px); min-height: 0; }
.tasks-page-header { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: 10px; flex-shrink: 0; }
.tasks-page-sub { font-size: 11px; color: var(--text-3); margin-top: 4px; }
.tasks-page-sub b { color: var(--text); font-weight: 500; }
.tasks-layout { display: grid; grid-template-columns: 320px 1fr; flex: 1; gap: 14px; min-height: 0; }
.tasks-list-pane { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; min-height: 0; }
.tasks-filters { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); flex-wrap: wrap; flex-shrink: 0; }
.task-filter { background: none; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-2); padding: 3px 9px; font-size: 11px; cursor: pointer; transition: all .15s; }
.task-filter:hover { color: var(--text); background: var(--surface2); }
.task-filter.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.tasks-list { flex: 1; overflow-y: auto; }
.task-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.task-row:hover { background: var(--surface2); }
.task-row.selected { background: var(--surface3); }
.task-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.task-dot-open        { background: var(--text-3); }
.task-dot-in_progress { background: #F59E0B; }
.task-dot-done        { background: var(--green); }
.task-dot-blocked     { background: var(--red); }
.task-row-body { flex: 1; min-width: 0; }
.task-row-title { font-size: 13px; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-row-meta { display: flex; gap: 6px; margin-top: 3px; font-size: 10px; flex-wrap: wrap; align-items: center; }
.task-status { color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 99px; background: var(--surface2); border: 1px solid var(--border); }
.task-status-in_progress { color: #F59E0B; border-color: rgba(245,158,11,0.2); background: rgba(245,158,11,0.08); }
.task-status-done { color: var(--green); border-color: rgba(34,197,94,0.2); background: var(--green-dim); }
.task-status-blocked { color: var(--red); border-color: rgba(239,68,68,0.2); background: var(--red-dim); }
.task-prio { color: var(--text-3); padding: 1px 6px; border-radius: 99px; border: 1px solid var(--border); }
.task-prio-high { color: var(--red); border-color: rgba(239,68,68,0.2); }
.task-prio-low { opacity: .6; }
.task-row-files { color: var(--text-3); font-size: 10px; }
.task-active-badge { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.2); padding: 1px 6px; border-radius: 99px; font-size: 9px; text-transform: uppercase; font-weight: 600; letter-spacing: .04em; margin-left: 6px; }

.task-detail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-y: auto; padding: 18px 22px; min-height: 0; }
.task-detail-header { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.task-detail-header input { flex: 1; background: transparent; border: 1px solid transparent; border-radius: var(--radius); padding: 6px 8px; font-size: 17px; font-weight: 600; color: var(--text); outline: none; transition: border-color .15s, background .15s; }
.task-detail-header input:hover, .task-detail-header input:focus { background: var(--surface2); border-color: var(--border); }
.task-detail-actions { display: flex; gap: 6px; flex-shrink: 0; }
.task-meta-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.task-meta-spacer { flex: 1; }
.task-detail-times { display: flex; flex-direction: column; gap: 2px; font-size: 10px; color: var(--text-3); text-align: right; }
.task-section { margin-bottom: 16px; }
.task-section-title { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.task-section-hint { font-weight: 400; text-transform: none; color: var(--text-3); letter-spacing: 0; }
.task-section textarea { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; color: var(--text); font-size: 13px; line-height: 1.55; font-family: inherit; outline: none; resize: vertical; box-sizing: border-box; }
.task-section textarea:focus { border-color: var(--border-2); }
.task-section-actions { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.task-search { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; color: var(--text); font-size: 12px; outline: none; flex: 1; max-width: 360px; }
.task-search:focus { border-color: var(--border-2); }
.task-file-results { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); max-height: 220px; overflow-y: auto; display: none; margin-top: 4px; max-width: 360px; }
.task-file-result { display: flex; gap: 8px; padding: 6px 10px; cursor: pointer; font-size: 12px; align-items: baseline; }
.task-file-result:hover { background: var(--surface2); }
.task-file-result-name { color: var(--text); font-family: var(--mono); }
.task-file-result-path { color: var(--text-3); font-family: var(--mono); font-size: 10.5px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-file-empty { padding: 10px; color: var(--text-3); font-size: 11px; text-align: center; }
.task-link { background: none; border: none; color: var(--text); text-decoration: underline; cursor: pointer; padding: 0; font: inherit; }

.task-dropzone { border: 1.5px dashed var(--border-2); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--text-3); font-size: 12px; transition: all .15s; cursor: pointer; }
.task-dropzone.over { background: var(--surface2); border-color: var(--text-2); color: var(--text); }
.task-attachments { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-top: 12px; }
.task-att { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; }
.task-att img { display: block; width: 100%; height: 130px; object-fit: cover; }
.task-att-bar { display: flex; justify-content: space-between; align-items: center; padding: 5px 8px; font-size: 11px; gap: 6px; }
.task-att-name { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 10.5px; }
.task-att-x { background: none; border: none; color: var(--text-3); cursor: pointer; font-size: 11px; padding: 0 4px; }
.task-att-x:hover { color: var(--red); }
.task-att-file { display: flex; justify-content: space-between; padding: 10px 12px; align-items: center; }
.task-att-file a { color: var(--text); font-family: var(--mono); font-size: 12px; text-decoration: none; flex: 1; }
.task-att-file a:hover { text-decoration: underline; }

.task-note-composer { display: flex; gap: 6px; align-items: stretch; }
.task-note-composer textarea { flex: 1; }
.task-notes { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.task-note { padding: 8px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); }
.task-note-meta { font-size: 10px; color: var(--text-3); margin-bottom: 3px; }
.task-note-text { color: var(--text); font-size: 12.5px; line-height: 1.5; }

.task-ai-log { display: flex; flex-direction: column; gap: 4px; }
.task-ai-log-item { padding: 6px 10px; background: var(--surface2); border-radius: var(--radius); font-size: 11px; display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.task-ai-log-time { color: var(--text-3); font-family: var(--mono); }
.task-ai-log-kind { color: var(--text); text-transform: uppercase; font-weight: 600; font-size: 9.5px; letter-spacing: .04em; }
.task-ai-log-summary { color: var(--text-2); flex: 1; }
.task-ai-log-files { width: 100%; display: flex; gap: 4px; margin-top: 2px; flex-wrap: wrap; }

/* Кейсы внутри задачи */
.task-cases { display: flex; flex-direction: column; gap: 6px; }
.task-cases-empty { padding: 14px; color: var(--text-3); font-size: 12px; background: var(--surface2); border: 1px dashed var(--border); border-radius: var(--radius); text-align: center; }
.task-case { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.task-case-header { display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; transition: background .12s; user-select: none; }
.task-case-header:hover { background: var(--surface3); }
.task-case-title { flex: 1; color: var(--text); font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-case-status { flex-shrink: 0; }
.task-case-arrow { color: var(--text-3); font-size: 10px; flex-shrink: 0; transition: transform .12s; }
.task-case-edits-badge { background: var(--surface3); color: var(--text-2); border: 1px solid var(--border-2); padding: 1px 7px; border-radius: 99px; font-size: 10px; font-weight: 500; flex-shrink: 0; }
.task-case-ai-badge { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.25); padding: 1px 7px; border-radius: 99px; font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; flex-shrink: 0; }

.task-case-body { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); background: var(--bg); }
.task-case-body.hidden { display: none; }
.task-case-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.task-case-section { display: flex; flex-direction: column; gap: 4px; }
.task-case-section-title { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.task-case-section textarea { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px; color: var(--text); font-size: 12.5px; font-family: inherit; outline: none; resize: vertical; box-sizing: border-box; }
.task-case-section textarea:focus { border-color: var(--border-2); }
.task-case-actions-inline { display: flex; gap: 6px; }
.task-case-ai-text { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 12px; color: var(--text); font-size: 12.5px; line-height: 1.55; }
.task-case-ai-text pre { margin: 6px 0; }
.task-case-edits { display: flex; flex-direction: column; gap: 4px; }
.task-case-edit { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); }
.task-case-edit-info { display: flex; gap: 8px; align-items: center; min-width: 0; flex: 1; }
.task-case-edit-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Create task modal */
.task-create-window { width: 100%; max-width: 540px; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-lg); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,0.7); }
.task-create-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--text); }
.task-create-close { background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.task-create-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.task-create-body input[type=text] { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 11px; color: var(--text); font-size: 14px; font-weight: 500; outline: none; }
.task-create-body input[type=text]:focus { border-color: var(--border-2); }
.task-create-body textarea { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; color: var(--text); font-size: 13px; font-family: inherit; outline: none; resize: vertical; }
.task-create-body textarea:focus { border-color: var(--border-2); }
.task-create-row { display: flex; gap: 12px; align-items: flex-end; }
.task-create-footer { display: flex; justify-content: flex-end; gap: 6px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* Pending action cards */
.ai-actions-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-width: 92%; }
.ai-page .ai-actions-list { max-width: min(800px, 92%); }
.ai-action { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-md); font-size: 12.5px; }
.ai-action-state { padding-top: 2px; }
.ai-action-done { opacity: .7; }
.ai-action-icon { font-size: 16px; flex-shrink: 0; }
.ai-action-summary { color: var(--text); flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.ai-action-state { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.ai-action-badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.ai-action-badge-ok    { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.25); }
.ai-action-badge-err   { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.25); cursor: help; }
.ai-action-badge-muted { background: var(--surface2); color: var(--text-3); border: 1px solid var(--border); }

/* AI memory modal */
.ai-mem-window { width: 100%; height: 100%; max-width: 1400px; max-height: calc(100vh - 40px); background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-lg); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,0.7); }
.ai-mem-header { display: flex; align-items: baseline; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.ai-mem-title { font-size: 13px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: .04em; }
.ai-mem-sub { font-size: 11px; color: var(--text-3); flex: 1; }
.ai-mem-close { background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.ai-mem-body { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }
.ai-mem-sidebar { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.ai-mem-list-actions { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.ai-mem-list { flex: 1; overflow-y: auto; }
.ai-mem-item { padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.ai-mem-item:hover { background: var(--surface2); }
.ai-mem-item.active { background: var(--surface3); }
.ai-mem-item-name { font-size: 12px; color: var(--text); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-mem-item-meta { font-size: 10px; color: var(--text-3); margin-top: 2px; font-family: var(--mono); }
.ai-mem-editor-pane { display: flex; flex-direction: column; min-height: 0; }
.ai-mem-editor-bar { display: flex; gap: 8px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.ai-mem-current { font-size: 12px; color: var(--text); font-family: var(--mono); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-mem-editor { flex: 1; min-height: 0; }

/* Diff modal */
.ai-diff-window { width: 100%; height: 100%; max-width: 1600px; max-height: calc(100vh - 40px); background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-lg); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,0.7); }
.ai-diff-header { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.ai-diff-title { font-size: 12px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: .04em; }
.ai-diff-path { font-family: var(--mono); font-size: 12px; color: var(--text-2); background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 2px 6px; flex: 1; }
.ai-diff-close { background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.ai-diff-body { flex: 1; position: relative; min-height: 0; }

.ai-composer-wrap { position: relative; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); flex-shrink: 0; background: var(--surface); }
.ai-composer-wrap-page { padding: 12px 0 0; border-top: 1px solid var(--border); background: transparent; }
.ai-composer { width: 100%; }
.ai-composer textarea { width: 100%; resize: none; font-family: inherit; font-size: 13px; padding: 9px 11px; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); outline: none; min-height: 48px; max-height: 200px; box-sizing: border-box; line-height: 1.55; }
.ai-composer textarea:focus { border-color: var(--border-2); }
.ai-composer textarea::placeholder { color: var(--text-3); }
.ai-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* @-mentions dropdown */
.ai-mentions { position: absolute; bottom: 100%; left: 12px; right: 12px; max-height: 240px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.4); z-index: 100; margin-bottom: 4px; }
.ai-mention-item { display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; cursor: pointer; font-size: 12px; }
.ai-mention-item:hover, .ai-mention-item.active { background: var(--surface2); }
.ai-mention-name { color: var(--text); font-family: var(--mono); }
.ai-mention-path { color: var(--text-3); font-family: var(--mono); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }

/* File picker modal (page) */
.ai-picker { width: 100%; max-width: 600px; height: 70vh; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-lg); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,0.7); }
.ai-picker-header { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); align-items: center; }
.ai-picker-header input { flex: 1; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; font-size: 13px; outline: none; }
.ai-picker-header input:focus { border-color: var(--border-2); }
.ai-picker-close { background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.ai-picker-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.ai-picker-item { display: flex; align-items: baseline; gap: 8px; padding: 8px 14px; cursor: pointer; font-size: 12px; border-bottom: 1px solid transparent; }
.ai-picker-item:hover { background: var(--surface2); }
.ai-picker-item.attached { background: var(--green-dim); }
.ai-picker-name { color: var(--text); font-family: var(--mono); }
.ai-picker-path { color: var(--text-3); font-family: var(--mono); font-size: 10.5px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-picker-state { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.ai-picker-item.attached .ai-picker-state { color: var(--green); }

/* ─── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ─── Utility ────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.spacer  { flex: 1; }

/* ─── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 700px) {
    :root {
        --sidebar-w: 100%;
        --bottom-nav-h: 56px;
        --topbar-h: 48px;
    }
    .layout {
        grid-template-columns: 1fr;
        /* topbar / main / bottom-nav. Сайдбар уходит из сетки и становится bottom-nav. */
        grid-template-rows: var(--topbar-h) 1fr auto;
        height: 100dvh;
    }

    /* ── Топбар: компактный, прячем виджет-кнопки под ⋯ ─── */
    .topbar { padding: 0 10px; padding-top: env(safe-area-inset-top, 0); height: auto; min-height: var(--topbar-h); }
    .topbar-logo {
        width: auto;
        border-right: none;
        font-size: 14px;
        padding-right: 6px;
    }
    .topbar-logo-icon { width: 22px; height: 22px; font-size: 14px; }
    /* Виджет-кнопки убираем; вместо них — кнопка overflow. */
    #btn-ai, #btn-db, #btn-console, #btn-debug, #btn-theme, #btn-install {
        display: none !important;
    }
    .topbar-actions { gap: 6px; }
    .topbar-actions .btn-sm { padding: 0 8px; font-size: 11px; }
    /* Overflow-кнопка ⋯ — её сам JS добавляет; если нет, ничего страшного. */
    .topbar-mobile-menu {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 32px; height: 32px;
        background: none; border: none;
        color: var(--text-2); cursor: pointer; font-size: 18px;
        border-radius: var(--radius);
    }
    .topbar-mobile-menu:hover { background: var(--surface2); }

    /* ── Сайдбар → bottom-nav ─── */
    .sidebar {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        flex-direction: row;
        justify-content: space-around;
        align-items: stretch;
        border-right: none;
        border-top: 1px solid var(--border);
        background: var(--bg);
        padding: 0;
        padding-bottom: env(safe-area-inset-bottom, 0);
        z-index: 100;
        height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0));
        overflow: visible;
    }
    .sidebar-section { display: none; }
    .sidebar-spacer { display: none; }
    .sidebar-footer { display: contents; }
    /* На мобиле в bottom-nav показываем только пометанные nav-primary и кнопку «Ещё». */
    .sidebar a:not(.nav-primary) { display: none; }
    .sidebar .nav-more { display: flex; }
    .sidebar a {
        flex: 1 1 0;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 2px;
        padding: 4px 2px;
        height: var(--bottom-nav-h);
        border-radius: 0;
        position: relative;
        color: var(--text-2);
    }
    .sidebar a.active { color: var(--text); }
    .sidebar a.active::before {
        content: '';
        position: absolute;
        top: 0; left: 20%; right: 20%;
        height: 2px;
        background: var(--accent);
        border-radius: 0 0 2px 2px;
    }
    .sidebar a svg { width: 18px; height: 18px; }
    .sidebar a .label {
        display: block;
        font-size: 9.5px;
        line-height: 1;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    /* Бэйджи внутри пунктов сайдбара — поверх иконки. */
    .sidebar a .sidebar-badge {
        position: absolute;
        top: 4px; right: calc(50% - 22px);
        min-width: 16px; height: 16px;
        font-size: 9.5px;
        padding: 0 4px;
    }

    /* ── Основной контент ─── */
    .main {
        padding: 12px;
        padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0) + 12px);
    }
    /* Карточки внутри страниц не должны рваться вправо. */
    .main * {
        max-width: 100%;
    }
    /* Длинные значения, mono-блоки и пр. — ломаем без жёстких переполнений. */
    .main pre,
    .main code,
    .main .mono,
    .main input[type="text"],
    .main input[type="search"],
    .main input[type="number"],
    .main textarea {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    /* ── Страница «Сервер»: pills и значения wrap'ятся ── */
    .page-header { flex-wrap: wrap; gap: 8px; }
    .server-card,
    .file-info,
    .info-row,
    .stat-row {
        flex-wrap: wrap;
        gap: 6px;
    }
    .info-row > *,
    .stat-row > * {
        min-width: 0;
        flex-shrink: 1;
        max-width: 100%;
    }
    .info-row .info-value,
    .stat-row .stat-value,
    .stat-row > span[id^="srv-"],
    .stat-row > span:not(.stat-label) {
        word-break: break-all;
        overflow-wrap: anywhere;
        text-align: right;
        max-width: 100%;
    }

    /* ── Files / DB layouts на мобиле ─── */
    .files-layout { grid-template-columns: 1fr; grid-template-rows: 180px 1fr; }
    .file-tree { border-right: none; border-bottom: 1px solid var(--border); }
    .files-resize { display: none; }
    .db-layout { grid-template-columns: 1fr; margin: -12px; }
    .db-sidebar { display: none; }

    /* Страницы с full-height layout (notes/db) — на мобиле сбрасываем
       desktop-margin (-32px/-40px рассчитан под desktop padding) и
       учитываем bottom-nav. */
    .notes,
    .db-layout {
        margin: -12px !important;
        margin-bottom: calc(-12px - var(--bottom-nav-h) - env(safe-area-inset-bottom, 0)) !important;
        height: calc(100dvh - var(--topbar-h) - var(--bottom-nav-h) - env(safe-area-inset-bottom, 0)) !important;
    }

    /* ── Заметки: список → отдельный экран, при выбранной заметке
          показываем только редактор. Sidebar всегда видна сверху
          компактной полоской, переключение по тапу. ── */
    .notes {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
    .notes-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 38vh;
    }
    .notes-side-head {
        padding: 8px;
        gap: 6px;
    }
    .notes-list {
        max-height: 28vh;
    }
    /* Toolbar редактора: переносим контрольки вниз, title на всю ширину */
    .notes-toolbar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px;
    }
    .notes-title-input {
        flex: 1 1 100%;
        font-size: 15px;
    }
    .notes-modes {
        font-size: 10px;
    }
    .notes-mode-btn {
        padding: 4px 8px;
        font-size: 10.5px;
    }
    /* Split-режим на мобиле слишком тесный — превращаем в две полосы. */
    .notes-panes-split {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }
    .notes-body {
        border-right: none;
        border-bottom: 1px solid var(--border);
        font-size: 13px;
        padding: 12px;
    }
    .notes-preview {
        padding: 12px 14px;
        font-size: 13px;
    }
    /* Share modal — на мобиле бери ширину экрана. */
    .notes-modal {
        width: 96vw;
        max-width: 460px;
    }

    /* ── Сервер: консоль и тулбар ─── */
    .console-toolbar {
        flex-wrap: wrap;
        padding: 8px;
        gap: 6px;
    }
    .console-toolbar > .card-title { width: 100%; margin-bottom: 4px !important; }
    .console-toolbar > input {
        flex: 1 1 100% !important;
        max-width: none !important;
        margin: 0 !important;
    }
    .console {
        height: 360px;
        padding: 10px;
        font-size: 11px;
    }
    .card { padding: 14px; }
    .card-header { flex-wrap: wrap; gap: 8px; }
    .btn-row { flex-wrap: wrap; gap: 6px; }
    .btn-row > .btn {
        flex: 1 1 auto;
        min-width: 0;
        white-space: normal;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-left: 12px;
        padding-right: 12px;
    }

    /* ── Виджеты: на мобиле раскрываем во весь экран ─── */
    .widget {
        left: 0 !important;
        right: 0 !important;
        top: env(safe-area-inset-top, 0) !important;
        bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0)) !important;
        width: auto !important;
        height: auto !important;
        border-radius: 0;
        border: none;
        background: var(--bg);
        opacity: 1 !important;
        backdrop-filter: none;
    }
    .widget-resize { display: none; }
    .widget-opacity { display: none; }
    .widget-header { cursor: default; padding: 10px 12px; }
    .widget-header { padding-top: max(10px, env(safe-area-inset-top, 0)); }
}

/* ─── External commands page ──────────────────────────────────── */
.extcmd { display: flex; flex-direction: column; height: 100%; min-height: 0; gap: 14px; }
.extcmd-head { display: flex; align-items: center; justify-content: space-between; }
.extcmd-title { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.extcmd-sub { font-size: 12px; color: var(--text-3); }
.extcmd-head-actions { display: flex; gap: 8px; }

.extcmd-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 14px;
    flex: 1;
    min-height: 0;
}

.extcmd-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.extcmd-filter {
    background: var(--surface2);
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    flex-shrink: 0;
}
.extcmd-filter::placeholder { color: var(--text-3); }
.extcmd-list { overflow-y: auto; flex: 1; padding: 4px 0 10px; }
.extcmd-group-title {
    padding: 12px 12px 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    font-weight: 600;
}
.extcmd-item {
    padding: 7px 12px;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background 0.08s, border-color 0.08s;
}
.extcmd-item:hover { background: var(--surface2); }
.extcmd-item.active {
    background: var(--surface2);
    border-left-color: var(--accent);
}
.extcmd-item-name {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.extcmd-item-meta {
    margin-top: 2px;
    font-size: 10.5px;
    color: var(--text-3);
    display: flex;
    gap: 8px;
}
.extcmd-item-id { font-family: var(--mono); }
.extcmd-item-fields { color: var(--text-2); }
.extcmd-item-empty { color: var(--text-3); }

.extcmd-main {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    min-width: 0;
}

.extcmd-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    flex: 1;
    overflow-y: auto;
}
.extcmd-empty {
    color: var(--text-3);
    font-size: 13px;
    padding: 40px;
    text-align: center;
}
.extcmd-empty-small {
    color: var(--text-3);
    font-size: 12px;
    padding: 14px 16px;
    text-align: center;
}
.extcmd-error {
    color: var(--red);
    font-size: 12px;
    padding: 14px 16px;
}

.extcmd-form-head { margin-bottom: 16px; }
.extcmd-form-name {
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.extcmd-form-id {
    color: var(--text-3);
    font-weight: 400;
    font-size: 12px;
    margin-left: 6px;
}
.extcmd-form-desc {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-2);
    line-height: 1.5;
}

.extcmd-fields { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.extcmd-no-fields { color: var(--text-3); font-size: 12px; padding: 12px 0; }
.extcmd-field-row { display: flex; flex-direction: column; gap: 5px; }
.extcmd-field-label {
    font-size: 11.5px;
    color: var(--text-2);
    font-weight: 500;
}
.extcmd-field-opt { color: var(--text-3); font-weight: 400; }
.extcmd-field-hint { font-size: 11px; color: var(--text-3); line-height: 1.45; }

.extcmd-input {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    color: var(--text);
    font-size: 12.5px;
    padding: 7px 10px;
    outline: none;
    font-family: var(--font);
    transition: border-color 0.08s;
}
.extcmd-input:focus { border-color: var(--border-2); }
.extcmd-input[type="number"] { font-family: var(--mono); }

.extcmd-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--text-2);
    font-size: 12px;
}
.extcmd-checkbox input { accent-color: var(--accent); }

.extcmd-actions { display: flex; align-items: center; gap: 12px; }
.extcmd-form-status { font-size: 12px; }
.extcmd-form-status.ok { color: var(--green); }
.extcmd-form-status.err { color: var(--red); }

/* ── reward_builder ───────────────────────────────────────────── */
.extcmd-rewards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}
.extcmd-reward {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
}
.extcmd-reward-head {
    display: flex;
    align-items: center;
    gap: 8px;
}
.extcmd-reward-num {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-3);
    min-width: 24px;
}
.extcmd-reward-type {
    flex: 1;
    min-width: 0;
}
.extcmd-reward-del {
    color: var(--red);
}
.extcmd-reward-subs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 6px;
    margin-top: 8px;
}
.extcmd-reward-sub {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.extcmd-reward-sub label {
    font-size: 10.5px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.extcmd-reward-empty {
    font-size: 11px;
    color: var(--text-3);
    padding: 4px 0 0 0;
}
.extcmd-reward-add {
    align-self: flex-start;
}
/* Advanced extra-поля внутри награды */
.extcmd-reward-adv-toggle {
    grid-column: 1 / -1;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-3);
    cursor: pointer;
    user-select: none;
    padding: 2px 0;
}
.extcmd-reward-adv-toggle:hover { color: var(--text-2); }
.extcmd-reward-sub-adv label { color: var(--text-3); }
.extcmd-sub-adv-tag {
    display: inline-block;
    margin-left: 6px;
    font-size: 9px;
    padding: 0 4px;
    border-radius: 3px;
    background: var(--surface);
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Кастомный комбобокс для lookup-полей */
.extcmd-combo {
    position: relative;
    display: flex;
    align-items: center;
}
.extcmd-combo .extcmd-combo-input {
    flex: 1;
    padding-right: 26px;
}
.extcmd-combo-arrow {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 6px;
}
.extcmd-combo-arrow:hover { color: var(--text); }
.extcmd-combo-list {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    z-index: 50;
    max-height: 240px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    padding: 4px 0;
}
.extcmd-combo-list.hidden { display: none; }
.extcmd-combo-opt {
    display: flex;
    gap: 8px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-2);
    line-height: 1.4;
}
.extcmd-combo-opt:hover { background: var(--surface2); color: var(--text); }
.extcmd-combo-id {
    font-family: var(--mono);
    color: var(--text-3);
    min-width: 32px;
    text-align: right;
}
.extcmd-combo-label { flex: 1; }
.extcmd-combo-empty,
.extcmd-combo-more {
    padding: 6px 10px;
    font-size: 11px;
    color: var(--text-3);
    font-style: italic;
}

.extcmd-recent-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    max-height: 260px;
    overflow-y: auto;
    flex-shrink: 0;
}
.extcmd-recent-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    font-weight: 600;
}
.extcmd-recent-count { color: var(--text-3); font-weight: 400; }

.extcmd-recent { display: flex; flex-direction: column; gap: 4px; }
.extcmd-rec {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    padding: 6px 10px;
}
.extcmd-rec-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}
.extcmd-rec-id {
    font-family: var(--mono);
    color: var(--text-3);
    font-size: 11px;
    min-width: 32px;
}
.extcmd-rec-name {
    font-family: var(--mono);
    color: var(--text);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.extcmd-rec-type {
    color: var(--text-3);
    font-family: var(--mono);
    font-size: 10.5px;
}
.extcmd-rec-state {
    font-family: var(--mono);
    font-size: 10.5px;
    padding: 1px 6px;
    border-radius: 3px;
}
.extcmd-rec-state.state-wait { background: var(--yellow-dim); color: var(--yellow); }
.extcmd-rec-state.state-ok { background: var(--green-dim); color: var(--green); }
.extcmd-rec-state.state-err { background: var(--red-dim); color: var(--red); }
.extcmd-rec-state.state-removed { background: var(--surface3); color: var(--text-3); }
.extcmd-rec-del { padding: 1px 8px !important; min-width: 0; }
.extcmd-rec-response {
    margin-top: 4px;
    padding: 4px 6px;
    font-size: 11.5px;
    color: var(--text-2);
    background: var(--bg);
    border-radius: 4px;
    font-family: var(--mono);
    line-height: 1.4;
    word-break: break-word;
}
.extcmd-rec-sql {
    margin: 6px 0 0 0;
    padding: 6px 8px;
    font-size: 11px;
    color: var(--text-2);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--mono);
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-all;
    user-select: all;
}
.extcmd-rec-sql.hidden { display: none; }

/* Шаблон в сайдбаре */
.extcmd-item-tpl {
    border-left: 2px solid var(--accent, var(--yellow));
}
.extcmd-tpl-del {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    font-size: 11px;
    padding: 0 4px;
    margin-left: auto;
}
.extcmd-tpl-del:hover { color: var(--red); }

/* mobile */
@media (max-width: 980px) {
    .extcmd-layout { grid-template-columns: 1fr; grid-template-rows: 220px 1fr; }
    .extcmd-recent-wrap { max-height: 180px; }
}

/* ── DB Widget ────────────────────────────────────────────────── */
.dbw {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--surface);
    overflow: hidden;
    min-height: 0;
}
.dbw-tabs {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}
.dbw-tab {
    background: none;
    border: 1px solid transparent;
    color: var(--text-3);
    cursor: pointer;
    font-size: 11.5px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
}
.dbw-tab:hover { color: var(--text); }
.dbw-tab.active {
    color: var(--text);
    background: var(--surface2);
    border-color: var(--border);
}
.dbw-mode {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

/* — режим browse — */
.dbw-browse {
    display: grid;
    grid-template-columns: 200px 1fr;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

/* — режим sql — */
.dbw-sql-mode {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}
.dbw-toolbar-sql {
    border-top: none;
}
.dbw-sql {
    width: 100%;
    min-height: 60px;
    max-height: 220px;
    resize: vertical;
    background: var(--surface2);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    padding: 6px 10px;
    outline: none;
    box-sizing: border-box;
    flex-shrink: 0;
}
.dbw-sql:focus { background: var(--bg); }
.dbw-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--surface);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
.dbw-side-head {
    display: flex;
    gap: 4px;
    padding: 6px 6px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.dbw-side-head input {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 11px;
    padding: 4px 6px;
    outline: none;
}
.dbw-side-head input:focus { border-color: var(--accent); }
.dbw-side-head button {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-3);
    cursor: pointer;
    font-size: 12px;
    padding: 0 8px;
}
.dbw-side-head button:hover { color: var(--text); }

.dbw-table-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 4px 0;
    min-height: 0;
}
.dbw-table-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 11.5px;
    color: var(--text-2);
    font-family: var(--mono);
    border-left: 2px solid transparent;
}
.dbw-table-item:hover { background: var(--surface2); color: var(--text); }
.dbw-table-item.active {
    background: var(--surface2);
    color: var(--text);
    border-left-color: var(--accent);
}
.dbw-table-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dbw-fav {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    font-size: 11px;
    padding: 0;
    width: 14px;
    flex-shrink: 0;
}
.dbw-fav.on { color: var(--yellow, #fbbf24); }
.dbw-fav:hover { color: var(--yellow, #fbbf24); }
.dbw-group-title {
    padding: 6px 8px 2px;
    font-size: 9.5px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.dbw-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--surface);
    overflow: hidden;
}
.dbw-toolbar {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.dbw-cur-table {
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}
.dbw-page-info {
    font-size: 11px;
    color: var(--text-3);
    font-family: var(--mono);
    padding: 0 4px;
    min-width: 90px;
    text-align: center;
}

.dbw-result {
    flex: 1 1 auto;
    overflow: auto;
    background: var(--bg);
    min-height: 0;
}
.dbw-loading,
.dbw-empty,
.dbw-empty-small {
    padding: 16px;
    text-align: center;
    color: var(--text-3);
    font-size: 12px;
}
.dbw-empty-small { padding: 10px; }
.dbw-err-block {
    padding: 12px;
    color: var(--red);
    font-family: var(--mono);
    font-size: 11px;
    white-space: pre-wrap;
}

.dbw-table-wrap { padding: 0; }
.dbw-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 11px;
}
.dbw-table th,
.dbw-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dbw-table th {
    background: var(--surface);
    color: var(--text-2);
    position: sticky;
    top: 0;
    font-weight: 600;
    z-index: 1;
}
.dbw-table tr:hover td { background: var(--surface); }
.dbw-null { color: var(--text-3); font-style: italic; }

.dbw-status {
    padding: 4px 8px;
    font-size: 10.5px;
    color: var(--text-3);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    font-family: var(--mono);
}
.dbw-status.ok { color: var(--green); }
.dbw-status.err { color: var(--red); }
.dbw-ok { color: var(--green); }
.dbw-err { color: var(--red); }

/* ── Notes (markdown editor + share) ──────────────────────────── */
.notes {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: calc(100vh - var(--topbar-h));
    margin: -32px -40px;
    background: var(--surface);
    overflow: hidden;
}
.notes-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--surface);
    overflow: hidden;
    min-width: 0;
}
.notes-side-head {
    display: flex;
    gap: 6px;
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.notes-side-head input {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 12px;
    padding: 5px 8px;
    outline: none;
    min-width: 0;
}
.notes-side-head input:focus { border-color: var(--accent); }

.notes-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.notes-item {
    padding: 8px 12px;
    cursor: pointer;
    border-left: 2px solid transparent;
    border-bottom: 1px solid var(--border);
}
.notes-item:hover { background: var(--surface2); }
.notes-item.active {
    background: var(--surface2);
    border-left-color: var(--accent);
}
.notes-item-title {
    font-size: 13px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
}
.notes-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10.5px;
    color: var(--text-3);
    font-family: var(--mono);
}
.notes-shared { font-size: 11px; }
.notes-empty,
.notes-err {
    padding: 16px;
    text-align: center;
    color: var(--text-3);
    font-size: 12px;
}
.notes-err { color: var(--red); }

.notes-main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}
.notes-editor {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.notes-blank {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-3);
    font-size: 14px;
}

.notes-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.notes-title-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    outline: none;
    padding: 2px 4px;
    min-width: 0;
}
.notes-title-input:focus { background: var(--surface2); border-radius: var(--radius-sm); }

.notes-modes {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.notes-mode-btn {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    font-size: 11px;
    padding: 4px 10px;
    border-right: 1px solid var(--border);
}
.notes-mode-btn:last-child { border-right: none; }
.notes-mode-btn.active { background: var(--surface2); color: var(--text); }
.notes-mode-btn:hover { color: var(--text); }

.notes-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
    font-size: 10.5px;
    font-family: var(--mono);
    color: var(--text-3);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.notes-save-status { color: var(--green); }

.notes-panes {
    flex: 1 1 auto;
    display: grid;
    overflow: hidden;
    min-height: 0;
}
.notes-panes-edit    { grid-template-columns: 1fr; }
.notes-panes-preview { grid-template-columns: 1fr; }
.notes-panes-split   { grid-template-columns: 1fr 1fr; }

.notes-panes-edit .notes-preview { display: none; }
.notes-panes-preview .notes-body { display: none; }

.notes-body {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: none;
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.6;
    padding: 16px 20px;
    outline: none;
    resize: none;
    box-sizing: border-box;
    border-right: 1px solid var(--border);
}
.notes-panes-edit .notes-body,
.notes-panes-preview .notes-body { border-right: none; }

.notes-preview {
    overflow-y: auto;
    padding: 16px 24px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 14px;
    line-height: 1.6;
    min-height: 0;
}
.notes-preview-html {
    padding: 0;
    background: var(--bg);
    overflow: hidden;
}
.notes-preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
    display: block;
}
.notes-preview h1, .notes-preview h2, .notes-preview h3, .notes-preview h4 {
    color: var(--text);
    margin-top: 20px;
    margin-bottom: 10px;
}
.notes-preview h1 { font-size: 22px; }
.notes-preview h2 { font-size: 18px; }
.notes-preview h3 { font-size: 16px; }
.notes-preview p { margin: 10px 0; }
.notes-preview ul, .notes-preview ol { padding-left: 24px; margin: 10px 0; }
.notes-preview li { margin: 3px 0; }
.notes-preview a { color: var(--accent); }
.notes-preview code {
    background: var(--surface2);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
}
.notes-preview pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    overflow-x: auto;
    margin: 12px 0;
}
.notes-preview pre code {
    background: none;
    padding: 0;
    font-size: 12px;
}
.notes-preview blockquote {
    border-left: 3px solid var(--border);
    padding: 2px 12px;
    color: var(--text-3);
    margin: 12px 0;
}
.notes-preview hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}
.notes-preview table {
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 12px;
}
.notes-preview th, .notes-preview td {
    border: 1px solid var(--border);
    padding: 4px 8px;
    text-align: left;
}
.notes-preview th { background: var(--surface2); color: var(--text); }
.notes-preview img { max-width: 100%; border-radius: 4px; }
.notes-preview input[type="checkbox"] { margin-right: 4px; accent-color: var(--accent); }

/* ── Code (pastebin) режим ─────────────────────────────────────── */
.notes-lang-select {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    padding: 4px 8px;
    outline: none;
    cursor: pointer;
    font-family: var(--mono);
}
.notes-lang-select:focus { border-color: var(--text-2); }

.notes-preview-code {
    padding: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.notes-code-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.notes-code-lang {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .04em;
    flex: 1;
}
.notes-code-copy {
    background: var(--surface2);
    color: var(--text-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 11px;
    padding: 3px 10px;
    cursor: pointer;
    transition: color .1s, border-color .1s;
}
.notes-code-copy:hover { color: var(--text); border-color: var(--border-2); }
.notes-code-pre {
    flex: 1;
    min-height: 0;
    overflow: auto;
    margin: 0;
    padding: 12px 16px;
    background: var(--bg);
}
.notes-code-pre code {
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.55;
    white-space: pre;
    background: none;
    padding: 0;
    color: var(--text);
}
/* highlight.js тема сама задаёт цвета токенов; фон берём от контейнера. */
.notes-code-pre code.hljs { background: transparent; padding: 0; }

/* Share modal */
.notes-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}
.notes-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 480px;
    max-width: 90vw;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.notes-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}
.notes-modal-close {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    font-size: 14px;
}
.notes-modal-close:hover { color: var(--text); }
.notes-modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.notes-share-toggle {
    display: flex;
    gap: 8px;
    align-items: center;
    cursor: pointer;
    color: var(--text);
    font-size: 13px;
}
.notes-share-toggle input { accent-color: var(--accent); }
.notes-share-url-wrap {
    display: flex;
    gap: 6px;
}
.notes-share-url-wrap.dim { opacity: 0.4; }
.notes-share-url {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 6px 10px;
    font-family: var(--mono);
    font-size: 11.5px;
    outline: none;
    min-width: 0;
}
.notes-share-actions {
    display: flex;
    justify-content: flex-end;
}
.notes-share-hint {
    font-size: 11px;
    color: var(--text-3);
    line-height: 1.45;
}
.notes-share-pass {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}

/* mobile */
@media (max-width: 980px) {
    .notes { grid-template-columns: 1fr; grid-template-rows: 200px 1fr; }
    .notes-sidebar { border-right: none; border-bottom: 1px solid var(--border); }
    .notes-panes-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
    .notes-body { border-right: none; border-bottom: 1px solid var(--border); }
}

/* Баннер «файл обновлён / доступ отозван» поверх редактора */
.file-stale-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 0 0 8px 0;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--yellow);
    border-radius: var(--radius);
    font-size: 12.5px;
}
.file-stale-banner.lost {
    border-left-color: var(--red);
    background: var(--red-dim);
}
.file-stale-banner .fs-ico { font-size: 14px; flex-shrink: 0; }
.file-stale-banner .fs-msg {
    flex: 1;
    color: var(--text);
    line-height: 1.4;
}

/* ── Mobile bottom-sheet («Ещё») ──────────────────────────────── */
.mobile-sheet {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}
.mobile-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}
.mobile-sheet-panel {
    position: relative;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    padding: 6px 16px calc(24px + env(safe-area-inset-bottom, 0));
    animation: sheetSlideUp 220ms ease-out;
    max-height: 80vh;
    overflow-y: auto;
}
@keyframes sheetSlideUp {
    from { transform: translateY(20%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.mobile-sheet-grab {
    width: 40px;
    height: 4px;
    margin: 6px auto 12px;
    background: var(--border-2);
    border-radius: 2px;
}
.mobile-sheet-title {
    font-size: 10.5px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 8px 4px 8px;
}
.mobile-sheet-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.mobile-sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 6px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    text-align: center;
}
.mobile-sheet-item:hover { background: var(--surface3); }
.mobile-sheet-icon {
    font-size: 20px;
    line-height: 1;
}

/* ── SmartSelect (замена <select>) ─────────────────────────────── */
.ss-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
    vertical-align: middle;
}
/* Оригинальный <select> прячем но оставляем в DOM для форм-событий. */
select.ss-native {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    left: 0; top: 0;
}
.ss-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 4px);
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
    padding: 6px 10px;
    cursor: pointer;
    text-align: left;
    line-height: 1.4;
    transition: border-color 0.1s;
    box-sizing: border-box;
}
.ss-trigger:hover { border-color: var(--border-2); }
.ss-trigger:focus,
.ss-wrap.ss-open .ss-trigger { outline: none; border-color: var(--accent); }
.ss-trigger.is-disabled { opacity: 0.5; cursor: not-allowed; }
.ss-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.ss-label.ss-placeholder { color: var(--text-3); }
.ss-caret {
    color: var(--text-3);
    font-size: 10px;
    flex-shrink: 0;
    transition: transform 0.15s;
}
.ss-wrap.ss-open .ss-caret { transform: rotate(180deg); }

.ss-popover {
    /* fixed + координаты из JS (getBoundingClientRect). Не absolute внутри
       .card/.sidebar с backdrop-filter — иначе dropdown блюрится и «наезжает». */
    position: fixed;
    z-index: 50000;
    /* min-width / top / left выставляет smart_select.js */
    width: max-content;
    max-width: min(560px, 90vw);
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius, 6px);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
    padding: 6px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}
.ss-popover.ss-above {
    /* направление вверх задаётся через top/bottom в JS */
}
.ss-search {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 4px);
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
    padding: 6px 10px;
    outline: none;
    flex-shrink: 0;
    margin-bottom: 4px;
}
.ss-search:focus { border-color: var(--accent); }
.ss-list {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    /* Явный лимит: если опций много — прокрутка внутри списка.
       max-height у .ss-popover иногда не срабатывает в некоторых
       контекстах, режем сам список. */
    max-height: 260px;
    margin: 0 -2px;
}
.ss-item {
    padding: 6px 10px;
    font-size: 12.5px;
    color: var(--text);
    cursor: pointer;
    border-radius: var(--radius-sm, 4px);
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ss-item.is-hover      { background: var(--surface2); }
.ss-item.is-selected   { background: rgba(59, 130, 246, 0.14); color: var(--text); }
.ss-item.is-selected.is-hover { background: rgba(59, 130, 246, 0.22); }
.ss-item.is-disabled   { color: var(--text-3); cursor: not-allowed; }
.ss-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-3);
    font-size: 12px;
}

/* ── App loader ────────────────────────────────────────────────── */
.app-loader {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.18s ease-out;
    pointer-events: all;
}
.app-loader.is-shown { opacity: 1; }
.app-loader-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.app-loader-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid var(--surface2);
    border-top-color: var(--text-2);
    animation: app-loader-spin 0.9s linear infinite;
}
.app-loader-text {
    color: var(--text-3);
    font-size: 12.5px;
    letter-spacing: 0.03em;
}
@keyframes app-loader-spin {
    to { transform: rotate(360deg); }
}
