/* --- Base Layout --- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", Arial, sans-serif;
  height: 100vh;
  background: #f9fafb;
  color: #333;
  overflow: hidden;
}

.container {
  display: flex;
  height: 100vh;
  position: relative;
}

/* --- Sidebar Toggle Button --- */
.sidebar-toggle {
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  padding: 8px;
  background: #4f46e5;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.sidebar-toggle:hover {
  background: #4338ca;
  transform: scale(1.05);
}

.sidebar-toggle.hidden {
  left: 15px;
}

/* --- Left Sidebar (Sections/Subsections) --- */
.sidebar {
  width: 310px;
  min-width: 200px;
  max-width: 500px;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  padding: 15px;
  padding-top: 65px; /* Space for toggle button */
  overflow-y: auto;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, margin-left 0.3s ease;
}

.sidebar.collapsed {
  transform: translateX(-100%);
  margin-left: -310px;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: #111827;
}

.sidebar input {
  width: 100%;
  padding: 8px 10px;
  margin: 12px 0;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  transition: 0.2s;
}

.sidebar input:focus {
  border-color: #4f46e5;
  outline: none;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

/* --- Resize Handles --- */
.resize-handle {
  width: 5px;
  background: #e5e7eb;
  cursor: col-resize;
  transition: background 0.2s;
  position: relative;
  flex-shrink: 0;
}

.resize-handle:hover {
  background: #4f46e5;
}

.resize-handle::before {
  content: '';
  position: absolute;
  top: 0;
  left: -5px;
  right: -5px;
  bottom: 0;
}

.resize-handle.resizing {
  background: #4338ca;
}

/* --- Middle Column (Snippets List) --- */
.snippets-column {
  width: 400px;
  min-width: 250px;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.column-header {
  padding: 20px;
  border-bottom: 1px solid #e5e7eb;
  background: #fafbfc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.column-header h2,
.column-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #111827;
}

#snippetsListContainer {
  padding: 15px;
  overflow-y: auto;
  flex: 1;
}

/* --- Right Column (Code Display) --- */
.code-display-column {
  flex: 1;
  min-width: 400px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#snippetDisplay {
  flex: 1;
  overflow: auto;
  padding: 15px;
}

#snippetDisplay pre {
  background: #1e293b;
  color: #e5e7eb;
  padding: 20px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#snippetDisplay pre code {
  background: transparent;
  color: inherit;
}

/* Copy Button */
.copy-btn {
  padding: 6px 12px;
  font-size: 13px;
  background: #10b981;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.2s;
}

.copy-btn:hover {
  background: #059669;
}

.copy-btn:active {
  transform: scale(0.95);
}

/* --- Tree View List --- */
.sections-list,
.subsections-list {
  list-style: none;
  margin: 0;
  padding-left: 10px;
}

.section-item,
.subsection-item {
  position: relative;
  margin: 4px 0;
  border-radius: 8px;
  padding: 6px 8px 6px 28px;
  cursor: pointer;
  transition: all 0.25s ease;
  background: #f9fafb;
  box-shadow: 0 0 0 transparent;
}

.section-item:hover,
.subsection-item:hover {
  background: #eef2ff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.section-item.active,
.subsection-item.active {
  background: #e0e7ff;
  border-left: 3px solid #4f46e5;
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.15);
}

/* --- Connector Lines (Tree) --- */
.subsections-list {
  margin-left: 16px;
  border-left: 1px dashed #d1d5db;
  padding-left: 14px;
  transition: all 0.3s ease;
}

/* --- Toggle Icons --- */
.toggle-btn {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: #6b7280;
  transition: transform 0.25s ease;
}

.toggle-btn.open {
  transform: translateY(-50%) rotate(90deg);
  color: #4f46e5;
}

/* --- Delete Button --- */
.delete-btn {
  color: #ef4444;
  font-weight: bold;
  font-size: 16px;
  padding: 0 6px;
  border-radius: 4px;
  transition: 0.2s;
  margin-left: 8px;
}

.delete-btn:hover {
  background: #ef4444;
  color: white;
}

/* --- Buttons --- */
button {
  cursor: pointer;
  padding: 8px 12px;
  background: #4f46e5;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  transition: 0.2s;
}

button:hover {
  background: #4338ca;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

.rename-input {
  width: 85%;
  padding: 4px 6px;
  font-size: 14px;
  border: 1px solid #4f46e5;
  border-radius: 5px;
  outline: none;
  background: #eef2ff;
  color: #111827;
  transition: 0.2s;
}

.rename-input:focus {
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.25);
}

#addSubsectionBtn {
  margin-top: 10px;
  width: 100%;
}

#addSnippetBtn {
  margin: 10px 0;
}

/* --- Snippet List --- */
#snippetsList {
  list-style: none;
  padding: 0;
  margin-top: 10px;
}

#snippetsList li {
  padding: 12px;
  cursor: pointer;
  background: #f3f4f6;
  margin-bottom: 8px;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

#snippetsList li:hover {
  background: #e0e7ff;
  border-left-color: #4f46e5;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

#snippetsList li.active {
  background: #e0e7ff;
  border-left-color: #4f46e5;
  font-weight: 500;
}

/* --- Scrollbar Styling --- */
.sidebar::-webkit-scrollbar,
#snippetsListContainer::-webkit-scrollbar,
#snippetDisplay::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.sidebar::-webkit-scrollbar-thumb,
#snippetsListContainer::-webkit-scrollbar-thumb,
#snippetDisplay::-webkit-scrollbar-thumb {
  background-color: #c7d2fe;
  border-radius: 6px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
#snippetsListContainer::-webkit-scrollbar-thumb:hover,
#snippetDisplay::-webkit-scrollbar-thumb:hover {
  background-color: #a5b4fc;
}

/* --- Responsive adjustments --- */
@media (max-width: 1024px) {
  .sidebar {
    width: 250px;
  }
  
  .snippets-column {
    width: 300px;
  }
}

/* --- Modal Styles --- */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: #ffffff;
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideDown 0.3s ease;
}

.modal-small {
  max-width: 400px;
}

@keyframes slideDown {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  padding: 20px 25px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  color: #111827;
  font-weight: 600;
}

.modal-close,
.password-modal-close {
  font-size: 28px;
  font-weight: 300;
  color: #6b7280;
  cursor: pointer;
  line-height: 1;
  transition: 0.2s;
}

.modal-close:hover,
.password-modal-close:hover {
  color: #ef4444;
  transform: rotate(90deg);
}

.modal-body {
  padding: 25px;
}

.modal-body label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #374151;
  font-size: 14px;
}

.modal-body input[type="text"],
.modal-body input[type="password"],
.modal-body textarea {
  width: 100%;
  padding: 12px 15px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  transition: 0.2s;
  background: #f9fafb;
}

.modal-body input[type="text"]:focus,
.modal-body input[type="password"]:focus,
.modal-body textarea:focus {
  outline: none;
  border-color: #4f46e5;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.modal-body textarea {
  min-height: 150px;
  resize: vertical;
  font-family: 'Courier New', monospace;
  line-height: 1.5;
}

.modal-footer {
  padding: 15px 25px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: 0.2s;
}

.modal-btn-cancel {
  background: #f3f4f6;
  color: #374151;
}

.modal-btn-cancel:hover {
  background: #e5e7eb;
  transform: translateY(-1px);
}

.modal-btn-submit {
  background: #4f46e5;
  color: white;
}

.modal-btn-submit:hover {
  background: #4338ca;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* Click to copy indicator */
#snippetDisplay pre {
  cursor: pointer;
  position: relative;
}

#snippetDisplay pre:hover::before {
  content: '🖱️ Click to copy';
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(79, 70, 229, 0.9);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  z-index: 10;
  animation: fadeIn 0.2s ease;
}

.copy-feedback {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #10b981;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  z-index: 3000;
  animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
  from {
    transform: translateX(100px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}