/* CSS Variables for theming */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f7fa;
    --bg-tertiary: #e8ecf1;
    --text-primary: #2c3e50;
    --text-secondary: #546e7a;
    --border-color: #d1d9e0;
    --accent-color: #3498db;
    --accent-hover: #2980b9;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --header-bg: #2c3e50;
    --header-gradient-end: #34495e;
    --header-text: #ffffff;
    --header-text-accent: #e8f4f8;
    --shadow: rgba(0, 0, 0, 0.1);
    --code-bg: #f8f9fa;
}

/* Dark mode variables */
body.dark-mode {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d30;
    --text-primary: #d4d4d4;
    --text-secondary: #969696;
    --border-color: #3e3e42;
    --accent-color: #4fc3f7;
    --accent-hover: #29b6f6;
    --success-color: #66bb6a;
    --danger-color: #ef5350;
    --header-bg: #1a1a1a;
    --header-gradient-end: #2d2d30;
    --header-text: #ffffff;
    --header-text-accent: #4fc3f7;
    --shadow: rgba(0, 0, 0, 0.3);
    --code-bg: #2d2d30;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Container */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--header-bg) 0%, var(--header-gradient-end, var(--header-bg)) 100%);
    color: var(--header-text);
    padding: 1.5rem 2rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 10;
    position: relative;
    overflow: visible;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.03) 50%, 
        transparent 100%);
    pointer-events: none;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 1;
}

.header-title {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    animation: fadeInUp 0.6s ease-out;
}

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

.logo {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--header-text);
    transition: transform 0.2s ease;
}

.logo:hover {
    transform: scale(1.02);
}

.header-description {
    font-size: 0.9rem;
    color: var(--header-text);
    margin: 0;
    opacity: 0.85;
    font-weight: 400;
    letter-spacing: 0.3px;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    animation: fadeInUp 0.6s ease-out 0.1s both;
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
    .header-title,
    .header-actions {
        animation: none;
    }
    
    .logo:hover {
        transform: none;
    }
}

/* Toolbar */
.toolbar {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    min-height: 60px;
}

.toolbar-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar-group:nth-child(1) {
    justify-self: start;
}

.toolbar-group:nth-child(2) {
    justify-self: center;
}

.toolbar-group:nth-child(3) {
    justify-self: end;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.btn .icon {
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
}

.btn:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-secondary {
    background-color: var(--danger-color);
}

.btn-secondary:hover {
    background-color: #c0392b;
}

.btn-icon {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    background-color: white;
    color: var(--text-primary);
    border: 1.5px solid var(--border-color);
    font-weight: 500;
    border-radius: 6px;
    min-width: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    white-space: nowrap;
}

.btn-icon .icon {
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
}

body.dark-mode .btn-icon {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-icon:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.btn-icon:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-icon:disabled {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    border-color: var(--border-color);
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#undoBtn,
#redoBtn {
    min-width: 96px;
    justify-content: center;
}

/* Main content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Panes */
.editor-pane,
.preview-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-primary);
}

.editor-pane {
    flex: 1;
    min-width: 300px;
}

.preview-pane {
    flex: 1;
    min-width: 300px;
    border-left: 1px solid var(--border-color);
}

.pane-header {
    padding: 0.75rem 1.5rem;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pane-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.pane-header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.btn-icon-small {
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.btn-icon-small:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* Editor textarea */
.editor-textarea {
    flex: 1;
    padding: 1.5rem;
    border: none;
    outline: none;
    resize: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow-y: auto;
}

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

/* Preview content */
.preview-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background-color: var(--bg-primary);
}

/* Markdown styling in preview */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
}

.preview-content h1 {
    font-size: 2rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.preview-content h2 {
    font-size: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.preview-content h3 { font-size: 1.25rem; }
.preview-content h4 { font-size: 1rem; }
.preview-content h5 { font-size: 0.875rem; }
.preview-content h6 { font-size: 0.75rem; }

.preview-content p {
    margin-bottom: 1rem;
    line-height: 1.7;
}

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

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

.preview-content ul,
.preview-content ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

.preview-content li {
    margin-bottom: 0.5rem;
    line-height: 1.7;
}

.preview-content code {
    background-color: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875em;
    color: var(--text-primary);
}

.preview-content pre {
    background-color: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.preview-content pre code {
    background-color: transparent;
    padding: 0;
    font-size: 0.875rem;
}

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

.preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.preview-content table th,
.preview-content table td {
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    text-align: left;
}

.preview-content table th {
    background-color: var(--bg-secondary);
    font-weight: 600;
}

.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.preview-content hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 2rem 0;
}

/* Task lists */
.preview-content input[type="checkbox"] {
    margin-right: 0.5rem;
}

/* Resizer */
.resizer {
    width: 4px;
    background-color: var(--border-color);
    cursor: col-resize;
    transition: background-color 0.2s;
}

.resizer:hover {
    background-color: var(--accent-color);
}

/* Footer */
.footer {
    padding: 1rem 1.5rem;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-left,
.footer-center,
.footer-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.footer-center {
    flex: 1;
    justify-content: center;
}

.stats-display {
    font-weight: 500;
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
}

.footer a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.footer-separator {
    color: var(--border-color);
    margin: 0 0.25rem;
}

.keyboard-hint {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-hover) 100%);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    color: #ffffff;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
    transition: all 0.3s ease;
}

.keyboard-hint:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

.keyboard-hint kbd {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-weight: 600;
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body.dark-mode .keyboard-hint {
    background: linear-gradient(135deg, #4fc3f7 0%, #29b6f6 100%);
    box-shadow: 0 2px 8px rgba(79, 195, 247, 0.3);
}

body.dark-mode .keyboard-hint:hover {
    box-shadow: 0 4px 12px rgba(79, 195, 247, 0.5);
}

/* Fullscreen mode */
.container.editor-fullscreen .editor-pane,
.container.preview-fullscreen .preview-pane {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    z-index: 1000;
    flex: none !important;
    padding-top: 0;
}

.container.editor-fullscreen .header,
.container.editor-fullscreen .toolbar,
.container.editor-fullscreen .rich-text-toolbar-wrapper,
.container.editor-fullscreen .preview-pane,
.container.editor-fullscreen .resizer,
.container.editor-fullscreen .footer {
    display: none;
}

.container.preview-fullscreen .header,
.container.preview-fullscreen .toolbar,
.container.preview-fullscreen .rich-text-toolbar-wrapper,
.container.preview-fullscreen .editor-pane,
.container.preview-fullscreen .resizer,
.container.preview-fullscreen .footer {
    display: none;
}

/* Show toolbars in editor fullscreen mode */
.container.editor-fullscreen .toolbar,
.container.editor-fullscreen .rich-text-toolbar-wrapper {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    overflow-x: auto;
    overflow-y: hidden;
}

.container.editor-fullscreen .rich-text-toolbar-wrapper {
    top: 60px; /* Below main toolbar */
}

.container.editor-fullscreen .editor-pane {
    padding-top: 180px; /* Space for both toolbars + header */
}

.container.editor-fullscreen .editor-pane .pane-header {
    position: fixed;
    top: 120px;
    left: 0;
    right: 0;
    z-index: 1001;
}

.container.editor-fullscreen .editor-textarea,
.container.editor-fullscreen .rich-text-editor {
    height: calc(100vh - 180px) !important;
    padding-top: 0;
}

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

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

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

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

/* Responsive design */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .preview-pane {
        border-left: none;
        border-top: 1px solid var(--border-color);
    }

    .resizer {
        display: none;
    }

    .toolbar {
        padding: 0.5rem 1rem;
    }

    .toolbar-group {
        flex-wrap: wrap;
    }

    .btn {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    .header {
        padding: 1rem 1.5rem;
    }

    .logo {
        font-size: 1.25rem;
    }

    .header-description {
        font-size: 0.75rem;
    }

    .header-actions {
        gap: 0.5rem;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }

    .footer-left,
    .footer-center,
    .footer-right {
        justify-content: center;
        font-size: 0.75rem;
    }

    .stats-display {
        font-size: 0.75rem;
        padding: 0.4rem 0.8rem;
    }

    .keyboard-hint {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.preview-content {
    animation: fadeIn 0.3s ease;
}

/* ===== Rich Text Editor Styles ===== */

/* Rich text editor container */
.rich-text-editor {
    width: 100%;
    height: 100%;
    padding: 1.5rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    overflow-y: auto;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    outline: none;
    cursor: text;
}

.rich-text-editor:focus {
    border-color: var(--accent-color);
}

/* Rich text toolbar */
.rich-text-toolbar-wrapper {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
}

.rich-text-toolbar-content {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar-section {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: nowrap;
}

.toolbar-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 0.25rem;
    white-space: nowrap;
}

.btn-select {
    padding: 0.5rem 1rem;
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    background: white;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 120px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

body.dark-mode .btn-select {
    background: var(--bg-tertiary);
}

.btn-select:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.btn-select:focus {
    outline: none;
    border-color: var(--accent-color);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.divider {
    width: 2px;
    height: 24px;
    background: var(--border-color);
    margin: 0 0.25rem;
    border-radius: 1px;
}

/* Rich text editor content styling */
.rich-text-editor h1,
.rich-text-editor h2,
.rich-text-editor h3,
.rich-text-editor h4,
.rich-text-editor h5,
.rich-text-editor h6 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

.rich-text-editor h1 { font-size: 2.5rem; }
.rich-text-editor h2 { font-size: 2rem; }
.rich-text-editor h3 { font-size: 1.75rem; }
.rich-text-editor h4 { font-size: 1.5rem; }
.rich-text-editor h5 { font-size: 1.25rem; }
.rich-text-editor h6 { font-size: 1rem; }

.rich-text-editor p {
    margin: 0.75rem 0;
}

.rich-text-editor ul,
.rich-text-editor ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

.rich-text-editor li {
    margin: 0.5rem 0;
}

.rich-text-editor blockquote {
    margin: 1rem 0;
    padding: 0.75rem 1.5rem;
    border-left: 4px solid var(--accent-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.rich-text-editor table {
    border-collapse: collapse;
    width: 100%;
    margin: 1rem 0;
}

.rich-text-editor table td,
.rich-text-editor table th {
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    text-align: left;
}

.rich-text-editor table th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.rich-text-editor table tr:hover {
    background: var(--bg-secondary);
}

.rich-text-editor img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1rem 0;
    display: block;
}

.rich-text-editor a {
    color: var(--accent-color);
    text-decoration: underline;
}

.rich-text-editor a:hover {
    color: var(--accent-hover);
}

.rich-text-editor code {
    background: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 0.9em;
    color: var(--text-primary);
}

.rich-text-editor pre {
    background: var(--code-bg);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid var(--border-color);
}

.rich-text-editor pre code {
    background: transparent;
    padding: 0;
}

.rich-text-editor hr {
    margin: 2rem 0;
    border: none;
    border-top: 2px solid var(--border-color);
}

/* Task list checkboxes */
.rich-text-editor input[type="checkbox"] {
    margin-right: 0.5rem;
    cursor: pointer;
}

/* Placeholder for empty editor */
.rich-text-editor:empty:before {
    content: 'Start typing your document here...';
    color: var(--text-secondary);
    pointer-events: none;
}

/* Selection styling in rich text editor */
.rich-text-editor ::selection {
    background: var(--accent-color);
    color: white;
}

/* ===== Find & Replace Dialog ===== */
.find-replace-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 10vh;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.find-replace-dialog.visible {
    opacity: 1;
    visibility: visible;
}

.find-replace-content {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 500px;
    margin: 0 1rem;
    animation: slideDown 0.2s ease;
    border: 1px solid var(--border-color);
}

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

.find-replace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 12px 12px 0 0;
}

.find-replace-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.find-replace-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.find-replace-close:hover {
    background: var(--danger-color);
    color: white;
}

.find-replace-body {
    padding: 1.25rem;
}

.find-replace-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.find-replace-label {
    min-width: 60px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.find-replace-input {
    flex: 1;
    padding: 0.625rem 0.875rem;
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.find-replace-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.find-replace-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.match-count {
    min-width: 80px;
    text-align: right;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 0.375rem 0.625rem;
    border-radius: 4px;
}

.match-count.error {
    color: var(--danger-color);
    background: rgba(231, 76, 60, 0.1);
}

.find-replace-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.find-replace-option {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.find-replace-option input[type="checkbox"] {
    accent-color: var(--accent-color);
    cursor: pointer;
}

.find-replace-option:hover {
    color: var(--text-primary);
}

.find-replace-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.find-replace-actions .btn {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
}

.find-replace-actions .btn-icon {
    background: var(--bg-tertiary);
}

body.dark-mode .find-replace-actions .btn-icon {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

/* Keyboard shortcut hints in footer */
.find-replace-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 0 0 12px 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.find-replace-footer kbd {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 0.125rem 0.375rem;
    font-family: 'SF Mono', 'Monaco', monospace;
    font-size: 0.6875rem;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .find-replace-content {
        margin: 0 0.5rem;
    }
    
    .find-replace-row {
        flex-wrap: wrap;
    }
    
    .find-replace-label {
        min-width: 100%;
        margin-bottom: 0.25rem;
    }
    
    .match-count {
        min-width: auto;
        margin-left: auto;
    }
    
    .find-replace-actions {
        justify-content: stretch;
    }
    
    .find-replace-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

/* ===== Custom Themes ===== */

/* Theme: Ocean */
body.theme-ocean {
    --bg-primary: #0a1628;
    --bg-secondary: #0d1d31;
    --bg-tertiary: #132640;
    --text-primary: #e0f0ff;
    --text-secondary: #8badc9;
    --border-color: #1e3a5f;
    --accent-color: #00b4d8;
    --accent-hover: #0096c7;
    --success-color: #00d9a5;
    --danger-color: #ff6b6b;
    --header-bg: #023e8a;
    --header-gradient-end: #0077b6;
    --header-text: #e0f0ff;
    --header-text-accent: #90e0ef;
    --shadow: rgba(0, 0, 0, 0.4);
    --code-bg: #132640;
}

/* Theme: Forest */
body.theme-forest {
    --bg-primary: #1a1f16;
    --bg-secondary: #232b1c;
    --bg-tertiary: #2d3825;
    --text-primary: #e8f0dc;
    --text-secondary: #a3b590;
    --border-color: #3d4a32;
    --accent-color: #7cb342;
    --accent-hover: #689f38;
    --success-color: #81c784;
    --danger-color: #ef5350;
    --header-bg: #33691e;
    --header-gradient-end: #558b2f;
    --header-text: #e8f0dc;
    --header-text-accent: #c5e1a5;
    --shadow: rgba(0, 0, 0, 0.4);
    --code-bg: #2d3825;
}

/* Theme: Sunset */
body.theme-sunset {
    --bg-primary: #1f1a1a;
    --bg-secondary: #2a2020;
    --bg-tertiary: #382828;
    --text-primary: #ffeedd;
    --text-secondary: #c9a89a;
    --border-color: #4a3535;
    --accent-color: #ff7043;
    --accent-hover: #f4511e;
    --success-color: #ffb74d;
    --danger-color: #ef5350;
    --header-bg: #e64a19;
    --header-gradient-end: #ff7043;
    --header-text: #ffeedd;
    --header-text-accent: #ffccbc;
    --shadow: rgba(0, 0, 0, 0.4);
    --code-bg: #382828;
}

/* Theme: Lavender */
body.theme-lavender {
    --bg-primary: #1c1a26;
    --bg-secondary: #252331;
    --bg-tertiary: #302d3d;
    --text-primary: #f0e6ff;
    --text-secondary: #b8a8d4;
    --border-color: #433d55;
    --accent-color: #b388ff;
    --accent-hover: #9c64ff;
    --success-color: #69f0ae;
    --danger-color: #ff8a80;
    --header-bg: #6a1b9a;
    --header-gradient-end: #8e24aa;
    --header-text: #f0e6ff;
    --header-text-accent: #e1bee7;
    --shadow: rgba(0, 0, 0, 0.4);
    --code-bg: #302d3d;
}

/* Theme: Light Rose */
body.theme-rose {
    --bg-primary: #fff5f5;
    --bg-secondary: #ffe4e4;
    --bg-tertiary: #ffd6d6;
    --text-primary: #4a2c2c;
    --text-secondary: #7d5a5a;
    --border-color: #e8b4b4;
    --accent-color: #e91e63;
    --accent-hover: #c2185b;
    --success-color: #4caf50;
    --danger-color: #f44336;
    --header-bg: #c2185b;
    --header-gradient-end: #e91e63;
    --header-text: #ffffff;
    --header-text-accent: #fce4ec;
    --shadow: rgba(0, 0, 0, 0.1);
    --code-bg: #ffd6d6;
}

/* Theme: Light Mint */
body.theme-mint {
    --bg-primary: #f0fdf4;
    --bg-secondary: #dcfce7;
    --bg-tertiary: #bbf7d0;
    --text-primary: #1a3d2e;
    --text-secondary: #4a6d5a;
    --border-color: #86efac;
    --accent-color: #10b981;
    --accent-hover: #059669;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --header-bg: #047857;
    --header-gradient-end: #10b981;
    --header-text: #ffffff;
    --header-text-accent: #d1fae5;
    --shadow: rgba(0, 0, 0, 0.1);
    --code-bg: #bbf7d0;
}

/* Theme Picker Dropdown */
.theme-picker {
    position: relative;
}

.theme-picker-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: transparent;
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    color: var(--header-text);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.theme-picker-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-color);
}

.theme-picker-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

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

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    text-align: left;
    transition: background 0.15s ease;
}

.theme-option:first-child {
    border-radius: 8px 8px 0 0;
}

.theme-option:last-child {
    border-radius: 0 0 8px 8px;
}

.theme-option:hover {
    background: var(--bg-secondary);
}

.theme-option.active {
    background: var(--accent-color);
    color: white;
}

.theme-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    flex-shrink: 0;
}

.theme-swatch-light { background: linear-gradient(135deg, #ffffff 50%, #f5f7fa 50%); }
.theme-swatch-dark { background: linear-gradient(135deg, #1e1e1e 50%, #252526 50%); }
.theme-swatch-ocean { background: linear-gradient(135deg, #00b4d8 50%, #0a1628 50%); }
.theme-swatch-forest { background: linear-gradient(135deg, #7cb342 50%, #1a1f16 50%); }
.theme-swatch-sunset { background: linear-gradient(135deg, #ff7043 50%, #1f1a1a 50%); }
.theme-swatch-lavender { background: linear-gradient(135deg, #b388ff 50%, #1c1a26 50%); }
.theme-swatch-rose { background: linear-gradient(135deg, #e91e63 50%, #fff5f5 50%); }
.theme-swatch-mint { background: linear-gradient(135deg, #10b981 50%, #f0fdf4 50%); }

/* ===== Markdown Syntax Highlighting ===== */

.syntax-highlight-container {
    position: relative;
    flex: 1;
    overflow: hidden;
    display: flex;
}

.syntax-highlight-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    pointer-events: none;
    z-index: 1;
}

.syntax-highlight-layer {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    padding: 1.5rem;
    color: var(--text-primary);
    min-height: 100%;
}

.syntax-highlight-textarea {
    position: relative;
    z-index: 2;
    background: transparent !important;
    color: transparent !important;
    caret-color: var(--text-primary);
    resize: none;
}

.syntax-highlight-textarea::selection {
    background: var(--accent-color);
    color: transparent;
}

/* Syntax highlighting colors */
:root {
    --sh-header: #e91e63;
    --sh-header-marker: #c2185b;
    --sh-bold: #ff5722;
    --sh-italic: #9c27b0;
    --sh-strikethrough: #757575;
    --sh-code: #00bcd4;
    --sh-code-bg: rgba(0, 188, 212, 0.1);
    --sh-link: #2196f3;
    --sh-link-url: #4caf50;
    --sh-image: #ff9800;
    --sh-blockquote: #607d8b;
    --sh-list-marker: #3f51b5;
    --sh-table: #795548;
    --sh-hr: #9e9e9e;
    --sh-marker: #9e9e9e;
}

body.dark-mode {
    --sh-header: #ff80ab;
    --sh-header-marker: #f48fb1;
    --sh-bold: #ffab91;
    --sh-italic: #ce93d8;
    --sh-strikethrough: #9e9e9e;
    --sh-code: #80deea;
    --sh-code-bg: rgba(128, 222, 234, 0.15);
    --sh-link: #90caf9;
    --sh-link-url: #a5d6a7;
    --sh-image: #ffcc80;
    --sh-blockquote: #b0bec5;
    --sh-list-marker: #9fa8da;
    --sh-table: #bcaaa4;
    --sh-hr: #757575;
    --sh-marker: #757575;
}

/* Theme-specific syntax colors */
body.theme-ocean {
    --sh-header: #00d9ff;
    --sh-header-marker: #00b4d8;
    --sh-bold: #ff6b9d;
    --sh-italic: #00d9a5;
    --sh-code: #ffd93d;
    --sh-code-bg: rgba(255, 217, 61, 0.1);
    --sh-link: #4ecdc4;
    --sh-link-url: #95e1d3;
    --sh-list-marker: #ff8a5c;
}

body.theme-forest {
    --sh-header: #aed581;
    --sh-header-marker: #7cb342;
    --sh-bold: #ffb74d;
    --sh-italic: #81c784;
    --sh-code: #4dd0e1;
    --sh-code-bg: rgba(77, 208, 225, 0.1);
    --sh-link: #64b5f6;
    --sh-link-url: #a5d6a7;
    --sh-list-marker: #ffcc80;
}

body.theme-sunset {
    --sh-header: #ff8a65;
    --sh-header-marker: #ff7043;
    --sh-bold: #ffd54f;
    --sh-italic: #ffab91;
    --sh-code: #4dd0e1;
    --sh-code-bg: rgba(77, 208, 225, 0.1);
    --sh-link: #4fc3f7;
    --sh-link-url: #81c784;
    --sh-list-marker: #ffcc80;
}

body.theme-lavender {
    --sh-header: #ea80fc;
    --sh-header-marker: #b388ff;
    --sh-bold: #ff80ab;
    --sh-italic: #82b1ff;
    --sh-code: #84ffff;
    --sh-code-bg: rgba(132, 255, 255, 0.1);
    --sh-link: #80d8ff;
    --sh-link-url: #b9f6ca;
    --sh-list-marker: #ffab91;
}

body.theme-rose {
    --sh-header: #e91e63;
    --sh-header-marker: #c2185b;
    --sh-bold: #d32f2f;
    --sh-italic: #7b1fa2;
    --sh-code: #0097a7;
    --sh-code-bg: rgba(0, 151, 167, 0.1);
    --sh-link: #1976d2;
    --sh-link-url: #388e3c;
    --sh-list-marker: #e64a19;
}

body.theme-mint {
    --sh-header: #10b981;
    --sh-header-marker: #059669;
    --sh-bold: #f59e0b;
    --sh-italic: #14b8a6;
    --sh-code: #0891b2;
    --sh-code-bg: rgba(8, 145, 178, 0.1);
    --sh-link: #3b82f6;
    --sh-link-url: #22c55e;
    --sh-list-marker: #f97316;
}

/* Header styles */
.sh-header {
    font-weight: bold;
}

.sh-h1 { color: var(--sh-header); font-size: 1.1em; }
.sh-h2 { color: var(--sh-header); font-size: 1.05em; }
.sh-h3 { color: var(--sh-header); }
.sh-h4, .sh-h5, .sh-h6 { color: var(--sh-header); opacity: 0.85; }

.sh-header-marker {
    color: var(--sh-header-marker);
    opacity: 0.7;
}

.sh-header-text {
    color: var(--sh-header);
}

/* Bold and italic */
.sh-bold .sh-bold-text {
    color: var(--sh-bold);
    font-weight: bold;
}

.sh-italic .sh-italic-text {
    color: var(--sh-italic);
    font-style: italic;
}

.sh-strikethrough .sh-strike-text {
    color: var(--sh-strikethrough);
    text-decoration: line-through;
}

.sh-marker {
    color: var(--sh-marker);
    opacity: 0.6;
}

/* Code */
.sh-inline-code {
    background: var(--sh-code-bg);
    border-radius: 3px;
    padding: 0 2px;
}

.sh-code-marker {
    color: var(--sh-marker);
}

.sh-code-text {
    color: var(--sh-code);
}

.sh-code-fence {
    color: var(--sh-marker);
}

.sh-code-lang {
    color: var(--sh-code);
    font-style: italic;
}

.sh-code-content {
    color: var(--sh-code);
    opacity: 0.9;
}

/* Links and images */
.sh-link-bracket,
.sh-link-paren {
    color: var(--sh-marker);
}

.sh-link-text {
    color: var(--sh-link);
}

.sh-link-url {
    color: var(--sh-link-url);
    opacity: 0.8;
}

.sh-image-marker {
    color: var(--sh-image);
}

.sh-image-alt {
    color: var(--sh-image);
    opacity: 0.8;
}

.sh-image-url {
    color: var(--sh-link-url);
    opacity: 0.7;
}

/* Blockquotes */
.sh-blockquote {
    color: var(--sh-blockquote);
    font-style: italic;
}

.sh-blockquote-marker {
    color: var(--sh-blockquote);
    font-weight: bold;
}

/* Lists */
.sh-list-marker {
    color: var(--sh-list-marker);
    font-weight: bold;
}

.sh-task-checkbox {
    color: var(--sh-list-marker);
}

.sh-task-checkbox.sh-checked {
    color: var(--success-color);
}

/* Tables */
.sh-table-pipe {
    color: var(--sh-table);
    font-weight: bold;
}

.sh-table-separator {
    color: var(--sh-table);
    opacity: 0.7;
}

/* Horizontal rule */
.sh-hr {
    color: var(--sh-hr);
}


/* ===== Statistics Panel ===== */

.stats-clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.stats-clickable:hover {
    background: var(--accent-color) !important;
    color: white !important;
    transform: scale(1.02);
}

.stats-clickable.active {
    background: var(--accent-color) !important;
    color: white !important;
}

.statistics-panel {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 400px;
    max-width: calc(100vw - 2rem);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.statistics-panel.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.stats-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 12px 12px 0 0;
}

.stats-panel-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stats-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.stats-close-btn:hover {
    background: var(--danger-color);
    color: white;
}

.stats-panel-content {
    padding: 1.25rem;
    max-height: 60vh;
    overflow-y: auto;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.stats-time {
    grid-template-columns: repeat(2, 1fr);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    transition: transform 0.2s ease;
}

.stat-item:hover {
    transform: translateY(-2px);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.25rem;
    text-align: center;
}

.stats-divider {
    height: 1px;
    background: var(--border-color);
    margin: 1rem 0;
}

.reading-level h4,
.stats-breakdown h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 0.75rem 0;
}

.reading-level-content {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 8px;
}

.level-meter {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.level-fill {
    height: 100%;
    background: var(--success-color);
    border-radius: 4px;
    transition: width 0.5s ease, background 0.3s ease;
}

.level-indicator {
    position: absolute;
    top: -4px;
    width: 16px;
    height: 16px;
    background: var(--bg-primary);
    border: 2px solid var(--accent-color);
    border-radius: 50%;
    transform: translateX(-50%);
    transition: left 0.5s ease;
}

.level-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.level-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

#readingLevelText {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.flesch-score {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.breakdown-items {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 0.8rem;
}

.breakdown-label {
    color: var(--text-secondary);
}

.breakdown-value {
    font-weight: 600;
    color: var(--accent-color);
}

/* Responsive */
@media (max-width: 480px) {
    .statistics-panel {
        width: calc(100vw - 1rem);
        bottom: 60px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .breakdown-items {
        grid-template-columns: 1fr;
    }
}

/* ===== Templates Modal ===== */

.templates-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.templates-modal.visible {
    opacity: 1;
    visibility: visible;
}

.templates-content {
    background: var(--bg-primary);
    border-radius: 16px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
}

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

.templates-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 16px 16px 0 0;
}

.templates-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.templates-close-btn {
    background: none;
    border: none;
    font-size: 1.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.templates-close-btn:hover {
    background: var(--danger-color);
    color: white;
}

.templates-search {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.templates-search input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9375rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.templates-search input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.templates-search input::placeholder {
    color: var(--text-secondary);
}

.templates-categories {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    flex-wrap: nowrap;
}

.category-btn {
    padding: 0.5rem 1rem;
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.category-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.category-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.template-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.25rem;
    background: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.template-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.template-card:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.template-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.template-info h3 {
    margin: 0 0 0.25rem 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.template-category {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
}

.no-templates {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.templates-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 0 0 16px 16px;
    text-align: center;
}

.templates-footer p {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 600px) {
    .templates-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .templates-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        padding: 1rem;
    }
    
    .template-card {
        padding: 1rem;
    }
    
    .template-icon {
        font-size: 2rem;
    }
}

/* ===== PWA Update ===== */

.update-notification {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-color);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 3000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.update-notification button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s ease;
}

.update-notification button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.update-notification button:last-child {
    padding: 0.25rem 0.5rem;
    font-size: 1.25rem;
    line-height: 1;
}

/* Offline indicator */
body.offline::before {
    content: '⚠️ Offline Mode';
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger-color);
    color: white;
    padding: 0.25rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    z-index: 3000;
}

