/* ═══════════════════════════════════════════════════
   Блокнот Pro — Dark Forest Theme
   Single professional theme. No switching.
   ═══════════════════════════════════════════════════ */

:root {
    /* Core palette */
    --primary-color: #1a3a2a;
    --primary-dark-color: #0d1f14;
    --accent-color: #e8a020;
    --accent-glow: rgba(232, 160, 32, 0.25);

    /* Backgrounds */
    --background-color: #0a1a12;
    --surface-color: #12281c;
    --surface-glass: rgba(18, 40, 28, 0.92);
    --surface-elevated: #163324;

    /* Text */
    --on-surface-color: #d0e4d6;
    --on-surface-secondary-color: #6a9478;

    /* Borders */
    --border-color: rgba(50, 160, 90, 0.2);
    --border-accent: rgba(232, 160, 32, 0.35);

    /* Editor */
    --editor-bg-color: #0c1e14;
    --editor-text-color: #c8ddd0;
    --line-numbers-bg-color: #10241a;
    --line-numbers-text-color: #3d6b4e;

    /* Semantic */
    --warning-color: #e8a020;
    --danger-color: #e05252;
    --success-color: #3daa5c;

    /* Typography */
    --font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --mono-font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Monaco, 'Courier New', monospace;
    --editor-font-size: 16px;
    --line-height: 1.6;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 20px rgba(232, 160, 32, 0.15);

    /* Radii */
    --radius: 10px;
    --radius-lg: 14px;

    /* Safe areas */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ── Reset ── */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

body {
    font-family: var(--font-family);
    background: radial-gradient(ellipse at 30% 20%, #0f2a1a 0%, #0a1a12 50%, #06120c 100%);
    color: var(--on-surface-color);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(50, 160, 90, 0.25); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(50, 160, 90, 0.4); }

/* ── Global transitions ── */
button, .btn {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}
button:hover, .btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
button:active, .btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

/* ═══ LAYOUT ═══ */
.main-container { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ── */
.header {
    background: linear-gradient(135deg, rgba(232, 160, 32, 0.08) 0%, rgba(18, 40, 28, 0.6) 100%);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(50, 160, 90, 0.15);
    box-shadow: 0 1px 12px rgba(0, 0, 0, 0.4);
    padding-top: var(--safe-area-top);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    box-sizing: content-box;
    position: relative;
    z-index: 1000;
}

.header-left { display: flex; align-items: center; flex: 1; }
.header-right { display: flex; align-items: center; gap: 10px; }

.header h1 {
    font-size: 20px;
    font-weight: 500;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--on-surface-color);
}

.menu-btn, .header-action-btn {
    background: none;
    border: none;
    color: var(--on-surface-color);
    font-size: 24px;
    cursor: pointer;
    padding: 8px 12px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    box-shadow: none;
}
.menu-btn { margin-right: 15px; }
.header-action-btn:active { background: rgba(255, 255, 255, 0.08); }

.save-indicator {
    color: var(--accent-color);
    font-size: 16px;
    margin-left: 8px;
    opacity: 0;
    transition: opacity 0.3s;
}
.save-indicator.show { opacity: 1; }

/* Voice recording */
.voice-recording {
    background: var(--danger-color) !important;
    color: white !important;
    animation: pulse-voice 1.5s infinite;
}
@keyframes pulse-voice {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.8; }
}

/* ── Tabs ── */
.tabs-container {
    display: flex;
    overflow-x: auto;
    background: var(--background-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    z-index: 5;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tabs-container::-webkit-scrollbar { display: none; }

.tab {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    color: var(--on-surface-secondary-color);
}
.tab::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-color);
    transform: scaleX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.tab.active::before { transform: scaleX(1); }
.tab:hover { background: rgba(255, 255, 255, 0.04); }
.tab.active {
    background: var(--surface-color);
    color: var(--accent-color);
    font-weight: 600;
}
.tab.pinned::before {
    content: '📌';
    font-size: 12px;
    position: absolute;
    top: 2px;
    right: 2px;
    height: auto;
    background: none;
    transform: none;
}
.tab-close {
    font-size: 16px;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    border-radius: 50%;
    flex-shrink: 0;
}
.tab-close:hover { background: rgba(255, 255, 255, 0.08); }
.new-tab-btn {
    padding: 10px;
    font-size: 20px;
    cursor: pointer;
    color: var(--accent-color);
    border: none;
    background: transparent;
    min-width: 44px;
    flex-shrink: 0;
    box-shadow: none;
}

/* ── Format Toolbar ── */
.format-toolbar {
    background: var(--surface-color);
    padding: 8px 10px;
    display: flex;
    gap: 5px;
    flex-wrap: nowrap;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    position: sticky;
    top: 0;
    z-index: 100;
}
@supports (position: sticky) {
    .format-toolbar {
        position: -webkit-sticky;
        position: sticky;
    }
}
.format-toolbar::-webkit-scrollbar { display: none; }
.format-toolbar::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to left, var(--surface-color), transparent);
    pointer-events: none;
}
.format-toolbar button {
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--on-surface-color);
    font-size: 16px;
    font-weight: bold;
    width: 36px;
    height: 36px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
    box-shadow: none;
}
.format-toolbar button:hover { background: rgba(255, 255, 255, 0.06); }
.format-toolbar button:active { background: rgba(255, 255, 255, 0.1); }
.format-toolbar button.strikethrough { text-decoration: line-through; }
.format-toolbar button i { font-style: italic; }

/* ── Editor ── */
.editor-wrapper {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    background: var(--editor-bg-color);
    color: var(--editor-text-color);
    transition: background 0.3s, color 0.3s;
}

.line-numbers {
    background: var(--line-numbers-bg-color);
    color: var(--line-numbers-text-color);
    padding: 15px 10px;
    text-align: right;
    font-family: var(--mono-font-family);
    font-size: var(--editor-font-size);
    line-height: var(--line-height);
    user-select: none;
    border-right: 1px solid var(--border-color);
    overflow: hidden;
    min-width: 45px;
    transition: background 0.3s, color 0.3s;
    white-space: pre;
}

.editor-container {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    position: relative;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

#notepad {
    width: 100%;
    height: 100%;
    flex: 1;
    padding: 0;
    font-size: var(--editor-font-size);
    line-height: var(--line-height);
    border: none;
    background: transparent;
    resize: none;
    font-family: var(--mono-font-family);
    color: var(--editor-text-color);
}
#notepad:focus { outline: none; }
#notepad.no-wrap { white-space: pre; word-wrap: normal; overflow-x: auto; }

/* ── Markdown Preview ── */
.markdown-preview {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.7;
    color: var(--editor-text-color);
    background: var(--editor-bg-color);
}
.markdown-preview h1 { font-size: 1.8em; margin: 0.5em 0; border-bottom: 1px solid var(--border-color); padding-bottom: 0.3em; }
.markdown-preview h2 { font-size: 1.5em; margin: 0.5em 0; }
.markdown-preview h3 { font-size: 1.25em; margin: 0.5em 0; }
.markdown-preview p { margin: 0.8em 0; }
.markdown-preview ul, .markdown-preview ol { padding-left: 2em; margin: 0.5em 0; }
.markdown-preview li { margin: 0.3em 0; }
.markdown-preview code { background: rgba(50, 160, 90, 0.1); padding: 2px 6px; border-radius: 4px; font-family: var(--mono-font-family); }
.markdown-preview pre { background: rgba(0, 0, 0, 0.3); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 1em 0; }
.markdown-preview pre code { background: none; padding: 0; }
.markdown-preview blockquote { border-left: 3px solid var(--accent-color); padding-left: 15px; margin: 1em 0; color: var(--on-surface-secondary-color); }
.markdown-preview a { color: var(--accent-color); }
.markdown-preview img { max-width: 100%; height: auto; border-radius: 8px; margin: 0.5em 0; }
.markdown-preview strong { color: var(--accent-color); }
.markdown-preview hr { border: none; border-top: 1px solid var(--border-color); margin: 1.5em 0; }
.markdown-preview table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.markdown-preview th, .markdown-preview td { border: 1px solid var(--border-color); padding: 8px 12px; text-align: left; }
.markdown-preview th { background: var(--surface-color); }

/* Split view */
.editor-wrapper.split-view .editor-container { width: 50%; }
.editor-wrapper.split-view .markdown-preview { display: block !important; width: 50%; border-left: 1px solid var(--border-color); }

/* ── Status Bar ── */
.status-bar {
    background: var(--background-color);
    border-top: 1px solid var(--border-color);
    padding: 5px 15px;
    padding-bottom: calc(5px + var(--safe-area-bottom));
    font-size: 12px;
    color: var(--on-surface-secondary-color);
    display: flex;
    gap: 20px;
    z-index: 5;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: center;
}
.status-bar.hidden { display: none; }
.status-bar-left { display: flex; gap: 20px; }
.status-bar-promo {
    font-size: 11px;
    color: var(--accent-color);
    text-decoration: none;
    white-space: nowrap;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.status-bar-promo:hover { opacity: 1; text-decoration: underline; }

/* ═══ SIDEBAR ═══ */
.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    transition: left 0.3s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
}
.sidebar.open { left: 0; }

.sidebar-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark-color));
    color: var(--on-surface-color);
    padding: 20px 15px;
    font-size: 18px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

.menu-items { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.menu-section-title {
    padding: 15px 15px 10px 15px;
    font-size: 11px;
    color: var(--on-surface-secondary-color);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.menu-item {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 6px;
    margin: 2px 8px;
    color: var(--on-surface-color);
    cursor: pointer;
}
.menu-item:hover {
    background: rgba(50, 160, 90, 0.08);
    transform: translateX(3px);
}
.menu-item:active {
    background: rgba(50, 160, 90, 0.14);
}
.menu-item-left {
    display: flex;
    align-items: center;
    flex: 1;
}
.menu-item-icon {
    margin-right: 15px;
    font-size: 20px;
    width: 24px;
    text-align: center;
}
.menu-item-badge {
    background: var(--accent-color);
    color: #000;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
}
.menu-item .check-icon {
    display: inline-block;
    width: 20px;
    text-align: center;
    opacity: 0;
}
.menu-item.checked .check-icon { opacity: 1; color: var(--accent-color); }

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    z-index: 150;
}
.overlay.show { display: block; }

/* ═══ MODALS ═══ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
}
.modal.show { display: flex; }

.modal-content {
    background: var(--surface-color);
    color: var(--on-surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-16px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-close {
    background: none;
    border: none;
    color: var(--on-surface-secondary-color);
    font-size: 24px;
    cursor: pointer;
    box-shadow: none;
}
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

/* ── Buttons ── */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
    font-weight: 500;
}
.btn-primary { background: var(--primary-color); color: var(--on-surface-color); border: 1px solid var(--border-color); }
.btn-primary:hover { background: var(--surface-elevated); }
.btn-secondary { background: var(--background-color); color: var(--on-surface-color); border: 1px solid var(--border-color); }
.btn-secondary:active { background: var(--surface-color); }
.btn-success { background: var(--success-color); color: #000; }
.btn-warning { background: var(--warning-color); color: #000; }
.btn-danger { background: var(--danger-color); color: white; }

/* ── Forms ── */
.form-group, .setting-group { margin-bottom: 20px; }
.form-group label, .setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--on-surface-secondary-color);
}
.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--background-color);
    color: var(--on-surface-color);
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none;
    border-color: var(--accent-color);
}
.form-group textarea { resize: vertical; min-height: 100px; }

.setting-options { display: flex; gap: 10px; flex-wrap: wrap; }
.radio-btn {
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    flex: 1;
    text-align: center;
    min-width: 80px;
    color: var(--on-surface-color);
}
.radio-btn.selected {
    background: var(--accent-color);
    color: #000;
    border-color: var(--accent-color);
    font-weight: 600;
}

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
.stat-item {
    background: var(--background-color);
    padding: 15px;
    border-radius: var(--radius);
    text-align: center;
    border: 1px solid var(--border-color);
}
.stat-value { font-size: 24px; font-weight: bold; color: var(--accent-color); }
.stat-label { font-size: 14px; margin-top: 5px; color: var(--on-surface-secondary-color); }

/* ── File Indicator ── */
#fileIndicator {
    position: fixed;
    top: calc(70px + var(--safe-area-top));
    right: calc(20px + var(--safe-area-right));
    padding: 8px 15px;
    background: var(--surface-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 13px;
    color: var(--on-surface-color);
    display: none;
    z-index: 1000;
    transition: opacity 0.3s;
    box-shadow: var(--shadow-md);
}
#fileIndicator::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success-color);
    margin-right: 8px;
}
#fileIndicator.unsaved::before {
    background: var(--accent-color);
    animation: pulse-indicator 1.5s infinite;
}
@keyframes pulse-indicator {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: calc(80px + var(--safe-area-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-elevated);
    color: var(--on-surface-color);
    padding: 14px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 400;
    max-width: 90%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; }

/* ── Zoom controls ── */
.zoom-control { display: flex; align-items: center; justify-content: center; gap: 15px; }
.zoom-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--background-color);
    color: var(--on-surface-color);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
}
.zoom-btn:active { background: var(--surface-color); }
.zoom-value { font-size: 18px; font-weight: 500; min-width: 60px; text-align: center; }

/* ── Format options / Share ── */
.format-option {
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--on-surface-color);
}
.format-option:hover { background: rgba(50, 160, 90, 0.06); border-color: rgba(50, 160, 90, 0.3); }
.format-option.selected { border-color: var(--accent-color); background: rgba(232, 160, 32, 0.06); }

/* ── Templates ── */
.template-option {
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.template-option:hover { background: rgba(50, 160, 90, 0.06); border-color: rgba(50, 160, 90, 0.3); }
.template-name { font-weight: 500; margin-bottom: 5px; }
.template-desc { font-size: 12px; color: var(--on-surface-secondary-color); }

/* ── Search Results ── */
.search-result-item {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}
.search-result-item:hover { background: rgba(50, 160, 90, 0.06); }
.search-result-title { font-weight: 500; margin-bottom: 5px; }
.search-result-snippet { font-size: 13px; color: var(--on-surface-secondary-color); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-highlight { background: var(--accent-color); color: #000; font-weight: bold; border-radius: 2px; padding: 1px 3px; }

/* ── Tags ── */
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    background: var(--primary-color);
    color: var(--on-surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 12px;
    gap: 6px;
}
.tag-remove { cursor: pointer; font-weight: bold; opacity: 0.8; }
.tag-remove:hover { opacity: 1; }
.tag-filter {
    padding: 6px 12px;
    background: var(--background-color);
    color: var(--on-surface-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.tag-filter:hover { background: rgba(50, 160, 90, 0.1); }
.tag-filter.active { background: var(--accent-color); color: #000; border-color: var(--accent-color); font-weight: 600; }

/* ── Drop Zone ── */
.file-drop-zone {
    border: 2px dashed rgba(50, 160, 90, 0.3);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    color: var(--on-surface-secondary-color);
    transition: all 0.3s;
}
.file-drop-zone.dragover { border-color: var(--accent-color); background: rgba(232, 160, 32, 0.04); }

/* ── Progress ── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(50, 160, 90, 0.15);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 10px;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), var(--success-color));
    transition: width 0.3s;
    border-radius: 3px;
}

/* ── About Modal ── */
#aboutModal .modal-body { text-align: center; font-size: 16px; }
#aboutModal a:hover { background: rgba(50, 160, 90, 0.1) !important; }

/* ── PWA Install Banner ── */
.install-pwa-banner {
    position: fixed;
    bottom: calc(20px + var(--safe-area-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-elevated);
    border: 1px solid var(--border-accent);
    color: var(--on-surface-color);
    padding: 12px 20px;
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    display: none;
    align-items: center;
    gap: 12px;
    z-index: 500;
    max-width: 90%;
}
.install-pwa-banner.show { display: flex; }
.install-pwa-banner button {
    background: var(--accent-color);
    color: #000;
    border: none;
    padding: 8px 16px;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
}
.install-pwa-close {
    background: rgba(255, 255, 255, 0.1) !important;
    color: var(--on-surface-color) !important;
    width: 24px;
    height: 24px;
    padding: 0 !important;
    border-radius: 50% !important;
    font-size: 18px;
    line-height: 24px;
}

/* ── QR Code ── */
#qrCodeDisplay { text-align: center; padding: 20px; }
#qrCodeCanvas { margin: 0 auto; display: block; }

/* ── Table Mode ── */
#tableContainer { background: var(--background-color); padding: 10px; }
.excel-table { border-collapse: collapse; width: 100%; background: var(--surface-color); font-family: var(--mono-font-family); font-size: 13px; }
.excel-table th { background: var(--primary-color); color: var(--on-surface-color); padding: 8px; text-align: center; font-weight: 600; border: 1px solid var(--border-color); position: sticky; top: 0; z-index: 10; }
.excel-table td { border: 1px solid var(--border-color); padding: 0; min-width: 80px; height: 30px; }
.excel-table td.row-header { background: var(--surface-color); text-align: center; font-weight: 600; color: var(--on-surface-secondary-color); padding: 8px; min-width: 40px; }
.excel-table input { width: 100%; height: 100%; border: none; padding: 6px 8px; background: transparent; color: var(--on-surface-color); font-family: inherit; font-size: inherit; }
.excel-table input:focus { outline: 2px solid var(--accent-color); background: var(--background-color); }
.excel-table td.formula-cell { background: rgba(50, 160, 90, 0.08); }
.excel-table td.error-cell { background: rgba(224, 82, 82, 0.1); }

.table-toolbar { background: var(--surface-color); padding: 8px 10px; border-bottom: 1px solid var(--border-color); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.table-toolbar button { padding: 6px 12px; border: 1px solid var(--border-color); background: var(--background-color); color: var(--on-surface-color); border-radius: 4px; cursor: pointer; font-size: 12px; transition: background 0.2s; }
.table-toolbar button:hover { background: var(--surface-color); }
.table-toolbar button:active { background: var(--accent-color); color: #000; }

/* ── Function Panel ── */
.function-panel { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface-color); border-top: 1px solid var(--border-color); box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4); z-index: 1000; max-height: 70vh; overflow-y: auto; transform: translateY(100%); transition: transform 0.3s ease; padding-bottom: var(--safe-area-bottom); }
.function-panel.show { transform: translateY(0); }
.function-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 15px; border-bottom: 1px solid var(--border-color); position: sticky; top: 0; background: var(--surface-color); z-index: 10; }
.function-panel-title { font-size: 18px; font-weight: 600; color: var(--on-surface-color); }
.function-panel-close { background: none; border: none; font-size: 24px; color: var(--on-surface-color); cursor: pointer; padding: 5px 10px; min-width: 44px; min-height: 44px; box-shadow: none; }
.function-categories { display: flex; gap: 5px; padding: 10px 15px; overflow-x: auto; border-bottom: 1px solid var(--border-color); -webkit-overflow-scrolling: touch; }
.function-category-btn { padding: 8px 16px; background: var(--background-color); border: 1px solid var(--border-color); border-radius: 20px; color: var(--on-surface-color); cursor: pointer; white-space: nowrap; font-size: 14px; transition: all 0.2s; }
.function-category-btn.active { background: var(--accent-color); color: #000; border-color: var(--accent-color); font-weight: 600; }
.function-list { padding: 10px 15px; }
.function-item { padding: 12px; border: 1px solid var(--border-color); border-radius: var(--radius); margin-bottom: 8px; cursor: pointer; transition: all 0.2s; background: var(--background-color); }
.function-item:active { background: var(--accent-color); color: #000; transform: scale(0.98); }
.function-item-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.function-item-desc { font-size: 12px; color: var(--on-surface-secondary-color); }
.function-item:active .function-item-desc { color: rgba(0, 0, 0, 0.7); }

.function-input-panel { padding: 15px; display: none; background: var(--surface-color); border-top: 1px solid var(--border-color); }
.function-input-panel.show { display: block; }
.function-input-group { margin-bottom: 15px; }
.function-input-label { display: block; font-weight: 600; margin-bottom: 8px; color: var(--on-surface-color); }
.function-input-field { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: var(--radius); font-size: 16px; background: var(--background-color); color: var(--on-surface-color); }
.function-input-buttons { display: flex; gap: 10px; margin-top: 15px; }
.function-input-buttons button { flex: 1; padding: 12px; border: none; border-radius: var(--radius); font-size: 16px; cursor: pointer; font-weight: 600; min-height: 44px; }
.btn-select-range { background: var(--accent-color); color: #000; }
.btn-insert-formula { background: var(--primary-color); color: var(--on-surface-color); }
.btn-cancel-formula { background: var(--background-color); color: var(--on-surface-color); border: 1px solid var(--border-color); }
.range-selection-mode .excel-table td { cursor: pointer; }
.range-selection-mode .excel-table td:hover { background: rgba(50, 160, 90, 0.15); }
.range-selection-mode .excel-table td.range-selected { background: rgba(50, 160, 90, 0.3); border: 2px solid var(--success-color); }

/* ═══ MEDICAL PANELS ═══ */
.med-panel { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); z-index: 301; display: none; align-items: flex-start; justify-content: center; padding: 20px; padding-top: calc(60px + var(--safe-area-top, 0px)); }
.med-panel.show { display: flex; }
.med-panel-content { background: var(--surface-color); border: 1px solid var(--border-color); border-radius: var(--radius-lg); max-width: 600px; width: 100%; max-height: calc(100vh - 80px - var(--safe-area-top, 0px)); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.med-panel-header { padding: 20px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; background: linear-gradient(135deg, #1a3a2a, #0f2a1e); color: var(--on-surface-color); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.med-panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.med-search-box { margin-bottom: 15px; position: relative; }
.med-search-box input { width: 100%; padding: 12px 40px 12px 15px; border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--background-color); min-height: 44px; color: var(--on-surface-color); }
.med-category-tabs { display: flex; gap: 8px; margin-bottom: 15px; overflow-x: auto; }
.med-category-tab { padding: 8px 16px; border: 1px solid var(--border-color); background: var(--background-color); color: var(--on-surface-color); border-radius: 20px; cursor: pointer; font-size: 13px; white-space: nowrap; min-height: 40px; }
.med-category-tab.active { background: var(--accent-color); color: #000; border-color: var(--accent-color); font-weight: 600; }
.med-item { background: var(--background-color); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 15px; margin-bottom: 10px; cursor: pointer; }
.med-item-name { font-weight: 600; font-size: 15px; color: var(--on-surface-color); }
.med-item-latin { font-size: 13px; color: var(--on-surface-secondary-color); font-style: italic; margin-top: 4px; }
.med-item-details { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border-color); }
.med-item.expanded .med-item-details { display: block; }
.med-detail-section { margin-bottom: 10px; }
.med-detail-label { font-size: 12px; font-weight: 600; color: var(--accent-color); margin-bottom: 4px; }
.med-detail-text { font-size: 13px; color: var(--on-surface-color); line-height: 1.4; }

/* ── Calculators ── */
.calc-container { background: var(--background-color); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 15px; margin-bottom: 15px; }
.calc-field { margin-bottom: 15px; }
.calc-field label { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--on-surface-color); margin-bottom: 8px; min-height: 44px; }
.calc-field input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; accent-color: var(--accent-color); }
.calc-field input[type="number"] { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--background-color); color: var(--on-surface-color); min-height: 44px; }
.calc-field select { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--background-color); color: var(--on-surface-color); min-height: 44px; }
.calc-result { background: linear-gradient(135deg, #1a3a2a, #0f2a1e); color: var(--on-surface-color); padding: 20px; border-radius: var(--radius-lg); text-align: center; margin-top: 20px; border: 1px solid var(--border-color); }
.calc-result-score { font-size: 48px; font-weight: 700; margin-bottom: 10px; color: var(--accent-color); }
.calc-result-label { font-size: 16px; margin-bottom: 5px; opacity: 0.85; }
.calc-result-risk { font-size: 18px; font-weight: 600; margin-top: 10px; color: var(--accent-color); }
.calc-result-desc { font-size: 14px; margin-top: 10px; opacity: 0.75; line-height: 1.4; }

/* ── Templates ── */
.template-item { background: var(--background-color); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 15px; margin-bottom: 10px; cursor: pointer; }
.template-item-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.template-icon { font-size: 28px; min-width: 40px; text-align: center; }
.template-name { font-weight: 600; font-size: 15px; color: var(--on-surface-color); }
.template-desc { font-size: 13px; color: var(--on-surface-secondary-color); line-height: 1.4; }

/* ── Global Search ── */
.gs-result {
    padding: 12px;
    margin-bottom: 8px;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}
.gs-result:hover { border-color: rgba(50, 160, 90, 0.4); }
.gs-result-title { font-weight: 600; color: var(--accent-color); margin-bottom: 4px; }
.gs-result-snippet { font-size: 13px; color: var(--on-surface-secondary-color); line-height: 1.5; }
.gs-hl { background: var(--accent-color); color: #000; padding: 2px 4px; border-radius: 2px; font-weight: 600; }

/* ═══ MOBILE FAB ═══ */
.format-fab {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom));
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-color);
    border: none;
    font-size: 28px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    z-index: 98;
    display: none;
    cursor: pointer;
    transition: transform 0.3s;
    color: #000;
}
.format-fab:active { transform: scale(0.95); }

.format-popup {
    position: fixed;
    bottom: calc(92px + env(safe-area-inset-bottom));
    right: 16px;
    background: var(--surface-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 12px;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-width: 320px;
    box-shadow: var(--shadow-lg);
    z-index: 99;
    animation: slideUp 0.3s ease;
}
.format-popup.active { display: grid; }
.format-popup button {
    width: 48px;
    height: 48px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--on-surface-color);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
}
.format-popup button:active { background: var(--accent-color); color: #000; transform: scale(0.9); }

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

.toolbar-position-btn {
    position: fixed;
    top: 60px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    color: var(--on-surface-color);
    font-size: 16px;
    z-index: 97;
    display: none;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

/* Notepad texture */
#notepad {
    font-family: var(--mono-font-family);
    line-height: 1.6;
    padding: 20px;
    background-image: linear-gradient(transparent 95%, rgba(50, 160, 90, 0.03) 50%);
    background-size: 100% 1.6em;
    background-attachment: local;
}

/* Pre blocks */
pre {
    background: var(--background-color);
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: var(--radius);
    overflow-x: auto;
    white-space: pre-wrap;
}

/* ── Loading Overlay ── */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(50, 160, 90, 0.15);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.loading-text { margin-top: 15px; color: var(--on-surface-secondary-color); font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
    .header h1 { font-size: 18px; }
    .format-toolbar { padding: 8px 5px; }
    .format-toolbar button { width: 40px; height: 40px; font-size: 18px; }

    .format-toolbar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        z-index: 1000;
        border-top: 1px solid var(--border-color);
        border-bottom: none;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
        background: var(--surface-color);
        height: 52px;
        overflow: hidden;
        transition: height 0.3s ease;
    }
    .format-toolbar.expanded {
        height: auto;
        max-height: 200px;
        overflow-x: auto;
        overflow-y: auto;
    }
    .format-toolbar::before {
        content: '▲ Форматирование';
        position: absolute;
        top: 0; left: 0; right: 0;
        height: 52px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--surface-color);
        color: var(--on-surface-secondary-color);
        font-size: 13px;
        cursor: pointer;
        z-index: 1;
        border-bottom: 1px solid var(--border-color);
    }
    .format-toolbar.expanded::before { content: '▼ Свернуть'; }
    .format-toolbar > * { margin-top: 52px; }

    .editor-container { padding: 15px 10px; padding-bottom: 60px; }
    .sidebar { width: 100%; left: -100%; }
    .modal-content { max-width: 95%; margin: 0 10px; }
    .stats-grid { grid-template-columns: 1fr; }
    .status-bar { font-size: 11px; padding: 4px 10px; padding-bottom: calc(4px + var(--safe-area-bottom)); gap: 10px; display: none; }
    .line-numbers { padding: 15px 5px; min-width: 35px; font-size: 14px; display: none; }
    #notepad { font-size: 16px; padding-bottom: 120px; }

    .editor-wrapper.split-view { flex-direction: column; }
    .editor-wrapper.split-view .editor-container { width: 100%; height: 50%; }
    .editor-wrapper.split-view .markdown-preview { width: 100%; height: 50%; border-left: none; border-top: 1px solid var(--border-color); }

    .tab { padding: 8px 12px; font-size: 13px; }
    .menu-item { padding: 16px 12px; }
    .setting-options { flex-direction: column; }
    .radio-btn { width: 100%; }
    .format-fab { display: flex; align-items: center; justify-content: center; }
    .toolbar-position-btn { display: flex; align-items: center; justify-content: center; }
}

@media (max-width: 480px) {
    .header h1 { font-size: 16px; }
    .stats-grid { grid-template-columns: 1fr; }
}

/* ── Print ── */
@media print {
    body { background: white !important; color: black !important; }
    .header, .tabs-container, .format-toolbar, .status-bar, .sidebar, .overlay, .modal, .toast { display: none !important; }
    .main-container { height: auto !important; }
    .editor-wrapper { height: auto !important; background: white !important; display: block !important; }
    .line-numbers { display: none !important; }
    .editor-container { padding: 0 !important; overflow: visible !important; }
    #notepad {
        border: none !important;
        background: white !important;
        color: black !important;
        height: auto !important;
        overflow: visible !important;
        white-space: pre-wrap !important;
        word-wrap: break-word !important;
        font-family: 'Georgia', 'Times New Roman', serif !important;
        font-size: 12pt !important;
        line-height: 1.6 !important;
        background-image: none !important;
    }
    .editor-wrapper::before {
        content: attr(data-note-title);
        display: block;
        font-size: 18pt;
        font-weight: bold;
        margin-bottom: 20px;
        padding-bottom: 10px;
        border-bottom: 2px solid #333;
    }
    .editor-wrapper::after {
        content: "Напечатано: " attr(data-print-date);
        display: block;
        margin-top: 30px;
        padding-top: 10px;
        border-top: 1px solid #ccc;
        font-size: 9pt;
        color: #666;
    }
    @page { margin: 2cm; }
}

.format-toolbar.position-top {
    top: 112px;
    bottom: auto;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}
