/* CSS Variables - Light Theme */
:root {
    --primary: #f97316;
    --primary-hover: #ea580c;
    --primary-light: #fff7ed;
    --secondary: #6c757d;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --light: #e9ecef;
    --dark: #212529;
    --border: #dee2e6;
    --border-light: #e9ecef;
    --white: #fdfdfd;
    --bg-light: #e0e2e6;
    --bg-main: #f0f2f5;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-sm: 4px;
    --transition: 0.2s ease;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    
    /* Text colors */
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    
    /* Editor colors */
    --editor-bg: #ffffff;
    --editor-text: #1a1a2e;
    --preview-bg: #ffffff;
    
    /* Scrollbar */
    --scrollbar-bg: #f1f1f1;
    --scrollbar-thumb: #c1c1c1;
}

/* Dark Theme - Pure Black */
[data-theme="dark"] {
    --primary: #f97316;
    --primary-hover: #ea580c;
    --primary-light: #fff7ed;
    --secondary: #9ca3af;
    --light: #171717;
    --dark: #f3f4f6;
    --border: #262626;
    --border-light: #404040;
    --white: #000000;
    --bg-light: #000000;
    --bg-main: #0a0a0a;
    --shadow: 0 2px 8px rgba(0,0,0,0.5);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.6);
    
    --text-primary: #f5f5f5;
    --text-secondary: #a3a3a3;
    --text-muted: #737373;
    
    --editor-bg: #000000;
    --editor-text: #f5f5f5;
    --preview-bg: #000000;
    
    --scrollbar-bg: #171717;
    --scrollbar-thumb: #404040;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-light);
    color: var(--text-primary);
    transition: background var(--transition), color var(--transition);
}

.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}

/* App Container */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-light);
}

/* Header */
.header {
    background: var(--bg-main);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-left: 4px;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 24px;
    height: 24px;
    color: var(--primary);
}

[data-theme="dark"] .logo-icon {
    filter: none;
}

.header-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    white-space: nowrap;
}

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

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--light);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--light);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    color: var(--primary);
}

.btn-icon:hover {
    background: var(--light);
    color: var(--primary-hover);
}

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

.header-left .btn-icon {
    width: 32px;
    height: 32px;
}

.header-left .btn-icon svg {
    width: 16px;
    height: 16px;
}

.btn-icon .sun-icon {
    display: none;
}

.btn-icon .moon-icon {
    display: block;
}

[data-theme="dark"] .btn-icon .sun-icon {
    display: block;
}

[data-theme="dark"] .btn-icon .moon-icon {
    display: none;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.8rem;
}

.btn-sm svg {
    width: 14px;
    height: 14px;
}

.btn-sm.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.preview.raw-mode {
    font-family: var(--font-mono);
    white-space: pre-wrap;
    word-break: break-word;
}

.preview.raw-mode pre {
    margin: 0;
    padding: 0;
    background: transparent;
}

/* AI Chat Panel */
.ai-chat-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-main);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
}

.ai-chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-model-select {
    font-size: 0.8rem;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-main);
    color: var(--text-primary);
    max-width: 200px;
}

.ai-chat-header .close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.ai-chat-header .close-btn:hover {
    background: var(--light);
    color: var(--text-primary);
}

.ai-chat-header .close-btn svg {
    width: 16px;
    height: 16px;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-message {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    max-width: 85%;
    word-break: break-word;
    line-height: 1.5;
}

.ai-message-user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
}

.ai-message-assistant {
    background: var(--light);
    color: var(--text-primary);
    align-self: flex-start;
}

.ai-message-system {
    background: var(--warning);
    color: var(--dark);
    align-self: flex-start;
    font-size: 0.8rem;
}

.ai-message-content {
    line-height: 1.6;
}

.ai-message-content p {
    margin-bottom: 0.4em;
}

.ai-message-content p:last-child {
    margin-bottom: 0;
}

.ai-message-content code {
    background: rgba(0,0,0,0.1);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.ai-message-content pre {
    background: var(--light);
    padding: 10px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.4em 0;
    font-size: 0.85rem;
}

.ai-message-content pre code {
    background: none;
    padding: 0;
}

.ai-message-content ul,
.ai-message-content ol {
    padding-left: 1.2em;
    margin: 0.3em 0;
}

.ai-message-content blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 0.8em;
    margin: 0.4em 0;
    color: var(--text-secondary);
}

.ai-message-content a {
    color: var(--primary);
}

.ai-message-content strong {
    font-weight: 600;
}

.ai-chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.ai-chat-input-area textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: none;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    min-height: 40px;
    max-height: 80px;
    background: var(--editor-bg);
    color: var(--editor-text);
}

.ai-chat-input-area textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.ai-chat-input-area .btn {
    align-self: flex-end;
}

.preview-section {
    position: relative;
}

/* Main Container */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-main);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width var(--transition);
}

.sidebar.collapsed {
    width: 0;
    border-right: none;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-main);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}

.search-box svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.875rem;
    color: var(--text-primary);
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.note-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.notes-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.note-item {
    padding: 12px;
    padding-right: 40px;
    margin-bottom: 4px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
    position: relative;
    background: transparent;
}

.note-item:hover {
    background: var(--light);
    border-color: var(--border);
}

.note-item.active {
    background: transparent;
    border-color: transparent;
}

.note-item.active .note-title {
    color: var(--primary);
}

[data-theme="dark"] .note-item.active {
    background: transparent;
}

[data-theme="dark"] .note-item.active .note-title,
[data-theme="dark"] .note-item.active .note-preview {
    color: var(--primary);
}

.note-item .note-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.note-item .note-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.note-item .delete-note {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.note-item:hover .delete-note {
    opacity: 1;
}

.note-item .delete-note:hover {
    background: var(--primary-light);
    color: var(--primary);
    transform: translateY(-50%) scale(1.1);
}

[data-theme="dark"] .note-item .delete-note {
    color: var(--text-muted);
}

[data-theme="dark"] .note-item .delete-note:hover {
    background: var(--primary-light);
    color: var(--primary);
}

/* Main Content */
.content {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: var(--bg-main);
}

.editor-section, .preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-section {
    border-right: 1px solid var(--border);
}

.section-header {
    padding: 10px 16px;
    background: var(--light);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.8rem;
    gap: 16px;
}

.editor-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: normal;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.toolbar-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
}

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

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 6px;
}

.preview-actions {
    display: flex;
    gap: 4px;
}

/* Editor */
.editor {
    flex: 1;
    padding: 20px;
    border: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    line-height: 1.7;
    background: var(--editor-bg);
    color: var(--editor-text);
    outline: none;
    transition: background var(--transition), color var(--transition);
}

.editor::placeholder {
    color: var(--text-muted);
}

.editor:focus {
    background: var(--editor-bg);
}

/* Preview */
.preview {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--preview-bg);
    color: var(--text-primary);
    line-height: 1.7;
    transition: background var(--transition), color var(--transition);
    min-height: 0;
}

.preview h1, .preview h2, .preview h3, .preview h4, .preview h5, .preview h6 {
    margin: 1.2em 0 0.5em;
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.3;
}

.preview h1 { font-size: 1.75rem; }
.preview h2 { font-size: 1.5rem; }
.preview h3 { font-size: 1.25rem; }
.preview h4 { font-size: 1.1rem; }

.preview p {
    margin-bottom: 1em;
}

.preview a {
    color: var(--primary);
    text-decoration: none;
}

.preview a:hover {
    text-decoration: underline;
}

.preview code {
    background: var(--light);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.9em;
    color: var(--primary);
}

.preview pre {
    background: var(--light);
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 1em 0;
}

.preview pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

.preview ul, .preview ol {
    padding-left: 1.5em;
    margin-bottom: 1em;
}

.preview li {
    margin-bottom: 0.5em;
}

.preview blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 1em;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.preview hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2em 0;
}

.preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.preview th, .preview td {
    border: 1px solid var(--border);
    padding: 10px;
    text-align: left;
}

.preview th {
    background: var(--light);
    font-weight: 600;
}

.preview img {
    max-width: 100%;
    border-radius: var(--radius);
}

/* Footer */
.footer {
    background: var(--bg-main);
    padding: 8px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.footer-right {
    display: flex;
    gap: 16px;
    align-items: center;
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status.success { color: var(--success); }
.status.error { color: var(--danger); }
.status.info { color: var(--info); }

.sync-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-main);
    border-radius: var(--radius);
    width: 90%;
    max-width: 480px;
    max-height: 85vh;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.close-btn:hover {
    background: var(--light);
    color: var(--primary-hover);
}

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

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.setting-label {
    font-weight: 500;
    color: var(--text-primary);
}

.setting-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.toggle-btn {
    width: 44px;
    height: 24px;
    border: none;
    border-radius: 12px;
    background: var(--border);
    cursor: pointer;
    position: relative;
    transition: background var(--transition);
}

.toggle-btn.active {
    background: var(--primary);
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-btn.active .toggle-slider {
    transform: translateX(20px);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--bg-main);
    color: var(--text-primary);
    transition: border-color var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

[data-theme="dark"] .form-group input:focus {
    border-color: var(--primary);
}

[data-theme="dark"] .btn-primary:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

[data-theme="dark"] .toolbar-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.message {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    display: none;
}

.message.success {
    background: #d4edda;
    color: #155724;
    display: block;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    display: block;
}

.message.info {
    background: #d1ecf1;
    color: #0c5460;
    display: block;
}

[data-theme="dark"] .message.success {
    background: rgba(40, 167, 69, 0.2);
    color: #75e691;
}

[data-theme="dark"] .message.error {
    background: rgba(220, 53, 69, 0.2);
    color: #ff6b7a;
}

[data-theme="dark"] .message.info {
    background: rgba(23, 162, 184, 0.2);
    color: #6dd5ed;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.about-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Mobile Bottom Navigation (hidden on desktop) */
.mobile-bottom-nav {
    display: none;
}

.mobile-fab {
    display: none;
}

/* Responsive - Tablet */
@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 220px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .content {
        flex-direction: column;
    }

    .editor-section {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .toolbar {
        display: none;
    }

    .section-header {
        flex-wrap: wrap;
    }
}

/* Responsive - Mobile */
@media (max-width: 640px) {
    /* ─── Layout ─── */
    html, body {
        /* Allow native scroll context so iOS rubber-band works */
        overflow: hidden;
        overscroll-behavior: none;
    }

    .app {
        /* No padding-bottom — the absolute panels handle their own bottom offset */
        padding-bottom: 0;
    }

    /* Prevent iOS zoom-on-focus: inputs must be >= 16px on mobile */
    input, textarea, select {
        font-size: 16px;
    }

    /* Hide the desktop footer on mobile to save space */
    .footer {
        display: none;
    }

    /* ─── Header ─── */
    .header {
        padding: 10px 12px;
        /* Slightly taller tap targets */
    }

    .header h1 {
        font-size: 1rem;
    }

    /* On mobile, hide the sidebar toggle (we have bottom nav instead) */
    #sidebarToggleBtn {
        display: none;
    }

    /* Hide the desktop "New" button on mobile (FAB replaces it) */
    #newNoteBtn {
        display: none;
    }

    .header-right {
        gap: 6px;
    }

    /* Ensure icon buttons have a 44px touch target */
    .btn-icon {
        width: 44px;
        height: 44px;
    }

    .btn-icon svg {
        width: 20px;
        height: 20px;
    }

    /* ─── Mobile Panel System ─── */
    /* All panels are hidden by default; JS adds .mobile-active to show one */
    .main-container {
        flex-direction: column;
        position: relative;
        flex: 1;
        overflow: hidden;
    }

    .sidebar {
        position: absolute;
        /* Leave room for the fixed bottom nav bar */
        inset: 0 0 calc(60px + env(safe-area-inset-bottom)) 0;
        width: 100%;
        height: auto;
        border: none;
        z-index: 1;
        display: none !important; /* Hidden by default; shown via .mobile-active */
        overflow: hidden;
        flex-direction: column;
    }

    .sidebar.mobile-active {
        display: flex !important;
    }

    .content {
        position: absolute;
        /* Leave room for the fixed bottom nav bar */
        inset: 0 0 calc(60px + env(safe-area-inset-bottom)) 0;
        overflow: hidden;
    }

    .editor-section {
        position: absolute;
        inset: 0;
        border: none;
        display: none !important;
        flex-direction: column;
    }

    .editor-section.mobile-active {
        display: flex !important;
    }

    .preview-section {
        position: absolute;
        inset: 0;
        border: none;
        display: none !important;
        flex-direction: column;
    }

    .preview-section.mobile-active {
        display: flex !important;
    }

    /* ─── Toolbar: scrollable strip instead of hidden ─── */
    .toolbar {
        display: flex;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        gap: 2px;
        padding-right: 4px;
    }

    .toolbar::-webkit-scrollbar {
        display: none;
    }

    .toolbar-btn {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }

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

    .section-header {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 8px 12px;
    }

    .editor-info {
        flex-shrink: 0;
    }

    /* ─── Sidebar: better mobile layout ─── */
    .sidebar-header {
        padding: 12px;
    }

    .search-box {
        margin-bottom: 6px;
    }

    .notes-list {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Make note items touch-friendly */
    .note-item {
        padding: 14px 48px 14px 12px;
        min-height: 64px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* Always show delete button on mobile (no hover on touch) */
    .note-item .delete-note {
        opacity: 1;
        width: 36px;
        height: 36px;
        right: 6px;
    }

    /* ─── Editor ─── */
    .editor {
        font-size: 1rem; /* Prevent iOS zoom on focus (needs >= 16px) */
        padding: 14px;
        -webkit-overflow-scrolling: touch;
    }

    /* ─── Preview ─── */
    .preview {
        padding: 14px;
        -webkit-overflow-scrolling: touch;
    }

    /* ─── Modal ─── */
    .modal {
        width: 100%;
        max-width: 100%;
        max-height: 92dvh;
        border-radius: var(--radius) var(--radius) 0 0;
        margin-top: auto;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }

    .modal-overlay {
        align-items: flex-end;
    }

    @keyframes slideIn {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    .form-actions {
        flex-wrap: wrap;
    }

    .form-actions .btn {
        flex: 1;
        min-width: 100px;
        justify-content: center;
    }

    /* ─── Bottom Navigation Bar ─── */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(60px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: var(--bg-main);
        border-top: 1px solid var(--border);
        z-index: 200;
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
        backdrop-filter: blur(10px);
    }

    [data-theme="dark"] .mobile-bottom-nav {
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.4);
    }

    .mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        background: transparent;
        border: none;
        cursor: pointer;
        color: var(--text-muted);
        font-size: 0.7rem;
        font-weight: 500;
        font-family: var(--font-sans);
        transition: color var(--transition), background var(--transition);
        padding: 6px 4px;
        /* Tap highlight */
        -webkit-tap-highlight-color: transparent;
        position: relative;
    }

    .mobile-nav-btn svg {
        width: 22px;
        height: 22px;
        transition: transform var(--transition);
    }

    .mobile-nav-btn span {
        line-height: 1;
    }

    .mobile-nav-btn.active {
        color: var(--primary);
    }

    .mobile-nav-btn.active svg {
        transform: translateY(-1px);
    }

    /* Active indicator pill */
    .mobile-nav-btn.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 3px;
        background: var(--primary);
        border-radius: 0 0 4px 4px;
    }

    /* ─── Floating Action Button ─── */
    .mobile-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        bottom: calc(72px + env(safe-area-inset-bottom));
        right: 18px;
        width: 52px;
        height: 52px;
        background: var(--primary);
        color: white;
        border: none;
        border-radius: 50%;
        box-shadow: none;
        cursor: pointer;
        z-index: 199;
        transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-fab svg {
        width: 24px;
        height: 24px;
    }

    .mobile-fab:active {
        transform: scale(0.92);
        box-shadow: none;
    }

    /* Hide FAB when not on Notes panel (it doesn't make sense elsewhere) */
    .mobile-fab.hidden-fab {
        opacity: 0;
        pointer-events: none;
        transform: scale(0.8);
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.saving {
    animation: pulse 1s infinite;
}