/* ---------- Sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

/* ---------- Search ---------- */

.sidebar-search {
  display: flex;
  align-items: center;
  padding: 6px;
  position: relative;
  flex-shrink: 0;
}

.sidebar-search-icon {
  position: absolute;
  left: 14px;
  font-size: 12px;
  pointer-events: none;
  opacity: 0.5;
}

.sidebar-search-input {
  width: 100%;
  height: 28px;
  padding: 4px 24px 4px 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.sidebar-search-input:focus {
  border-color: var(--accent-border);
}

.sidebar-search-input::placeholder {
  color: var(--text);
  opacity: 0.4;
}

.sidebar-search-clear {
  position: absolute;
  right: 10px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  opacity: 0.5;
  padding: 0 4px;
}

.sidebar-search-clear:hover {
  opacity: 1;
}

/* ---------- Content ---------- */

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ---------- Sections ---------- */

.sidebar-section {
  padding: 4px 0;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  opacity: 0.7;
  cursor: pointer;
  user-select: none;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.sidebar-section-header:hover {
  opacity: 1;
}

.sidebar-section-chevron {
  font-size: 10px;
  width: 12px;
  text-align: center;
}

/* ---------- File Item ---------- */

.sidebar-file {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding-right: 8px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
  position: relative;
}

.sidebar-file:hover {
  background: var(--accent-bg);
}

.sidebar-file.active {
  background: var(--accent-bg);
  border-left: 2px solid var(--accent);
}

.sidebar-file-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-file-label {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-file.active .sidebar-file-label {
  font-weight: 500;
  color: var(--text-h);
}

.sidebar-open-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  opacity: 0.6;
}

/* ---------- Folder Item ---------- */

.sidebar-folder {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding-right: 8px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.sidebar-folder:hover {
  background: var(--accent-bg);
}

.sidebar-folder-chevron {
  font-size: 10px;
  width: 12px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-folder-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-folder-label {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-folder-count {
  font-size: 10px;
  color: var(--text);
  opacity: 0.4;
  flex-shrink: 0;
}

/* ---------- Drag & Drop ---------- */

.sidebar-file.dragging {
  opacity: 0.4;
}

.sidebar-folder.drop-target {
  background: var(--accent-bg);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  border-radius: 4px;
}

.sidebar-section-header.drop-target {
  background: var(--accent-bg);
}

.sidebar-files-area {
  min-height: 8px;
}

/* ---------- Templates ---------- */

.sidebar-template {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  cursor: pointer;
  transition: background 0.1s;
}

.sidebar-template:hover {
  background: var(--accent-bg);
}

.sidebar-template-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-template-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-template-name {
  font-size: 12px;
  color: var(--text);
  line-height: 1.2;
}

.sidebar-template-desc {
  font-size: 10px;
  color: var(--text);
  opacity: 0.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

/* ---------- Empty State ---------- */

.sidebar-empty {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text);
  opacity: 0.4;
  font-style: italic;
}

/* ---------- Rename Input ---------- */

.sidebar-rename-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--accent-border);
  border-radius: 2px;
  background: var(--bg);
  color: var(--text-h);
  font-size: 12px;
  padding: 1px 4px;
  outline: none;
  font-family: inherit;
}

/* ---------- Footer ---------- */

.sidebar-footer {
  display: flex;
  gap: 4px;
  padding: 6px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-footer-btn {
  flex: 1;
  height: 26px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.1s, background 0.1s;
}

.sidebar-footer-btn:hover {
  color: var(--accent);
  background: var(--accent-bg);
}

/* ---------- Resize Handle ---------- */

.sidebar-resize {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}

.sidebar-resize:hover::after {
  content: '';
  position: absolute;
  top: 0;
  right: 3px;
  width: 2px;
  height: 100%;
  background: var(--accent);
  opacity: 0.5;
}

/* ---------- Context Menu ---------- */

.sidebar-context-menu {
  position: fixed;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 4px;
  z-index: 300;
  min-width: 160px;
}

.sidebar-context-menu button {
  display: block;
  width: 100%;
  padding: 5px 10px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.sidebar-context-menu button:hover {
  background: var(--accent-bg);
  color: var(--text-h);
}

.sidebar-context-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.sidebar-context-label {
  padding: 3px 10px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text);
  opacity: 0.5;
  text-transform: uppercase;
}

.sidebar-context-danger {
  color: var(--error) !important;
}

/* ---------- Responsive: Mobile Drawer ---------- */

@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 85vw !important;
    max-width: 320px;
    z-index: 400;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    animation: sidebar-slide-in 0.2s ease-out;
  }

  @keyframes sidebar-slide-in {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
  }

  .sidebar-file {
    height: 44px;
  }

  .sidebar-folder {
    height: 44px;
  }

  .sidebar-template {
    height: 44px;
  }

  .sidebar-search-input {
    height: 36px;
    font-size: 14px;
  }

  .sidebar-resize {
    display: none;
  }
}

/* Mobile sidebar backdrop — rendered from App.tsx */
.sidebar-backdrop {
  display: none;
}

@media (max-width: 767px) {
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 399;
    animation: sidebar-backdrop-in 0.2s ease-out;
  }

  @keyframes sidebar-backdrop-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}
