/* ==========================================================================
   sidebar.css — Dark sidebar: brand, search, toolbar, project tree
   UI/UX Pro Max — Fixed left panel with dark gradient
   ========================================================================== */

/* ---------- Sidebar Inner Container ---------- */
.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: var(--space-lg) 0;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, #131B2E 100%);
}

/* ---------- Brand ---------- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 0 var(--space-xl) var(--space-lg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: var(--space-md);
}

.sidebar-brand-logo {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--sidebar-accent) 100%);
  border-radius: var(--radius);
  flex-shrink: 0;
}

.brand-text {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--sidebar-text-bright);
  letter-spacing: -0.02em;
}

.brand-text-sub {
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.3);
  font-weight: 400;
}

/* ---------- Search ---------- */
.sidebar-search {
  padding: 0 var(--space-lg) var(--space-md);
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
  width: 15px;
  height: 15px;
  transition: color var(--transition-fast);
}

.sidebar-search input[type="text"] {
  width: 100%;
  height: 34px;
  padding: var(--space-sm) 30px var(--space-sm) 32px;
  font-size: var(--text-sm);
  color: var(--sidebar-text-bright);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  transition: all var(--transition-fast);
}

.sidebar-search input[type="text"]::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.sidebar-search input[type="text"]:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.sidebar-search input[type="text"]:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--sidebar-accent);
  box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.25);
}

.sidebar-search input[type="text"]:focus + .search-icon,
.sidebar-search input[type="text"]:focus ~ .search-icon {
  color: var(--sidebar-accent);
}

/* Search clear button */
.search-clear-btn {
  position: absolute;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: var(--radius-full);
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.search-clear-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--sidebar-text-bright);
}

/* Search result count */
.search-result-count {
  padding: var(--space-xs) var(--space-lg);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 0.02em;
}

/* Search snippet */
.tree-item-snippet {
  padding: 1px var(--space-md) 2px var(--space-2xl);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: 5px;
}

/* Fulltext toggle */
.fulltext-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.fulltext-toggle:hover {
  color: rgba(255, 255, 255, 0.6);
}

.fulltext-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--sidebar-accent);
  cursor: pointer;
}

/* ---------- Toolbar ---------- */
.sidebar-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg) var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  margin-top: auto;
  background: var(--sidebar-bg);
}
.sidebar-toolbar .sidebar-btn-group {
  margin-left: auto;
}

.sidebar-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 5px 10px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.45);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.sidebar-btn:hover {
  color: var(--sidebar-text-bright);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
}

.sidebar-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.4);
}

.sidebar-btn:active {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(0.97);
}

.sidebar-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.sidebar-btn svg {
  width: 13px;
  height: 13px;
  opacity: 0.7;
}

/* Dropdown menu (export) */
.sidebar-dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 100;
  background: var(--sidebar-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: var(--space-xs);
  min-width: 160px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sidebar-dropdown-item {
  display: block;
  width: 100%;
  padding: 6px 10px;
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  text-align: left;
}

.sidebar-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text-bright);
}

/* ---------- Dark Input (sidebar context) ---------- */
.sidebar-dark-input {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  color: var(--sidebar-text-bright) !important;
}

.sidebar-dark-input:focus {
  border-color: var(--sidebar-accent) !important;
  box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.25) !important;
}

.sidebar-dark-input option {
  background: var(--sidebar-bg);
  color: var(--sidebar-text-bright);
}

/* ---------- Project Tree ---------- */
.sidebar-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--space-sm);
}

/* ---------- Tree Group ---------- */
.tree-group {
  margin-bottom: var(--space-xs);
}

.tree-group-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.35);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
  user-select: none;
}

.tree-group-header:hover {
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.03);
}

.tree-group-header:focus-visible {
  box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.4);
}

.tree-group-header:active {
  background: rgba(255, 255, 255, 0.05);
}

/* Chevron rotation animation */
.tree-group-header .chevron {
  transition: transform var(--transition-fast);
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  opacity: 0.5;
}

.tree-group-header[aria-expanded="false"] .chevron {
  transform: rotate(0deg);
}

.tree-group-header[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}

/* Group count badge */
.group-count {
  margin-left: auto;
  font-size: 10px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 7px;
  border-radius: var(--radius-full);
  line-height: 1.5;
}

/* Smooth collapse animation */
.tree-group-items {
  overflow: hidden;
  transition: max-height var(--transition-slow) ease;
}

.tree-group-header[aria-expanded="false"] + .tree-group-items {
  max-height: 0;
}

.tree-group-header[aria-expanded="true"] + .tree-group-items {
  max-height: 3000px;
}

/* ---------- Tree Item (Project) ---------- */
.tree-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
  min-height: 32px;
  padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-2xl);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--sidebar-text);
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
  margin-left: 2px;
  gap: var(--space-sm);
}

.tree-item:hover {
  background: #334155;
  color: var(--sidebar-text-bright);
}

.tree-item:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(129, 140, 248, 0.5);
}

.tree-item:active {
  background: var(--sidebar-active);
}

.tree-item.active {
  background: rgba(99, 102, 241, 0.12);
  color: var(--sidebar-text-bright);
  border-left-color: var(--primary-500, #6366F1);
  font-weight: 500;
}

.tree-item-name {
  flex: 1;
  min-width: 0;
  line-height: var(--leading-normal);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-item-assignee {
  flex-shrink: 0;
  font-size: 11px;
  color: #64748B;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: auto;
}

.tree-item.active .tree-item-assignee {
  color: rgba(255, 255, 255, 0.55);
}

/* ---------- Tree Item Row (with star) ---------- */
.tree-item-row {
  display: flex;
  align-items: center;
}
.tree-item-row .tree-item {
  flex: 1;
  min-width: 0;
}

/* ---------- Tri-state Button (star / bg / none) ---------- */
.state-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  transition: color 0.15s;
}
/* none 狀態：幾乎透明，hover 才顯現 */
.state-btn[data-state="none"] { color: transparent; }
.tree-item-row:hover .state-btn[data-state="none"] { color: rgba(255, 255, 255, 0.25); }
/* star 狀態：黃色常駐 */
.state-btn.state-star { color: #FBBF24; }
/* bg 狀態：灰色常駐 */
.state-btn.state-bg { color: rgba(255, 255, 255, 0.35); }
/* hover 統一高亮 */
.state-btn:hover { color: #FBBF24 !important; }

/* Star filter active state */
.star-filter-active { color: #FBBF24 !important; }

/* Background filter active state */
.bg-filter-active { color: var(--sidebar-accent) !important; }

/* Background project dimming */
.tree-item-row.tree-item-bg { opacity: 0.4; }
.tree-item-row.tree-item-bg:hover { opacity: 0.7; }

/* Assignee select dropdown below active project */
.tree-item-assignee-select {
  padding: 0 var(--space-md) var(--space-xs) calc(var(--space-2xl) + 4px);
}

.tree-item-assignee-select select {
  width: 100%;
  height: 24px;
  font-size: 11px;
  padding: 1px 4px;
  background: var(--sidebar-surface);
  color: var(--sidebar-text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
}
.tree-item-assignee-select select:hover {
  border-color: rgba(255,255,255,0.2);
}
.tree-item-assignee-select select:focus {
  border-color: var(--sidebar-accent);
  box-shadow: 0 0 0 2px rgba(129,140,248,0.2);
}
.tree-item-assignee-select select option {
  background: var(--sidebar-bg);
  color: var(--sidebar-text-bright);
}

/* ---------- Edit Mode ---------- */

/* Segmented control for edit tabs */
.sidebar-edit-tabs {
  display: flex;
  gap: 1px;
  margin: 0 var(--space-sm) var(--space-md);
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.sidebar-edit-tabs .seg-btn {
  flex: 1;
  padding: 5px 8px;
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  color: rgba(255, 255, 255, 0.4);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.sidebar-edit-tabs .seg-btn:hover {
  color: rgba(255, 255, 255, 0.7);
}

.sidebar-edit-tabs .seg-btn[data-active="true"] {
  background: rgba(255, 255, 255, 0.12);
  color: var(--sidebar-text-bright);
  font-weight: 500;
}

/* Edit group */
.edit-group {
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.edit-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
}

.edit-item-parent {
  font-weight: 600;
}

.edit-item-child {
  padding-left: var(--space-xl);
}

.edit-item-name {
  flex: 1;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-item-parent .edit-item-name {
  color: rgba(255, 255, 255, 0.85);
}

/* Edit popover */
.edit-popover-wrap {
  position: relative;
  flex-shrink: 0;
}

.edit-popover {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 50;
  background: var(--sidebar-bg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: var(--space-xs);
  min-width: 80px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.edit-popover-btn {
  display: block;
  width: 100%;
  padding: 4px 8px;
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  color: rgba(255, 255, 255, 0.6);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
}

.edit-popover-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text-bright);
}

.edit-popover-btn-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger-500);
}

/* Rename form */
.rename-form {
  padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-lg);
}

.rename-form-child {
  padding-left: var(--space-2xl);
}

.rename-form-actions {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

/* Add sub-project */
.edit-add-sub {
  padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-xl);
}

.edit-add-sub-btn {
  color: rgba(255, 255, 255, 0.3) !important;
  font-size: 12px !important;
}

.edit-add-sub-btn:hover {
  color: var(--sidebar-accent) !important;
}

.edit-add-sub-form {
  padding-top: var(--space-xs);
}

/* ---------- Drag Sort Mode ---------- */
.sortable-groups {
  padding: 0 var(--space-xs);
}

.drag-group {
  margin-bottom: var(--space-md);
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-sm);
  padding: var(--space-xs);
}

.drag-group-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.6);
  cursor: grab;
}

.drag-handle {
  cursor: grab;
  flex-shrink: 0;
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-items {
  min-height: 20px;
  padding: var(--space-xs) 0;
}

.drag-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px var(--space-sm) 4px var(--space-xl);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
  cursor: grab;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.drag-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.sortable-ghost {
  opacity: 0.4;
  background: rgba(129, 140, 248, 0.1) !important;
  border-radius: var(--radius-sm);
}

/* ---------- Add Project Panel ---------- */
.sidebar-add-panel {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: var(--space-sm);
}

.add-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-lg);
  font-size: 13px;
  font-weight: 600;
  color: var(--sidebar-text-bright);
}

.icon-btn-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.icon-btn-sm:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-text-bright);
}

.add-panel-body {
  padding: 0 var(--space-lg) var(--space-md);
}

.add-panel-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.4);
  margin: var(--space-sm) 0 var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.add-panel-ai-btn {
  margin-top: var(--space-xs);
  color: var(--sidebar-accent) !important;
  border-color: rgba(129, 140, 248, 0.2) !important;
}

.add-panel-ai-btn:hover {
  background: rgba(129, 140, 248, 0.1) !important;
}

.add-panel-ai-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* Keywords */
.add-panel-kw-input-row {
  display: flex;
  gap: var(--space-xs);
}

.add-panel-kw-input-row input {
  flex: 1;
}

.add-panel-kw-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

.kw-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--sidebar-accent);
  background: rgba(129, 140, 248, 0.12);
  border-radius: var(--radius-full);
}

.kw-tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  padding: 0;
  background: transparent;
  border: none;
  color: rgba(129, 140, 248, 0.6);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.kw-tag-remove:hover {
  color: var(--sidebar-accent);
}

.add-panel-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

/* ---------- Empty State ---------- */
.sidebar-empty {
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
  color: rgba(255, 255, 255, 0.3);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

/* ---------- Footer ---------- */
.sidebar-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: auto;
}

/* ---------- Dark Scrollbar ---------- */
.sidebar-tree::-webkit-scrollbar {
  width: 4px;
}

.sidebar-tree::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-tree::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
}

.sidebar-tree::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

.sidebar-tree {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}
