:root {
  --bg-dark: #0d1b2e;
  --bg-sidebar: #0a1626;
  --bg-card: #ffffff;
  --bg-code: #eef0f3;
  --text-light: #e8edf5;
  --text-muted: #8a97ab;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: #1c2c44;
  --danger: #e5484d;
  --tag-bg: #e6f0ff;
  --tag-text: #2563eb;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-light);
}

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

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 14px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.sidebar-header h1 {
  font-size: 18px;
  margin: 0;
}

.logo-mark {
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 13px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
}
.logo-mark.small { width: 30px; height: 30px; font-size: 11px; }

.sidebar-search input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #101f36;
  color: var(--text-light);
  font-size: 13px;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

.section-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
}

.sidebar-divider { height: 1px; background: var(--border); margin: 4px 0; }
.sidebar-subtitle { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); padding: 0 10px; }

.section-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-light);
}
.section-item:hover { background: #101f36; }
.section-item.active { background: var(--accent); color: white; }

.section-item .count {
  font-size: 11px;
  color: var(--text-muted);
  background: #101f36;
  padding: 1px 7px;
  border-radius: 20px;
}
.section-item.active .count { background: rgba(255,255,255,0.25); color: white; }

.section-actions {
  display: none;
  gap: 6px;
}
.section-item:hover .section-actions { display: flex; }
.section-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
}
.section-actions button:hover { color: white; }

.btn-new-entry, .btn-new-section {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.btn-new-entry { background: var(--accent); color: white; }
.btn-new-entry:hover { background: var(--accent-hover); }
.btn-new-section {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border);
}
.btn-new-section:hover { color: var(--text-light); border-color: var(--text-muted); }

.sidebar-footer { margin-top: auto; }
.btn-logout {
  width: 100%;
  padding: 9px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- Main ---------- */
.main {
  flex: 1;
  padding: 28px 36px;
  overflow-y: auto;
}

.main-header { margin-bottom: 20px; }
.main-header h2 { margin: 0; font-size: 20px; }

.entries {
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 980px;
}

.empty-state {
  color: var(--text-muted);
  font-size: 14px;
}

.entry-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 22px 24px;
  color: #1a2233;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15), 0 8px 24px rgba(0,0,0,0.18);
  transition: box-shadow 0.15s ease;
}
.entry-card:hover {
  box-shadow: 0 2px 4px rgba(0,0,0,0.18), 0 12px 32px rgba(0,0,0,0.22);
}

.entry-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eef0f3;
}

.entry-card-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.project-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #4338ca;
  background: #eef0ff;
  padding: 2px 9px;
  border-radius: 20px;
}

.entry-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #8a97ab;
  font-size: 15px;
  flex-shrink: 0;
}
.entry-edit-btn:hover { color: #1a2233; }

/* ---------- Bloc "terminal" pour les commandes ---------- */
.term-block {
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.term-titlebar {
  background: #1e293b;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.term-dots { display: flex; gap: 5px; }
.term-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.term-dots span:nth-child(1) { background: #ef4444; }
.term-dots span:nth-child(2) { background: #eab308; }
.term-dots span:nth-child(3) { background: #22c55e; }

.term-label {
  flex: 1;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 600;
}

.term-body {
  background: #0f172a;
  padding: 14px 16px;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}
.term-body code { color: #e2e8f0; }

.term-body .tok-comment { color: #64748b; font-style: italic; }
.term-body .tok-string { color: #fbbf24; }
.term-body .tok-keyword { color: #60a5fa; font-weight: 600; }
.term-body .tok-variable { color: #5eead4; }

.code-block-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: #cbd5e1;
}
.code-block-copy:hover { background: rgba(255,255,255,0.15); }
.code-block-copy.copied { color: white; background: var(--accent); border-color: var(--accent); }

/* ---------- Zone de texte explicatif ---------- */
.text-zone {
  background: #f8fafc;
  border-left: 4px solid #94a3b8;
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  margin-bottom: 14px;
}
.text-zone-label { font-size: 12px; font-weight: 700; color: #475569; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.3px; }
.text-zone-content { font-size: 14px; line-height: 1.6; color: #334155; white-space: pre-line; }
.text-zone-content div { margin: 0; }

/* ---------- Zone image ---------- */
.image-zone {
  margin: 0 0 14px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}
.image-zone img { display: block; width: 100%; max-height: 480px; object-fit: contain; background: #f1f5f9; }
.image-zone figcaption {
  padding: 8px 12px;
  font-size: 12px;
  color: #64748b;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

.lang-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
  color: white;
}
.lang-badge-bash { background: #16a34a; }
.lang-badge-cmd { background: #d97706; }
.lang-badge-powershell { background: #2563eb; }
.lang-badge-sql { background: #9333ea; }
.lang-badge-text { background: #64748b; }

.tok-comment { color: #94a3b8; font-style: italic; }
.tok-string { color: #b45309; }
.tok-keyword { color: #1d4ed8; font-weight: 600; }
.tok-variable { color: #0f766e; }

.entry-note {
  font-size: 13px;
  color: #4a5568;
  margin-top: 8px;
  line-height: 1.5;
}

.entry-tags {
  margin-top: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay[hidden] {
  display: none !important;
}

.modal {
  background: #101f36;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-small { max-width: 400px; }

.modal h3 { margin: 0 0 16px 0; }

.modal form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-row {
  display: flex;
  gap: 16px;
}
.form-row .form-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-row label { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-top: 0; }

.modal label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  font-weight: 600;
}

.modal input[type=text],
.modal input[type=password],
.modal select,
.modal textarea {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a1626;
  color: var(--text-light);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.modal input[type=text]:focus,
.modal input[type=password]:focus,
.modal select:focus,
.modal textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}
.modal textarea { resize: vertical; }

.block-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #0a1626;
}
.block-row-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.block-row-header select {
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0d1b2e;
  color: var(--text-light);
  outline: none;
  width: auto;
  flex-shrink: 0;
}
.block-row-header select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}
.block-row-header input[type=text] {
  font-size: 12px;
  padding: 6px 8px;
  width: auto;
  flex: 1;
  min-width: 140px;
}
.block-row-header .btn-remove-block { flex-shrink: 0; margin-left: auto; }
.block-row textarea {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  min-height: 110px;
  line-height: 1.6;
}

/* ---------- Barres d'outils mini (code + texte riche) ---------- */
.mini-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.mini-toolbar-label { font-size: 11px; color: var(--text-muted); margin-right: 2px; }
.mini-toolbar-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.mini-toolbar button {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0d1b2e;
  color: var(--text-light);
  font-size: 12px;
  cursor: pointer;
}
.mini-toolbar button:hover { background: #16263f; border-color: var(--text-muted); }
.mini-toolbar input[type=color] {
  width: 28px;
  height: 28px;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0d1b2e;
  cursor: pointer;
}

/* ---------- Éditeur riche (zone Texte explicatif) ---------- */
.rich-editable {
  min-height: 100px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a1626;
  color: var(--text-light);
  font-size: 14px;
  line-height: 1.6;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.rich-editable:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}
.rich-editable:empty:before {
  content: attr(data-placeholder);
  color: var(--text-muted);
}

.block-image-zone {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* On masque l'input file natif (moche, non stylable directement) et on
   affiche à la place un bouton personnalisé qui déclenche le vrai input. */
.block-image-zone input[type=file] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.block-image-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #101f36;
  color: var(--text-light);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.block-image-upload-btn:hover { background: #16263f; border-color: var(--text-muted); }

.block-image-preview-wrap img {
  max-width: 120px;
  max-height: 80px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover;
}
.block-image-status {
  font-size: 12px;
  color: var(--text-muted);
}
.btn-remove-block {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.btn-primary, .btn-secondary, .btn-danger {
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text-light); }
.btn-secondary:hover { border-color: var(--text-muted); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); margin-right: auto; }
.btn-danger:hover { background: var(--danger); color: white; }

/* ---------- Login page ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: #101f36;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-logo { margin-bottom: 24px; }
.login-logo .logo-mark { margin: 0 auto 12px; }
.login-logo h1 { margin: 0; font-size: 20px; }
.login-sub { color: var(--text-muted); font-size: 13px; margin-top: 6px; }

#loginForm { display: flex; flex-direction: column; gap: 10px; text-align: left; }
#loginForm label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
#loginForm input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a1626;
  color: var(--text-light);
  font-size: 14px;
}
#loginForm button {
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
#loginForm button:hover { background: var(--accent-hover); }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin: 4px 0 0 0;
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
