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

:root {
  --bg: #111111;
  --sidebar: #181818;
  --surface: #1e1e1e;
  --surface2: #252525;
  --border: rgba(255,255,255,0.08);
  --text: #f0f0f0;
  --muted: #888888;
  --accent: #5a9cf5;
  --accent2: #3a7fd4;
  --danger: #e25555;
  --tag: #2c2c2c;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ── AUTH ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
#auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#auth-title {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
}
#auth-subtitle {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 8px;
}
#auth-box input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 10px 12px;
  outline: none;
  font-family: var(--font);
}
#auth-box input:focus { border-color: var(--accent); }
#auth-box input::placeholder { color: var(--muted); }
#auth-login-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
}
#auth-login-btn:hover { background: var(--accent2); }
#auth-register-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  padding: 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
}
#auth-register-btn:hover { color: var(--text); border-color: var(--muted); }
#auth-error {
  color: var(--danger);
  font-size: 12px;
  text-align: center;
  min-height: 16px;
}

/* ── APP LAYOUT ── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ── */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 16px 12px 10px;
  border-bottom: 1px solid var(--border);
}

#app-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
#app-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.3px;
}
#logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
#logout-btn:hover { color: var(--text); background: var(--surface2); }

#search-box {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  font-family: var(--font);
}
#search-box:focus { border-color: var(--accent); }
#search-box::placeholder { color: var(--muted); }

#sidebar-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.sidebar-btn {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  padding: 6px 4px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}
.sidebar-btn:hover { background: var(--surface); color: var(--text); }
#new-note-btn { background: var(--accent); color: #fff; border-color: var(--accent2); font-weight: 600; }
#new-note-btn:hover { background: var(--accent2); }

#notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  -webkit-overflow-scrolling: touch;
}
#notes-list::-webkit-scrollbar { width: 4px; }
#notes-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.note-item-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  margin-bottom: 3px;
}

.note-item-delete {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background: var(--danger);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
}

.note-item {
  position: relative;
  z-index: 1;
  background: var(--sidebar);
  padding: 9px 10px;
  border-radius: 6px;
  transition: transform 0.2s ease;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
}
.note-item:hover { background: var(--surface2); }
.note-item.active { background: var(--surface); border-color: var(--accent); }

.note-item-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item-preview {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.note-item-date {
  font-size: 10px;
  color: #555;
  margin-top: 3px;
}
.note-item-tags {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.tag-pill {
  font-size: 10px;
  background: var(--tag);
  color: var(--muted);
  padding: 1px 6px;
  border-radius: 10px;
}

/* Archive */
#archive-section {
  border-top: 1px solid var(--border);
  padding: 8px 6px 6px;
}
#archive-toggle {
  width: 100%;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  padding: 4px 4px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font);
}
#archive-toggle:hover { color: var(--text); }
#archive-list { display: none; }
#archive-list.open { display: block; }

/* ── EDITEUR ── */
#editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar);
  flex-wrap: wrap;
}

#note-title-input {
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  outline: none;
  min-width: 100px;
  flex: 1;
  font-family: var(--font);
}
#note-title-input::placeholder { color: var(--muted); }

.sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

.tool-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
  font-family: var(--font);
}
.tool-btn:hover { background: var(--surface2); color: var(--text); border-color: var(--border); }
.tool-btn.active { background: var(--accent); color: #fff; }
.danger-btn { color: var(--danger) !important; }
.danger-btn:hover { background: rgba(226,85,85,0.15) !important; border-color: var(--danger) !important; }

/* Find & Replace */
#fnr-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
#fnr-bar.open { display: flex; }

.fnr-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 5px;
  outline: none;
  width: 140px;
  font-family: var(--font);
}
.fnr-input:focus { border-color: var(--accent); }
.fnr-input::placeholder { color: var(--muted); }

.fnr-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.12s;
  font-family: var(--font);
}
.fnr-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent2); }
#fnr-count { font-size: 11px; color: var(--muted); }
#fnr-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  margin-left: auto;
}
#fnr-close:hover { color: var(--text); }

/* Tags */
#tags-bar {
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 34px;
}
.tag-edit {
  background: var(--tag);
  color: var(--muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.tag-rm {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  line-height: 1;
}
.tag-rm:hover { color: var(--danger); }
#add-tag-input {
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  outline: none;
  width: 90px;
  padding: 2px 4px;
  font-family: var(--font);
}
#add-tag-input::placeholder { color: #444; }

/* Editeur */
#editor-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#note-editor {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
  padding: 24px 28px;
  font-size: 14px;
  line-height: 1.9;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  letter-spacing: 0.3px;
  caret-color: var(--accent);
  -webkit-user-select: text;
  user-select: text;
}
#note-editor::placeholder { color: #333; }
#note-editor::-webkit-scrollbar { width: 5px; }
#note-editor::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Empty state */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #444;
  gap: 10px;
}
#empty-state p { font-size: 14px; }
#empty-state small { font-size: 11px; color: #333; }

/* Status bar */
#status-bar {
  padding: 5px 16px;
  font-size: 11px;
  color: #555;
  display: flex;
  gap: 16px;
  border-top: 1px solid var(--border);
  background: var(--sidebar);
}
#status-bar span { color: var(--muted); }

/* Context menu */
#note-context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 0;
  min-width: 150px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.ctx-item {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
}
.ctx-item:hover { background: var(--surface2); }
.ctx-danger { color: var(--danger) !important; }
.ctx-danger:hover { background: rgba(226,85,85,0.15) !important; }

/* Modal */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#modal-overlay.open { display: flex; }
#modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 24px;
  width: 340px;
  max-width: 90vw;
}
#modal h3 { font-size: 14px; margin-bottom: 8px; color: var(--text); font-weight: 500; }
#modal-body { color: #888; font-size: 13px; margin-bottom: 16px; }
#modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  padding: 7px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.12s;
}
.modal-btn:hover { background: var(--surface); }
.modal-btn.primary { background: var(--accent); border-color: var(--accent2); }
.modal-btn.primary:hover { background: var(--accent2); }
.modal-btn.danger { background: rgba(226,85,85,0.2); border-color: var(--danger); color: var(--danger); }
.modal-btn.danger:hover { background: var(--danger); color: #fff; }

/* ── MOBILE MENU ── */
#mobile-menu-btn {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 60;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}

/* ── RESPONSIVE ── */
@media (max-width: 700px) {
  #sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 50;
    width: 270px;
    min-width: 270px;
    transition: left 0.25s ease;
  }
  #sidebar.open {
    left: 0;
  }
  #sidebar-overlay.open {
    display: block;
  }
  #mobile-menu-btn {
    display: block;
  }
  #toolbar {
    padding-top: 14px;
    padding-left: 50px;
  }
  #note-editor {
    padding: 16px 14px;
    font-size: 14px;
  }
  .fnr-input { width: 100px; }
  .sep { display: none; }
}
