:root {
    --bg-dark: #2b2b2b;
    --bg-panel: #1e1e1e;
    --bg-menu: #3c3c3c;
    --border: #3a3a3a;
    --accent: #0078d4;
    --accent-hover: #106ebe;
    --text-main: #e0e0e0;
    --text-dim: #888;
    --danger: #ff5555;
    --success: #4caf50;
    --warn: #ff9800;
}

* { margin: 0; padding: 0; box-sizing: border-box; outline: none; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- UI COMPONENTS --- */
.btn {
    padding: 8px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { background: #555; cursor: not-allowed; opacity: 0.6; }
.btn.small { padding: 4px 8px; font-size: 11px; }
.btn.danger { background: var(--danger); }

/* --- MENU BAR --- */
#menu-bar {
    background: var(--bg-menu);
    height: 30px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #1e1e1e;
    user-select: none;
    z-index: 1000;
    font-size: 13px;
}

.menu-item {
    padding: 0 15px;
    height: 100%;
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
}
.menu-item:hover { background: #505050; }
.menu-item.active { background: var(--accent) !important; }

.dropdown {
    display: none;
    position: absolute;
    top: 30px; left: 0;
    background: #2d2d2d;
    border: 1px solid #454545;
    min-width: 200px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 1001;
}
.dropdown-item { padding: 8px 20px; cursor: pointer; color: var(--text-main); }
.dropdown-item:hover:not(.disabled) { background: var(--accent); }
.dropdown-item.disabled { opacity: 0.5; cursor: default; }
.separator { height: 1px; background: #454545; margin: 4px 0; }

/* --- FILENAME EDITING --- */
#filename-display {
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.2s, color 0.2s;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Базовый шрифт */
    font-weight: 500;
}

/* Состояние Unsaved (стиль Blender) */
#filename-display.is-unsaved {
    font-style: italic;
    color: var(--text-dim);
    opacity: 0.8;
}

#filename-display:hover {
    border-bottom-color: var(--accent);
    color: var(--accent-hover);
}
#filename-input {
    background: #222;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 2px;
    padding: 2px 5px;
    font-size: 11px;
    font-weight: bold;
    font-family: inherit;
    outline: none;
    width: 150px;
}

/* --- SUBMENU --- */
.dropdown-item {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dropdown-item .shortcut {
    color: #text-dim; /* Использование переменной */
    font-size: 11px;
    margin-left: 20px;
}

.dropdown-item .arrow {
    font-size: 10px;
    color: #aaa;
    margin-left: 10px;
}

.submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: -5px;
    background: #2d2d2d;
    border: 1px solid #454545;
    min-width: 220px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 1002;
}

/* Объединенное правило открытия для всех подменю (включая Импорт и Историю) */
.dropdown-item:hover > .submenu,
.dropdown-item:hover > #history-submenu {
    display: block !important;
}

/* --- UNDO HISTORY SPECIFIC --- */

#history-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: -5px;
    background: #2d2d2d;
    border: 1px solid #454545;
    min-width: 260px;
    box-shadow: 5px 5px 15px rgba(0,0,0,0.5);
    z-index: 1005;
    max-height: 350px; 
    overflow-y: auto;
    overflow-x: hidden;
}

.history-step {
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-main);
    cursor: pointer;
    border-bottom: 1px solid #3a3a3a;
    display: flex;
    justify-content: space-between;
}

.history-step:hover {
    background: var(--accent-hover);
}

.history-step .history-time {
    color: var(--text-dim);
    font-size: 10px;
    margin-left: 10px;
}

.history-step.active {
    background: var(--accent);
    border-left: 3px solid var(--success);
    color: white;
}

.history-step.active .history-time {
    color: rgba(255,255,255,0.7);
}

/* Стилизация скроллбара */
#history-submenu::-webkit-scrollbar { width: 6px; }
#history-submenu::-webkit-scrollbar-track { background: #1e1e1e; }
#history-submenu::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

/* --- TOOLBAR --- */
#toolbar {
    display: none;
    background: var(--bg-panel);
    padding: 8px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}
#toolbar.active { display: flex; }
.toolbar-group { display: flex; gap: 5px; padding-right: 10px; border-right: 1px solid #555; }
.toolbar-group:last-child { border: none; }

/* --- MAIN AREA --- */
#workspace {
    position: relative;
    flex: 1;
    display: flex;
    overflow: hidden;
}

#canvas-container {
    flex: 1;
    position: relative;
    background: var(--bg-dark);
    overflow: hidden;
}

canvas { display: block; cursor: default; }
canvas:active { cursor: default; }
canvas.editing { cursor: default; }

/* --- PROPERTIES PANEL --- */
#properties-panel {
    width: 350px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 15px;
    display: none;
    z-index: 40;
}
#properties-panel.active { display: block; }

.prop-group { margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.prop-group h3 { margin-bottom: 10px; color: var(--accent); font-size: 14px; }
.prop-row { margin-bottom: 10px; }
.prop-row label { display: block; margin-bottom: 5px; font-size: 12px; color: var(--text-dim); }

input[type="text"], input[type="number"], textarea, select {
    width: 100%; padding: 8px;
    background: #333; border: 1px solid #555;
    border-radius: 4px; color: var(--text-main);
    font-family: inherit;
}
textarea { min-height: 60px; resize: vertical; font-family: monospace; line-height: 1.4; }
input[type="color"] { width: 100%; height: 35px; border: 1px solid #555; cursor: pointer; }

/* --- OUTPUT ITEMS --- */
.output-item {
    background: #2a2a2a; padding: 10px; margin-bottom: 10px;
    border-radius: 4px; border-left: 3px solid var(--accent);
}
.output-item.default { border-left-color: var(--success); }
.output-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

/* --- OVERLAYS --- */
#mode-indicator {
    position: absolute; top: 10px; left: 10px;
    background: rgba(30,30,30,0.9); padding: 6px 10px;
    border-radius: 4px; font-size: 12px; font-weight: bold; pointer-events: none;
}
.view-mode { color: var(--success); }
.edit-mode { color: var(--warn); }

.zoom-info {
    position: absolute; bottom: 10px; left: 10px;
    background: rgba(30,30,30,0.9); padding: 8px;
    border-radius: 4px; font-size: 12px; pointer-events: none;
}

#context-menu {
    position: fixed; background: #2a2a2a;
    border: 1px solid #555; border-radius: 4px;
    padding: 5px 0; z-index: 2000; display: none;
    min-width: 180px; box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
#context-menu.active { display: block; }
.ctx-item { padding: 8px 15px; cursor: pointer; font-size: 13px; }
.ctx-item:hover { background: #3a3a3a; }

/* --- MODAL --- */
.modal-overlay {
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 3000;
    display: none;
    justify-content: center;
    align-items: center;
}
.modal-overlay.active { display: flex; }

.modal-box {
    background: var(--bg-panel);
    width: 90%; 
    max-width: 1200px;
    height: 85vh;
    border: 1px solid var(--border);
    border-radius: 0;
    box-shadow: 0 10px 30px rgba(0,0,0,0.7);
    display: flex; 
    flex-direction: column;
    position: relative;
}

.modal-header {
    background: var(--bg-menu);
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h1 {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-main);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    padding: 0;
    position: static;
}
.modal-close:hover { color: var(--text-main); }

.modal-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.left-menu {
    width: 240px;
    background: var(--bg-dark);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
}

.menu-section {
    border-bottom: 1px solid var(--border);
}

.help-menu-item {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}

.help-menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.help-menu-item.active {
    background: rgba(0, 120, 212, 0.15);
    border-left-color: var(--accent);
    color: var(--accent);
}

.modal-content {
    flex: 1;
    overflow-y: auto;
    padding: 30px 40px;
    color: var(--text-main);
    line-height: 1.6;
}

/* Help Content Styles */
.modal-content h2 { 
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border); 
    padding-bottom: 10px;
}
.modal-content h3 { 
    color: var(--success); 
    font-size: 16px;
    font-weight: 600;
    margin-top: 25px;
    margin-bottom: 12px;
}
.modal-content h4 {
    color: var(--text-main);
    font-size: 14px;
    font-weight: 600;
    margin-top: 20px;
    margin-bottom: 10px;
}
.modal-content p {
    margin-bottom: 15px;
    color: var(--text-dim);
    font-size: 13px;
}
.modal-content ul, .modal-content ol { 
    padding-left: 25px; 
    margin-bottom: 15px; 
}
.modal-content li { 
    margin-bottom: 8px;
    color: var(--text-dim);
    font-size: 13px;
}

.modal-content table { 
    width: 100%; 
    border-collapse: collapse; 
    margin: 20px 0; 
    font-size: 13px; 
}
.modal-content th { 
    text-align: left; 
    padding: 10px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border); 
    color: var(--text-dim); 
    font-weight: 600;
}
.modal-content td { 
    border-bottom: 1px solid var(--border); 
    padding: 10px;
    color: var(--text-dim);
}
.modal-content kbd {
    background: var(--bg-dark); 
    border-radius: 3px; 
    padding: 3px 6px;
    font-family: monospace; 
    font-size: 12px;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.modal-content code {
    background: var(--bg-dark);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Consolas', monospace;
    font-size: 12px;
    color: var(--success);
}

.modal-content pre {
    background: var(--bg-dark); 
    padding: 15px; 
    border-radius: 4px;
    overflow-x: auto; 
    font-family: 'Consolas', monospace; 
    font-size: 12px;
    border: 1px solid var(--border); 
    color: #ccc;
    margin: 15px 0;
}
.modal-content pre code {
    background: transparent;
    padding: 0;
    border: none;
}
.modal-content a { color: var(--accent); text-decoration: none; }
.modal-content a:hover { text-decoration: underline; }

.info-box {
    background: rgba(0, 120, 212, 0.1);
    border-left: 3px solid var(--accent);
    padding: 15px;
    margin: 20px 0;
    border-radius: 0;
}

.info-box p {
    margin: 0;
    color: var(--text-main);
}

/* Scrollbar */
.left-menu::-webkit-scrollbar,
.modal-content::-webkit-scrollbar {
    width: 8px;
}

.left-menu::-webkit-scrollbar-track,
.modal-content::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

.left-menu::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.left-menu::-webkit-scrollbar-thumb:hover,
.modal-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}