/* sidebar.css — Asset Browser sidebar styles */

/* ── App body shell (sidebar + main side-by-side) ──────────────────────────── */

#app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  width: 100%;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */

.sidebar {
  width: 280px;
  min-width: 160px;
  max-width: 600px;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

/* ── Sidebar resize handle ──────────────────────────────────────────────────── */

.sidebar-resize-handle {
  width: 3px;
  flex-shrink: 0;
  cursor: col-resize;
  position: relative;
  background: transparent;
  transition: background .12s;
  z-index: 10;
}

/* Nubbin — short grip pill centered on the handle */
.sidebar-resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 28px;
  border-radius: 99px;
  background: var(--gray-400, #9ca3af);
  opacity: .35;
  transition: opacity .15s;
}

.sidebar-resize-handle:hover::after {
  opacity: .65;
}

.sidebar-resize-handle.dragging {
  background: var(--accent, #C4622A);
}

.sidebar-resize-handle.dragging::after {
  opacity: 0;
}

/* Prevent text selection while dragging */
body.sidebar-resizing {
  user-select: none;
  cursor: col-resize;
}

/* ── Sidebar header ─────────────────────────────────────────────────────────── */

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  background: var(--primary);
  color: var(--white);
  flex-shrink: 0;
  height: 48px;
  box-sizing: border-box;
}

.sidebar-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
  color: rgba(255,255,255,.9);
  flex: 1;
}

/* ── Refresh button ─────────────────────────────────────────────────────────── */

.sidebar-refresh-btn {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius-sm);
  color: var(--white);
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, opacity .15s;
  width: 28px;
  height: 28px;
}

.sidebar-refresh-btn:hover    { background: rgba(255,255,255,.25); }
.sidebar-refresh-btn:disabled { opacity: .5; cursor: default; }

.sidebar-refresh-btn svg { width: 14px; height: 14px; }

.sidebar-refresh-btn.spinning svg {
  animation: spin .7s linear infinite;
}

/* ── Filter + menu buttons (shared active style) ────────────────────────────── */

.sidebar-filter-btn,
.sidebar-menu-btn {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius-sm);
  color: var(--white);
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s ease, border-color .2s ease;
  width: 28px;
  height: 28px;
}

.sidebar-filter-btn { position: relative; }

.sidebar-filter-btn:hover,
.sidebar-menu-btn:hover { background: rgba(255,255,255,.25); }

.sidebar-filter-btn.active,
.sidebar-menu-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

.sidebar-filter-btn svg,
.sidebar-menu-btn svg { width: 14px; height: 14px; }

.sidebar-filter-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--accent);
  color: var(--white);
  font-size: 0.58rem;
  font-weight: 700;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border: 1.5px solid var(--primary);
}

.sidebar-filter-btn.active .sidebar-filter-badge {
  background: var(--white);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Slide-in panels (filter + menu) ────────────────────────────────────────── */

.sidebar-filter-panel,
.sidebar-menu-panel {
  flex-shrink: 0;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  transition: max-height .22s ease, opacity .18s ease, padding .2s ease;
}

.sidebar-filter-panel {
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 10px;
}

.sidebar-filter-panel.open {
  max-height: 400px;
  opacity: 1;
  pointer-events: auto;
  padding: 10px;
}

.sidebar-menu-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 10px;
}

.sidebar-menu-panel.open {
  max-height: 600px;
  opacity: 1;
  pointer-events: auto;
  padding: 8px 10px;
}

/* ── Menu panel content ──────────────────────────────────────────────────────── */

.sidebar-menu-section-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-400);
  padding: 2px 0 6px;
}

.sidebar-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--gray-700);
  user-select: none;
  transition: background .1s;
}

.sidebar-menu-item:hover { background: var(--gray-50); }

.sidebar-menu-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.sf-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sf-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--gray-400);
}

.sf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.sf-chip {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--gray-300);
  background: var(--white);
  color: var(--gray-600);
  cursor: pointer;
  transition: background .1s, color .1s, border-color .1s;
  font-family: inherit;
  line-height: 1.5;
}

.sf-chip:hover {
  border-color: var(--primary-light);
  color: var(--primary);
  background: var(--primary-50);
}

/* Possession / Infra — single-select: active = primary */
[data-filter-type="possession"] .sf-chip.active,
[data-filter-type="infra"] .sf-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

/* Lifecycle — multi-select: each stage has its badge colour when active */
[data-filter-type="lifecycle"] .sf-chip.active               { background: var(--primary);   border-color: var(--primary);   color: #fff; }
[data-filter-type="lifecycle"] .sf-chip[data-value="Active"].active         { background: var(--green);    border-color: var(--green);    color: #fff; }
[data-filter-type="lifecycle"] .sf-chip[data-value="Inventory"].active      { background: var(--primary);  border-color: var(--primary);  color: #fff; }
[data-filter-type="lifecycle"] .sf-chip[data-value="Pre-Deployment"].active { background: #0e7490;         border-color: #0e7490;         color: #fff; }
[data-filter-type="lifecycle"] .sf-chip[data-value="For Repair"].active     { background: var(--yellow);   border-color: var(--yellow);   color: #fff; }
[data-filter-type="lifecycle"] .sf-chip[data-value="For Upgrade"].active    { background: var(--purple);   border-color: var(--purple);   color: #fff; }
[data-filter-type="lifecycle"] .sf-chip[data-value="For Parts"].active      { background: #b45309;         border-color: #b45309;         color: #fff; }
[data-filter-type="lifecycle"] .sf-chip[data-value="Decommissioned"].active { background: var(--red);      border-color: var(--red);      color: #fff; }
[data-filter-type="lifecycle"] .sf-chip[data-value="Disposed of"].active    { background: var(--gray-500); border-color: var(--gray-500); color: #fff; }

.sf-clear-btn {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--gray-400);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: color .1s, background .1s;
}

.sf-clear-btn:hover { color: var(--red); background: var(--red-bg); }

/* ── Search input ───────────────────────────────────────────────────────────── */

.sidebar-search {
  padding: 8px;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
  position: relative;
}

.sidebar-search input {
  width: 100%;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 10px;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
  transition: border-color .15s;
  background: var(--gray-50);
}

.sidebar-search input:focus {
  border-color: var(--primary);
  background: var(--white);
}

.sidebar-search-clear {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color .15s, background .15s;
}

.sidebar-search-clear:hover {
  color: var(--gray-700);
  background: var(--gray-200);
}

/* ── Tree scroll area ───────────────────────────────────────────────────────── */

.sidebar-tree {
  flex: 1;
  overflow-y: scroll;
  overflow-x: hidden;
  padding: 4px 0;
  will-change: scroll-position;
  contain: layout paint;
}

/* ── Tree loading/empty states ──────────────────────────────────────────────── */

.sb-loading,
.sb-empty {
  padding: 20px 16px;
  font-size: 0.8rem;
  color: var(--gray-400);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Customer row (level 1) ─────────────────────────────────────────────────── */

.sb-customer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  cursor: pointer;
  user-select: none;
  transition: background .12s;
  white-space: nowrap;
  overflow: hidden;
  border-bottom: 1px solid transparent;
}

.sb-customer:hover    { background: #eef2f9; }
.sb-customer.expanded { background: #f0f4fb; border-bottom: 1px solid var(--gray-200); }

.sb-customer-chevron {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--gray-400);
  transition: transform .2s;
}

.sb-customer.expanded .sb-customer-chevron {
  transform: rotate(90deg);
  color: var(--primary);
}

.sb-customer-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--primary);
  opacity: .7;
}

.sb-customer-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-800);
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.sb-customer-count {
  font-size: 0.7rem;
  color: var(--gray-400);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  background: var(--gray-100);
  border-radius: 10px;
  padding: 1px 6px;
}

/* ── Asset list (level 2 container) ─────────────────────────────────────────── */

.sb-asset-list {
  display: none;
  flex-direction: column;
  border-left: 2px solid #d0ddf0;
  margin-left: 20px;
  margin-bottom: 2px;
}

.sb-asset-list.visible { display: flex; }

.sb-asset-loading,
.sb-asset-empty {
  padding: 7px 12px;
  font-size: 0.76rem;
  color: var(--gray-400);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Asset row (level 2) ────────────────────────────────────────────────────── */

.sb-asset {
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: background .1s;
  border-left: 3px solid transparent;
  margin-left: -2px;
}

.sb-asset:hover  { background: #eef2f9; }

.sb-asset.active {
  background: #e8eef9;
  border-left-color: var(--primary);
}

.sb-asset-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-asset.active .sb-asset-name { color: var(--primary); }

/* ── Asset meta row (badges + type) ─────────────────────────────────────────── */

.sb-asset-meta-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.sb-asset-type {
  font-size: 0.68rem;
  color: var(--gray-400);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Mini status badges ──────────────────────────────────────────────────────── */

.sb-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}

.sb-poss-it   { background: var(--green-bg);  color: var(--green);  border-color: #86efac; }
.sb-poss-user { background: var(--yellow-bg); color: var(--yellow); border-color: #fde047; }
.sb-infra     { background: var(--gray-100);  color: var(--gray-600); border-color: var(--gray-400); }

.sb-user-last     { background: #f0f9ff; color: #0369a1; border-color: #7dd3fc; font-weight: 500; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.sb-user-assigned { background: #fdf4ff; color: #7e22ce; border-color: #d8b4fe; font-weight: 500; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.sb-user-same     { background: #f0fdf4; color: #15803d; border-color: #86efac; font-weight: 500; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }

.sb-lc-predeployment { background: #cffafe; color: #0e7490; border-color: #67e8f9; }
.sb-lc-active        { background: var(--green-bg);   color: var(--green);   border-color: #86efac; }
.sb-lc-inventory     { background: var(--primary-50); color: var(--primary); border-color: #93c5fd; }
.sb-lc-repair        { background: var(--yellow-bg);  color: var(--yellow);  border-color: #fde047; }
.sb-lc-upgrade       { background: var(--purple-bg);  color: var(--purple);  border-color: #c4b5fd; }
.sb-lc-parts         { background: #fff3e0;           color: #b45309;        border-color: #fcd34d; }
.sb-lc-decommissioned{ background: var(--red-bg);     color: var(--red);     border-color: #fca5a5; }
.sb-lc-disposed      { background: var(--gray-100);   color: var(--gray-600);border-color: var(--gray-300); }
.sb-lc-unknown       { background: var(--gray-100);   color: var(--gray-500);border-color: var(--gray-200); }

/* ── Mini spinner (reuses @keyframes spin from main.css) ────────────────────── */

.sb-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

/* ── Menu sub-sections ──────────────────────────────────────────────────────── */

.sidebar-menu-subsection { border-top: 1px solid var(--gray-100); }
.sidebar-menu-subsection:first-child { border-top: none; }

.sidebar-menu-subsection-header {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: none; border: none; padding: 6px 2px;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--gray-400); cursor: pointer;
  font-family: inherit; text-align: left; user-select: none;
  transition: color .12s;
}
.sidebar-menu-subsection-header:hover { color: var(--gray-600); }

.subsection-chevron { width: 12px; height: 12px; flex-shrink: 0; transition: transform .2s; }
.sidebar-menu-subsection.open .subsection-chevron { transform: rotate(180deg); }

.sidebar-menu-subsection-body {
  overflow: hidden;
  max-height: 0;
}
/* Only animate subsection collapse/expand after the panel has fully opened */
.sidebar-menu-panel.ready .sidebar-menu-subsection-body {
  transition: max-height .2s ease;
}
.sidebar-menu-subsection.open .sidebar-menu-subsection-body { max-height: 200px; }

/* ── Checkbox rows (inline wrap) ────────────────────────────────────────────── */
.sidebar-menu-checkbox-row { display: flex; flex-wrap: wrap; gap: 2px 4px; padding-bottom: 4px; }

/* ── Label + control rows ───────────────────────────────────────────────────── */
.sidebar-menu-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.sidebar-menu-row-label { font-size: 0.72rem; color: var(--gray-500); white-space: nowrap; flex-shrink: 0; }

.sidebar-menu-select {
  font-size: 0.72rem; font-family: inherit; color: var(--gray-700);
  background: var(--white); border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm); padding: 2px 4px;
  cursor: pointer; outline: none; flex: 1;
  transition: border-color .15s;
}
.sidebar-menu-select:focus { border-color: var(--primary); }

/* ── Sort chips ─────────────────────────────────────────────────────────────── */
.sidebar-sort-chips { display: flex; flex-wrap: wrap; gap: 4px; padding-bottom: 6px; }

.sidebar-sort-chip {
  font-size: 0.68rem; font-weight: 600; padding: 2px 7px;
  border-radius: 4px; border: 1px solid var(--gray-300);
  background: var(--white); color: var(--gray-500);
  cursor: pointer; font-family: inherit; line-height: 1.5;
  transition: background .1s, color .1s, border-color .1s;
}
.sidebar-sort-chip:hover { border-color: var(--primary-light); color: var(--primary); background: var(--primary-50); }
.sidebar-sort-chip.active { background: var(--primary); border-color: var(--primary); color: var(--white); }

/* ── Menu panel footer (remember toggle) ───────────────────────────────────── */
.sidebar-menu-footer {
  border-top: 1px solid var(--gray-100);
  padding-top: 4px;
  margin-top: 2px;
}

.sidebar-menu-remember {
  font-size: 0.72rem;
  color: var(--gray-500);
  padding: 3px 2px;
}

.sidebar-menu-remember input[type="checkbox"] {
  accent-color: var(--primary);
  width: 13px;
  height: 13px;
}

/* ── Filter panel footer (remember toggle) ──────────────────────────────────── */
.sf-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 2px;
}

.sf-remember-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--gray-400);
  cursor: pointer;
  user-select: none;
}

.sf-remember-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 13px;
  height: 13px;
  cursor: pointer;
}

/* ── Billable count badge ───────────────────────────────────────────────────── */
.sb-customer-billable {
  font-size: 0.7rem; font-variant-numeric: tabular-nums;
  background: var(--green-bg); color: var(--green);
  border-radius: 10px; padding: 1px 6px; flex-shrink: 0;
}

/* ── Mobile: sidebar overlays content ───────────────────────────────────────── */

@media (max-width: 700px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 64px;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
    width: 280px;
    min-width: 280px;
  }

  #app-main {
    width: 100%;
  }
}
