/* SchemeOG Canvas Styles */

/* ================================================
   CSS Variables (Brand Design System)
   ================================================ */
:root {
    /* Primary Colors */
    --blue: #1a6ddb;
    --blue-light: #5b9cf5;
    --blue-hover: #1558b8;

    /* Text Colors */
    --text-dark: #0f1729;
    --text-muted: #64748b;
    --text-subtle: #8a96a8;

    /* Backgrounds */
    --bg-page: #f1f5fb;
    --bg-white: #ffffff;
    --bg-hover: #f9fafb;
    --bg-active: #f3f4f6;

    /* Borders */
    --border-light: #e5e7eb;
    --border-blue: rgba(91, 156, 245, 0.18);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    --shadow-modal: 0 12px 40px rgba(0, 0, 0, 0.15);
    --glass-shadow: 0 8px 32px rgba(91, 156, 245, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-btn: 10px;
    --radius-modal: 16px;

    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #dc2626;
    --info: #3b82f6;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;

    /* Scale Factor */
    --scale: 1.12;

    /* Font Sizes */
    --fs-2xs:    calc(10px * var(--scale));
    --fs-xs:     calc(11px * var(--scale));
    --fs-sm:     calc(12px * var(--scale));
    --fs-base:   calc(13px * var(--scale));
    --fs-md:     calc(14px * var(--scale));
    --fs-lg:     calc(15px * var(--scale));
    --fs-xl:     calc(16px * var(--scale));
    --fs-2xl:    calc(18px * var(--scale));
    --fs-3xl:    calc(20px * var(--scale));
    --fs-4xl:    calc(24px * var(--scale));

    /* Icon Sizes */
    --icon-sm:   calc(16px * var(--scale));
    --icon-base: calc(20px * var(--scale));
    --icon-lg:   calc(24px * var(--scale));

    /* Button Heights */
    --btn-sm:    calc(32px * var(--scale));
    --btn-md:    calc(40px * var(--scale));
    --btn-lg:    calc(44px * var(--scale));

    /* Z-index layer system */
    --z-canvas:    1;      /* canvas nodes, edges */
    --z-toolbar:   10;     /* toolbar, minimap, zoom controls */
    --z-ui-chrome: 100;    /* schema-title-header, breadcrumb */
    --z-sidebar:   200;    /* ai-sidebar, icon-sidebar */
    --z-dropdown:  300;    /* dropdowns inside sidebar */
    --z-modal:     500;    /* popups, modals */
    --z-overlay:   700;    /* full-screen overlay */
    --z-toast:     900;    /* notifications */
    --z-tooltip:   1100;   /* tooltips (global data-gtip system) */
    --z-critical:  9999;   /* loading screen, blocking UI */
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f1f5fb;
    overflow: hidden !important;
    color: #000000;
}

#canvas {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: #f1f5fb;
    overflow: hidden;
    /* Курсор управляется через JavaScript при нажатии пробела */
    cursor: default;
    /* Отключаем выделение текста при двойном клике */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Floating tools (справа внизу) */
.canvas-float-tools {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: var(--z-modal);
}

.canvas-float-btn {
    width: var(--btn-lg);
    height: var(--btn-lg);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #9ca3af;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all 0.2s ease;
    opacity: 0.7;
}

.canvas-float-btn:hover {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(0, 0, 0, 0.08);
    color: #6b7280;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    opacity: 1;
}

.canvas-float-btn:active {
    transform: scale(0.97);
    background: #f9fafb;
}

/* Active (toggled on) state — e.g. mini-map toggle */
.canvas-float-btn.active {
    background: rgba(239, 246, 255, 0.9);
    border-color: rgba(147, 197, 253, 0.4);
    color: #3b82f6;
    opacity: 1;
}

.canvas-float-btn svg {
    width: var(--icon-base);
    height: var(--icon-base);
}

.canvas-float-btn[data-tooltip] {
    position: relative;
}

.canvas-float-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    right: calc(100% + 8px);
    left: auto;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    padding: 4px 8px;
    background: #1f2937;
    color: white;
    font-size: var(--fs-sm);
    font-weight: 500;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-in-out;
    z-index: var(--z-tooltip);
}

.canvas-float-btn[data-tooltip]:hover::after {
    opacity: 1;
}

/* Loader */
/* Canvas reload skeleton cards */
@keyframes croShimmer {
    0% { background-position: -300px 0; }
    100% { background-position: calc(300px + 100%) 0; }
}
.cro-card {
    background: #e2e8f0;
    background-image: linear-gradient(90deg, #e2e8f0 0px, #f1f5f9 80px, #e2e8f0 160px);
    background-size: 300px 100%;
    background-repeat: no-repeat;
    animation: croShimmer 1.6s ease-in-out infinite;
    border-radius: 12px;
}
.cro-arrow {
    width: 20px;
    height: 2px;
    background: #cbd5e1;
    position: relative;
    flex-shrink: 0;
}
.cro-arrow::after {
    content: '';
    position: absolute;
    right: -1px;
    top: -4px;
    width: 0;
    height: 0;
    border-left: 7px solid #cbd5e1;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
}

.canvas-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-toast);
}

.canvas-loader.active {
    display: flex;
}

.loader-content {
    text-align: center;
    color: white;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-text {
    font-size: var(--fs-3xl);
    font-weight: 600;
    margin-bottom: 8px;
}

.loader-subtext {
    font-size: var(--fs-md);
    opacity: 0.8;
}

/* Schema Title (Top Left) */
.schema-title-header {
    position: fixed;
    top: 14px;
    left: 84px; /* 20px (отступ слева) + 44px (ширина кнопки схем) + 20px (gap) */
    background: transparent;
    height: var(--btn-lg);
    padding: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    gap: 8px;
}

.schema-title-breadcrumb {
    color: #6b7280;
    text-decoration: none;
    font-size: var(--fs-md);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s;
}

.schema-title-breadcrumb:hover {
    color: #2563eb;
}

.schema-title-separator {
    color: #d1d5db;
    font-size: var(--fs-md);
    user-select: none;
}

/* Schemas Quick Access (отдельная кнопка слева) */
.schemas-quick-access {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
}

.schemas-toggle-btn {
    width: var(--btn-lg);
    height: var(--btn-lg);
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: white;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    outline: none;
}

/* .schemas-toggle-btn:hover {
    background: #f9fafb;
    border-color: #1a6ddb;
    color: #1a6ddb;
    box-shadow: 0 4px 16px rgba(249, 115, 22, 0.2);
} */

.schemas-toggle-btn:focus {
    outline: none;
}

.schemas-toggle-btn:active {
    transform: scale(0.95);
}

.schema-title-text {
    font-size: var(--fs-lg);
    font-weight: 500;
    color: #374151;
    margin: 0;
    cursor: text;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: all 0.15s ease;
    letter-spacing: -0.3px;
    /* Truncate long names with ellipsis */
    max-width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.schema-title-text:hover {
    background: transparent;
    border-color: transparent;
    color: #111827;
    text-decoration: underline;
    text-decoration-style: dashed;
    text-decoration-color: #cbd5e1;
    text-underline-offset: 3px;
}

.schema-title-input {
    font-size: var(--fs-lg);
    font-weight: 500;
    color: #111827;
    padding: 2px 6px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    outline: none;
    letter-spacing: -0.3px;
    max-width: 500px;
    min-width: 200px;
    width: auto;
    font-family: inherit;
    line-height: inherit;
    margin: 0;
}

.schema-title-input:focus {
    border-color: transparent;
    background: transparent;
    text-decoration: none;
}

.schema-title-text[contenteditable="true"] {
    background: transparent;
    border-color: transparent;
    text-decoration: none;
    outline: none;
    cursor: text;
}



/* Toolbar */
.toolbar {
    position: fixed;
    top: 20px;
    right: 80px;
    display: none;
    gap: 10px;
    background: white;
    padding: 10px 15px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: var(--z-overlay);
    border: 1px solid #e5e5e5;
}

.view-code-btn {
    padding: 8px 16px;
    font-size: var(--fs-md);
    font-weight: 500;
    border: none;
    border-radius: 8px;
    background: #ffffff;
    color: #000000;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #e5e5e5;
}

.view-code-btn:hover {
    background: #f5f5f5;
    transform: translateY(-1px);
}

.view-code-btn:active {
    transform: translateY(0);
}

/* ========================================
   TOP TOOLBAR - Flexbox контейнер справа сверху
   ======================================== */
.top-toolbar {
    position: fixed;
    top: 14px;
    right: 14px;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: var(--z-modal);
    flex-wrap: nowrap;
    max-width: calc(100vw - 28px);
    justify-content: flex-end;
    box-sizing: border-box;
}

/* Универсальная кнопка toolbar — compact minimalist style */
.toolbar-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: none;
    transition: all 0.15s ease;
    color: #64748b;
    opacity: 1;
    padding: 0;
}

.toolbar-btn svg {
    width: 18px;
    height: 18px;
}

.toolbar-btn:hover {
    background: rgba(0, 0, 0, 0.07);
    border-color: rgba(0, 0, 0, 0.07);
    color: #1e293b;
    opacity: 1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.toolbar-btn:hover svg {
    stroke: #1e293b;
}

.toolbar-btn:active {
    transform: scale(0.95);
}

/* Lock toggle стили внутри toolbar */
.toolbar-btn.lock-toggle {
    position: relative;
    padding: 0;
}

.toolbar-btn.lock-toggle input {
    display: none;
}

.toolbar-btn.lock-toggle .lock-toggle-slider {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #6b7280;
}

.toolbar-btn.lock-toggle .lock-open {
    display: block;
}

.toolbar-btn.lock-toggle .lock-closed {
    display: none;
}

.toolbar-btn.lock-toggle input:checked + .lock-toggle-slider .lock-open {
    display: none;
}

.toolbar-btn.lock-toggle input:checked + .lock-toggle-slider .lock-closed {
    display: block;
}

.toolbar-btn.lock-toggle:has(input:checked) {
    background: rgba(254, 243, 199, 0.6);
    border-color: rgba(245, 158, 11, 0.3);
    opacity: 0.9;
}

.toolbar-btn.lock-toggle:has(input:checked) .lock-toggle-slider {
    color: #d97706;
}

/* Legacy стили для обратной совместимости */
.schema-settings-btn,
.schema-share-btn,
.schema-copy-btn,
.schema-download-btn {
    display: none; /* Скрываем старые кнопки */
}

/* Lock Toggle Button (MCP mode) - legacy */
.schema-lock-toggle {
    display: none; /* Скрываем старую кнопку */
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: var(--z-modal);
    transition: all 0.2s ease;
}

.schema-lock-toggle:hover {
    background: #f8f9fa;
    border-color: #d0d0d0;
}

.schema-lock-toggle input {
    display: none;
}

.schema-lock-toggle .lock-toggle-slider {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: color 0.2s ease;
}

.schema-lock-toggle .lock-open {
    display: block;
}

.schema-lock-toggle .lock-closed {
    display: none;
}

/* Locked state */
.schema-lock-toggle input:checked + .lock-toggle-slider {
    color: #d97706;
}

.schema-lock-toggle input:checked + .lock-toggle-slider .lock-open {
    display: none;
}

.schema-lock-toggle input:checked + .lock-toggle-slider .lock-closed {
    display: block;
}

/* When locked - show yellow background */
.schema-lock-toggle:has(input:checked) {
    background: #fef3c7;
    border-color: #fbbf24;
}

/* Locked mode - disable editing UI */
body.locked-mode .left-sidebar { /* left-sidebar removed */
    opacity: 0.4;
    pointer-events: none;
}

body.locked-mode #canvas {
    cursor: default !important;
}

/* Visual indicator when locked */
body.locked-mode::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #fbbf24, #f59e0b);
    z-index: var(--z-critical);
}

.schema-copy-btn {
    position: fixed;
    top: 20px;
    right: 228px;
    width: var(--btn-md);
    height: var(--btn-md);
    border-radius: 8px;
    background: white;
    border: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: var(--z-modal);
    transition: all 0.2s ease;
    color: #333;
}

.schema-copy-btn:hover {
    background: #fff7ed;
    border-color: #1a6ddb;
}

.schema-copy-btn:hover svg {
    stroke: #1a6ddb;
}

.schema-copy-btn:active {
    transform: scale(0.95);
}

.schema-paste-btn {
    position: fixed;
    top: 20px;
    right: 228px;
    width: var(--btn-md);
    height: var(--btn-md);
    border-radius: 8px;
    background: white;
    border: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: var(--z-modal);
    transition: all 0.2s ease;
    color: #333;
}

.schema-paste-btn:hover {
    background: #fff7ed;
    border-color: #1a6ddb;
}

.schema-paste-btn:hover svg {
    stroke: #1a6ddb;
}

.schema-paste-btn:active {
    transform: scale(0.95);
}

.schema-download-btn {
    position: fixed;
    top: 20px;
    right: 176px;
    width: var(--btn-md);
    height: var(--btn-md);
    border-radius: 8px;
    background: white;
    border: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: var(--z-modal);
    transition: all 0.2s ease;
    color: #333;
}

.schema-download-btn:hover {
    background: #f8f9fa;
    border-color: #d0d0d0;
}

.schema-download-btn:active {
    transform: scale(0.95);
}

.account-circle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: var(--btn-md);
    height: var(--btn-md);
    border-radius: 8px;
    background: white;
    border: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: var(--z-modal);
    transition: all 0.2s ease;
    font-size: var(--fs-2xl);
    user-select: none;
    color: #333;
}

.account-circle svg {
    width: var(--icon-base);
    height: var(--icon-base);
}

.account-circle:hover {
    background: #f8f9fa;
    border-color: #d0d0d0;
}

.account-circle:active {
    transform: scale(0.95);
}

/* Tooltips - единый стиль (чёрный фон, белый текст) */
.element-tooltip {
    position: fixed;
    background: #1f2937;
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    border: none;
    font-size: var(--fs-sm);
    font-weight: 500;
    pointer-events: none;
    z-index: var(--z-tooltip);
    display: none;
    white-space: normal;
    max-width: 300px;
    word-wrap: break-word;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.element-tooltip.show,
.element-tooltip.visible {
    display: block;
}

/* ============================================= */
/* DESCRIPTION PANEL (slides from right) */
/* ============================================= */

.description-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    right: -320px;
    width: 320px;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: var(--z-critical); /* Выше toolbar кнопок (999999) */
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}

.description-panel.visible {
    right: 0;
}

.description-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.description-panel-header h3 {
    margin: 0;
    font-size: var(--fs-xl);
    font-weight: 600;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.description-panel-content {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
}

.description-panel-content textarea {
    width: 100%;
    height: 100%;
    min-height: 200px;
    padding: 12px;
    font-size: var(--fs-md);
    line-height: 1.6;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    resize: none;
    background: #f9fafb;
    color: #374151;
    transition: border-color 0.2s, background 0.2s;
    margin: 0;
    box-sizing: border-box;
}

.description-panel-content textarea:focus {
    outline: none;
    border-color: #1a6ddb;
    background: #fff;
}

/* SVG Canvas Elements */
#canvas svg {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    /* Allow connection point circles at card edges to render beyond SVG viewport
       without being clipped. The parent #canvas overflow:hidden still constrains
       content to the canvas area. */
    overflow: visible;
}

/* SVG Карточки, условия и ASCII */
.schemeog-card,
.schemeog-condition,
.schemeog-ascii {
    cursor: move;
    user-select: none;
    pointer-events: all;
}

.schemeog-card:hover rect,
.schemeog-condition:hover path,
.schemeog-ascii:hover rect {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.schemeog-card.dragging,
.schemeog-condition.dragging,
.schemeog-ascii.dragging {
    opacity: 0.8;
}

/* Выделенные элементы - БЕЗ ОБВОДКИ */
.schemeog-card.selected,
.schemeog-condition.selected,
.schemeog-ascii.selected {
    opacity: 1;
    cursor: move;
}

/* Подсветка элементов во время обводки рамкой выделения */
.schemeog-card.selection-hover rect:first-child,
.schemeog-condition.selection-hover path:first-child,
.schemeog-ascii.selection-hover rect:first-child {
    filter: drop-shadow(0 0 4px rgba(249, 115, 22, 0.3));
    transition: filter 0.15s ease;
}

/* Анимация для выделенных элементов */
.selection-outline {
    animation: none;
    opacity: 0.7;
}

/* Режим read-only: курсор по умолчанию */
.read-only-mode .schemeog-card,
.read-only-mode .schemeog-condition,
.read-only-mode .schemeog-card.selected,
.read-only-mode .schemeog-condition.selected {
    cursor: default !important;
}

/* Legacy Card Styles (для старых версий) */
.card {
    background: white;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    cursor: move;
    user-select: none;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* Scheme Code Viewer */
.scheme-code-viewer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 500px;
    background: white;
    border-left: 1px solid #e5e5e5;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: var(--z-overlay);
    display: none;
    flex-direction: column;
}

.scheme-code-viewer.active {
    display: flex;
}

.code-header {
    padding: 20px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.code-content {
    flex: 1;
    overflow: auto;
    padding: 20px;
}

.code-block {
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 0;
    margin: 8px 0;
    overflow: hidden;
    position: relative;
}

.code-block .code-lang {
    display: block;
    background: #333;
    color: #888;
    font-size: var(--fs-xs);
    padding: 4px 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.code-block pre {
    margin: 0;
    padding: 12px 15px;
    overflow-x: auto;
}

.code-block pre code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Courier New', monospace;
    font-size: var(--fs-base);
    line-height: 1.5;
    color: #d4d4d4;
    white-space: pre;
    display: block;
}

/* Inline code */
code.inline-code {
    background: #f0f0f0;
    color: #e53935;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 0.9em;
}

/* Markdown rendered content in descriptions */
.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
    margin: 12px 0 8px 0;
    line-height: 1.3;
}

.markdown-content h1 { font-size: 1.4em; }
.markdown-content h2 { font-size: 1.2em; }
.markdown-content h3 { font-size: 1.1em; }

.markdown-content p {
    margin: 6px 0;
    line-height: 1.5;
}

.markdown-content ul,
.markdown-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.markdown-content li {
    margin: 4px 0;
    line-height: 1.4;
}

.markdown-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 12px 0;
}

.markdown-content a {
    color: #1a6ddb;
    text-decoration: none;
}

.markdown-content a:hover {
    text-decoration: underline;
}

/* Tooltip markdown styles */
#tooltip-content .code-block {
    margin: 6px 0;
}

#tooltip-content .code-block pre {
    padding: 8px 12px;
}

#tooltip-content code.inline-code {
    font-size: 0.85em;
}

#tooltip-content p {
    margin: 4px 0;
}

/* Marked.js code block styles (when using marked.js library) */
pre {
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 12px 15px;
    margin: 8px 0;
    overflow-x: auto;
}

pre code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Courier New', monospace;
    font-size: var(--fs-base);
    line-height: 1.5;
    color: #d4d4d4;
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

/* Inline code from marked.js */
code {
    background: #f0f0f0;
    color: #e53935;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 0.9em;
}

/* Side panel and tooltip specific styles for code */
#tooltip-content pre,
#card-description pre,
#card-description-text pre,
.card-detail-panel pre {
    background: #1e1e1e;
    padding: 10px 12px;
    margin: 6px 0;
}

#tooltip-content code,
#card-description code,
#card-description-text code,
.card-detail-panel code {
    font-size: 0.85em;
}

.close-btn {
    padding: 8px 16px;
    background: #f5f5f5;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    cursor: pointer;
    font-size: var(--fs-md);
    font-weight: 500;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: #e5e5e5;
}

/* Popups (legacy — aligned with unified modal system) */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 41, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-toast);
    animation: fadeInOverlay var(--transition-base);
}

.popup-content {
    background: linear-gradient(165deg, #ffffff 0%, #f8faff 100%);
    border: 1px solid var(--border-blue);
    border-radius: var(--radius-modal);
    padding: 30px;
    max-width: min(560px, 95vw);
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--glass-shadow);
    animation: modalSlideIn var(--transition-base);
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

.popup-header {
    margin-bottom: 20px;
}

.popup-header h2 {
    font-size: var(--fs-4xl);
    font-weight: 600;
    color: #000000;
}

.popup-body {
    margin-bottom: 20px;
}

.popup-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Forms */
input[type="text"],
input[type="email"],
textarea {
    width: 100%;
    padding: 12px 16px;
    font-size: var(--fs-md);
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    background: #ffffff;
    color: #000000;
    outline: none;
    transition: all 0.2s ease;
    margin-bottom: 12px;
}

input:focus,
textarea:focus {
    border-color: #000000;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

button {
    padding: 10px 20px;
    font-size: var(--fs-md);
    font-weight: 500;
    border: 1.5px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    outline: none;
}

button:focus {
    outline: none;
}

/* Стили кнопок в стиле "Только обводки" (Вариант 3) */
.btn-primary, button.primary {
    background: transparent;
    color: #000000;
    border: 1.5px solid #000000;
}

.btn-primary:hover, button.primary:hover {
    background: #fafafa;
}

.btn-secondary, button.secondary {
    background: transparent;
    color: #6b7280;
    border: 1.5px solid #d1d5db;
}

.btn-secondary:hover, button.secondary:hover {
    background: #f9fafb;
}

.btn-danger, button.danger {
    background: transparent;
    color: #dc2626;
    border: 1.5px solid #dc2626;
}

.btn-danger:hover, button.danger:hover {
    background: #fef2f2;
}

/* Кнопка закрытия (X) */
.btn-close {
    background: transparent;
    color: #6b7280;
    border: none;
    padding: 0;
    width: var(--btn-sm);
    height: var(--btn-sm);
    min-width: var(--btn-sm);
    min-height: var(--btn-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: var(--fs-4xl);
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-close:hover {
    background: #f3f4f6;
    color: #374151;
}

.btn-close-absolute {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: var(--z-toolbar);
}

/* Utility classes */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

/* ================================================
   POPUP БЛОКИРОВКА UI - КРИТИЧЕСКИ ВАЖНО!
   Когда попап открыт, весь остальной UI блюрится
   и недоступен для клика
   ================================================ */

/* Overlay для всех попапов */
/* ================================================
   UNIFIED MODAL OVERLAY (Brand Design System)
   ================================================ */
.popup-overlay,
.card-detail-overlay,
.modal-overlay,
.confirm-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 41, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-sidebar);
    animation: fadeInOverlay var(--transition-base);
}

.popup-overlay.show,
.card-detail-overlay.show,
.modal-overlay.show,
.modal-overlay.active,
.confirm-modal.active {
    display: flex;
}

/* Попап подтверждения удаления - ВЫШЕ всех остальных попапов */
#delete-confirm-popup {
    z-index: var(--z-critical) !important;
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* NOTE: .popup-overlay.show uses display: flex from unified styles above */

/* ================================================
   UNIFIED MODAL CONTAINER (Brand Design System)
   ================================================ */

/* Unified popup panel base */
.popup-panel {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideIn 0.2s ease-out;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}
.popup-panel-sm { max-width: min(520px, 95vw); }
.popup-panel-md { max-width: min(600px, 95vw); }
.popup-panel-lg { max-width: min(720px, 95vw); }
.popup-panel-xl { max-width: min(960px, 95vw); }

@media (max-width: 640px) {
    .popup-panel { width: 95%; max-height: 90vh; }
}

/* Modal container — glassmorphism style from brandbook */
.modal-container,
.modal-content,
.confirm-modal-content {
    background: linear-gradient(165deg, #ffffff 0%, #f8faff 100%);
    border: 1px solid var(--border-blue);
    border-radius: var(--radius-modal);
    box-shadow: var(--glass-shadow);
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Shared modal width — used by Version History, Export popups */
.app-modal {
    width: 560px;
    max-width: min(560px, calc(100vw - 32px));
}
@media (max-width: 639px) {
    .app-modal {
        width: calc(100vw - 32px);
        max-width: calc(100vw - 32px);
        margin: 0 16px;
    }
}

/* ============================================
   SHARE POPUP -- Minimalist Redesign
   ============================================ */
.share-modal {
    overflow: visible;
    border: 1px solid rgba(59, 130, 246, 0.12);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(59, 130, 246, 0.18);
    background: #FFFFFF;
}

.share-modal-title {
    font-size: var(--fs-xl);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    max-width: calc(100% - 48px);
    font-family: 'Outfit', 'DM Sans', sans-serif;
    line-height: 1.3;
    color: var(--text-dark);
}

.share-modal-schema-name {
    font-weight: 400;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
    font-size: var(--fs-md);
}

.share-modal-body {
    padding: 0;
    overflow: visible;
}

.share-section {
    padding: 16px 24px;
    border-bottom: 1px solid #E2E8F0;
}

.share-section:last-child {
    border-bottom: none;
}

.share-section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    color: #94A3B8;
    margin-bottom: 10px;
    font-family: 'DM Sans', 'Outfit', sans-serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.share-section-label svg {
    opacity: 0.6;
    flex-shrink: 0;
    color: #94A3B8;
}

/* Section header row: label on left, toggle on right */
.share-section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 0;
}

.share-section-header-row .share-section-label {
    margin-bottom: 0;
}

/* Muted hint text shown when a link section is disabled */
.share-section-hint {
    font-size: var(--fs-sm);
    color: #94A3B8;
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    margin-top: 8px;
    line-height: 1.45;
}

/* Share Link toggle row (legacy, kept for backward compat) */
.share-access-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.share-access-toggle-label {
    font-size: var(--fs-sm);
    color: var(--text-dark);
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
}

.share-toggle-label {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.share-toggle-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.share-toggle-track {
    width: 38px;
    height: 22px;
    background: #d1d5db;
    border-radius: 11px;
    position: relative;
    transition: background 0.25s;
}

.share-toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.share-toggle-track--blue {}

.share-toggle-input:checked + .share-toggle-track {
    background: var(--blue);
}

.share-toggle-input:checked + .share-toggle-track::after {
    transform: translateX(16px);
}

.share-toggle-input:focus + .share-toggle-track {
    box-shadow: 0 0 0 3px rgba(26, 109, 219, 0.12);
}

/* Link copy row */
.share-link-copy-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.share-link-labels-row {
    margin-top: 10px;
    margin-bottom: 4px;
}
.share-link-type-label {
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.share-link-input {
    flex: 1;
    height: 36px;
    font-size: 12px;
    padding: 0 12px;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    background: #F8FAFC;
    color: #475569;
    outline: none;
    min-width: 0;
    font-family: 'JetBrains Mono', 'DM Mono', 'Courier New', monospace;
    box-sizing: border-box;
    cursor: text;
    transition: border-color var(--transition-fast);
}

.share-link-input:focus {
    border-color: var(--blue);
    background: #FFFFFF;
}

.share-link-copy-btn-new {
    height: 36px;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    background: #3B82F6;
    color: white;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
    font-family: 'DM Sans', 'Outfit', sans-serif;
    flex-shrink: 0;
    box-sizing: border-box;
}

.share-link-copy-btn-new:hover {
    background: #1D4ED8;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.share-link-copy-btn-new.copied {
    background: var(--success);
    color: white;
}

/* Invite row */
.share-invite-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.share-invite-input {
    flex: 1;
    height: 38px;
    font-size: var(--fs-sm);
    padding: 0 14px;
    border: 1.5px solid rgba(26, 109, 219, 0.12);
    border-radius: var(--radius-btn);
    background: var(--bg-white);
    color: var(--text-dark);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    min-width: 0;
    font-family: 'DM Sans', -apple-system, sans-serif;
    box-sizing: border-box;
}

.share-invite-input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26, 109, 219, 0.08);
}

.share-invite-input::placeholder {
    color: var(--text-subtle);
    font-weight: 400;
}

.share-invite-send-btn {
    height: 38px;
    padding: 0 18px;
    font-size: var(--fs-sm);
    font-weight: 600;
    border: none;
    border-radius: var(--radius-btn);
    background: var(--blue);
    color: white;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
    font-family: 'Outfit', sans-serif;
    flex-shrink: 0;
    box-sizing: border-box;
}

.share-invite-send-btn:hover {
    background: var(--blue-hover);
    box-shadow: 0 4px 12px rgba(26, 109, 219, 0.25);
    transform: translateY(-1px);
}

.share-invite-send-btn:active {
    transform: translateY(0) scale(0.98);
}

.share-invite-send-btn svg {
    flex-shrink: 0;
    opacity: 0.85;
}

/* Role dropdown */
.share-role-dropdown-wrap {
    position: relative;
    flex-shrink: 0;
}

.share-role-btn {
    height: 38px;
    padding: 0 26px 0 12px;
    font-size: var(--fs-sm);
    border: 1.5px solid rgba(26, 109, 219, 0.12);
    border-radius: var(--radius-btn);
    background: var(--bg-white);
    color: var(--text-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    position: relative;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    font-family: 'DM Sans', -apple-system, sans-serif;
    box-sizing: border-box;
    font-weight: 500;
}

.share-role-btn:hover {
    border-color: rgba(26, 109, 219, 0.3);
    background: rgba(26, 109, 219, 0.03);
}

.share-invite-message {
    margin-top: 10px;
    font-size: var(--fs-sm);
    padding: 10px 14px;
    border-radius: var(--radius-md);
}

/* Contacts autocomplete */
.contacts-autocomplete-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}

.contacts-autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(26, 109, 219, 0.1);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.04);
    z-index: var(--z-modal);
    max-height: 200px;
    overflow-y: auto;
    display: none;
    padding: 4px;
}

.contacts-autocomplete-dropdown.open { display: block; }

.contacts-autocomplete-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.12s;
    border-radius: var(--radius-md);
}

.contacts-autocomplete-item:hover { background: rgba(26, 109, 219, 0.05); }

.contacts-autocomplete-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.contacts-autocomplete-info { flex: 1; min-width: 0; }

.contacts-autocomplete-email {
    font-size: var(--fs-sm);
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contacts-autocomplete-name {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* People with access divider */
.share-people-divider {
    font-size: var(--fs-2xs);
    font-weight: 600;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-family: 'Outfit', sans-serif;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(26, 109, 219, 0.06);
}

/* People list */
.share-people-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 180px;
    overflow-y: auto;
}

.share-person-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.share-person-row:hover { background: rgba(26, 109, 219, 0.04); }

.share-person-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-2xs);
    font-weight: 600;
    color: white;
    flex-shrink: 0;
    text-transform: uppercase;
    font-family: 'Outfit', sans-serif;
}

.share-person-info { flex: 1; min-width: 0; }

.share-person-email {
    font-size: var(--fs-sm);
    color: var(--text-dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    line-height: 1.4;
}

.share-person-status { font-size: var(--fs-2xs); color: var(--text-subtle); margin-top: 1px; }

.share-person-role {
    font-size: var(--fs-2xs);
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    background: rgba(26, 109, 219, 0.05);
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500;
    font-family: 'DM Sans', sans-serif;
}

.share-person-remove {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--text-subtle);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 16px;
    font-weight: 300;
    line-height: 1;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    opacity: 0;
}

.share-person-row:hover .share-person-remove { opacity: 1; }

.share-person-remove:hover {
    background: rgba(220, 38, 38, 0.08);
    color: var(--danger);
}

.share-chevron {
    flex-shrink: 0;
    opacity: 0.35;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.share-role-btn:hover .share-chevron { opacity: 0.7; }

/* Dropdown menu */
.share-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(26, 109, 219, 0.1);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.04);
    z-index: var(--z-toast);
    min-width: 200px;
    overflow: hidden;
    padding: 4px;
    animation: shareDropdownIn 0.15s ease-out;
}

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

.share-dropdown-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 14px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s;
    font-family: 'DM Sans', -apple-system, sans-serif;
    border-radius: var(--radius-md);
}

.share-dropdown-item:hover { background: rgba(26, 109, 219, 0.05); }

.share-dropdown-item-title { font-size: var(--fs-sm); font-weight: 500; color: var(--text-dark); line-height: 1.3; }

.share-dropdown-item-desc { font-size: var(--fs-xs); color: var(--text-subtle); margin-top: 2px; line-height: 1.3; }

/* Password Protection */
.share-section-password { border-bottom: none; }

.share-password-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.share-password-status {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    font-family: 'DM Sans', sans-serif;
}

.share-password-status.active {
    color: var(--success);
    font-weight: 500;
}

.share-password-btn {
    height: 32px;
    padding: 0 14px;
    font-size: var(--fs-xs);
    font-weight: 600;
    border: 1.5px solid rgba(26, 109, 219, 0.15);
    border-radius: var(--radius-btn);
    background: var(--bg-white);
    color: var(--text-dark);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    font-family: 'Outfit', sans-serif;
}

.share-password-btn:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: rgba(26, 109, 219, 0.04);
}

.share-password-btn.danger {
    border-color: rgba(220, 38, 38, 0.2);
    color: var(--danger);
}

.share-password-btn.danger:hover {
    border-color: var(--danger);
    background: rgba(220, 38, 38, 0.04);
}

.share-password-form {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.share-password-input {
    height: 36px;
    font-size: var(--fs-sm);
    padding: 0 12px;
    border: 1.5px solid rgba(26, 109, 219, 0.12);
    border-radius: var(--radius-btn);
    background: var(--bg-white);
    color: var(--text-dark);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    font-family: 'DM Sans', sans-serif;
    box-sizing: border-box;
    width: 100%;
}

.share-password-input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26, 109, 219, 0.08);
}

.share-password-input::placeholder { color: var(--text-subtle); }

.share-password-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

.share-password-cancel {
    height: 32px;
    padding: 0 14px;
    font-size: var(--fs-xs);
    font-weight: 500;
    border: 1.5px solid rgba(26, 109, 219, 0.1);
    border-radius: var(--radius-btn);
    background: var(--bg-white);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: 'DM Sans', sans-serif;
}

.share-password-cancel:hover { background: rgba(0, 0, 0, 0.03); }

.share-password-save {
    height: 32px;
    padding: 0 18px;
    font-size: var(--fs-xs);
    font-weight: 600;
    border: none;
    border-radius: var(--radius-btn);
    background: var(--blue);
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: 'Outfit', sans-serif;
}

.share-password-save:hover {
    background: var(--blue-hover);
    box-shadow: 0 2px 8px rgba(26, 109, 219, 0.25);
}

/* Footer */
.share-modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    background: rgba(26, 109, 219, 0.02);
    border-top: 1px solid rgba(26, 109, 219, 0.06);
    padding: 14px 24px;
}

.share-done-btn {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: white;
    background: var(--blue);
    border: none;
    border-radius: var(--radius-btn);
    padding: 9px 32px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: 'Outfit', sans-serif;
    letter-spacing: 0.01em;
}

.share-done-btn:hover {
    background: var(--blue-hover);
    box-shadow: 0 4px 12px rgba(26, 109, 219, 0.25);
    transform: translateY(-1px);
}

.share-done-btn:active { transform: translateY(0) scale(0.98); }

/* Mobile */
@media (max-width: 639px) {
    .share-modal { width: calc(100vw - 32px); margin: 0 16px; }
    .share-section { padding: 14px 18px; }
    .share-invite-row { flex-wrap: wrap; gap: 8px; }
    .share-invite-input { width: 100%; min-width: 100%; }
    .share-role-dropdown-wrap { flex: 1; }
    .share-invite-send-btn { flex: 1; }
    .share-modal-schema-name { max-width: 140px; }
    .share-modal-footer { padding: 12px 18px; }
    .share-done-btn { padding: 8px 24px; font-size: var(--fs-xs); }
    .share-person-remove { opacity: 1; }
    .share-link-copy-row { flex-wrap: wrap; }
    .share-link-copy-btn-new { width: 100%; justify-content: center; }
}

@media (max-width: 400px) {
    .share-section { padding: 12px 14px; }
    .share-invite-row { gap: 6px; }
    .share-modal-footer { padding: 10px 14px; }
}

/* Modal header — gradient from brandbook */
.modal-header,
.confirm-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-blue);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(180deg, #ffffff 0%, #fafcff 50%, #f5f8ff 100%);
}

.modal-header h3 {
    margin: 0;
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: var(--text-dark);
    font-family: 'Outfit', 'DM Sans', sans-serif;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-header h3 svg {
    opacity: 0.6;
}

/* Modal body */
.modal-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
}

.modal-body p {
    color: var(--text-muted);
    font-size: var(--fs-md);
    margin-bottom: 16px;
}

/* Modal close button — consistent style across all popups */
.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-active);
    border-radius: var(--radius-btn);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: var(--fs-4xl);
    font-weight: 300;
    line-height: 0;
    padding: 0;
    padding-bottom: 2px; /* Visual centering for × character */
    transition: all var(--transition-base);
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
}

.modal-close:hover {
    background: var(--border-light);
    color: var(--text-dark);
    transform: scale(1.05);
}

.modal-close:active {
    transform: scale(0.95);
}

.modal-close:focus {
    outline: none;
    box-shadow: none;
}

/* Modal footer with action buttons */
.modal-footer,
.confirm-modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-blue);
    background: var(--bg-hover);
    border-radius: 0 0 var(--radius-modal) var(--radius-modal);
}

/* Modal form elements */
.modal-label {
    display: block;
    margin-bottom: 6px;
    font-size: var(--fs-base);
    font-weight: 500;
    color: #555;
}

.modal-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: var(--fs-md);
    font-family: 'DM Sans', sans-serif;
    color: #374151;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26, 109, 219, 0.1);
}

.modal-input::placeholder {
    color: #9ca3af;
}

/* Empty state in modal */
.modal-empty {
    text-align: center;
    color: #9ca3af;
    padding: 40px 20px;
    font-size: var(--fs-md);
}

/* ================================================
   UNIFIED BUTTON STYLES (Brand Design System)
   ================================================ */

/* Base modal button */
.btn-modal,
.confirm-modal-btn {
    padding: 10px 20px;
    font-size: var(--fs-md);
    font-weight: 600;
    border-radius: var(--radius-btn);
    border: none;
    cursor: pointer;
    font-family: 'Outfit', 'DM Sans', sans-serif;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* Primary button — filled blue with gradient */
.btn-modal.primary {
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-hover) 100%);
    color: #fff;
    border: none !important;
    box-shadow: 0 4px 12px rgba(26, 109, 219, 0.3);
}

.btn-modal.primary:hover {
    background: linear-gradient(135deg, var(--blue-hover) 0%, #0f4a99 100%);
    box-shadow: 0 6px 16px rgba(26, 109, 219, 0.4);
    transform: translateY(-1px);
}

.btn-modal.primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(26, 109, 219, 0.2);
}

/* Secondary button — outlined */
.btn-modal.secondary,
.confirm-modal-btn.cancel {
    background: var(--bg-white);
    color: var(--text-dark);
    border: 1.5px solid var(--border-light);
}

.btn-modal.secondary:hover,
.confirm-modal-btn.cancel:hover {
    background: var(--bg-hover);
    border-color: #d1d5db;
}

/* Ghost button — text only */
.btn-modal.ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-modal.ghost:hover {
    background: var(--bg-hover);
    color: var(--text-dark);
}

/* Small button variant */
.btn-modal.sm {
    padding: 6px 14px;
    font-size: var(--fs-base);
}

/* Large button variant */
.btn-modal.lg {
    padding: 14px 28px;
    font-size: var(--fs-xl);
}

/* Remove focus outlines from modal buttons */
.btn-modal:focus,
.btn-modal.primary:focus,
.btn-modal.secondary:focus,
.btn-modal.danger:focus,
.btn-modal.sm:focus,
.confirm-modal-btn:focus {
    outline: none;
    box-shadow: none;
    border-color: inherit;
}

/* Ensure no focus ring on any variant */
.btn-modal:focus-visible {
    outline: 2px solid var(--blue-light);
    outline-offset: 2px;
}

/* Danger button variant */
.btn-modal.danger,
.confirm-modal-btn.danger {
    background: var(--danger);
    color: #fff;
    border: none;
}

.btn-modal.danger:hover,
.confirm-modal-btn.danger:hover {
    background: #b91c1c;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
    transform: translateY(-1px);
}

.btn-modal.danger:active,
.confirm-modal-btn.danger:active {
    transform: translateY(0);
}

/* Success button variant */
.btn-modal.success {
    background: var(--success);
    color: #fff;
}

.btn-modal.success:hover {
    background: #059669;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    transform: translateY(-1px);
}

/* ================================================
   CONFIRM MODAL SPECIFIC STYLES
   ================================================ */

/* Confirm modal content — smaller padding */
.confirm-modal-content {
    max-width: 400px;
    width: 90%;
    padding: 0;
    animation: modalSlideIn var(--transition-base);
}

/* Confirm modal body (when not using header/body structure) */
.confirm-modal-body {
    padding: 24px;
}

/* Confirm modal title */
.confirm-modal-title,
.modal-title {
    font-family: 'Outfit', sans-serif;
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
}

/* Confirm modal text */
.confirm-modal-text {
    font-size: var(--fs-md);
    color: var(--text-muted);
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Modal slide in animation */
@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ================================================
   JS DYNAMIC MODAL CLASSES
   Used by dynamically-created modals (delete confirm, confirm, input, tag edit)
   Matches the same visual style as the unified modal system
   ================================================ */

/* Full-screen overlay for dynamically-created JS modals */
.js-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 41, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: calc(var(--z-sidebar) + 50000); /* above card-detail-overlay (200000) so JS modals always show on top */
    animation: fadeInOverlay var(--transition-base);
}

/* Inner box for dynamically-created JS modals */
.js-modal-box {
    position: relative;
    background: linear-gradient(165deg, #ffffff 0%, #f8faff 100%);
    border: 1px solid var(--border-blue);
    border-radius: var(--radius-modal);
    box-shadow: var(--glass-shadow);
    max-width: 420px;
    width: calc(100vw - 32px);
    padding: 0;
    animation: modalSlideIn var(--transition-base);
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    overflow: hidden;
}

.js-modal-box-body {
    padding: 24px 24px 20px;
}

.js-modal-box-title {
    font-size: var(--fs-xl);
    font-weight: 600;
    color: var(--text-dark);
    font-family: 'Outfit', 'DM Sans', sans-serif;
    margin: 0 0 8px;
}

.js-modal-box-text {
    font-size: var(--fs-md);
    color: var(--text-muted);
    margin: 0 0 20px;
    line-height: 1.5;
}

.js-modal-box-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 14px 24px;
    border-top: 1px solid var(--border-blue);
    background: var(--bg-hover);
    border-radius: 0 0 var(--radius-modal) var(--radius-modal);
}

.js-modal-icon-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.js-modal-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-btn);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.js-modal-icon.danger {
    background: #fef2f2;
}

.js-modal-icon.info {
    background: rgba(26, 109, 219, 0.08);
}

.js-modal-input-field {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 12px;
    font-size: var(--fs-md);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    outline: none;
    margin-bottom: 16px;
    font-family: 'DM Sans', sans-serif;
    color: var(--text-dark);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.js-modal-input-field:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26, 109, 219, 0.1);
}

/* Modal content wide variant */
.modal-content-wide {
    max-width: 500px;
}

/* Modal field group */
.modal-field {
    margin-bottom: 20px;
}

/* Modal actions footer */
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Modal description text */
.modal-description {
    font-size: var(--fs-md);
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.5;
}

.modal-description strong {
    color: var(--text-dark);
    font-weight: 600;
}

/* ================================================
   MODAL ALERT VARIANTS (Warning, Success, Danger)
   ================================================ */

/* Warning alert in modal */
.modal-warning {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin-bottom: 16px;
    font-size: var(--fs-base);
    color: #92400e;
    font-weight: 500;
}

.modal-warning svg {
    flex-shrink: 0;
    margin-top: 1px;
}

/* Danger warning in modal */
.modal-danger-warning {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin-bottom: 20px;
    font-size: var(--fs-base);
    color: #991b1b;
    font-weight: 500;
}

/* Success modal header */
.modal-success-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    text-align: center;
}

.modal-success-header .modal-title {
    margin-bottom: 0;
}

.modal-success-icon {
    width: 68px;
    height: 68px;
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-hover) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse-success 2s ease-in-out infinite;
}

@keyframes pulse-success {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Danger modal header */
.modal-danger-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.modal-danger-header .modal-title {
    margin-bottom: 0;
    color: var(--danger);
}

.modal-danger-icon {
    width: var(--btn-lg);
    height: var(--btn-lg);
    background: rgba(220, 38, 38, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Token display in modal */
.modal-token-display {
    background: rgba(26, 109, 219, 0.05);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 20px;
}

.modal-token-display code {
    font-family: 'JetBrains Mono', monospace;
    font-size: var(--fs-base);
    word-break: break-all;
    display: block;
    color: var(--text-dark);
}

/* ================================================
   CUSTOM MODAL (Alert/Confirm)
   ================================================ */

.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 41, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-tooltip);
    animation: fadeInOverlay var(--transition-base);
}

.custom-modal {
    background: linear-gradient(165deg, #ffffff 0%, #f8faff 100%);
    border: 1px solid var(--border-blue);
    border-radius: var(--radius-modal);
    padding: 32px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: var(--glass-shadow);
    animation: modalSlideIn var(--transition-slow);
}

.custom-modal-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.custom-modal-icon.success {
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
}

.custom-modal-icon.error {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
}

.custom-modal-icon.warning {
    background: rgba(245, 158, 11, 0.12);
    color: var(--warning);
}

.custom-modal-icon.info {
    background: rgba(26, 109, 219, 0.08);
    color: var(--blue);
}

.custom-modal-icon svg {
    width: var(--btn-sm);
    height: var(--btn-sm);
}

.custom-modal-title {
    font-family: 'Outfit', sans-serif;
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.custom-modal-message {
    font-size: var(--fs-md);
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.custom-modal-btn {
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-hover) 100%);
    color: #fff;
    border: none;
    padding: 12px 32px;
    border-radius: var(--radius-btn);
    font-family: 'Outfit', sans-serif;
    font-size: var(--fs-md);
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(26, 109, 219, 0.3);
    transition: all var(--transition-base);
}

.custom-modal-btn:hover {
    background: linear-gradient(135deg, var(--blue-hover) 0%, #0f4a99 100%);
    box-shadow: 0 6px 16px rgba(26, 109, 219, 0.4);
    transform: translateY(-1px);
}

/* Icon-only button in modals */
.btn-modal-icon {
    width: var(--btn-sm);
    height: var(--btn-sm);
    padding: 0;
    border: none;
    background: #f3f4f6;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: all 0.15s ease;
}

.btn-modal-icon:hover {
    background: #e5e7eb;
    color: #374151;
}

/* Dropdown trigger in modals */
.modal-dropdown-trigger {
    height: var(--btn-md);
    padding: 0 12px;
    padding-right: 32px;
    font-size: var(--fs-md);
    font-family: 'DM Sans', sans-serif;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    position: relative;
}

.modal-dropdown-trigger:hover {
    border-color: #d1d5db;
}

.modal-dropdown-trigger:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26, 109, 219, 0.1);
}

/* Version history item */
.version-item {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 14px 16px;
    transition: all 0.15s ease;
}

.version-item:hover {
    background: #f3f4f6;
    border-color: var(--border-light);
}

.version-item .version-date {
    font-weight: 600;
    color: var(--text-dark);
    font-size: var(--fs-md);
}

.version-item .version-meta {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    margin-top: 4px;
}

.version-item .version-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* Empty state */
.modal-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.modal-empty svg {
    opacity: 0.3;
    margin-bottom: 16px;
}

.modal-empty p {
    margin: 0;
}

/* Legacy popup support - keep old classes working */
.popup-overlay > div:first-child,
.popup-card {
    background: #fff;
    border-radius: var(--radius-modal);
    box-shadow: var(--shadow-modal);
}

.popup-overlay > div:first-child .border-b,
.popup-card .popup-header {
    border-color: var(--border-light);
    background: linear-gradient(180deg, #fafbff 0%, #fff 100%);
}

/* Form elements in modals */
.popup-overlay select,
.popup-card select,
.modal-container select,
#schema-project-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='%23666'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 12px center;
    background-size: 12px;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-btn);
    padding: 10px 36px 10px 14px;
    font-size: var(--fs-md);
    font-family: 'DM Sans', -apple-system, sans-serif;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.15s ease;
    min-width: 150px;
}

.popup-overlay select:hover,
.popup-card select:hover,
.modal-container select:hover,
#schema-project-select:hover {
    border-color: var(--blue-light);
    background-color: #fafbff;
}

.popup-overlay select:focus,
.popup-card select:focus,
.modal-container select:focus,
#schema-project-select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26, 109, 219, 0.1);
    outline: none;
}

.popup-overlay select option,
#schema-project-select option {
    padding: 10px 14px;
}

.popup-overlay button.text-blue-600,
.popup-card .btn-link {
    color: var(--blue);
    transition: all 0.15s ease;
}

.popup-overlay button.text-blue-600:hover,
.popup-card .btn-link:hover {
    color: var(--blue-hover);
}

/* Блокировка UI элементов когда попап открыт */
body.popup-open #canvas,
body.popup-open .toolbar,
body.popup-open .top-toolbar,
body.popup-open .schema-title-header {
    pointer-events: none;
    filter: blur(3px);
    opacity: 0.6;
    transition: filter 0.2s ease, opacity 0.2s ease;
}

/* When AI sidebar is open — canvas title is covered, disable pointer events */
body.ai-sidebar-open .schema-title-header {
    pointer-events: none;
}

/* Восстановление UI когда попап закрыт */
body:not(.popup-open) #canvas,
body:not(.popup-open) .toolbar,
body:not(.popup-open) .top-toolbar,
body:not(.popup-open) .schema-title-header {
    pointer-events: auto;
    filter: none;
    opacity: 1;
    transition: filter 0.2s ease, opacity 0.2s ease;
}

/* Стили для card-detail-popup */
.card-detail-popup {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    width: 90%;
    max-width: min(520px, 95vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideIn 0.2s ease-out;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    z-index: var(--z-toast);
}

/* Card save status indicator */
.card-save-status {
    padding: 6px 16px;
    font-size: 12px;
    color: #999;
    text-align: right;
    border-top: 1px solid #f0f0f0;
    min-height: 28px;
    transition: opacity 0.3s ease;
}
.card-save-status.saving {
    color: #f59e0b;
}
.card-save-status.saved {
    color: #10b981;
}
.card-save-status.error {
    color: #ef4444;
}

/* Заголовок карточки детали */
.card-detail-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-blue);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #ffffff 0%, #fafcff 50%, #f5f8ff 100%);
    border-radius: var(--radius-modal, 16px) var(--radius-modal, 16px) 0 0;
}

.card-detail-title {
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: #000000;
    margin-bottom: 4px;
}

.card-detail-subtitle {
    font-size: var(--fs-xs);
    color: #737373;
}

.card-detail-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.card-detail-edit-btn,
.card-detail-save-btn,
.card-detail-cancel-btn,
.card-detail-close {
    width: var(--btn-sm);
    height: var(--btn-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: var(--fs-4xl);
    line-height: 1;
    padding: 0;
    color: #6b7280;
}

.card-detail-edit-btn:hover,
.card-detail-save-btn:hover,
.card-detail-cancel-btn:hover,
.card-detail-close:hover {
    background: #f3f4f6;
    color: #374151;
}

.card-detail-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.card-tags-popup {
    margin-bottom: 12px;
}

.card-tags-popup h4 {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: #000000;
    margin-bottom: 6px;
}

.card-tag-popup {
    display: inline-block;
    padding: 2px 6px;
    margin: 2px;
    border-radius: 3px;
    font-size: var(--fs-2xs);
    font-weight: 400;
    border: 1px solid currentColor;
    background: transparent;
    opacity: 0.8;
}

/* ================================================
   STATUSES MANAGER — unified modal elements
   ================================================ */
.statuses-manager-add {
    border-top: 1px solid var(--border-light);
    padding-top: 16px;
}

.statuses-color-input {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
    flex-shrink: 0;
}

.card-description {
    font-size: var(--fs-lg);
    line-height: 1.6;
    color: #000000;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.card-description-textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    font-size: var(--fs-lg);
    line-height: 1.6;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    resize: vertical;
    font-family: inherit;
}

.card-detail-title-input {
    width: 100%;
    font-size: var(--fs-4xl);
    font-weight: 600;
    padding: 4px 8px;
    border: 2px solid #000000;
    border-radius: 6px;
    margin-bottom: 8px;
}

/* ========================================
   iOS-STYLE SWITCH (Completed toggle)
   ======================================== */

/* Контейнер секции */
.completed-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.completed-label {
    font-size: var(--fs-base);
    color: #6b7280;
    font-weight: 500;
}

/* iOS Switch */
.ios-switch {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
    flex-shrink: 0;
}

.ios-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.ios-switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #e9e9eb;
    border-radius: 31px;
    transition: background-color 0.3s ease;
}

.ios-switch-slider:before {
    position: absolute;
    content: "";
    height: 27px;
    width: 27px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Checked state - зелёный как на iPhone */
.ios-switch input:checked + .ios-switch-slider {
    background-color: #34c759;
}

.ios-switch input:checked + .ios-switch-slider:before {
    transform: translateX(20px);
}

/* Hover effect */
.ios-switch:hover .ios-switch-slider {
    background-color: #d1d1d6;
}

.ios-switch input:checked + .ios-switch-slider:hover {
    background-color: #2db84d;
}

/* Focus для accessibility */
.ios-switch input:focus + .ios-switch-slider {
    box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.3);
}

/* Active press effect */
.ios-switch:active .ios-switch-slider:before {
    width: 31px;
}

.ios-switch input:checked:active + .ios-switch-slider:before {
    transform: translateX(16px);
}

/* ========================================
   STATUS SELECTOR & MANAGEMENT STYLES
   ======================================== */

/* Status dropdown items */
.status-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #374151;
    transition: background-color 0.15s;
}

.status-dropdown-item:hover {
    background-color: #f3f4f6;
}

.status-dropdown-item.active {
    background-color: #eff6ff;
    font-weight: 500;
}

.status-dropdown-item .status-item-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Status management list items */
.status-manager-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #fff;
    transition: box-shadow 0.15s;
}

.status-manager-item:hover {
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.status-manager-item .status-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.1);
}

.status-manager-item .status-item-name {
    flex: 1;
    font-size: 14px;
    color: #374151;
    font-weight: 500;
}

.status-manager-item .status-item-count {
    font-size: 12px;
    color: #9ca3af;
    margin-right: 4px;
}

.status-manager-item .status-item-actions {
    display: flex;
    gap: 4px;
}

.status-manager-item .status-item-actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: #9ca3af;
    transition: color 0.15s, background 0.15s;
}

.status-manager-item .status-item-actions button:hover {
    color: #374151;
    background: #f3f4f6;
}

.status-manager-item .status-item-actions button.delete-btn:hover {
    color: #ef4444;
    background: #fef2f2;
}

/* Status edit inline form */
.status-edit-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.status-edit-form input[type="text"] {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #3b82f6;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
}

.status-edit-form input[type="color"] {
    width: 28px;
    height: 28px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    cursor: pointer;
    padding: 1px;
}

/* ========================================
   СТИЛИ ДЛЯ УПРАВЛЕНИЯ ДОСТУПОМ К СХЕМАМ
   ======================================== */

/* Карточки типов доступа */
.access-option {
    display: block;
    cursor: pointer;
}

.access-radio {
    display: none;
}

.access-card {
    padding: 16px;
    border: 2px solid #e5e5e5;
    border-radius: 12px;
    transition: all 0.2s ease;
    background: white;
}

.access-card:hover {
    border-color: #cbd5e1;
    background: #f8f9fa;
}

.access-radio:checked + .access-card {
    border-color: #1a6ddb;
    background: #fff7ed;
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

/* Кнопка настроек доступа в списке схем */
.schema-access-btn {
    opacity: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-2xl);
    cursor: pointer;
    border: none;
    background: transparent;
    color: #6b7280;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.schema-access-btn:hover {
    background: #f3f4f6;
    color: #1a6ddb;
}

.group:hover .schema-access-btn {
    opacity: 1;
}

/* Список приглашенных пользователей */
.invite-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: white;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
}

.invite-item-email {
    flex: 1;
    font-size: var(--fs-md);
    color: #374151;
}

.invite-item-status {
    font-size: var(--fs-sm);
    color: #6b7280;
    margin-right: 12px;
}

.invite-item-remove {
    width: var(--icon-lg);
    height: var(--icon-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.invite-item-remove:hover {
    background: #fee2e2;
    color: #dc2626;
}

/* Анимация для показа блоков */
.show-with-fade {
    animation: fadeIn 0.3s ease;
}

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

/* Уведомление об успешном копировании */
.copy-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    background: #10b981;
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: var(--z-tooltip);
    animation: slideIn 0.3s ease, slideOut 0.3s ease 2.7s;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* Редактирование тегов в попапе карточки - МИНИМАЛИСТИЧНЫЙ ДИЗАЙН */
.card-tags-edit {
    margin-bottom: 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.card-tags-edit h4 {
    display: none; /* Скрываем заголовок, теги теперь в header */
}

.card-tags-edit-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 24px;
    margin-bottom: 8px;
    align-items: center;
}

.card-tag-editable {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: var(--fs-xs);
    font-weight: 500;
    border: 1px solid;
    transition: all 0.15s;
    line-height: 1.4;
    cursor: pointer;
    position: relative;
}

.card-tag-editable:hover {
    filter: brightness(1.1);
}

.card-tag-remove {
    cursor: pointer;
    font-size: var(--fs-base);
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.15s;
    margin-left: 2px;
}

.card-tag-remove:hover {
    opacity: 1;
}

.card-tag-add-btn {
    padding: 2px 8px;
    background: transparent;
    border: 1px dashed #d1d5db;
    border-radius: 3px;
    color: #9ca3af;
    font-size: var(--fs-2xs);
    font-weight: 400;
    cursor: pointer;
    transition: all 0.15s;
    opacity: 0.6;
    line-height: 1.4;
}

.card-tag-add-btn:hover {
    opacity: 1;
    border-color: #6b7280;
    color: #6b7280;
    background: rgba(107, 114, 128, 0.05);
}

.card-tag-dropdown {
    position: absolute;
    margin-top: 4px;
    padding: 8px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    max-height: 320px;
    overflow-y: auto;
    z-index: var(--z-modal);
    min-width: 220px;
}

.card-tag-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: var(--fs-sm);
}

.card-tag-dropdown-item:hover {
    background: #f9fafb;
}

.card-tag-dropdown-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1.5px solid;
    flex-shrink: 0;
}

/* Стили для попапа карточки - заголовок редактируется по двойному клику */
.card-detail-title-input {
    width: 100%;
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: #1f2937;
    padding: 8px 12px;
    border: 2px solid transparent;
    border-radius: 6px;
    background: #f9fafb;
    transition: all 0.2s;
}

.card-detail-title-input:hover {
    background: #f3f4f6;
}

.card-detail-title-input:focus {
    outline: none;
    border-color: #1a6ddb;
    background: white;
}

.card-description-edit {
    margin-top: 12px;
}

.card-description-edit h4 {
    margin: 0 0 6px 0;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: #374151;
}

/* Collapsible description */
.card-description-display {
    position: relative;
}

.card-description-display.is-collapsed #card-description-text {
    max-height: 96px;
    overflow: hidden;
    position: relative;
}

.card-description-display.is-collapsed::after {
    content: '';
    position: absolute;
    bottom: 28px;
    left: 0;
    right: 0;
    height: 32px;
    background: linear-gradient(transparent, #fff);
    pointer-events: none;
}

.card-description-display.is-expanded #card-description-text {
    max-height: none;
    overflow: visible;
}

.description-toggle-btn {
    display: none;
    background: none;
    border: none;
    color: #6366f1;
    font-size: var(--fs-sm);
    cursor: pointer;
    padding: 4px 0;
    margin-top: 4px;
    font-weight: 500;
    transition: color 0.15s;
}

.description-toggle-btn:hover {
    color: #4f46e5;
}

.description-toggle-btn.visible {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.description-toggle-btn svg {
    transition: transform 0.2s;
}

.card-description-display.is-expanded .description-toggle-btn svg {
    transform: rotate(180deg);
}

.card-description-textarea {
    display: block !important;
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: var(--fs-md);
    line-height: 1.6;
    color: #374151;
    background: #f9fafb;
    resize: vertical;
    transition: all 0.2s;
}

.card-description-textarea:hover {
    background: #f3f4f6;
}

.card-description-textarea:focus {
    outline: none;
    border-color: #1a6ddb;
    background: white;
}

/* Markdown Preview */
.card-description-preview {
    margin-top: 16px;
    padding: 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.card-description-preview-label {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-description-preview-content {
    font-size: var(--fs-md);
    line-height: 1.6;
    color: #374151;
}

.card-description-preview-content h1 {
    font-size: var(--fs-3xl);
    font-weight: 700;
    margin: 12px 0 8px 0;
    color: #111827;
}

.card-description-preview-content h2 {
    font-size: var(--fs-2xl);
    font-weight: 600;
    margin: 10px 0 6px 0;
    color: #111827;
}

.card-description-preview-content h3 {
    font-size: var(--fs-xl);
    font-weight: 600;
    margin: 8px 0 4px 0;
    color: #111827;
}

.card-description-preview-content p {
    margin: 8px 0;
}

.card-description-preview-content ul,
.card-description-preview-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.card-description-preview-content li {
    margin: 4px 0;
}

.card-description-preview-content code {
    background: #e5e7eb;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: var(--fs-base);
}

.card-description-preview-content pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 12px 0;
}

.card-description-preview-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.card-description-preview-content strong {
    font-weight: 600;
    color: #111827;
}

.card-description-preview-content em {
    font-style: italic;
}

.card-description-preview-content a {
    color: #1a6ddb;
    text-decoration: underline;
}

.card-description-preview-content a:hover {
    color: #1558b8;
}

/* Убираем старые кнопки редактирования */
.card-detail-edit-btn,
.card-detail-save-btn,
.card-detail-cancel-btn {
    display: none !important;
}

/* Заголовок карточки - обычный текст, редактируется по двойному клику */
.card-detail-title {
    font-size: var(--fs-2xl);
    font-weight: 600;
    color: #1f2937;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: text;
    transition: background 0.2s;
    margin: 0;
}

.card-detail-title:hover {
    background: #f9fafb;
}

/* Скрываем input по умолчанию */
.hidden {
    display: none !important;
}

/* Когда input активен */
.card-detail-title-input:not(.hidden) {
    display: block !important;
}

/* Левая панель инструментов */
.left-sidebar {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    /* z-index must be higher than other fixed UI elements (toolbar at 1001, etc.)
       so that tooltip ::after pseudo-elements are not obscured by sibling stacking
       contexts. Tooltips are z-index 10000 within this stacking context. */
    z-index: calc(var(--z-tooltip) + 1);
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 0 10px 10px 0;
    box-shadow: 1px 0 4px rgba(0, 0, 0, 0.04);
    max-height: calc(100vh - 40px);
    /* overflow: visible is required so ::after tooltip pseudo-elements can render
       outside the bounds of this container without being clipped. Any other overflow
       value creates a new stacking context that would clip positioned descendants. */
    overflow: visible;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.sidebar-btn {
    width: var(--btn-lg);
    height: var(--btn-lg);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 50%;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: none;
    outline: none;
    opacity: 0.85;
}

.sidebar-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
    color: #334155;
    box-shadow: none;
    opacity: 1;
}

.sidebar-btn:focus {
    outline: none;
}

.sidebar-btn:active {
    transform: scale(0.97);
    background: rgba(0, 0, 0, 0.04);
}

/* Тултипы для кнопок сайдбара */
.sidebar-btn[data-tooltip] {
    position: relative;
}

.sidebar-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    padding: 4px 8px;
    background: #1f2937;
    color: white;
    font-size: var(--fs-sm);
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-in-out;
    z-index: var(--z-tooltip);
}

.sidebar-btn[data-tooltip]:hover::after {
    opacity: 1;
}

/* Тултипы для кнопок сайдбара с i18n — override ниже после generic [data-tooltip-i18n] */
.sidebar-btn[data-tooltip-i18n] {
    position: relative;
}

/* Schemas Quick Access Dropdown */
.schemas-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 300px;
    max-width: 400px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: calc(var(--z-tooltip) + 2); /* Above left-sidebar (10001) and all toolbars */
    max-height: 500px;
    display: flex;
    flex-direction: column;
}

.schemas-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.schemas-dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    font-size: var(--fs-md);
    color: #111827;
    background: #f9fafb;
    border-radius: 12px 12px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Кнопка "+" в хедере дропдауна — стиль как у "All" */
.schemas-header-plus-btn {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: var(--fs-md);
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.schemas-header-plus-btn:hover {
    background: white;
    border-color: #9ca3af;
    color: #374151;
}

.schemas-view-all-btn {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.schemas-view-all-btn:hover {
    background: white;
    border-color: #9ca3af;
    color: #374151;
}

.schemas-create-btn {
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    color: #6b7280;
    border: none;
    border-top: 1px solid #e5e7eb;
    border-radius: 0;
    font-size: var(--fs-base);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
}

.schemas-create-btn:hover {
    background: #f9fafb;
    color: #374151;
}

.schemas-create-btn:active {
    transform: scale(0.98);
}

.schemas-dropdown-content {
    overflow-y: auto;
    max-height: 350px;
    padding: 8px 0;
}

.schemas-dropdown-loading {
    padding: 20px;
    text-align: center;
    color: #9ca3af;
    font-size: var(--fs-md);
}

.schemas-dropdown-empty {
    padding: 20px;
    text-align: center;
    color: #9ca3af;
    font-size: var(--fs-md);
}

.schemas-dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #374151;
    font-size: var(--fs-md);
}

.schemas-dropdown-item:hover {
    background: #f3f4f6;
}

.schemas-dropdown-item.active {
    background: #fff7ed;
    color: #1558b8;
    font-weight: 500;
}

.schemas-dropdown-item.active .schema-name-btn {
    color: #1558b8;
    font-weight: 500;
}

/* Schema info container - название + проект */
.schema-info-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    cursor: pointer;
}

.schema-info-container:hover .schema-name-text {
    color: #1558b8;
}

.schema-name-text {
    font-size: var(--fs-md);
    color: inherit;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.schema-project-text {
    font-size: var(--fs-xs);
    color: #9ca3af;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.schemas-dropdown-item.active .schema-name-text {
    color: #1558b8;
    font-weight: 500;
}

/* Schema name button - основное название (legacy) */
.schema-name-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    text-align: left;
    color: inherit;
    font-size: var(--fs-md);
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.schema-name-btn:hover {
    color: #1558b8;
}

/* Schema rename button - карандаш */
.schema-rename-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.schemas-dropdown-item:hover .schema-rename-btn {
    opacity: 1;
}

.schema-rename-btn:hover {
    background: #e5e7eb;
    color: #374151;
}

/* Project headers in schemas dropdown */
.schemas-dropdown-project-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 4px;
    margin-top: 4px;
}

.schemas-dropdown-project-header:first-child {
    margin-top: 0;
    padding-top: 4px;
}

.schemas-dropdown-project-header .project-name {
    font-size: var(--fs-xs);
    font-weight: 500;
    color: #6b7280;
}

.schemas-dropdown-project-header .project-count {
    font-size: var(--fs-2xs);
    color: #9ca3af;
}

/* Rename input mode */
.schema-rename-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #1a6ddb;
    border-radius: 4px;
    font-size: var(--fs-md);
    outline: none;
}

/* Tooltips для топбара (schema-settings, share, download) */
[data-tooltip-i18n] {
    position: relative;
}

[data-tooltip-i18n]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 10px;
    background: #1f2937;
    color: white;
    font-size: var(--fs-sm);
    font-weight: 500;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-in-out;
    z-index: var(--z-tooltip);
}

[data-tooltip-i18n]:hover::after {
    opacity: 1;
}

/* Override for sidebar buttons - position tooltip to the right, no !important needed (more specific selector) */
.sidebar-btn[data-tooltip-i18n]::after {
    content: attr(data-tooltip);
    left: calc(100% + 8px);
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    padding: 4px 8px;
    height: auto;
}

.sidebar-btn[data-tooltip-i18n]:hover::after {
    opacity: 1;
}

/* Specific data-tooltip tooltips (centered below) — scoped to actual users of this attribute */
/* Elements: canvas float btns, schemas sidebar close, share popup btns, viewport btns, AI panel, sidebar schema action btns, icon preview */
.schemas-sidebar-close[data-tooltip],
.canvas-float-btn[data-tooltip]:not(.canvas-float-btn),
button[data-tooltip]:not([data-tooltip-i18n]):not(.sidebar-btn):not(.toolbar-btn):not(.canvas-float-btn),
span[data-tooltip]:not([data-tooltip-i18n]),
div[data-tooltip]:not([data-tooltip-i18n]) {
    position: relative;
}

.schemas-sidebar-close[data-tooltip]::after,
button[data-tooltip]:not([data-tooltip-i18n]):not(.sidebar-btn):not(.toolbar-btn):not(.canvas-float-btn)::after,
span[data-tooltip]:not([data-tooltip-i18n])::after,
div[data-tooltip]:not([data-tooltip-i18n])::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 10px;
    background: #1f2937;
    color: white;
    font-size: var(--fs-sm);
    font-weight: 500;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-in-out;
    z-index: var(--z-tooltip);
}

.schemas-sidebar-close[data-tooltip]:hover::after,
button[data-tooltip]:not([data-tooltip-i18n]):not(.sidebar-btn):not(.toolbar-btn):not(.canvas-float-btn):hover::after,
span[data-tooltip]:not([data-tooltip-i18n]):hover::after,
div[data-tooltip]:not([data-tooltip-i18n]):hover::after {
    opacity: 1;
}

/* ========================================
   SCHEMA FILTERS & OWNER ICONS
   ======================================== */

/* Кнопки фильтров схем */
/* Минималистичные кнопки фильтров */
.schema-filter-btn {
    padding: 5px 12px;
    font-size: var(--fs-sm);
    font-weight: 500;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s ease;
}

.schema-filter-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.schema-filter-btn.active {
    background: #f3f4f6;
    color: #111827;
    font-weight: 600;
}

/* ========================================
   ROLE BADGES
   ======================================== */

/* Бейджики ролей для схем */
/* Минималистичные бейджи ролей */
.role-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: var(--fs-2xs);
    font-weight: 500;
    letter-spacing: 0.3px;
}

.role-badge.editor {
    background: #fff7ed;
    color: #1a6ddb;
    border: 1px solid #fed7aa;
}

.role-badge.viewer {
    background: #f9fafb;
    color: #6b7280;
    border: 1px solid #e5e7eb;
}

/* ==========================================
   Custom Select Dropdown Styles
   ========================================== */

.custom-select {
    position: relative;
    display: inline-block;
}

.custom-select-trigger {
    padding: 10px 32px 10px 12px;
    font-size: var(--fs-md);
    font-weight: 500;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 140px;
}

.custom-select-trigger:hover {
    border-color: #9ca3af;
}

.custom-select.open .custom-select-trigger {
    border-color: #000000;
}

.custom-select-arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    transition: transform 0.2s;
}

.custom-select.open .custom-select-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: #ffffff;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: var(--z-tooltip);
    min-width: 100%;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s;
}

.custom-select.open .custom-select-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-select-option {
    padding: 8px 12px;
    font-size: var(--fs-base);
    font-weight: 500;
    color: #000000;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-select-option:first-child {
    border-radius: 6px 6px 0 0;
}

.custom-select-option:last-child {
    border-radius: 0 0 6px 6px;
}

.custom-select-option:hover {
    background: #f5f5f5;
}

.custom-select-option.selected {
    background: #fafafa;
}

/* ===============================
   ASCII CARD STYLES
   =============================== */

/* ASCII карточка - основной контейнер */
/* cursor: move наследуется из общего стиля .schemeog-ascii выше */

.schemeog-ascii rect {
    transition: stroke-width 0.15s ease;
}

.schemeog-ascii:hover rect {
    stroke-width: 2.5;
}

/* ASCII текст - моноширинный шрифт */
.schemeog-ascii text {
    font-family: 'Courier New', 'Consolas', 'Monaco', 'Liberation Mono', 'Lucida Console', monospace;
    /* Улучшение рендеринга текста */
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ASCII placeholder для пустого контента */
.schemeog-ascii text[font-style="italic"] {
    opacity: 0.7;
}

/* ASCII ошибка - визуальный стиль */
.schemeog-ascii-error rect {
    animation: ascii-error-pulse 2s ease-in-out infinite;
}

@keyframes ascii-error-pulse {
    0%, 100% {
        stroke-opacity: 1;
    }
    50% {
        stroke-opacity: 0.6;
    }
}

/* ASCII при низком zoom - улучшенная читаемость */
.schemeog-ascii.zoom-low text {
    font-weight: 500;
}

/* ASCII при высоком zoom - более тонкий шрифт */
.schemeog-ascii.zoom-high text {
    font-weight: 400;
}

/* Выделенная ASCII карточка */
.schemeog-ascii.selected rect {
    stroke-width: 1.5;
    filter: none;
}

/* ===============================
   HTML CARD STYLES
   =============================== */

/* HTML карточка - основной контейнер */
.schemeog-html {
    cursor: move;
    user-select: none;
    pointer-events: all;
}

.schemeog-html rect {
    transition: stroke-width 0.15s ease;
}

.schemeog-html:hover rect {
    stroke-width: 2.5;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.schemeog-html.dragging {
    opacity: 0.8;
}

/* HTML карточка - заголовок */
.schemeog-html text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* HTML карточка - выделенная */
.schemeog-html.selected {
    opacity: 1;
    cursor: move;
}

.schemeog-html.selected rect {
    stroke-width: 1.5;
    filter: none;
}

/* HTML карточка - selection hover */
.schemeog-html.selection-hover rect:first-child {
    filter: drop-shadow(0 0 4px rgba(249, 115, 22, 0.3));
    transition: filter 0.15s ease;
}

/* HTML карточка - ошибка рендеринга */
.schemeog-html-error rect {
    animation: html-error-pulse 2s ease-in-out infinite;
}

@keyframes html-error-pulse {
    0%, 100% {
        stroke-opacity: 1;
    }
    50% {
        stroke-opacity: 0.6;
    }
}

/* foreignObject внутри HTML карточки */
.schemeog-html foreignObject {
    overflow: hidden;
}

/* ===============================
   IFRAME CARD STYLES
   =============================== */

.schemeog-iframe {
    cursor: move;
    user-select: none;
    pointer-events: all;
}

.schemeog-iframe > rect:first-child {
    transition: stroke-width 0.15s ease;
}

.schemeog-iframe:hover > rect:first-child {
    stroke-width: 2.5;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.schemeog-iframe.dragging {
    opacity: 0.8;
}

.schemeog-iframe text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.schemeog-iframe.selected {
    opacity: 1;
    cursor: move;
}

.schemeog-iframe.selected > rect:first-child {
    stroke-width: 1.5;
    filter: none;
}

.schemeog-iframe.selection-hover rect:first-child {
    filter: drop-shadow(0 0 4px rgba(249, 115, 22, 0.3));
    transition: filter 0.15s ease;
}

.schemeog-iframe foreignObject {
    overflow: hidden;
}

/* ====================================
   Schemas Sidebar (выдвижная панель)
   ==================================== */

/* Overlay (затемнение фона) */
.schemas-sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: calc(var(--z-tooltip) + 1); /* Above left-sidebar (10001) and all toolbars */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.schemas-sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Sidebar панель */
.schemas-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    background: #ffffff;
    z-index: calc(var(--z-tooltip) + 2); /* Above overlay (10001), left-sidebar (10001) and all toolbars */
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.schemas-sidebar.active {
    transform: translateX(0);
}

/* Header */
.schemas-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #fafafa;
}

.schemas-sidebar-header h2 {
    font-size: var(--fs-xl);
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.schemas-sidebar-title {
    font-size: var(--fs-xl);
    font-weight: 600;
    color: #111827;
    margin: 0;
    text-decoration: none;
    transition: color 0.15s;
}

.schemas-sidebar-title:hover {
    color: #1a6ddb;
}

.schemas-sidebar-close {
    width: var(--btn-sm);
    height: var(--btn-sm);
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: all 0.15s ease;
}

.schemas-sidebar-close:hover {
    background: #f3f4f6;
    color: #374151;
}

.schemas-sidebar-new {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    height: 28px;
    background: #1a6ddb;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
    white-space: nowrap;
}

.schemas-sidebar-new:hover {
    background: #1557b0;
}

/* Sidebar search */
.schemas-sidebar-search {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 8px 12px 6px;
    padding: 0 10px;
    height: 30px;
    background: transparent;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    transition: border-color 0.2s ease;
}

.schemas-sidebar-search:focus-within {
    border-color: #94a3b8;
}

.schemas-sidebar-search input {
    flex: 1;
    padding: 0;
    border: none;
    background: transparent;
    font-size: 13px;
    color: #334155;
    outline: none;
    min-width: 0;
}

.schemas-sidebar-search input::placeholder {
    color: #94a3b8;
}

.schemas-sidebar-search-icon {
    flex-shrink: 0;
    color: #94a3b8;
    pointer-events: none;
    transition: color 0.2s ease;
}

.schemas-sidebar-search:focus-within .schemas-sidebar-search-icon {
    color: #64748b;
}

.schemas-sidebar-search-clear {
    display: none;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    background: #cbd5e1;
    border-radius: 50%;
    cursor: pointer;
    color: #64748b;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.schemas-sidebar-search-clear:hover {
    background: #94a3b8;
    color: #fff;
}

.schemas-sidebar-search.has-value .schemas-sidebar-search-clear {
    display: flex;
}

/* Footer row — profile + settings */
.schemas-sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px 12px;
    border-top: 1px solid #f1f5f9;
    margin-top: -4px;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    padding: 0;
}

.sidebar-footer-btn:hover {
    background: #f1f5f9;
    color: #374151;
}

/* Контент (список схем) */
.schemas-sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden; /* prevent horizontal scroll when schema names are long */
    padding: 8px 0;
}

.schemas-sidebar-loading {
    padding: 40px 20px;
    text-align: center;
    color: #9ca3af;
    font-size: var(--fs-md);
}

.schemas-sidebar-empty {
    padding: 40px 20px;
    text-align: center;
    color: #9ca3af;
    font-size: var(--fs-md);
}

/* Группа проекта */
.schemas-sidebar-project {
    margin-bottom: 4px;
}

.schemas-sidebar-project-header {
    padding: 6px 12px 2px;
    font-size: var(--fs-2xs);
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Элемент схемы — компактный, без иконки */
.schemas-sidebar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s ease;
    border: none;
    border-left: 2px solid transparent;
    background: none;
    width: 100%;
    text-align: left;
}

.schemas-sidebar-item:hover {
    background: #f9fafb;
}

.schemas-sidebar-item.active {
    border-left-color: #94a3b8;
    background: #f9fafb;
}

.schemas-sidebar-item-name {
    font-size: var(--fs-base);
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.schemas-sidebar-item-date {
    font-size: var(--fs-2xs);
    color: #c0c0c0;
    flex-shrink: 0;
    margin-left: 8px;
}

.schemas-sidebar-rename-btn {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #d1d5db;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-left: 2px;
    border-radius: 3px;
}

.schemas-sidebar-item:hover .schemas-sidebar-rename-btn {
    opacity: 1;
}

.schemas-sidebar-rename-btn:hover {
    color: #3b82f6;
    background: #eff6ff;
}

.schemas-sidebar-duplicate-btn {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #d1d5db;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-left: 2px;
    border-radius: 3px;
}

.schemas-sidebar-item:hover .schemas-sidebar-duplicate-btn {
    opacity: 1;
}

.schemas-sidebar-duplicate-btn:hover {
    color: #10b981;
    background: #ecfdf5;
}

.schemas-sidebar-pin-btn {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #d1d5db;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-left: 4px;
    border-radius: 3px;
}

.schemas-sidebar-item:hover .schemas-sidebar-pin-btn,
.schemas-sidebar-pin-btn.pinned {
    opacity: 1;
}

.schemas-sidebar-pin-btn.pinned {
    color: #f59e0b;
}

.schemas-sidebar-pin-btn:hover {
    color: #f59e0b;
    background: #fef3c7;
}

.schemas-sidebar-item.pinned .schemas-sidebar-item-name {
    color: #1f2937;
}

/* Keyboard hint */
.schemas-sidebar-hint {
    padding: 12px 16px;
    border-top: 1px solid #f3f4f6;
    font-size: var(--fs-xs);
    color: #9ca3af;
    text-align: center;
}

.schemas-sidebar-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    background: #f3f4f6;
    border-radius: 4px;
    font-family: inherit;
    font-size: var(--fs-xs);
}

/* ================================================
   RESPONSIVE BREAKPOINTS
   ================================================ */

/* Tablet: 1024px and below */
@media (max-width: 1024px) {
    /* Schemas sidebar — slightly narrower on tablet */
    .schemas-sidebar {
        width: 280px;
    }

    /* Schema title — reduce max-width so it doesn't overlap toolbar */
    .schema-title-text {
        max-width: 220px;
    }

    /* Modal containers — give a bit more breathing room */
    .modal-container,
    .modal-content,
    .confirm-modal-content {
        max-width: 92vw;
    }

    /* Card detail popup */
    .card-detail-popup {
        max-width: 520px;
        width: 92%;
    }

    /* Toolbar buttons — compact gap */
    .top-toolbar {
        gap: 3px;
    }
}

/* Mobile: 768px and below */
@media (max-width: 768px) {
    /* Schemas sidebar — full-width slide-in on mobile */
    .schemas-sidebar {
        width: 100%;
        max-width: 320px;
    }

    /* Schema title header — compact on mobile */
    .schema-title-header {
        padding: 0;
    }

    .schema-title-text {
        font-size: var(--fs-sm);
        max-width: 160px;
    }

    .schema-title-input {
        font-size: var(--fs-sm);
        max-width: 160px;
        min-width: 120px;
    }

    /* Left sidebar — slightly smaller buttons on mobile */
    .left-sidebar {
        padding: 8px;
        gap: 6px;
    }

    .sidebar-btn {
        width: calc(var(--btn-lg) * 0.9);
        height: calc(var(--btn-lg) * 0.9);
    }

    /* Canvas float tools — more compact */
    .canvas-float-tools {
        gap: 6px;
    }

    .canvas-float-btn {
        width: calc(var(--btn-lg) * 0.9);
        height: calc(var(--btn-lg) * 0.9);
    }

    /* Toolbar buttons — enforce 44px minimum for Apple HIG touch targets */
    .toolbar-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Modal containers — full-width on small screens */
    .modal-container,
    .modal-content,
    .confirm-modal-content {
        max-width: 95vw;
        max-height: 90vh;
        border-radius: 12px;
    }

    .modal-header,
    .confirm-modal-header {
        padding: 16px 18px;
    }

    .modal-body {
        padding: 16px 18px;
    }

    .modal-footer,
    .confirm-modal-buttons {
        padding: 12px 18px;
        gap: 8px;
    }

    /* Card detail popup */
    .card-detail-popup {
        width: 95%;
        max-width: 100%;
        max-height: 80vh;
    }

    .card-detail-header {
        padding: 14px 16px;
    }

    .card-detail-content {
        padding: 12px;
    }

    /* Popup content (legacy) */
    .popup-content {
        padding: 20px;
        width: 95%;
        max-height: 85vh;
    }

    /* Schemas toggle button */
    .schemas-toggle-btn {
        width: calc(var(--btn-lg) * 0.9);
        height: calc(var(--btn-lg) * 0.9);
    }

    /* Modal footer buttons — stack vertically if tight */
    .modal-footer button,
    .confirm-modal-buttons button {
        padding: 8px 14px;
        font-size: var(--fs-sm);
    }
}

/* Small mobile: 480px and below */
@media (max-width: 480px) {
    /* Schemas sidebar — full screen */
    .schemas-sidebar {
        width: 100%;
        max-width: 100%;
    }

    /* Schema title — very compact */
    .schema-title-header {
        padding: 0;
        height: calc(var(--btn-lg) * 0.85);
    }

    .schema-title-text {
        font-size: var(--fs-xs);
        max-width: 100px;
    }

    .schema-title-input {
        font-size: var(--fs-xs);
        max-width: 100px;
        min-width: 80px;
    }

    /* Left sidebar — smaller */
    .left-sidebar {
        padding: 6px;
        gap: 4px;
        border-radius: 0 8px 8px 0;
    }

    .sidebar-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Canvas float tools */
    .canvas-float-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Toolbar — enforce 44px minimum for Apple HIG touch targets */
    .toolbar-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 6px;
    }

    .toolbar-btn svg {
        width: 16px;
        height: 16px;
    }

    /* Modal containers — edge-to-edge on small phones */
    .modal-container,
    .modal-content,
    .confirm-modal-content {
        max-width: 98vw;
        max-height: 92vh;
        border-radius: 10px;
    }

    .modal-header h3 {
        font-size: var(--fs-xl);
    }

    .modal-header,
    .confirm-modal-header {
        padding: 12px 14px;
    }

    .modal-body {
        padding: 12px 14px;
    }

    .modal-footer,
    .confirm-modal-buttons {
        padding: 10px 14px;
        flex-wrap: wrap;
    }

    /* Modal footer — stack buttons on very small screens */
    .modal-footer button,
    .confirm-modal-buttons button {
        flex: 1;
        min-width: 80px;
        padding: 8px 10px;
        font-size: var(--fs-sm);
        text-align: center;
    }

    /* Card detail popup */
    .card-detail-popup {
        width: 98%;
        max-height: 88vh;
    }

    .card-detail-header {
        padding: 12px 12px;
    }

    .card-detail-title {
        font-size: var(--fs-xl);
    }

    .card-detail-content {
        padding: 10px;
    }

    /* Popup content (legacy) */
    .popup-content {
        padding: 16px;
        border-radius: 10px;
    }

    .popup-header h2 {
        font-size: var(--fs-3xl);
    }

    /* Popup footer — stack buttons */
    .popup-footer {
        flex-direction: column;
        gap: 8px;
    }

    .popup-footer button {
        width: 100%;
    }


    /* Schemas sidebar header */
    .schemas-sidebar-header {
        padding: 12px 14px;
    }

    .schemas-sidebar-search {
        padding: 6px 10px;
    }
}

/* Legacy small mobile rule — kept for backward compat, extended */
@media (max-width: 400px) {
    .schemas-sidebar {
        width: 100%;
    }
}

/* ── Browser zoom overflow safeguards ──
   Prevents fixed UI elements from overflowing the viewport when
   the user uses browser zoom (Cmd+Plus / Ctrl+Plus).
   The JS zoom-compensator.js handles counter-scaling; these CSS
   rules provide additional containment as a safety net. */

.canvas-float-tools {
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
}

.top-toolbar {
    max-width: calc(100vw - 28px);
    max-width: calc(100dvw - 28px);
}

#minimap-container {
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
    max-width: calc(100vw - 40px);
    max-width: calc(100dvw - 40px);
}

/* HTML cards - disable pointer events on content to allow drag */
.schemeog-html foreignObject,
.schemeog-html foreignObject * {
    pointer-events: none !important;
}

/* === Pointer-events layer system === */
/* When AI sidebar is open, canvas elements don't receive pointer events */
body.ai-sidebar-open .canvas-container,
body.ai-sidebar-open #svg-canvas {
    pointer-events: none;
}

/* When a popup/modal is open, sidebar and canvas don't receive pointer events */
body.popup-open .left-sidebar,
body.popup-open .icon-sidebar,
body.popup-open .canvas-container,
body.popup-open #svg-canvas {
    pointer-events: none;
}
