:root {
  --bg-sidebar: #f8f9fa;
  --bg-main: #ffffff;
  --border: #e2e8f0;
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --danger-hover: #dc2626;

  --item-hover: #f1f5f9;
  --item-active: #e0e7ff;
  --item-active-text: #4f46e5;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text-main);
  background: var(--bg-main);
  height: 100vh;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
}

#app {
  display: flex;
  height: 100%;
}

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

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Sidebar ===== */
.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
  transition: width 0.2s ease;
}

.brand {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.search-box {
  padding: 0 20px 16px 20px;
}
.search-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  font-size: 14px;
  outline: none;
  color: var(--text-main);
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.doc-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.sidebar-category {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
  margin: 16px 0 8px 8px;
  letter-spacing: 0.5px;
}

.doc-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
  margin-bottom: 4px;
  animation: slideIn 0.3s ease forwards;
  opacity: 0;
}
.doc-item:nth-child(1) { animation-delay: 0.05s; }
.doc-item:nth-child(2) { animation-delay: 0.1s; }
.doc-item:nth-child(3) { animation-delay: 0.15s; }
.doc-item:nth-child(n+4) { opacity: 1; animation: none; } 

.doc-item:hover {
  background: var(--item-hover);
  transform: translateX(4px);
}
.doc-item.active {
  background: var(--item-active);
  color: var(--item-active-text);
  font-weight: 600;
}
.doc-item svg {
  opacity: 0.7;
  margin-right: 10px;
  transition: 0.2s;
  flex-shrink: 0;
}
.doc-item.active svg {
  opacity: 1;
  color: var(--primary);
}

.doc-item .meta {
  margin-left: auto;
  opacity: 0;
  transition: 0.2s;
  color: var(--text-muted);
}
.doc-item:hover .meta { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff;
}

.footer-hint {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Main Area ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  overflow: hidden;
  animation: fadeIn 0.4s ease;
}

.top-bar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  border-bottom: 1px solid transparent;
  transition: 0.2s;
}
.content-scroll[onscroll] .top-bar {
  border-bottom-color: var(--border); 
}

.breadcrumbs {
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 80px 0;
}

.document-container {
  max-width: 760px;
  margin: 40px auto;
  padding: 0 30px;
  animation: fadeIn 0.5s ease;
  transition: max-width 0.3s ease;
}

.doc-title {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.2;
  color: var(--text-main);
  letter-spacing: -1px;
}

/* Tags & Categories Elements */
.tag-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}
.tag-pill {
  background: rgba(79, 70, 229, 0.1);
  color: var(--primary);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}
.tag-pill:hover {
  background: rgba(79, 70, 229, 0.2);
}

.doc-body {
  font-size: 17px;
  line-height: 1.75;
  color: #334155;
  white-space: normal;
  font-family: var(--font-sans);
}

.doc-body[data-format="text"] {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  background: #f8fafc;
  padding: 24px;
  border-radius: 12px;
  font-size: 14px;
  border: 1px solid var(--border);
}

/* ===== Editor ===== */
.editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.input-title {
  font-size: 36px;
  font-weight: 800;
  border: none;
  outline: none;
  width: 100%;
  margin-bottom: 16px;
  color: var(--text-main);
  background: transparent;
  letter-spacing: -1px;
}
.input-title::placeholder { color: #cbd5e1; }

.editor-toolbar {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.select-fmt {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 14px;
  background: white;
  color: var(--text-main);
  font-weight: 500;
  cursor: pointer;
}
.select-fmt:hover { border-color: #cbd5e1; }

.textarea-body {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-main);
  background: transparent;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.2);
}
.btn-primary:hover { 
  background: var(--primary-hover);
  box-shadow: 0 6px 15px rgba(79, 70, 229, 0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background: white;
  border: 1px solid var(--border);
  color: var(--text-main);
}
.btn-secondary:hover { 
  background: var(--bg-sidebar); 
  border-color: #cbd5e1;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { 
  color: var(--text-main); 
  background: rgba(0,0,0,0.04); 
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.btn-icon-only {
  padding: 8px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: white;
  transition: all 0.2s;
}
.btn-icon-only:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #f5f3ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(79,70,229,0.15);
}

/* ===== Login / Empty States ===== */
.centered-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: #f1f5f9;
}
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.08);
  animation: fadeIn 0.3s ease;
}
.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 120px;
  animation: fadeIn 0.5s ease;
}

.hidden { display: none !important; }
.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 16px;
  background: var(--danger-bg);
  padding: 10px;
  border-radius: 6px;
  text-align: center;
  border: 1px solid rgba(239,68,68,0.2);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  transform: translateY(20px);
  opacity: 0;
  transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* Markdown fixes */
.doc-body img { max-width: 100%; border-radius: 8px; margin: 16px 0; border: 1px solid var(--border); }
.doc-body h1, .doc-body h2, .doc-body h3, .doc-body h4 {
  margin-top: 28px;
  margin-bottom: 12px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.3;
}
.doc-body p { margin-bottom: 16px; }
.doc-body ul, .doc-body ol { margin: 16px 0 16px 24px; }
.doc-body li { margin-bottom: 8px; }
.doc-body a { color: var(--primary); text-decoration: none; font-weight: 600; }
.doc-body a:hover { text-decoration: underline; }
.doc-body strong { color: #0f172a; }
.doc-body em { color: #475569; }

.doc-body code {
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  opacity: 1 !important;
}
.doc-body pre {
  background: #0f172a;
  color: #e2e8f0 !important;
  padding: 20px;
  border-radius: 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  margin: 22px 0;
  box-shadow: 0 10px 25px rgba(0,0,0,0.14);
  opacity: 1 !important;
}
.doc-body pre code { background: transparent !important; color: inherit !important; padding: 0 !important; }
.doc-body pre *, .doc-body code * { opacity: 1 !important; }

.doc-body blockquote {
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  margin: 18px 0;
  color: #475569;
  background: rgba(79,70,229,0.05);
  border-radius: 10px;
}
.doc-body table { width: 100%; border-collapse: collapse; margin: 22px 0; font-size: 14px; }
.doc-body th, .doc-body td { border: 1px solid var(--border); padding: 10px 14px; text-align: left; }
.doc-body th { background: #f8fafc; font-weight: 700; }
.doc-body hr { border: none; height: 1px; background: var(--border); margin: 36px 0; }

/* Sommaire / TOC */
.toc-details {
  background: #f8fafc;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 24px;
}
.toc-details summary {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  cursor: pointer;
  outline: none;
}
.toc-details summary:hover { color: var(--primary); }
.toc-details ul { margin-top: 12px !important; }

/* Copy Button */
.code-wrapper { position: relative; }
.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #e2e8f0;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.2s;
  backdrop-filter: blur(4px);
}
.copy-btn:hover { background: rgba(255,255,255,0.18); }
.copy-btn:active { transform: scale(0.95); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px); display: flex; align-items: center;
  justify-content: center; z-index: 200; animation: fadeIn 0.2s ease;
}
.modal {
  background: white; padding: 30px; border-radius: 16px; width: 420px;
  max-width: 90%; box-shadow: 0 30px 80px rgba(0,0,0,0.25); animation: fadeIn 0.25s ease;
}
.modal h3 { margin-top: 0; margin-bottom: 10px; font-size: 20px; }
.modal p { color: var(--text-muted); margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; }

/* Mode Focus */
body.focus-mode .sidebar { display: none !important; }
body.focus-mode .document-container { max-width: 900px; }

/* Split View Edition */
.split-view { display: flex; gap: 20px; height: calc(100vh - 200px); }
.split-view > * { flex: 1; min-width: 0; }
.preview-pane { padding: 20px; border: 1px solid var(--border); border-radius: 8px; background: white; overflow-y: auto; }

/* Sidebar Collapsable */
body.sidebar-collapsed .sidebar { width: 72px; }
body.sidebar-collapsed .brand h1, 
body.sidebar-collapsed .search-box, 
body.sidebar-collapsed .sidebar-text,
body.sidebar-collapsed .sidebar-category,
body.sidebar-collapsed .sidebar-user-info,
body.sidebar-collapsed .doc-item span { display: none; }
body.sidebar-collapsed .brand { justify-content: center; padding: 20px 0; }
body.sidebar-collapsed .sidebar-footer { flex-direction: column; padding: 16px 10px; }
body.sidebar-collapsed .sidebar-footer .btn { width: 100%; padding: 8px; justify-content: center; }

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    z-index: 200;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  .sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }
  .document-container { padding: 0 16px; margin: 20px auto; }
  .top-bar { padding: 0 16px; }
  .doc-title { font-size: 28px; }
  .split-view { flex-direction: column; }
}