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

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
    --radius: 8px;
    --radius-sm: 4px;
}

[data-theme="dark"] {
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-light: #312e81;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'kern' 1, 'liga' 1;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    transition: background 0.3s, border-color 0.3s;
}

.header-left { display: flex; align-items: center; gap: 16px; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 24px; }
.logo-text { font-size: 18px; font-weight: 700; color: var(--primary); }
.document-title-wrapper { padding-left: 16px; border-left: 1px solid var(--border); }
.document-title {
    border: none; outline: none; font-size: 16px; font-weight: 500;
    padding: 6px 12px; border-radius: var(--radius-sm); background: transparent;
    color: var(--text); min-width: 200px; transition: background 0.2s;
}
.document-title:hover, .document-title:focus { background: var(--primary-light); }
.header-right { display: flex; gap: 8px; }

.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
    border: none; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.btn-icon { padding: 8px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }

.toolbar {
    display: flex; align-items: center; padding: 6px 16px; background: var(--surface);
    border-bottom: 1px solid var(--border); gap: 4px; overflow-x: auto; flex-wrap: wrap;
    transition: background 0.3s, border-color 0.3s;
}
.toolbar-group { display: flex; align-items: center; gap: 2px; }
.toolbar-divider { width: 1px; height: 24px; background: var(--border); margin: 0 6px; }

.toolbar-btn {
    display: flex; align-items: center; justify-content: center; width: 32px; height: 32px;
    border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm);
    cursor: pointer; color: var(--text-secondary);
    transition: all 0.15s ease;
    position: relative;
}
.toolbar-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
}
.toolbar-btn:active:not(.active) {
    transform: scale(0.9);
    background: var(--primary-light);
}
.toolbar-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary-hover);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 1px 0 rgba(255,255,255,0.1);
    transform: translateY(1px);
}
.toolbar-btn.active:hover {
    background: var(--primary-hover);
    color: white;
}

.toolbar-select {
    padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); font-size: 13px; color: var(--text); cursor: pointer;
    outline: none; font-family: inherit; transition: border-color 0.2s;
}
.toolbar-select:hover, .toolbar-select:focus { border-color: var(--primary); }
.toolbar-color-btn {
    position: relative; display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border: none; background: transparent; border-radius: var(--radius-sm);
    cursor: pointer; color: var(--text-secondary); transition: all 0.15s;
}
.toolbar-color-btn:hover { background: var(--primary-light); color: var(--primary); }
.color-input { position: absolute; width: 100%; height: 100%; opacity: 0; cursor: pointer; top: 0; left: 0; }

.editor-container { flex: 1; overflow-y: auto; padding: 40px 20px; background: var(--bg); transition: background 0.3s; }
.page-wrapper { display: flex; justify-content: center; }
.page {
    width: 100%; max-width: 816px; min-height: 1056px; background: var(--surface);
    padding: 72px 80px; box-shadow: var(--shadow-lg); border-radius: 2px; outline: none;
    font-size: 16px; line-height: 1.7; color: var(--text);
    transition: background 0.3s, color 0.3s, transform 0.3s;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
    -webkit-text-size-adjust: 100%;
}
.page:focus { outline: none; }
.page h1 { font-size: 2em; margin-bottom: 0.5em; }
.page h2 { font-size: 1.5em; margin-bottom: 0.5em; margin-top: 1em; }
.page h3 { font-size: 1.25em; margin-bottom: 0.5em; margin-top: 1em; }
.page h4 { font-size: 1.1em; margin-bottom: 0.5em; margin-top: 1em; }
.page p { margin-bottom: 1em; }
.page ul, .page ol { margin-bottom: 1em; padding-left: 2em; }
.page li { margin-bottom: 0.25em; }
.page blockquote {
    border-left: 4px solid var(--primary); padding: 12px 20px; margin: 1em 0;
    background: var(--primary-light); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: italic; color: var(--text-secondary);
}
.page pre {
    background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: var(--radius);
    overflow-x: auto; margin: 1em 0; font-family: 'Courier New', monospace;
}
.page a { color: var(--primary); text-decoration: underline; }
.page img { max-width: 100%; height: auto; border-radius: var(--radius-sm); margin: 1em 0; }
.page table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.page table td, .page table th { border: 1px solid var(--border); padding: 8px 12px; min-width: 80px; }
.page table th { background: var(--primary-light); font-weight: 600; }
.page hr { border: none; border-top: 2px solid var(--border); margin: 2em 0; }

.footer {
    display: flex; align-items: center; justify-content: space-between; padding: 6px 16px;
    background: var(--surface); border-top: 1px solid var(--border); font-size: 12px;
    color: var(--text-secondary); transition: background 0.3s, border-color 0.3s;
}
.footer-right { display: flex; gap: 12px; align-items: center; }
.footer-divider { color: var(--border); }
.status-indicator { display: flex; align-items: center; gap: 6px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.saved { background: #22c55e; }
.status-dot.unsaved { background: #f59e0b; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 500px; overflow: hidden; animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header {
    display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
    background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-secondary);
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); transition: all 0.15s;
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-body { padding: 20px; }
.modal-body p { margin-bottom: 16px; color: var(--text-secondary); }
.save-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.save-option {
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    cursor: pointer; transition: all 0.15s; text-align: center; font-family: inherit;
}
.save-option:hover { border-color: var(--primary); background: var(--primary-light); }
.save-icon { font-size: 32px; }
.save-label { font-weight: 600; font-size: 14px; color: var(--text); }
.save-desc { font-size: 11px; color: var(--text-secondary); }

.search-modal { max-width: 600px; }
.search-input-group { display: flex; gap: 8px; margin-bottom: 12px; }
.search-input {
    flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text); font-size: 14px; outline: none; font-family: inherit;
}
.search-input:focus { border-color: var(--primary); }
.search-buttons { display: flex; gap: 8px; }
.search-btn {
    padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); cursor: pointer; font-size: 13px;
    font-family: inherit; transition: all 0.15s;
}
.search-btn:hover { background: var(--primary-light); border-color: var(--primary); }
.search-btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.search-btn-primary:hover { background: var(--primary-hover); }
.search-options { display: flex; gap: 16px; margin-top: 12px; font-size: 13px; }
.search-option { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.toc-modal { max-width: 700px; max-height: 80vh; }
.toc-list { list-style: none; max-height: 400px; overflow-y: auto; }
.toc-item { padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer; transition: background 0.15s; margin-bottom: 4px; }
.toc-item:hover { background: var(--primary-light); }
.toc-item-h1 { font-weight: 600; }
.toc-item-h2 { padding-left: 24px; }
.toc-item-h3 { padding-left: 48px; font-size: 14px; }
.toc-item-h4 { padding-left: 72px; font-size: 13px; }

.version-modal { max-width: 600px; }
.version-list { max-height: 400px; overflow-y: auto; }
.version-item {
    display: flex; justify-content: space-between; align-items: center; padding: 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px;
    transition: all 0.15s;
}
.version-item:hover { background: var(--primary-light); border-color: var(--primary); }
.version-info { flex: 1; }
.version-title { font-weight: 600; margin-bottom: 4px; }
.version-date { font-size: 12px; color: var(--text-secondary); }
.version-actions { display: flex; gap: 4px; }
.version-btn {
    padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); cursor: pointer; font-size: 12px; transition: all 0.15s;
}
.version-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }

.zoom-control { display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.zoom-btn {
    width: 24px; height: 24px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); cursor: pointer; display: flex;
    align-items: center; justify-content: center; transition: all 0.15s;
}
.zoom-btn:hover { background: var(--primary-light); border-color: var(--primary); }
.zoom-btn:active { transform: scale(0.9); }
.zoom-value { min-width: 40px; text-align: center; font-size: 12px; }

.theme-toggle {
    position: relative; width: 36px; height: 36px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.theme-toggle:hover { background: var(--primary-light); border-color: var(--primary); }

.drop-zone {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(79, 70, 229, 0.1); border: 4px dashed var(--primary);
    display: none; align-items: center; justify-content: center; z-index: 9999; pointer-events: none;
}
.drop-zone.active { display: flex; }
.drop-zone-text {
    background: var(--surface); padding: 32px 64px; border-radius: var(--radius);
    font-size: 24px; font-weight: 600; color: var(--primary); box-shadow: var(--shadow-lg);
}

body.focus-mode .header, body.focus-mode .toolbar, body.focus-mode .footer {
    opacity: 0; transition: opacity 0.3s;
}
body.focus-mode .header:hover, body.focus-mode .toolbar:hover, body.focus-mode .footer:hover { opacity: 1; }
body.fullscreen .page { max-width: none; min-height: 100vh; padding: 40px; }

@media (max-width: 768px) {
    .page { padding: 40px 24px; min-height: auto; }
    .header-left { gap: 8px; }
    .document-title { min-width: 100px; font-size: 14px; }
    .toolbar { padding: 4px 8px; }
    .save-options { grid-template-columns: 1fr; }
}
@media print {
    .header, .toolbar, .footer, .modal-overlay, .drop-zone, .tour-overlay { display: none !important; }
    .editor-container { padding: 0; overflow: visible; }
    .page { box-shadow: none; padding: 0; max-width: none; }
}

/* ========================================= */
/*          ИНТЕРАКТИВНЫЙ ТУР                */
/* ========================================= */

.tour-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tour-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.tour-highlight {
    position: absolute;
    background: transparent;
    border-radius: 6px;
    z-index: 1;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.tour-highlight::after {
    content: '';
    position: absolute;
    inset: -4px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    animation: tourPulse 2s infinite;
    pointer-events: none;
    box-shadow: 0 0 20px rgba(79, 70, 229, 0.5);
}

@keyframes tourPulse {
    0%, 100% { 
        opacity: 1; 
        box-shadow: 0 0 20px rgba(79, 70, 229, 0.5);
    }
    50% { 
        opacity: 0.7; 
        box-shadow: 0 0 30px rgba(79, 70, 229, 0.8);
    }
}

.tour-tooltip {
    position: absolute;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 20px;
    width: 340px;
    max-width: calc(100vw - 40px);
    z-index: 2;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    border: 1px solid var(--border);
}

.tour-overlay.active .tour-tooltip {
    opacity: 1;
    transform: translateY(0);
}

.tour-tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.tour-step-counter {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 3px 10px;
    border-radius: 12px;
}

.tour-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    line-height: 1;
}

.tour-close:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.tour-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.tour-description {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.tour-progress {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 16px;
}

.tour-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-hover));
    border-radius: 2px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}

.tour-footer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 4px;
}

.tour-footer-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 32px;
}

.tour-footer-bottom {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.tour-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s;
    white-space: nowrap;
}

.tour-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
}

.tour-btn-next {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.tour-btn-next:hover {
    background: var(--primary-hover);
    color: white;
}

.tour-btn-skip {
    color: var(--text-secondary);
    border: none;
    background: transparent;
    padding: 8px 0;
}

.tour-btn-skip:hover {
    color: var(--text);
    background: transparent;
    text-decoration: underline;
}

.tour-btn-prev:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tour-dont-show {
    display: none;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    margin-left: auto;
}

.tour-dont-show:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.tour-dont-show input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
    margin: 0;
}

.tour-dont-show span {
    white-space: nowrap;
}

.tour-tooltip.final .tour-dont-show {
    display: flex;
}

.tour-tooltip.final .tour-title {
    color: var(--primary);
}

.tour-tooltip.final .tour-btn-next {
    background: #22c55e;
    border-color: #22c55e;
    padding: 10px 20px;
    font-size: 14px;
}

.tour-tooltip.final .tour-btn-next:hover {
    background: #16a34a;
}
/* Широкое модальное окно для сохранения */
.modal-wide {
    max-width: 700px !important;
}

.save-options-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

@media (max-width: 768px) {
    .save-options-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .save-options-grid {
        grid-template-columns: 1fr;
    }
}
