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

html, body {
  height: 100%; /* Ensure html and body take full height */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: #000;
  color: #fff;
  overflow: hidden; /* Prevent body scroll, children will manage */
}

.container {
  height: 100vh; /* Make container take full viewport height */
  display: flex;
  flex-direction: column;
}

.header {
  background-color: #111;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: 0.5rem;
  flex-wrap: wrap; /* Allow items to wrap on smaller screens */
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  flex-grow: 1; /* Allow title to take available space */
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap; /* Allow buttons to wrap */
}

.btn {
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-primary {
  background-color: #fff;
  color: #000;
}

.btn-primary:hover {
  background-color: #e5e5e5;
}

.btn-secondary {
  background-color: #333;
  color: #fff;
  border: 1px solid #555;
}

.btn-secondary:hover {
  background-color: #444;
}

.btn-success {
  background-color: #fff;
  color: #000;
  font-weight: 600;
}

.btn-success:hover {
  background-color: #e5e5e5;
}

.main-content {
  display: flex;
  flex: 1; /* Allow main-content to fill remaining vertical space */
  overflow: hidden; /* Hide any overflow, children will manage */
  min-height: 0; /* Important for flex children to shrink */
}

/* Fixed sidebar with proper scrolling and responsive behavior */
.sidebar {
  width: 280px;
  background-color: #111;
  border-right: 1px solid #333;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* sidebar collapse styles for the new Toggle List control */
.main-content.sidebar-collapsed .sidebar {
  display: none;
}
.main-content.sidebar-collapsed .editor-container {
  width: 100%;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
  display: flex; /* Added for mobile close button */
  justify-content: space-between; /* Added for mobile close button */
  align-items: center; /* Added for mobile close button */
}

.sidebar-header h3 {
  font-size: 1rem;
  color: #ccc;
  margin: 0;
}

/* New: Close button for mobile sidebar */
.sidebar-header .close-sidebar-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  display: none; /* Hidden by default, shown on mobile */
}
.sidebar-header .close-sidebar-btn:hover {
  color: #ccc;
}


.document-list {
  flex: 1; /* Allow list to take available space and scroll */
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Custom scrollbar for document list */
.document-list::-webkit-scrollbar {
  width: 6px;
}

.document-list::-webkit-scrollbar-track {
  background: #222;
}

.document-list::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 3px;
}

.document-list::-webkit-scrollbar-thumb:hover {
  background: #666;
}

.document-item {
  background-color: #222;
  padding: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
  position: relative;
  min-height: 60px;
}

.document-item:hover {
  background-color: #333;
}

.document-item.active {
  background-color: #fff;
  color: #000;
}

.document-title {
  font-weight: 500;
  margin-bottom: 0.25rem;
  padding-right: 25px;
  word-wrap: break-word;
}

.document-date {
  font-size: 0.75rem;
  color: #888;
}

.document-item.active .document-date {
  color: #666;
}

.delete-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 1.2rem;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: all 0.2s;
}

.delete-btn:hover {
  background-color: #ff4444;
  color: #fff;
}

.document-item.active .delete-btn {
  color: #666;
}

.document-item.active .delete-btn:hover {
  background-color: #ff4444;
  color: #fff;
}

.document-link {
  display: block;
  color: inherit;
  text-decoration: none;
  height: 100%;
}

.document-item:hover .document-link {
  text-decoration: none;
}

.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden; /* Editor container should hide its own overflow */
}

.editor-header {
  background-color: #111;
  padding: 0.75rem;
  border-bottom: 1px solid #333;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.title-input {
  flex: 1;
  background-color: #222;
  border: 1px solid #444;
  color: #fff;
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 1rem;
}

.title-input:focus {
  outline: none;
  border-color: #fff;
}

/* Added styles for disabled title input in view mode */
.title-input:disabled {
  background-color: #111;
  border-color: #333;
  color: #ccc;
  cursor: not-allowed;
}

/* Added mode indicator styling */
.mode-indicator {
  padding: 0.25rem 0.75rem;
  background-color: #222;
  border: 1px solid #444;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #2196f3;
  white-space: nowrap;
}

/* Fixed editor wrapper to handle preview mode properly */
.editor-wrapper {
  flex: 1;
  display: flex;
  min-height: 0; /* Allow children to manage their own height for scrolling */
  overflow: hidden; /* Hide wrapper overflow, children will manage */
}

.editor-panel {
  flex: 1;
  position: relative;
  transition: all 0.3s ease;
  min-width: 0;
}

.editor-panel.split-view {
  flex: 1;
}

/* Updated preview panel for full-width view mode */
.preview-panel {
  flex: 1;
  background-color: #111;
  border-left: 1px solid #333;
  overflow-y: auto; /* Ensure vertical scrolling */
  overflow-x: hidden; /* Prevent horizontal scroll for preview content */
  display: flex; /* Make it a flex container for the preview-content */
  flex-direction: column;
  transition: all 0.3s ease;
  min-width: 0;
}

/* Added full-width preview mode */
.preview-panel.full-width {
  width: 100%;
  border-left: none;
}
/* Ensure preview-content takes full height within preview-panel */
.preview-content {
    flex-grow: 1; /* Allow content to grow and push scrollbar */
}

/* Fixed CodeMirror styling with proper scrollbars */
.CodeMirror {
  height: 100% !important;
  background-color: #000 !important;
  color: #fff !important;
  font-size: 14px;
  line-height: 1.5;
}

.CodeMirror-scroll {
  overflow-y: auto !important;
  overflow-x: auto !important;
}

.CodeMirror-scrollbar-filler {
  background-color: #000 !important;
}

.CodeMirror-vscrollbar::-webkit-scrollbar,
.CodeMirror-hscrollbar::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.CodeMirror-vscrollbar::-webkit-scrollbar-track,
.CodeMirror-hscrollbar::-webkit-scrollbar-track {
  background: #222;
}

.CodeMirror-vscrollbar::-webkit-scrollbar-thumb,
.CodeMirror-hscrollbar::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 4px;
}

.CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover,
.CodeMirror-hscrollbar::-webkit-scrollbar-thumb:hover {
  background: #666;
}

.CodeMirror-cursor {
  border-left: 2px solid #fff !important;
}

.CodeMirror-selected {
  background-color: #333 !important;
}

.CodeMirror-gutters {
  background-color: #111 !important;
  border-right: 1px solid #333 !important;
}

.CodeMirror-linenumber {
  color: #666 !important;
}

.notification {
  position: fixed;
  top: 12px;
  right: 12px;
  padding: 0.75rem 1rem;
  background-color: #1f2937; /* dark slate to match theme */
  color: #fff;
  border: 1px solid #374151;
  border-radius: 6px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
  max-width: 320px;
  pointer-events: none; /* prevent blocking buttons when hidden */
}

.notification.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.notification.error {
  background-color: #b91c1c; /* red-700 */
  border-color: #7f1d1d;
  color: #fff;
}

.notification .notification-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.notification .notification-text {
  line-height: 1.4;
}

.notification .notification-close {
  margin-left: auto;
  background: transparent;
  border: 1px solid #4b5563;
  color: #d1d5db;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.notification .notification-close:hover {
  background-color: #374151;
  color: #fff;
}

/* Added comprehensive mobile responsive design */
@media (max-width: 1024px) {
  .sidebar {
    width: 250px;
  }

  .preview-content {
    padding: 1.5rem;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 220px;
  }

  .header h1 {
    font-size: 1.1rem;
  }

  .title-input {
    min-width: 160px;
  }
}

@media (max-width: 640px) {
  .main-content {
    flex-direction: column;
  }

  /* Header adjustments for mobile */
  .header {
    padding: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
  }
  .header h1 {
    font-size: 1.1rem;
    flex-grow: 1;
    text-align: left;
    margin-bottom: 0.5rem; /* Space below title if it wraps */
    width: 100%; /* Title takes full width */
  }
  .header-actions {
    width: 100%; /* Actions take full width */
    justify-content: flex-end; /* Align buttons to the right */
    margin-top: 0; /* No extra top margin */
  }
  .header-actions .btn {
    flex-shrink: 0;
    margin-left: 0.5rem; /* Space between buttons */
  }
  #newDocBtn {
    margin-right: auto; /* Push New Document button to the left */
    margin-left: 0;
  }
  #toggleSidebarBtn {
    margin-left: auto; /* Push toggle to the right */
  }


  /* Sidebar default state on mobile: HIDDEN as an overlay */
  .sidebar {
    position: fixed; /* Use fixed to overlay */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; /* Full screen height */
    z-index: 1000; /* Ensure it's on top */
    background-color: #000; /* Full blackout */
    display: none; /* Hidden by default */
    flex-direction: column; /* Stack header and list vertically */
    border-right: none; /* No border on full screen overlay */
  }

  /* Class to show sidebar on mobile */
  .sidebar.active {
    display: flex;
  }

  /* Show close button on mobile sidebar */
  .sidebar-header .close-sidebar-btn {
    display: block;
  }

  /* Document list should scroll vertically */
  .document-list {
    flex: 1; /* Allow it to take remaining vertical space */
    overflow-y: auto; /* Crucial for vertical scrolling */
    overflow-x: hidden; /* No horizontal scroll */
    flex-direction: column; /* Stack items vertically */
    padding: 1rem;
    gap: 0.5rem;
  }

  .document-item {
    min-width: unset; /* Remove fixed width constraints */
    flex-shrink: 1; /* Allow it to shrink */
  }

  /* Hide the editor/preview when sidebar is active on mobile */
  .main-content.sidebar-active .editor-container {
    display: none;
  }

  /* Editor Header on Mobile */
  .editor-header {
    flex-wrap: wrap;
    padding: 0.75rem;
    gap: 0.5rem;
    justify-content: flex-end; /* Push action buttons to the right */
  }
  .title-input {
    width: 100%; /* Full width for title input */
    margin-bottom: 0.5rem; /* Space below title */
    flex-grow: 1;
  }
  #saveBtn, #toggleEditViewModeBtn {
    flex-shrink: 0;
  }
  /* Mode indicator stays hidden for now as per user request */
  #modeIndicator {
    display: none !important;
  }

  /* Single column for editor/preview on small screens */
  .editor-wrapper {
    flex-direction: column;
  }

  .editor-panel {
    width: 100%; /* Full width when active */
  }
  .preview-panel {
    width: 100%; /* Full width when active */
    border-left: none; /* No border when full width */
  }

  /* Responsive view/edit mode toggle */
  .editor-panel.hidden-on-mobile {
    display: none;
  }
  .preview-panel.hidden-on-mobile {
    display: none;
  }
}

@media (max-width: 480px) {
  .header h1 {
    font-size: 1rem;
  }

  .btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.78rem;
  }

  .CodeMirror {
    font-size: 12px;
  }
}

/* Added loading state styles */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.document-item.loading {
  background-color: #333;
}

/* Added better focus states for accessibility */
.btn:focus,
.title-input:focus,
.document-item:focus {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.delete-btn:focus {
  outline: 2px solid #ff4444;
  outline-offset: 1px;
}

/* GitHub-like markdown styling for preview */
.preview-content {
  max-width: 100%;
  padding: 2rem;
  font-size: 16px;
  line-height: 1.6;
  color: #e6e6e6;
  flex-grow: 1; /* Ensure content takes full height within its parent */
}

.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
  font-weight: 700;
  line-height: 1.25;
  margin: 1.5rem 0 0.75rem;
  color: #fff;
}

.preview-content h1 {
  font-size: 1.75rem;
  border-bottom: 1px solid #2a2a2a;
  padding-bottom: .3rem;
}
.preview-content h2 {
  font-size: 1.5rem;
  border-bottom: 1px solid #2a2a2a;
  padding-bottom: .3rem;
}
.preview-content h3 {
  font-size: 1.25rem;
}
.preview-content h4 {
  font-size: 1.125rem;
}

.preview-content p {
  margin: 0.75rem 0;
}
.preview-content a {
  color: #58a6ff;
  text-decoration: none;
}
.preview-content a:hover {
  text-decoration: underline;
}

.preview-content ul,
.preview-content ol {
  padding-left: 1.25rem;
  margin: 0.75rem 0;
}

.preview-content blockquote {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  border-left: 4px solid #444;
  color: #c7c7c7;
  background: #0d0d0d;
}

.preview-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
  background: #0f0f0f;
  border: 1px solid #2a2a2a;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  color: #e6e6e6;
}

.preview-content pre {
  background: #0b0b0b;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 1rem;
  overflow: auto; /* enable scroll for long code blocks */
  margin: 1rem 0;
}

.preview-content pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
}

/* ensure scrollbars for preview as well */
.preview-panel::-webkit-scrollbar {
  width: 8px;
}
.preview-panel::-webkit-scrollbar-track {
  background: #222;
}
.preview-panel::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 4px;
}
.preview-panel::-webkit-scrollbar-thumb:hover {
  background: #666;
}* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: #000;
  color: #fff;
  /* allow natural page flow and mobile scrolling */
  min-height: 100vh;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: 1.5rem;
}

.container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background-color: #111;
  padding: 0.75rem 1rem; /* slightly tighter by default */
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.btn {
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-primary {
  background-color: #fff;
  color: #000;
}

.btn-primary:hover {
  background-color: #e5e5e5;
}

.btn-secondary {
  background-color: #333;
  color: #fff;
  border: 1px solid #555;
}

.btn-secondary:hover {
  background-color: #444;
}

.btn-success {
  background-color: #fff;
  color: #000;
  font-weight: 600;
}

.btn-success:hover {
  background-color: #e5e5e5;
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  position: relative; /* support sidebar overlay positioning */
}

/* Fixed sidebar with proper scrolling and responsive behavior */
.sidebar {
  width: 280px;
  background-color: #111;
  border-right: 1px solid #333;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 2;
}

/* sidebar collapse styles for the new Toggle List control */
@media (min-width: 769px) {
  .main-content.sidebar-collapsed .sidebar {
    display: none;
  }
  .main-content.sidebar-open .sidebar {
    display: flex;
  }
}

.sidebar-backdrop {
  display: none;
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: 1px solid #333;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: #d1d5db;
  font-size: 1.1rem;
  line-height: 1;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.sidebar-close-btn:hover {
  background-color: #333;
  color: #fff;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.sidebar h3 {
  font-size: 1rem;
  color: #ccc;
  margin: 0;
}

.document-list {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Custom scrollbar for document list */
.document-list::-webkit-scrollbar {
  width: 6px;
}

.document-list::-webkit-scrollbar-track {
  background: #222;
}

.document-list::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 3px;
}

.document-list::-webkit-scrollbar-thumb:hover {
  background: #666;
}

.document-item {
  background-color: #222;
  padding: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
  position: relative;
  min-height: 60px;
}

.document-item:hover {
  background-color: #333;
}

.document-item.active {
  background-color: #fff;
  color: #000;
}

.document-title {
  font-weight: 500;
  margin-bottom: 0.25rem;
  padding-right: 25px;
  word-wrap: break-word;
}

.document-date {
  font-size: 0.75rem;
  color: #888;
}

.document-item.active .document-date {
  color: #666;
}

.delete-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 1.2rem;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: all 0.2s;
}

.delete-btn:hover {
  background-color: #ff4444;
  color: #fff;
}

.document-item.active .delete-btn {
  color: #666;
}

.document-item.active .delete-btn:hover {
  background-color: #ff4444;
  color: #fff;
}

.document-link {
  display: block;
  color: inherit;
  text-decoration: none;
  height: 100%;
}

.document-item:hover .document-link {
  text-decoration: none;
}

.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-header {
  background-color: #111;
  padding: 0.75rem;
  border-bottom: 1px solid #333;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.title-input {
  flex: 1;
  background-color: #222;
  border: 1px solid #444;
  color: #fff;
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 1rem;
}

.title-input:focus {
  outline: none;
  border-color: #fff;
}

/* Added styles for disabled title input in view mode */
.title-input:disabled {
  background-color: #111;
  border-color: #333;
  color: #ccc;
  cursor: not-allowed;
}

/* Added mode indicator styling */
.mode-indicator {
  padding: 0.25rem 0.75rem;
  background-color: #222;
  border: 1px solid #444;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #2196f3;
  white-space: nowrap;
}

/* Fixed editor wrapper to handle preview mode properly */
.editor-wrapper {
  flex: 1;
  display: flex;
  min-height: 0;
}

.editor-panel {
  flex: 1;
  position: relative;
  transition: all 0.3s ease;
  min-width: 0;
}

.editor-panel.split-view {
  flex: 1;
}

/* Updated preview panel for full-width view mode */
.preview-panel {
  flex: 1;
  background-color: #111;
  border-left: 1px solid #333;
  overflow-y: auto;
  display: none;
  transition: all 0.3s ease;
  min-width: 0;
}

/* Added full-width preview mode */
.preview-panel.full-width {
  width: 100%;
  border-left: none;
}

/* Fixed CodeMirror styling with proper scrollbars */
.CodeMirror {
  height: 100% !important;
  background-color: #000 !important;
  color: #fff !important;
  font-size: 14px;
  line-height: 1.5;
}

.CodeMirror-scroll {
  overflow-y: auto !important;
  overflow-x: auto !important;
}

.CodeMirror-scrollbar-filler {
  background-color: #000 !important;
}

.CodeMirror-vscrollbar::-webkit-scrollbar,
.CodeMirror-hscrollbar::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.CodeMirror-vscrollbar::-webkit-scrollbar-track,
.CodeMirror-hscrollbar::-webkit-scrollbar-track {
  background: #222;
}

.CodeMirror-vscrollbar::-webkit-scrollbar-thumb,
.CodeMirror-hscrollbar::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 4px;
}

.CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover,
.CodeMirror-hscrollbar::-webkit-scrollbar-thumb:hover {
  background: #666;
}

.CodeMirror-cursor {
  border-left: 2px solid #fff !important;
}

.CodeMirror-selected {
  background-color: #333 !important;
}

.CodeMirror-gutters {
  background-color: #111 !important;
  border-right: 1px solid #333 !important;
}

.CodeMirror-linenumber {
  color: #666 !important;
}

.notification {
  position: fixed;
  top: 12px;
  right: 12px;
  padding: 0.75rem 1rem;
  background-color: #1f2937; /* dark slate to match theme */
  color: #fff;
  border: 1px solid #374151;
  border-radius: 6px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
  max-width: 320px;
  pointer-events: none; /* prevent blocking buttons when hidden */
}

.notification.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.notification.error {
  background-color: #b91c1c; /* red-700 */
  border-color: #7f1d1d;
  color: #fff;
}

.notification .notification-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.notification .notification-text {
  line-height: 1.4;
}

.notification .notification-close {
  margin-left: auto;
  background: transparent;
  border: 1px solid #4b5563;
  color: #d1d5db;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.notification .notification-close:hover {
  background-color: #374151;
  color: #fff;
}

/* Added comprehensive mobile responsive design */
@media (max-width: 1024px) {
  .sidebar {
    width: 250px;
  }

  .preview-content {
    padding: 1.5rem;
  }
}

@media (max-width: 768px) {
  .header {
    align-items: flex-start;
    row-gap: 0.5rem;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .header-actions .btn {
    flex: 1 1 auto;
  }

  .main-content {
    flex-direction: column;
    padding-top: 0.5rem;
  }

  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 70vh;
    background-color: #111;
    border: 1px solid #202020;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.55);
    overflow: hidden;
    transform: translateY(-14px) scale(0.98);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.2s ease;
  }

  .main-content.sidebar-open .sidebar {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }

  .sidebar-backdrop {
    position: absolute;
    inset: -1rem -1rem 0;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    display: block;
    transition: opacity 0.2s ease;
  }

  .main-content.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-header {
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .sidebar-close-btn {
    display: inline-flex;
  }

  .document-list {
    padding: 0.75rem 1.25rem 1.25rem;
    overflow-y: auto;
    flex-direction: column;
    gap: 0.75rem;
  }

  .editor-container {
    width: 100%;
  }

  .editor-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .editor-controls {
    width: 100%;
    justify-content: stretch;
  }

  .editor-controls .btn,
  #viewModeBtn,
  #editModeBtn,
  #saveBtn {
    width: 100%;
  }

  .editor-wrapper {
    flex-direction: column;
  }

  .editor-panel,
  .preview-panel {
    width: 100%;
    min-height: 320px;
  }
}

@media (max-width: 540px) {
  .header h1 {
    font-size: 1.05rem;
  }

  .btn {
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
  }

  .document-item {
    min-height: 64px;
  }
}

@media (max-width: 480px) {
  .header h1 {
    font-size: 1rem;
  }

  .btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.78rem;
  }

  .sidebar {
    height: 150px;
  }

  .document-item {
    min-width: 130px;
  }

  .CodeMirror {
    font-size: 12px;
  }
}

/* Added loading state styles */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.document-item.loading {
  background-color: #333;
}

/* Added better focus states for accessibility */
.btn:focus,
.title-input:focus,
.document-item:focus {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.delete-btn:focus {
  outline: 2px solid #ff4444;
  outline-offset: 1px;
}

/* GitHub-like markdown styling for preview */
.preview-content {
  max-width: 100%;
  padding: 2rem;
  font-size: 16px;
  line-height: 1.6;
  color: #e6e6e6;
}

.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
  font-weight: 700;
  line-height: 1.25;
  margin: 1.5rem 0 0.75rem;
  color: #fff;
}

.preview-content h1 {
  font-size: 1.75rem;
  border-bottom: 1px solid #2a2a2a;
  padding-bottom: .3rem;
}
.preview-content h2 {
  font-size: 1.5rem;
  border-bottom: 1px solid #2a2a2a;
  padding-bottom: .3rem;
}
.preview-content h3 {
  font-size: 1.25rem;
}
.preview-content h4 {
  font-size: 1.125rem;
}

.preview-content p {
  margin: 0.75rem 0;
}
.preview-content a {
  color: #58a6ff;
  text-decoration: none;
}
.preview-content a:hover {
  text-decoration: underline;
}

.preview-content ul,
.preview-content ol {
  padding-left: 1.25rem;
  margin: 0.75rem 0;
}

.preview-content blockquote {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  border-left: 4px solid #444;
  color: #c7c7c7;
  background: #0d0d0d;
}

.preview-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
  background: #0f0f0f;
  border: 1px solid #2a2a2a;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  color: #e6e6e6;
}

.preview-content pre {
  background: #0b0b0b;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 1rem;
  overflow: auto; /* enable scroll for long code blocks */
  margin: 1rem 0;
}

.preview-content pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
}

/* ensure scrollbars for preview as well */
.preview-panel::-webkit-scrollbar {
  width: 8px;
}
.preview-panel::-webkit-scrollbar-track {
  background: #222;
}
.preview-panel::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 4px;
}
.preview-panel::-webkit-scrollbar-thumb:hover {
  background: #666;
}
