/* ═══════════════════════════════════════════════════════════
   CHATTO — CHAT SIDEBAR  (single source of truth)
   Used by: chat.html · agent-market.html · connection-hub.html
   ═══════════════════════════════════════════════════════════ */

/* ── App layout shell ── */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* ══════════════════════════════════════
   SIDEBAR SHELL
══════════════════════════════════════ */
.sidebar {
  /* geometry */
  position: fixed;
  left: 0; top: 0;
  width: 240px;
  height: 100vh;
  z-index: 200;

  /* visuals */
  background: var(--sidebar-bg, #F2F2F2);
  border-right: 1px solid var(--border, #E8E8E8);

  /* layout — three rows: header / content / footer */
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* collapse animation */
  transition: width 220ms ease;
}

[data-theme="dark"] .sidebar {
  background: #13151F;
  border-color: #2A2D3A;
}

/* Collapsed state — icons only */
.sidebar.collapsed { width: 80px; }

/* ── Main content shifts when sidebar collapses ── */
.sidebar-main {
  flex: 1;
  margin-left: 240px;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: margin-left 220ms ease;
}
.sidebar.collapsed ~ .sidebar-main { margin-left: 72px; }

/* ══════════════════════════════════════
   HEADER
══════════════════════════════════════ */
.sidebar-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 24px 12px;
  gap: 8px;
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  overflow: hidden;
  min-width: 0;
  flex: 1;
}
.sidebar-logo > svg { flex-shrink: 0; width: 18px; height: 18px; }
.sidebar-logo-text {
  display: flex;
  align-items: center;
  gap: 0;
  white-space: nowrap;
  transition: opacity 180ms ease;
}
.sidebar-logo-mti  { font-family: 'Poppins', sans-serif; font-size: 13px; font-weight: 700; color: #797979; letter-spacing: 0.2px; }
.sidebar-logo-chatto { font-family: 'Poppins', sans-serif; font-size: 13px; font-weight: 700; color: #00A73C; letter-spacing: 0.2px; }

/* Toggle button */
.sidebar-toggle {
  flex-shrink: 0;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer;
  border-radius: 6px; padding: 0;
  color: var(--text-muted, #8C8C8C);
  transition: background 180ms ease, color 180ms ease;
}
.sidebar-toggle:hover  { background: var(--hover-neutral, #E9E9E8); color: var(--text-primary, #202123); }
.sidebar-toggle:focus-visible { outline: 2px solid var(--primary, #00A73C); outline-offset: 1px; }
.sidebar-toggle svg,
.sidebar-toggle i { width: 16px !important; height: 16px !important; display: block; }

[data-theme="dark"] .sidebar-toggle { color: #64748B; }
[data-theme="dark"] .sidebar-toggle:hover { background: #1F2235; color: #F1F3F9; }

/* Collapsed: hide entire logo, center toggle */
.sidebar.collapsed .sidebar-logo { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 20px 0 16px; }

/* ══════════════════════════════════════
   CONTENT  (scrollable middle section)
══════════════════════════════════════ */
.sidebar-content {
  flex: 1;
  min-height: 0;          /* allow flex child to shrink below content size */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Search row ── */
.sidebar-search {
  flex-shrink: 0;
  padding: 0 8px 6px;
}
.sidebar-search-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
  color: var(--text-muted, #8C8C8C); font-size: 14px;
  transition: background 180ms ease;
}
.sidebar-search-row:hover { background: var(--hover-neutral, #E9E9E8); color: var(--text-primary, #202123); }
.sidebar-search-row input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 14px; font-family: 'Open Sans', sans-serif;
  color: var(--text-primary, #202123); cursor: pointer;
}
.sidebar-search-row input::placeholder { color: var(--text-muted, #8C8C8C); }
.sidebar-search-row input:focus { cursor: text; }
.sidebar-search-row i,
.sidebar-search-row svg { width: 16px !important; height: 16px !important; display: block; flex-shrink: 0; }

/* ── Nav ── */
nav.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
nav.sidebar-nav::-webkit-scrollbar { width: 3px; }
nav.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border, #E8E8E8); border-radius: 2px; }

/* ── Nav item ── */
.sidebar-nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  width: 100%; height: 40px;
  padding: 0 16px; border-radius: 12px;
  border: none; background: transparent; cursor: pointer;
  font-size: 14px; font-weight: 400;
  font-family: 'Open Sans', sans-serif;
  color: var(--text-secondary, #666666);
  text-decoration: none; text-align: left;
  white-space: nowrap; overflow: hidden;
  transition: background 160ms ease, color 160ms ease;
  margin-bottom: 2px;
}
.sidebar-nav-item:hover  { background: #F2F2F2; color: var(--text-primary, #202123); }
.sidebar-nav-item.active { background: #ECECEC; color: var(--text-primary, #202123); font-weight: 600; }
.sidebar-nav-item:focus-visible { outline: 2px solid var(--primary, #00A73C); outline-offset: -2px; }

[data-theme="dark"] .sidebar-nav-item:hover  { background: #1F2235; color: #F1F3F9; }
[data-theme="dark"] .sidebar-nav-item.active { background: #22253A; color: #F1F3F9; }

/* Nav item icon */
.sidebar-nav-icon {
  flex-shrink: 0;
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted, #8C8C8C);
}
.sidebar-nav-item:hover .sidebar-nav-icon,
.sidebar-nav-item.active .sidebar-nav-icon { color: var(--text-primary, #202123); }
[data-theme="dark"] .sidebar-nav-item:hover .sidebar-nav-icon,
[data-theme="dark"] .sidebar-nav-item.active .sidebar-nav-icon { color: #F1F3F9; }

.sidebar-nav-icon i,
.sidebar-nav-icon svg { width: 16px !important; height: 16px !important; display: block; }

/* Nav item label */
.sidebar-nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* Nav item right action (e.g. "+" for Agent Market) */
.sidebar-nav-action {
  flex-shrink: 0;
  width: 22px; height: 22px;
  display: none;
  align-items: center; justify-content: center;
  border-radius: 6px; border: none; background: transparent;
  cursor: pointer; font-size: 18px; font-weight: 300;
  line-height: 1; color: var(--text-muted, #8C8C8C);
  transition: background 160ms ease, color 160ms ease;
  padding: 0;
}
.sidebar-nav-item:hover .sidebar-nav-action { display: flex; }
.sidebar-nav-action:hover { background: var(--hover-neutral, #E9E9E8); color: var(--text-primary, #202123); }

/* Chevron (accordion) */
.sidebar-nav-chevron {
  flex-shrink: 0; color: var(--text-muted, #8C8C8C);
  transition: transform 220ms ease;
}
.sidebar-nav-chevron i,
.sidebar-nav-chevron svg { width: 14px !important; height: 14px !important; display: block; }
.sidebar-nav-item.open .sidebar-nav-chevron { transform: rotate(90deg); }

/* ── Accordion children ── */
.sidebar-nav-children {
  max-height: 0; overflow: hidden;
  transition: max-height 260ms cubic-bezier(.4,0,.2,1);
}
.sidebar-nav-item.open + .sidebar-nav-children { max-height: 600px; }

.sidebar-nav-children-inner {
  margin: 2px 0 4px 20px;
  border-left: 1.5px solid var(--border, #E8E8E8);
  padding: 2px 0 2px 8px;
}
[data-theme="dark"] .sidebar-nav-children-inner { border-color: #2A2D3A; }

/* ── Conversation items ── */
.sidebar-conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer;
  border-left: 2px solid transparent; margin-bottom: 1px;
  transition: background 160ms ease;
}
.sidebar-conv-item:hover  { background: var(--hover-neutral, #E9E9E8); }
.sidebar-conv-item.active { border-left-color: var(--primary, #00A73C); }
[data-theme="dark"] .sidebar-conv-item.active { border-left-color: #4ADE80; }

.sidebar-conv-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--border, #E8E8E8); flex-shrink: 0;
}
.sidebar-conv-item.active .sidebar-conv-dot { background: var(--primary, #00A73C); }

.sidebar-conv-name {
  flex: 1; font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-secondary, #666666);
}
.sidebar-conv-item:hover .sidebar-conv-name,
.sidebar-conv-item.active .sidebar-conv-name { color: var(--text-primary, #202123); }
.sidebar-conv-item.active .sidebar-conv-name { font-weight: 600; }

.sidebar-conv-actions { display: none; align-items: center; gap: 2px; flex-shrink: 0; }
.sidebar-conv-item:hover .sidebar-conv-actions { display: flex; }

.sidebar-conv-act {
  width: 20px; height: 20px; border: none; background: transparent;
  color: var(--text-muted, #8C8C8C); cursor: pointer; border-radius: 4px;
  display: flex; align-items: center; justify-content: center; padding: 0;
  transition: all 160ms ease;
}
.sidebar-conv-act:hover { background: var(--hover-neutral, #E9E9E8); color: var(--text-primary, #202123); }
.sidebar-conv-act.danger:hover { background: var(--danger-light, #fff1f0); color: var(--danger, #ff4d4f); }
.sidebar-conv-act i,
.sidebar-conv-act svg { width: 12px !important; height: 12px !important; display: block; }

/* ── Sub "New chat" button ── */
.sidebar-new-sub {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px;
  font-size: 12.5px; font-weight: 500; color: var(--text-muted, #8C8C8C);
  cursor: pointer; transition: background 160ms ease, color 160ms ease;
  border: none; background: transparent; width: 100%; text-align: left;
  margin-bottom: 2px;
}
.sidebar-new-sub:hover { background: var(--hover-neutral, #E9E9E8); color: var(--primary, #00A73C); }
.sidebar-new-sub i,
.sidebar-new-sub svg { width: 13px !important; height: 13px !important; display: block; }

/* ── Empty state ── */
.sidebar-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  gap: 8px;
  color: var(--text-muted, #8C8C8C);
}
.sidebar-empty.hidden { display: none; }
.sidebar-empty-icon { opacity: 0.4; }
.sidebar-empty-icon i,
.sidebar-empty-icon svg { width: 32px !important; height: 32px !important; display: block; }
.sidebar-empty-title { font-size: 12px; font-weight: 600; color: var(--text-muted, #8C8C8C); }
.sidebar-empty-sub   { font-size: 12px; line-height: 1.5; color: var(--text-muted, #8C8C8C); }

/* ══════════════════════════════════════
   FOOTER
══════════════════════════════════════ */
footer.sidebar-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 0px 20px;
  border-top: 1px solid #E5E5E5;
}
[data-theme="dark"] footer.sidebar-footer { border-color: #2A2D3A; }

.sidebar-footer-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; height: 40px;
  padding: 0 16px; border-radius: 12px;
  border: none; background: transparent; cursor: pointer;
  font-size: 13.5px; font-weight: 400;
  font-family: 'Open Sans', sans-serif;
  color: var(--text-secondary, #666666);
  text-align: left; white-space: nowrap; overflow: hidden;
  transition: background 160ms ease, color 160ms ease;
  text-decoration: none;
}
.sidebar-footer-item:hover  { background: #F2F2F2; color: var(--text-primary, #202123); }
.sidebar-footer-item:focus-visible { outline: 2px solid var(--primary, #00A73C); outline-offset: -2px; }

[data-theme="dark"] .sidebar-footer-item { color: #9AA5B4; }
[data-theme="dark"] .sidebar-footer-item:hover { background: #1F2235; color: #F1F3F9; }

.sidebar-footer-icon {
  flex-shrink: 0; width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted, #8C8C8C);
}
.sidebar-footer-item:hover .sidebar-footer-icon { color: var(--text-primary, #202123); }
.sidebar-footer-icon i,
.sidebar-footer-icon svg { width: 16px !important; height: 16px !important; display: block; }

/* ══════════════════════════════════════
   COLLAPSED STATE — icons only, centered
══════════════════════════════════════ */
.sidebar.collapsed .sidebar-logo            { display: none; }
.sidebar.collapsed .sidebar-search          { display: none; }
.sidebar.collapsed .sidebar-nav-label,
.sidebar.collapsed .sidebar-nav-action,
.sidebar.collapsed .sidebar-nav-chevron     { display: none; }
.sidebar.collapsed .sidebar-nav-item        { justify-content: center; padding: 0; gap: 0; border-radius: 10px; }
.sidebar.collapsed .sidebar-nav-item:hover,
.sidebar.collapsed .sidebar-nav-item.active { background: #22253A; }
.sidebar.collapsed nav.sidebar-nav          { padding: 2px 0px 8px; }
.sidebar.collapsed .sidebar-nav-children   { display: none; }
.sidebar.collapsed .sidebar-empty          { display: none; }
.sidebar.collapsed .sidebar-footer-item    { justify-content: center; padding: 0; gap: 0; border-radius: 10px; }
.sidebar.collapsed footer.sidebar-footer   { padding: 12px 0px 20px; }
/* Hide text label only — NOT the icon span (.sidebar-footer-icon) */
.sidebar.collapsed .sidebar-footer-item > span:not(.sidebar-footer-icon) { display: none; }

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
@media (max-width: 1024px) {
  .sidebar { width: 72px; }
  .sidebar.expanded { width: 240px; }
  .sidebar-main { margin-left: 72px; }
  .sidebar.expanded ~ .sidebar-main { margin-left: 240px; }

  .sidebar .sidebar-logo            { display: none; }
  .sidebar .sidebar-search          { display: none; }
  .sidebar .sidebar-nav-label,
  .sidebar .sidebar-nav-action,
  .sidebar .sidebar-nav-chevron     { display: none; }
  .sidebar .sidebar-nav-item        { justify-content: center; padding: 0; gap: 0; }
  .sidebar .sidebar-nav-children   { display: none; }
  .sidebar .sidebar-footer-item    { justify-content: center; padding: 0; gap: 0; }
  /* Hide text label only — NOT the icon span (.sidebar-footer-icon) */
  .sidebar .sidebar-footer-item > span:not(.sidebar-footer-icon) { display: none; }
}

@media (max-width: 767px) {
  .sidebar { transform: translateX(-100%); width: 240px; }
  .sidebar.expanded { transform: translateX(0); }
  .sidebar-main { margin-left: 0; }
}

/* ══════════════════════════════════════
   CONTENT AREA (non-fixed usage)
   agent-market uses .market-main,
   connection-hub uses .main,
   chat uses .main-content
══════════════════════════════════════ */
/* ── Content areas sit to the right of the fixed sidebar ── */
.main-content {
  margin-left: 240px;
  width: calc(100% - 240px);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left 220ms ease, width 220ms ease;
}
.market-main,
.main {
  margin-left: 240px;
  width: calc(100% - 240px);
  transition: margin-left 220ms ease, width 220ms ease;
}

/* Collapsed adjustments — all three page variants */
.sidebar.collapsed ~ .main-content,
.sidebar.collapsed ~ .market-main,
.sidebar.collapsed ~ .main {
  margin-left: 72px;
  width: calc(100% - 72px);
}
