/* ============================================================
   TELEGRAM-STYLE CHAT FOLDERS
   Horizontal chip row above DM/room lists + mobile bottom nav +
   folder-management modal.
   ============================================================ */

/* ── Folder chip row ─────────────────────────────────────────── */
.folder-chip-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 12px 10px;
  margin: 0 -12px 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 5;
  justify-content: space-evenly;
}
.folder-chip-row::-webkit-scrollbar { display: none; }
.folder-chip-row-sidebar {
  margin: 8px -8px 0;
  padding: 4px 8px 8px;
  border-bottom: none;
  background: transparent;
  position: static;
}

.folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 14px 12px;
  background: var(--bg-primary);
  border: none;
  color: #a7a7a7;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.22s ease, color 0.22s ease, border-color 0.22s ease, transform 0.24s cubic-bezier(.2,.86,.24,1), box-shadow 0.24s ease;
  line-height: 1.2;
  position: relative;
  transform: translate3d(0, 0, 0);
}
.folder-chip:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transform: translate3d(0, -1px, 0);
}
.folder-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
  transform: translate3d(0, -1px, 0);

}
.folder-chip i { font-size: 12px; }
.folder-chip-name { display: inline-block; }
.folder-chip-count {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px 0px 6px;
  margin-left: 2px;
  line-height: 16px;
  transition: background 0.22s ease, color 0.22s ease, transform 0.22s ease;
}
.folder-chip:not(.active) .folder-chip-count {
  background: var(--accent);
  color: #fff;
}
.folder-chip.active .folder-chip-count {
  background: #fff;
  color: var(--accent);
  transform: translate3d(0, 0, 0) scale(1.02);
}
.folder-chip-manage {
  padding: 6px 10px;
  color: var(--text-muted);
}
.folder-chip-manage:hover { color: var(--accent); }

/* ── Navigation rail / folder tab bar ──────────────────────── */
/* Mobile: premium bottom tab bar                               */
.mobile-bottom-nav {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  background: var(--bg-primary);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 50;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 18px rgba(0, 0, 0, 0.22);
}
.mobile-bottom-nav::-webkit-scrollbar { display: none; }
.mobile-bottom-nav .folder-chip-row {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  position: static;
  flex: 1;
  justify-content: space-around;
  touch-action: pan-x;
  gap: 0;
  overflow: visible;
}



/* Hide bottom nav when a chat is open (mobile and desktop) */
#rooms-resize-handle {
  display: none;
}

@media (max-width: 959px) {
  body.in-chat .mobile-bottom-nav {
    display: none !important;
  }

  /* ── Mobile tab bar: vertical chip (icon top, label below) ── */
  .mobile-bottom-nav .folder-chip {
    flex: 1;
    flex-direction: column;
    min-width: 75px;
    max-width: 90px;
    height: 64px;
    padding: 10px 6px 8px;
    border: none;
    border-radius: 0;
    gap: 8px;
    justify-content: center;
    align-items: center;
    text-align: center;
    white-space: normal;
    position: relative;
    background: transparent;
    color: var(--text-muted);
    transform: none;
    box-shadow: none;
    transition: color 0.2s ease;
  }

  /* Pill indicator behind the icon for active chip */
  .mobile-bottom-nav .folder-chip::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%) scaleX(0.25);
    width: 79px;
    height: 55px;
    border-radius: 8px;
    background: var(--accent);
    opacity: 0;
    transition: transform 0.28s cubic-bezier(.2, .86, .24, 1), opacity 0.22s ease;
    pointer-events: none;
  }

  .mobile-bottom-nav .folder-chip.active::before {
    transform: translateX(-50%) scaleX(1);
    opacity: 0.16;
  }

  .mobile-bottom-nav .folder-chip:hover {
    background: transparent;
    color: var(--text-secondary);
    transform: none;
    box-shadow: none;
  }

  .mobile-bottom-nav .folder-chip.active {
    background: transparent;
    border-color: transparent;
    color: var(--accent);
    font-weight: 600;
    transform: none;
  }

  .mobile-bottom-nav .folder-chip i {
    font-size: 17px;
    line-height: 1;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    transition: transform 0.22s cubic-bezier(.2, .86, .24, 1);
  }

  .mobile-bottom-nav .folder-chip.active i {
    transform: translateY(-1px) scale(1.12);
  }

  .mobile-bottom-nav .folder-chip-name {
    display: block;
    max-width: 78px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.2;
    position: relative;
    z-index: 1;
  }

  .mobile-bottom-nav .folder-chip-count {
    position: absolute;
    top: 5px;
    left: calc(50% + 6px);
    min-width: 16px;
    padding: 1px 5px;
    font-size: 9px;
    line-height: 14px;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    z-index: 2;
    transform: none;
  }

  /* Keep badge accent on active (unlike desktop which inverts) */
  .mobile-bottom-nav .folder-chip.active .folder-chip-count {
    background: var(--accent);
    color: #fff;
    transform: none;
  }

  .mobile-bottom-nav .folder-chip-manage {
    flex: 0 0 52px;
    height: 64px;
    border-radius: 0;
    flex-direction: column;
    gap: 4px;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    padding: 10px 4px 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    min-width: 52px;
    max-width: 64px;
    transform: none;
  }

  .mobile-bottom-nav .folder-chip-manage:hover {
    color: var(--accent);
    background: transparent;
    transform: none;
  }

  .mobile-bottom-nav .folder-chip-manage i {
    font-size: 20px;
    position: relative;
    z-index: 1;
  }
}

/* ── Folder-management modal ────────────────────────────────── */
.folders-manager-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 16px;
  animation: folders-fade 0.15s ease-out both;
}
@keyframes folders-fade { from { opacity: 0; } to { opacity: 1; } }
.folders-manager-modal {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 14px;
  border: 1px solid var(--border);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  animation: folders-pop 0.2s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes folders-pop {
  from { transform: scale(0.92) translateY(10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.folders-manager-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.folders-manager-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.folders-manager-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
}
.folders-manager-close:hover { color: var(--accent); }
.folders-manager-body {
  padding: 10px 14px;
  overflow-y: auto;
  flex: 1;
}
.folders-manager-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 18px;
  text-align: center;
}
.folders-manager-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 8px 6px;
}
.folders-manager-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background 0.15s;
}
.folders-manager-row.is-hidden {
  opacity: 0.72;
}
.folders-manager-row:hover { background: var(--bg-tertiary); }
.folders-manager-row.is-dragging {
  opacity: 0.56;
  background: var(--bg-tertiary);
}
.folders-manager-row.drag-over-before {
  box-shadow: inset 0 2px 0 var(--accent);
}
.folders-manager-row.drag-over-after {
  box-shadow: inset 0 -2px 0 var(--accent);
}
.folders-manager-row-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.folders-manager-drag-handle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: grab;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
}
.folders-manager-drag-handle:hover {
  background: var(--bg-primary);
  color: var(--accent);
}
.folders-manager-drag-handle:active {
  cursor: grabbing;
}
.folders-manager-row-info > i {
  font-size: 16px;
  color: var(--accent);
  flex-shrink: 0;
}
.folders-manager-row-info > div {
  min-width: 0;
  flex: 1;
}
.folders-manager-row-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folders-manager-row-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.folders-manager-row-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.folders-manager-row-actions .btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.folders-manager-row-actions .btn-ghost:hover { background: var(--bg-primary); color: var(--accent); }
.folders-manager-row-actions .btn-ghost.danger:hover { color: #ef4444; }
.folders-manager-row-actions .btn-ghost[disabled] {
  opacity: 0.32;
  cursor: not-allowed;
  pointer-events: none;
}
.folders-manager-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.folders-manager-footer .btn-accent,
.folders-manager-footer .btn-ghost {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.folders-manager-footer .btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.folders-manager-footer .btn-accent:hover { filter: brightness(1.1); }
.folders-manager-footer .btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.folders-manager-footer .btn-ghost:hover { background: var(--bg-tertiary); }

/* Folder item picker (inherits .folders-manager-* styles) */
.folder-picker-body { padding: 8px 14px; }
.folder-picker-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 10px 6px 4px;
}
.folder-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s;
}
.folder-picker-row:hover { background: var(--bg-tertiary); }
.folder-picker-row input[type="checkbox"] { accent-color: var(--accent); }
.folder-picker-row i { color: var(--text-muted); width: 14px; text-align: center; }
.folder-picker-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* ── RTL tweaks ──────────────────────────────────────────────── */
[dir="rtl"] .folder-chip-row { direction: rtl; }
[dir="rtl"] .folder-chip-count { margin-left: 0; margin-right: 2px; }
[dir="rtl"] .folders-manager-footer { justify-content: flex-start; }

/* ══════════════════════════════════════════════════════════════
   DESKTOP 3-COLUMN LAYOUT  (≥ 960px)
   Left: navigation rail (folder tabs)
   Middle: chat list (rooms-screen)
   Right: chat pane (chat-screen)
   ══════════════════════════════════════════════════════════════ */
@media (min-width: 960px) {

  /* ── App shell: horizontal flex container ── */
  #app-shell {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: fixed;
    inset: 0;
  }
  .folder-chip:hover {  color: var(--bg-primary); }

  /* ── Navigation rail: vertical icon column ── */
  .mobile-bottom-nav {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    flex-direction: column;
    width: 90px;
    height: 100%;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    border-top: none;
    padding: 10px 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    justify-content: flex-start;
    align-items: center;
    background: #61626d;
    z-index: 1;
  }
  .mobile-bottom-nav::-webkit-scrollbar { display: none; }

  /* Chip row becomes a vertical stack inside the rail */
  .mobile-bottom-nav .folder-chip-row {
    flex-direction: column;
    padding: 6px 0;
    gap: 12px;
    margin: 0;
    width: 100%;
    flex: 0;
    justify-content: flex-start;
    align-items: center;
    border-bottom: none;
    overflow: visible;
  }

  /* Each folder chip: square icon button with label below */
  .mobile-bottom-nav .folder-chip {
    flex-direction: column;
    width: 100px;
    height: 60px;
    padding: 8px 4px 6px;
    border: none;
    gap: 4px;
    font-size: 10.5px;
    line-height: 1.2;
    text-align: center;
    justify-content: center;
    white-space: normal;
    overflow: hidden;
    background: #61626d;
  }
  .mobile-bottom-nav .folder-chip i {
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
  }
  .mobile-bottom-nav .folder-chip-name {
    display: block;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: normal;
    line-height: 21px;
  }
  .mobile-bottom-nav .folder-chip-count {
    position: absolute;
    top: 4px;
    right: 19px;
    min-width: 16px;
    padding: 1px 4px;
    font-size: 9px;
  }
  .mobile-bottom-nav .folder-chip {
    position: relative;
  }
  .mobile-bottom-nav .folder-chip-manage {
    width: 64px;
    height: 44px;
    border-radius: 14px;
    flex-direction: column;
    gap: 3px;
    justify-content: center;
    font-size: 18px;
    padding: 4px;
    border: none;
  }

  /* ── Rooms screen: fixed-width list column ── */
  #rooms-screen {
    position: relative !important;
    display: flex !important;
    flex: 0 0 320px;
    width: 320px;
    height: 100%;
    overflow: hidden;
    border-right: 1px solid var(--border);
    padding-bottom: 0;  /* no fixed-nav offset needed on desktop */
  }

  #rooms-resize-handle {
    display: block;
    width: 5px;
    flex-shrink: 0;
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s ease, opacity 0.15s ease;
    margin: 0 -3px;
    position: relative;
    z-index: 2;
  }

  #rooms-resize-handle:hover,
  #rooms-resize-handle.dragging {
    background: var(--accent);
    opacity: 0.5;
  }

  #rooms-screen.rooms-resizing {
    transition: none !important;
  }

  /* ── Chat screen: fills remaining width ── */
  #chat-screen {
    position: relative !important;
    display: flex !important;
    flex: 1;
    min-width: 0;
    height: 100%;
  }

  /* ── Chat empty state: centered placeholder ── */
  #chat-empty-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    isolation: isolate;
    overflow: hidden;
    flex: 1;
    gap: 12px;
    padding: 40px;
    background: var(--bg-primary-dark, var(--bg-primary));
  }
  #chat-empty-state::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('/assets/bg/pattern.svg');
    background-repeat: repeat;
    background-size: 420px auto;
    opacity: 0.07;
    pointer-events: none;
    z-index: 0;
  }
  #chat-empty-state > * {
    position: relative;
    z-index: 1;
  }
  body.ui-ready:not(.in-chat) #chat-empty-state { display: flex; }
  body.ui-ready:not(.in-chat) #chat-screen .chat-header { display: none !important; }
  body.ui-ready:not(.in-chat) .chat-body { display: none !important; }

  /* Back-button: hidden on desktop (no full-screen nav needed) */
  .header-back-btn { display: none; }

  /* Header: slight adjustment for no back button */
  .chat-header { padding-left: 12px; }
}
