/*
 * Project Notes - Material Darker Theme
 * Inspired by Material Design with dark palette
 */

:root {
    /* Colors - Material Darker Theme */
    --bg-primary: #212121;
    --bg-secondary: #292929;
    --bg-tertiary: #303030;
    --bg-elevated: #2a2a2a;

    --border-primary: #3a3a3a;
    --border-secondary: #2d2d2d;

    --text-primary: #eeffff;
    --text-secondary: #89ddff;
    --text-muted: #4a4a4a;

    --accent-blue: #82aaff;
    --accent-violet: #c792ea;
    --accent-blue-hover: #a3c5ff;
    --accent-violet-hover: #d8b2f4;

    --success: #c3e88d;
    --warning: #ffcb6b;
    --error: #f07178;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.2);
    --shadow-glow: 0 0 20px rgba(88, 166, 255, 0.2);

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Base styles */
html {
    font-size: 16px;
    background: var(--bg-primary);
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    line-height: 1.6;
}

/* Header */
header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    padding: var(--spacing-md) var(--spacing-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Search input */
input[type="search"] {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

input[type="search"]:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
    background: var(--bg-elevated);
}

input[type="search"]::placeholder {
    color: var(--text-muted);
}

/* Main layout */
.main-layout {
    position: relative;
    height: calc(100vh - 65px);
    overflow-x: hidden;
}

/* Sidebar */
aside {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(0);
    transition: transform 0.25s ease;
    z-index: 10;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    padding: var(--spacing-lg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

aside::-webkit-scrollbar {
    width: 8px;
}

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

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

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

aside h2 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 0 0 var(--spacing-sm) 0;
}

aside hr {
    border: none;
    border-top: 1px solid var(--border-primary);
    margin: 0;
}

/* File tree and search results */
#file-tree a,
#search-results a {
    display: block;
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-size: 0.9rem;
    margin-bottom: var(--spacing-xs);
}

#file-tree a:hover,
#search-results a:hover {
    background: var(--bg-tertiary);
    color: var(--accent-blue);
    transform: translateX(2px);
}

/* Search results header */
.search-results-header {
    padding: var(--spacing-sm) 0;
    margin-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-secondary);
}

.search-results-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Search results list */
.search-results-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.search-result-item {
    margin: 0;
}

.search-result-link {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    text-decoration: none;
    color: var(--text-primary);
    transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-result-link:hover {
    transform: translateY(-1px);
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-sm);
}

.search-result-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
    opacity: 0.7;
    line-height: 1;
}

.search-result-content {
    flex: 1;
    min-width: 0;
}

.search-result-header {
    margin-bottom: var(--spacing-xs);
}

.search-result-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.search-result-path {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    margin-bottom: var(--spacing-xs);
}

.search-result-snippet {
    margin: var(--spacing-xs) 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.search-result-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
    flex-wrap: wrap;
}

.search-result-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
}

.search-result-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.tag-pill {
    background: rgba(130, 170, 255, 0.15);
    color: var(--accent-blue);
    border: 1px solid rgba(130, 170, 255, 0.3);
    border-radius: 999px;
    padding: 0 var(--spacing-sm);
    font-size: 0.7rem;
    line-height: 1.6;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-weight: 500;
}

/* No results message */
.search-no-results {
    text-align: center;
    padding: var(--spacing-xl) var(--spacing-md);
    color: var(--text-secondary);
}

.search-no-results-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.search-no-results-text {
    font-size: 0.95rem;
    margin-bottom: var(--spacing-sm);
}

.search-no-results-text strong {
    color: var(--accent-violet);
}

.search-no-results-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Search help */
.search-help {
    padding: var(--spacing-md);
}

.search-help-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--accent-blue);
    margin-bottom: var(--spacing-xs);
}

.search-help-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
}

.search-help-examples {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.search-help-example {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-secondary);
}

.search-help-example code {
    background: var(--bg-primary);
    color: var(--accent-violet);
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-weight: 500;
    min-width: 110px;
}

.search-help-example span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Main content */
main {
    margin-left: 280px;
    transition: margin-left 0.25s ease;
    background: var(--bg-primary);
    padding: var(--spacing-xl);
    overflow-y: auto;
    height: 100%;
}

main::-webkit-scrollbar {
    width: 10px;
}

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

main::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 5px;
}

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

/* Editor */
.editor-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-header label {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.toggle-preview-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.toggle-preview-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--spacing-lg);
    min-height: 70vh;
    transition: grid-template-columns var(--transition-normal);
}

/* Mode: Éditeur seul */
.editor-grid.preview-hidden {
    grid-template-columns: 1fr;
}

.editor-grid.preview-hidden #preview {
    display: none !important;
}

/* Mode: Preview seule */
.editor-grid.editor-hidden {
    grid-template-columns: 1fr;
}

.editor-grid.editor-hidden .editor-panel {
    display: none !important;
}

/* Mode: Split (défaut) */
.editor-grid.split-view {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.editor-grid.split-view .editor-panel,
.editor-grid.split-view #preview {
    display: block !important;
}

.editor-panel {
    position: relative;
}

#editor {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    padding: var(--spacing-md);
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', 'Monaco', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    min-height: 75vh;
    width: 100%;
    resize: vertical;
    transition: border-color var(--transition-fast);
}

#editor:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

/* CodeMirror integration */
.CodeMirror {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', 'Monaco', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    height: calc(100vh - 180px);
    transition: border-color var(--transition-fast);
}

/* Cacher le textarea original quand CodeMirror est actif */
.editor-panel textarea#editor {
    display: none !important;
    position: absolute !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    height: 0 !important;
    width: 0 !important;
}

.editor-panel .CodeMirror ~ textarea {
    display: none !important;
    position: absolute !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    height: 0 !important;
    width: 0 !important;
}

.CodeMirror-focused {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.CodeMirror-gutters {
    background: var(--bg-tertiary);
    border-right: 1px solid var(--border-primary);
}

.CodeMirror-linenumber {
    color: var(--text-muted);
}

.CodeMirror-cursor {
    border-left: 2px solid var(--accent-blue);
}

.CodeMirror-selected {
    background: rgba(88, 166, 255, 0.2);
}

.CodeMirror-line::selection,
.CodeMirror-line > span::selection,
.CodeMirror-line > span > span::selection {
    background: rgba(88, 166, 255, 0.2);
}

.editor-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
}

.editor-actions-primary {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
}

.save-status {
    color: var(--text-secondary);
    min-height: 1.25rem;
    display: inline-flex;
    align-items: center;
}

/* Preview */
.preview {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 2rem 3rem;
    overflow-y: auto;
    max-height: calc(100vh - 180px);
    height: calc(100vh - 180px);
}

.markdown-preview {
    min-height: 75vh;
    box-shadow: inset 0 0 0 1px rgba(88, 166, 255, 0.05);
}

.markdown-preview::-webkit-scrollbar {
    width: 8px;
}

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

.preview h1, .preview h2, .preview h3, .preview h4, .preview h5, .preview h6 {
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 0.8em;
    line-height: 1.4;
}

.preview h1 {
    font-size: 2em;
    color: #c792ea;
    border-bottom: 1px solid var(--border-primary);
    padding-bottom: 0.3em;
    margin-bottom: 1em;
}

.preview h2 {
    font-size: 1.5em;
    color: #82aaff;
    margin-bottom: 0.9em;
}

.preview h3 {
    font-size: 1.25em;
    color: #89ddff;
}

.preview h4 {
    font-size: 1.1em;
    color: #c3e88d;
}

.preview h5 {
    font-size: 1em;
    color: #ffcb6b;
}

.preview h6 {
    font-size: 1em;
    color: #f07178;
}

.preview p {
    margin-top: 0;
    margin-bottom: 1em;
    line-height: 1.6;
}

.preview p:last-child {
    margin-bottom: 0;
}

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

.preview li {
    margin-top: 0.3em;
    margin-bottom: 0.3em;
    line-height: 1.5;
}

.preview ul > li::marker {
    color: #c792ea;
}

.preview ol > li::marker {
    color: #82aaff;
    font-weight: 600;
}

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

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

.preview a {
    color: #82aaff;
    text-decoration: none;
    font-weight: 500;
}

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

.preview strong, .preview b {
    color: #ffcb6b;
    font-weight: 600;
}

.preview em, .preview i {
    color: #89ddff;
    font-style: italic;
}

.preview code {
    background: var(--bg-tertiary);
    padding: 0.2em 0.4em;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    color: #f07178;
    font-weight: 500;
}

.preview pre {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    overflow-x: auto;
    margin: 0 0 1em 0;
    line-height: 1.5;
}

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

.preview blockquote {
    border-left: 3px solid var(--accent-blue);
    padding-left: var(--spacing-md);
    margin-left: 0;
    color: var(--text-secondary);
    font-style: italic;
}

.preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.preview table thead {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
}

.preview table thead th {
    color: white;
    font-weight: 600;
    text-align: left;
    padding: var(--spacing-md);
    border: none;
}

.preview table tbody tr {
    border-bottom: 1px solid var(--border-primary);
    transition: background var(--transition-fast);
}

.preview table tbody tr:last-child {
    border-bottom: none;
}

.preview table tbody tr:hover {
    background: var(--bg-secondary);
}

.preview table td {
    padding: var(--spacing-md);
    border: none;
    color: var(--text-primary);
}

.preview table tbody td {
    border-right: 1px solid var(--border-primary);
}

.preview table tbody td:last-child {
    border-right: none;
}

/* Buttons */
button,
[type="submit"],
[type="button"] {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-lg);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

button:hover,
[type="submit"]:hover,
[type="button"]:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

button:active,
[type="submit"]:active,
[type="button"]:active {
    transform: translateY(0);
}

button.secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}

button.secondary:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-sm);
}

/* Slash command palette */
#slash-commands-palette {
    background: var(--bg-secondary);
    border: 1px solid var(--accent-blue);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    padding: var(--spacing-xs);
    min-width: 220px;
    max-height: 320px;
    overflow-y: auto;
}

#slash-commands-palette::-webkit-scrollbar {
    width: 6px;
}

#slash-commands-palette::-webkit-scrollbar-track {
    background: transparent;
}

#slash-commands-palette::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 3px;
}

#slash-commands-palette li {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    color: var(--text-primary);
    transition: all var(--transition-fast);
    border-radius: var(--radius-sm);
    margin: var(--spacing-xs) 0;
    font-size: 0.9rem;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

#slash-commands-palette li::before {
    content: '⌘';
    color: var(--text-muted);
    font-size: 0.85em;
}

#slash-commands-palette li:hover {
    background: var(--bg-tertiary);
    color: var(--accent-blue);
    transform: translateX(2px);
}

#slash-commands-palette li[style*="background-color"] {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet)) !important;
    color: white !important;
    font-weight: 500;
    transform: translateX(2px);
}

#slash-commands-palette li[style*="background-color"]::before {
    color: rgba(255, 255, 255, 0.8);
}

/* Labels */
label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: var(--spacing-sm);
    display: block;
}

/* Progress indicator */
progress {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
}

progress::-webkit-progress-bar {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

progress::-webkit-progress-value {
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-violet));
    border-radius: var(--radius-sm);
}

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

/* Form elements base styles */
input, textarea, select {
    font-family: inherit;
    font-size: inherit;
}

/* Remove default form margins */
form {
    margin: 0;
}

/* Ensure flex containers work properly */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
}

/* Modal styles */
#new-note-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-blue);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    min-width: 350px;
    max-width: 90%;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: slideUp 0.3s ease;
    z-index: 1;
}

.modal-content h2 {
    margin: 0 0 var(--spacing-md) 0;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.modal-content label {
    display: block;
    margin-bottom: var(--spacing-xs);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
}

.modal-content input[type="text"] {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.95rem;
    transition: all var(--transition-fast);
}

.modal-content input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.modal-content p {
    font-size: 0.8rem;
    margin-top: 0.25rem;
    margin-bottom: 0;
}

.modal-content form > div {
    margin-top: 1rem !important;
}

.modal-content button {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.9rem;
}

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

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

/* File tree hierarchical styles */
#file-tree {
    font-size: 0.9rem;
}

.folder-item {
    margin: var(--spacing-xs) 0;
}

.folder-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    user-select: none;
}

.folder-header:hover {
    background: var(--bg-tertiary);
    color: var(--accent-blue);
}

.folder-toggle {
    display: inline-block;
    font-size: 0.7rem;
    transition: transform var(--transition-fast);
    min-width: 12px;
}

.folder-toggle.expanded {
    transform: rotate(90deg);
}

.folder-icon {
    font-size: 1rem;
}

.folder-name {
    flex: 1;
    font-weight: 500;
}

.folder-children {
    padding-left: var(--spacing-lg);
    overflow: hidden;
    transition: all var(--transition-fast);
}

.file-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-size: 0.9rem;
    margin: var(--spacing-xs) 0;
    cursor: pointer;
}

.file-item:hover {
    background: var(--bg-tertiary);
    color: var(--accent-blue);
    transform: translateX(2px);
}

/* Drag and drop styles */
.file-item.dragging {
    opacity: 0.5;
    background: var(--bg-tertiary);
}

.folder-item.drag-over .folder-header {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    color: white;
    box-shadow: var(--shadow-glow);
}

.file-item.drag-over {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    color: white;
    box-shadow: var(--shadow-glow);
}

/* Folder creation button */
.folder-create-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    width: 100%;
    margin-bottom: var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
}

.folder-create-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* Sidebar toggle styles */
.main-layout.sidebar-hidden aside {
    transform: translateX(-100%);
}

.main-layout.sidebar-hidden main {
    margin-left: 0;
}

.auto-save-status {
    margin-left: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Utility class to hide elements */
.hidden {
    display: none !important;
}

/* Bouton de fermeture sidebar - caché par défaut (desktop) */
.sidebar-close-btn {
    display: none;
}

/* ========================================
   STYLES POUR L'ARBORESCENCE DE NOTES
   ======================================== */

.note-tree {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.folder, .file {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.folder-header {
    cursor: pointer;
    user-select: none;
    padding: 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.folder-icon {
    flex-shrink: 0;
}

.folder-content {
    display: block;
}

.file {
    padding: 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.file-icon {
    flex-shrink: 0;
}

.file a {
    color: var(--accent-blue);
    text-decoration: none;
    cursor: pointer;
    word-break: break-word;
    flex: 1;
}

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

/* Indentation levels - Desktop */
.indent-level-1 { padding-left: 0; }
.indent-level-2 { padding-left: 1.5rem; }
.indent-level-3 { padding-left: 3rem; }
.indent-level-4 { padding-left: 4.5rem; }
.indent-level-5 { padding-left: 6rem; }
.indent-level-6 { padding-left: 7.5rem; }
.indent-level-7 { padding-left: 9rem; }
.indent-level-8 { padding-left: 10.5rem; }

/* ========================================
   RESPONSIVE DESIGN - Mobile & Tablet
   ======================================== */

/* Tablettes et petits écrans (max 768px) */
@media screen and (max-width: 768px) {
    /* Empêcher tout débordement horizontal */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    body {
        position: relative;
    }

    /* Tous les éléments doivent respecter la largeur */
    * {
        max-width: 100%;
    }

    /* Header responsive */
    header {
        flex-wrap: wrap;
        padding: 0.75rem;
        gap: 0.5rem;
        width: 100%;
        box-sizing: border-box;
    }

    header h1 {
        font-size: 1.2rem;
        margin: 0;
    }

    header input[type="search"] {
        max-width: 100%;
        flex: 1 1 100%;
        order: 10;
    }

    header button {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }

    /* Main layout en colonne pour mobile */
    .main-layout {
        flex-direction: column;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Sidebar masquée par défaut sur mobile */
    aside {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        overflow-x: hidden;
        box-shadow: var(--shadow-lg);
        background: var(--bg-primary);
    }

    aside.sidebar-visible {
        left: 0;
    }

    /* Overlay pour fermer la sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 999;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar-overlay.active {
        display: block;
        animation: fadeIn 0.3s ease;
    }

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

    /* Main content prend toute la largeur */
    main {
        margin-left: 0 !important;
        width: 100%;
        max-width: 100vw;
        padding: 1rem;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    #editor-container,
    #main-content {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* Editor grid en colonne sur mobile */
    .editor-grid {
        grid-template-columns: 1fr !important;
        gap: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .editor-panel,
    .editor-form {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* Forcer la preview seule visible par défaut sur mobile */
    .editor-grid.mobile-preview-only .editor-panel {
        display: none !important;
    }

    /* Ajuster les tailles de police */
    body {
        font-size: 14px;
    }

    /* Modales en plein écran sur mobile */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 1rem;
    }

    /* Boutons d'action en colonne */
    .editor-actions-primary {
        flex-direction: column;
        gap: 0.5rem;
    }

    .editor-actions-primary button {
        width: 100%;
    }

    /* Toggle preview button plus visible */
    .toggle-preview-btn {
        min-width: auto;
    }

    /* File tree compact */
    #file-tree {
        font-size: 0.9rem;
    }

    /* Réduire le padding des sections sidebar */
    aside section {
        padding: 0.75rem;
    }

    /* Preview prend tout l'espace et est centré */
    .preview {
        min-height: 60vh;
        padding: 0.75rem;
        max-width: 100%;
        width: 100%;
        margin: 0 auto;
        box-sizing: border-box;
        overflow-x: auto;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* S'assurer que le contenu du preview ne déborde pas */
    .preview * {
        max-width: 100%;
        box-sizing: border-box;
    }

    .preview pre {
        overflow-x: auto;
        max-width: 100%;
    }

    .preview table {
        display: block;
        overflow-x: auto;
        max-width: 100%;
    }

    .preview img {
        max-width: 100%;
        height: auto;
    }

    .preview code {
        word-break: break-all;
    }

    /* Centrer le contenu de la page d'accueil sur mobile */
    .note-tree {
        max-width: 100%;
        width: 100%;
        padding: 0.5rem;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .note-tree * {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Indentation réduite sur mobile pour éviter les débordements */
    .indent-level-1 { padding-left: 0 !important; }
    .indent-level-2 { padding-left: 0.75rem !important; }
    .indent-level-3 { padding-left: 1.5rem !important; }
    .indent-level-4 { padding-left: 2.25rem !important; }
    .indent-level-5 { padding-left: 3rem !important; }
    .indent-level-6 { padding-left: 3.75rem !important; }
    .indent-level-7 { padding-left: 4.5rem !important; }
    .indent-level-8 { padding-left: 5.25rem !important; }

    /* Les dossiers et fichiers */
    .folder,
    .file {
        max-width: 100%;
        overflow: hidden;
        padding-top: 0.3rem !important;
        padding-bottom: 0.3rem !important;
    }

    .folder-header {
        max-width: 100%;
        overflow: hidden;
        padding: 0.3rem 0 !important;
        font-size: 0.9rem;
    }

    .file {
        font-size: 0.9rem;
    }

    .file-icon,
    .folder-icon {
        font-size: 1rem;
    }

    /* Améliorer la sidebar sur mobile */
    aside {
        padding-top: 1rem;
    }

    /* Bouton de fermeture dans le menu mobile */
    .sidebar-close-btn {
        display: block;
        position: sticky;
        top: 0;
        right: 0;
        background: var(--bg-tertiary);
        border: none;
        color: var(--text-primary);
        font-size: 1.5rem;
        padding: 0.5rem;
        cursor: pointer;
        width: 100%;
        text-align: right;
        z-index: 10;
        margin-bottom: 1rem;
    }

    /* CodeMirror ajusté pour mobile */
    .CodeMirror,
    .cm-editor {
        font-size: 14px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    .cm-scroller {
        overflow-x: auto;
        max-width: 100%;
    }

    /* Accordéon de dossiers plus compact */
    .folder-header {
        padding: 0.4rem 0 !important;
        font-size: 0.9rem;
    }

    .file {
        padding: 0.3rem 0 !important;
        font-size: 0.9rem;
    }
}

/* Smartphones en mode portrait (max 480px) */
@media screen and (max-width: 480px) {
    /* Encore plus strict sur les débordements */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
        width: 100vw;
    }

    header h1 {
        font-size: 1rem;
    }

    header button {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
    }

    aside {
        width: 100%;
        left: -100%;
    }

    .modal-content {
        width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    body {
        font-size: 13px;
    }

    /* Réduire encore plus les marges */
    main {
        padding: 0.25rem;
    }

    .preview {
        padding: 0.5rem;
    }

    /* Centrage parfait pour très petits écrans */
    #editor-container {
        padding: 0;
    }

    .note-tree {
        padding: 0.25rem;
    }

    /* Texte plus petit si nécessaire */
    .folder-header,
    .file {
        font-size: 0.85rem;
    }

    /* Adapter la modale de recherche sur mobile */
    .search-modal-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        max-height: 100vh;
    }

    .search-modal-input {
        font-size: 14px;
    }

    .search-modal-results {
        max-height: calc(100vh - 200px);
    }
}

/* ==========================================================================
   Search Modal Styles
   ========================================================================== */

.search-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
    opacity: 0;
    transition: opacity 200ms ease;
}

.search-modal.active {
    opacity: 1;
}

.search-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.search-modal-container {
    position: relative;
    width: 90%;
    max-width: 680px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    display: flex;
    flex-direction: column;
    max-height: 70vh;
    transform: translateY(-20px);
    transition: transform 200ms ease;
}

.search-modal.active .search-modal-container {
    transform: translateY(0);
}

/* Header */
.search-modal-header {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-primary);
}

.search-modal-input-wrapper {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.search-modal-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-modal-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    padding: var(--spacing-sm) 0;
}

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

.search-modal-kbd {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    font-size: 11px;
    font-family: monospace;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Body */
.search-modal-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.search-modal-results {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-sm);
}

/* Results Header */
.search-modal-results-header {
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.search-modal-results-count {
    font-weight: 500;
}

/* Result Item */
.search-modal-result-item {
    display: flex;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    margin: var(--spacing-xs) 0;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
}

.search-modal-result-item:hover {
    background: var(--bg-tertiary);
}

.search-modal-result-item.selected {
    background: linear-gradient(135deg, rgba(130, 170, 255, 0.15), rgba(199, 146, 234, 0.15));
    border-color: var(--accent-blue);
}

.search-modal-result-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.search-modal-result-content {
    flex: 1;
    min-width: 0;
}

.search-modal-result-title {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.search-modal-result-title mark {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    color: white;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
}

.search-modal-result-path {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.search-modal-result-snippet {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-modal-result-snippet mark {
    background: rgba(130, 170, 255, 0.3);
    color: var(--accent-blue);
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 500;
}

.search-modal-result-footer {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

.search-modal-result-tags {
    display: flex;
    gap: var(--spacing-xs);
    flex-wrap: wrap;
}

.search-modal-result-tags .tag-pill {
    background: var(--bg-tertiary);
    color: var(--accent-blue);
    border: 1px solid var(--border-primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.search-modal-result-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Help */
.search-modal-help {
    padding: var(--spacing-lg);
    text-align: center;
}

.search-modal-help-title {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--spacing-lg);
}

.search-modal-help-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
}

.search-modal-help-item {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    padding: var(--spacing-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.search-modal-help-item:hover {
    border-color: var(--accent-blue);
    transform: translateY(-2px);
}

.search-modal-help-item code {
    background: var(--bg-primary);
    color: var(--accent-blue);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: 'Fira Code', 'Cascadia Code', monospace;
    border: 1px solid var(--border-primary);
}

.search-modal-help-item span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Loading */
.search-modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    gap: var(--spacing-md);
}

.search-modal-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-primary);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.search-modal-loading p {
    color: var(--text-muted);
    margin: 0;
}

/* No Results */
.search-modal-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    text-align: center;
}

.search-modal-no-results-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.search-modal-no-results-text {
    color: var(--text-primary);
    margin: 0 0 var(--spacing-sm) 0;
}

.search-modal-no-results-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

/* Error */
.search-modal-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    text-align: center;
}

.search-modal-error-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
}

.search-modal-error p {
    color: var(--error);
    margin: 0;
}

/* Footer */
.search-modal-footer {
    border-top: 1px solid var(--border-primary);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
}

.search-modal-footer-hint {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.search-modal-footer-hint kbd {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    font-size: 11px;
    font-family: monospace;
    color: var(--text-secondary);
}

/* Scrollbar pour les résultats */
.search-modal-results::-webkit-scrollbar {
    width: 8px;
}

.search-modal-results::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.search-modal-results::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 4px;
}

.search-modal-results::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
