* { box-sizing: border-box; }
:root { --toolbar-height: 56px; }
html, body { height: 100%; margin: 0; }
body { font-family: "Open Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
button { font: inherit; color: inherit; cursor: pointer; }
.icon { width: 1.1em; height: 1.1em; flex-shrink: 0; color: var(--accent); }

/* Écran de connexion */
.login-screen { height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-screen form { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; max-width: 280px; padding: 2rem; border: 1px solid var(--border); border-radius: 8px; background: var(--sidebar-bg); }
.login-screen input[type="password"] { padding: 0.6rem; font-size: 16px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--fg); }
.login-screen button { padding: 0.6rem; border: none; border-radius: 4px; background: var(--accent); color: #fff; }
.login-screen .error { color: var(--danger); font-size: 0.9rem; margin: 0; }

/* Shell applicatif */
#app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
#tree { background: var(--sidebar-bg); border-right: 1px solid var(--border); overflow-y: auto; padding: 0; }
#editor-area { display: flex; flex-direction: column; min-width: 0; }
#editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; height: var(--toolbar-height); padding: 0 1rem; border-bottom: 1px solid var(--border); }
#current-title { font-weight: 700; font-size: 1.1rem; text-transform: uppercase; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 4rem; }
#save-status { font-size: 0.85rem; opacity: 0.7; white-space: nowrap; }
#editor-container { flex: 1; overflow: auto; }
.icon-button { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.4rem 0.6rem; background: none; border: 1px solid transparent; }
.icon-button:hover { background: var(--sidebar-bg); border-color: var(--border); }
#sidebar-toggle { display: none; }
#sidebar-backdrop { display: none; }

@media (max-width: 700px) {
    #app { grid-template-columns: 1fr; }
    #sidebar-toggle { display: inline-flex; }
    #export-link, #logout-form { display: none; }
    #tree {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 30;
        width: 85%;
        max-width: 320px;
        max-height: none;
        border-right: 1px solid var(--border);
        border-bottom: none;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    body.sidebar-open #tree { transform: translateX(0); }
    #sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }
    body.sidebar-open #sidebar-backdrop { opacity: 1; pointer-events: auto; }
    #editor-toolbar { padding: 0 0.5rem; }
    .icon-button span.label { display: none; }
    .icon-button { padding: 0.6rem; min-width: 44px; min-height: 44px; justify-content: center; }
    .icon { width: 1.3em; height: 1.3em; }
}

/* Arborescence */
.tree-root-actions { display: flex; align-items: stretch; height: var(--toolbar-height); border-bottom: 1px solid var(--border); }
.tree-root-actions .icon-button { flex: 1; justify-content: center; padding: 0; border: none; background: var(--root-actions-bg); color: var(--root-actions-fg); font-weight: bold; text-transform: uppercase; font-size: 14px; transition: all ease .3s; }
.tree-root-actions .icon-button:hover { color: var(--root-actions-hover-fg); background-color: var(--root-actions-hover-bg); }
ul.tree-children { list-style: none; margin: 0; padding-left: 0; }
.tree-children:not(.tree-root) { border-left: 12px solid var(--border-accent); }
.tree-folder-row, .tree-note { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 0.25rem; font-weight: 600; border-bottom: 1px solid #9994; }
.tree-folder-row:hover, .tree-note:hover { background: var(--bg); }
.tree-note.active { background: var(--bg); opacity: 1; }
.tree-note.active .tree-note-title { color: var(--accent); }
.tree-note-title, .tree-folder-name { display: flex; align-items: center; gap: 0.5rem; background: none; border: none; text-align: left; font: inherit; color: inherit; padding: 0 0.8rem; height: 45px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.tree-folder-name { font-weight: 700; }
.tree-note { opacity: .6; }

/* Regroupement visuel des notes sous un dossier */
.tree-note-group { background: var(--group-bg); margin-top: 0.2rem; }
.tree-note-group .tree-note:hover, .tree-note-group .tree-note.active { background: var(--bg); opacity: 1; }

/* Menu kebab (3 points), visible seulement au survol de la ligne ou si son menu est ouvert */
.tree-menu-wrap { position: relative; flex-shrink: 0; margin-right: .5rem; }
.tree-kebab { display: inline-flex; opacity: 0; background: none; border: none; padding: 0.3rem; border-radius: 3px; }
.tree-folder-row:hover .tree-kebab, .tree-note:hover .tree-kebab, .tree-menu-wrap:has(.tree-menu) .tree-kebab { opacity: 1; }
.tree-kebab:hover { background: var(--border); }

.tree-menu { position: absolute; right: 0; top: 100%; z-index: 10; min-width: 170px; background: var(--bg); border: 1px solid var(--border); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); display: flex; flex-direction: column; }
.tree-menu-item { display: flex; align-items: center; gap: 0.6rem; width: 100%; padding: 0.6rem 0.8rem; background: none; border: none; border-radius: 4px; text-align: left; font-size: 0.9rem; }
.tree-menu-item:hover { background: var(--sidebar-bg); }

@media (max-width: 700px) {
    .tree-kebab { opacity: 1; padding: 0.5rem; min-width: 36px; min-height: 36px; justify-content: center; align-items: center; }
}
