:root{
    --bg:#F6F3ED;
    --card:#ffffff;
    --ink:#2A2622;
    --sub:#8A8175;
    --line:#E7E1D6;
    --accent:#C97A4A;
    --accent-soft:#F0DCC9;
    --pin:#B5551F;
  }
  html[data-theme="dark"]{
    --bg:#1E1B18;
    --card:#2A2622;
    --ink:#EDE7DD;
    --sub:#9C9186;
    --line:#3D3833;
    --accent:#E0925C;
    --accent-soft:#4A3A2C;
    --pin:#E0925C;
  }
  html{
    background:var(--bg);
    transition:background 0.2s ease;
  }
  body{
    transition:background 0.2s ease, color 0.2s ease;
  }
  *{box-sizing:border-box;}
  body{
    margin:0;
    background:var(--bg);
    color:var(--ink);
    font-family:'Georgia', 'Iowan Old Style', serif;
  }

  .app{
    display:flex;
    min-height:100vh;
  }

  .sidebar{
    width:300px;
    flex-shrink:0;
    background:var(--card);
    border-right:1px solid var(--line);
    padding:20px 12px;
    display:flex;
    flex-direction:column;
    gap:4px;
  }
  .sidebar-brand{
    display:flex;
    align-items:center;
    gap:8px;
    padding:0 10px;
    margin-bottom:22px;
  }
  .brand-dot{font-size:20px;}
  .brand-name{
    font-size:19px;
    letter-spacing:0.5px;
  }
  .brand-name span{color:var(--accent);}
  .side-item{
    display:flex;
    align-items:center;
    gap:12px;
    width:100%;
    text-align:left;
    border:none;
    background:transparent;
    color:var(--ink);
    font-family:inherit;
    font-size:14px;
    padding:10px 14px;
    border-radius:999px;
  }
  .side-icon{font-size:15px;}
  .side-item:hover{background:var(--bg);}
  .side-item.active{
    background:var(--accent-soft);
    font-weight:bold;
  }

  .content{
    flex:1;
    min-width:0;
    padding-left:24px;
  }

  header{
    padding:28px 24px 18px;
    max-width:1400px;
    margin:0;
    position:relative;
  }
  h1{
    font-size:28px;
    font-weight:400;
    letter-spacing:0.5px;
    margin:0 0 16px;
  }
  h1 span{color:var(--accent);}
  .composer{
    background:var(--card);
    border:1px solid var(--line);
    border-radius:10px;
    padding:14px 16px;
    box-shadow:0 1px 2px rgba(0,0,0,0.03);
    cursor:text;
    max-width:600px;
    margin:0 auto;
  }
  .composer input, .composer textarea{
    width:100%;
    border:none;
    outline:none;
    background:transparent;
    font-family:'Iowan Old Style', Georgia, serif;
    color:var(--ink);
    resize:none;
  }
  .composer input{
    font-size:22px;
    margin-bottom:6px;
    padding:6px 0;
  }
  .composer textarea{
    font-size:14px;
    line-height:1.5;
    min-height:40px;
    padding:6px 0;
  }
  .composer-actions{
    display:flex;
    justify-content:flex-end;
    gap:8px;
    margin-top:8px;
  }
  button{
    font-family:inherit;
    cursor:pointer;
  }
  .btn{
    border:1px solid var(--line);
    background:var(--card);
    color:var(--sub);
    padding:6px 14px;
    border-radius:6px;
    font-size:13px;
  }
  .btn.primary{
    background:#A85320;
    border-color:#A85320;
    color:#fff;
  }
  .btn:hover{opacity:0.85;}
  main{
    max-width:1400px;
    margin:0;
    padding:8px 24px 60px;
  }
  .empty{
    text-align:center;
    color:var(--sub);
    margin-top:80px;
    font-style:italic;
  }
  .grid{
    display:grid;
    grid-template-columns:repeat(auto-fill, minmax(220px,1fr));
    gap:16px;
    margin-top:20px;
    align-items:start;
  }
  .note{
    background:var(--card);
    border:1px solid var(--line);
    border-radius:8px;
    padding:16px 18px;
    position:relative;
    transition:box-shadow 0.15s ease, transform 0.15s ease;
    display:flex;
    flex-direction:column;
    max-height:160px;
    overflow:hidden;
  }
  .note:hover{
    box-shadow:0 4px 14px rgba(0,0,0,0.08);
    transform:translateY(-1px);
  }
  .note.pinned{
    border-color:var(--accent-soft);
    background:linear-gradient(180deg, var(--card), var(--accent-soft) 200%);
  }
  .note-title{
    font-size:14px;
    margin:0 0 4px;
    padding-right:20px;
    word-break:break-word;
  }
  .note-body{
    font-size:12px;
    color:var(--sub);
    line-height:1.5;
    white-space:pre-wrap;
    word-break:break-word;
    max-height:4.5em;
    overflow:hidden;
    display:-webkit-box;
    -webkit-line-clamp:3;
    -webkit-box-orient:vertical;
  }
  .pin-toggle{
    position:absolute;
    top:10px;
    right:10px;
    background:none;
    border:none;
    font-size:15px;
    color:var(--sub);
    padding:2px;
    line-height:1;
  }
  .note.pinned .pin-toggle{color:var(--pin);}
  .note-footer{
    display:flex;
    justify-content:space-between;
    align-items:center;
    margin-top:16px;
    padding-top:10px;
    border-top:1px solid var(--line);
    opacity:0;
    transition:opacity 0.15s ease;
  }
  .note:hover .note-footer{opacity:1;}
  .note-footer button{
    background:none;
    border:none;
    color:var(--sub);
    font-size:12px;
    text-decoration:underline;
  }
  .note-footer button:hover{color:var(--accent);}
  .note-title:focus, .note-body:focus, .course-label:focus{
    outline:none;
  }
  .note-title:empty::before{
    content:"Créer une note...";
    color:var(--sub);
    pointer-events:none;
  }
  .note-title:not(:empty) + .note-body:empty::before{
    content:"Créer une note...";
    color:var(--sub);
    pointer-events:none;
  }
  .section-label{
    font-size:11px;
    text-transform:uppercase;
    letter-spacing:1.5px;
    color:var(--sub);
    margin:26px 0 4px;
  }

  /* --- Liste de courses --- */
  .view{display:none;}
  .view.active{display:block;}

  .courses-composer{
    background:var(--card);
    border:1px solid var(--line);
    border-radius:10px;
    padding:12px 14px;
    display:flex;
    gap:8px;
    margin-top:16px;
  }
  .courses-composer input{
    flex:1;
    border:none;
    outline:none;
    background:transparent;
    font-family:'Iowan Old Style', Georgia, serif;
    font-size:14px;
    color:var(--ink);
  }
  .courses-list{
    list-style:none;
    margin:16px 0 0;
    padding:0;
    display:flex;
    flex-direction:column;
    gap:8px;
  }
  #checkedSection .courses-list{margin-top:8px;}
  .course-item{
    display:flex;
    align-items:center;
    gap:10px;
    background:var(--card);
    border:1px solid var(--line);
    border-radius:8px;
    padding:10px 12px;
  }
  .course-item.checked .course-label{
    color:var(--sub);
    text-decoration:line-through;
  }
  .course-check{
    width:18px;
    height:18px;
    border-radius:4px;
    border:1.5px solid var(--accent);
    background:transparent;
    flex-shrink:0;
    position:relative;
  }
  .course-item.checked .course-check{
    background:var(--accent);
  }
  .course-item.checked .course-check::after{
    content:'✓';
    color:#fff;
    font-size:11px;
    position:absolute;
    top:50%;left:50%;
    transform:translate(-50%,-50%);
  }
  .course-label{
    flex:1;
    font-size:14px;
    word-break:break-word;
  }
  .course-del{
    background:none;
    border:none;
    color:var(--sub);
    font-size:12px;
    text-decoration:underline;
    opacity:0;
    transition:opacity 0.15s ease;
  }
  .course-item:hover .course-del{opacity:1;}
  .courses-footer{
    display:flex;
    justify-content:space-between;
    align-items:center;
    margin-top:14px;
  }
  .courses-footer .btn{font-size:12px;padding:5px 12px;}

  /* --- Toggle thème sombre --- */
  .theme-toggle{
    position:absolute;
    top:28px;
    right:24px;
    width:36px;
    height:36px;
    border-radius:50%;
    border:1px solid var(--line);
    background:var(--card);
    color:var(--ink);
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:16px;
    line-height:1;
  }
  .theme-toggle:hover{opacity:0.85;}
  header{position:relative;}

  /* --- Note agrandie (modal) --- */
  .note-overlay{
    position:fixed;
    inset:0;
    background:rgba(30,27,24,0.55);
    display:flex;
    align-items:center;
    justify-content:center;
    z-index:1000;
    padding:24px;
  }
  .note.expanded{
    width:min(600px, 90vw);
    max-height:min(80vh, 700px);
    min-height:auto;
    cursor:default;
    box-shadow:0 12px 40px rgba(0,0,0,0.25);
    padding:0;
    overflow:hidden;
    display:flex;
    flex-direction:column;
  }
  .note.expanded .note-modal-body{
    padding:20px 20px 18px;
    overflow-y:auto;
    flex:1;
  }
  .note.expanded .note-title{
    font-size:20px;
    padding-right:30px;
  }
  .note.expanded .note-body{
    font-size:14.5px;
  }
  .note-modal-meta, .note-modal-toolbar{display:none;}
  .note.expanded .note-footer{display:none;}
  .note.expanded .note-modal-meta{display:block;}
  .note.expanded .note-modal-toolbar{display:flex;}
  .note.expanded .pin-toggle{
    top:16px;
    right:16px;
    font-size:18px;
  }
  .note-modal-meta{
    padding:6px 20px;
    text-align:right;
    font-size:12px;
    color:var(--sub);
  }
  .note-modal-toolbar{
    align-items:center;
    justify-content:space-between;
    padding:8px 12px;
    border-top:1px solid var(--line);
  }
  .note-modal-toolbar .toolbar-icons{
    display:flex;
    align-items:center;
    gap:4px;
  }
  .note-modal-toolbar button{
    background:none;
    border:none;
    color:var(--sub);
    width:32px;
    height:32px;
    border-radius:50%;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:15px;
  }
  .note-modal-toolbar button:hover{background:var(--bg);}
  .note-modal-toolbar .close-btn{
    width:auto;
    border-radius:6px;
    padding:0 14px;
    font-weight:bold;
    color:var(--ink);
    font-size:13px;
  }

  /* --- Popup mot de passe --- */
  .pwd-overlay{
    position:fixed;
    inset:0;
    background:rgba(30,27,24,0.55);
    display:flex;
    align-items:center;
    justify-content:center;
    z-index:2000;
    padding:24px;
  }
  .pwd-modal{
    background:var(--card);
    border:1px solid var(--line);
    border-radius:10px;
    width:min(380px, 100%);
    padding:20px;
    box-shadow:0 12px 40px rgba(0,0,0,0.25);
  }
  .pwd-modal-title{
    font-size:15px;
    margin-bottom:14px;
    color:var(--ink);
  }
  .pwd-modal-input{
    width:100%;
    border:1px solid var(--line);
    border-radius:6px;
    background:var(--bg);
    color:var(--ink);
    font-family:inherit;
    font-size:14px;
    padding:9px 10px;
    outline:none;
  }
  .pwd-modal-input:focus{border-color:var(--accent);}
  .pwd-modal-input.pwd-masked{-webkit-text-security:disc;text-security:disc;}
  .pwd-modal-actions{
    display:flex;
    justify-content:flex-end;
    gap:8px;
    margin-top:16px;
  }