/* ── history.css ──────────────────────────────────────────────────────────────
   Session History sidebar panel — all styles in one place.
   Loaded by index.html after styles.css.
   Uses the same CSS variables as the rest of the app.
   ────────────────────────────────────────────────────────────────────────── */


/* ── Wrapper ─────────────────────────────────────────────────────────────── */

.chat-history-wrap {
  margin: 0 12px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  flex-shrink: 0;
  transition: border-color 0.2s;
}

.chat-history-wrap:has(.ch-open) {
  border-color: var(--border-hi);
}

/* Hide when sidebar is collapsed */
.sidebar.collapsed .chat-history-wrap {
  display: none;
}


/* ── Header row ──────────────────────────────────────────────────────────── */

.ch-header {
  display: flex;
  align-items: center;
}

.ch-toggle-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  background: none;
  border: none;
  color: var(--text-mid);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
  user-select: none;
}

.ch-toggle-btn:hover {
  color: var(--text);
}

.ch-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.ch-toggle-btn:hover .ch-icon {
  opacity: 1;
}

.ch-label {
  flex: 1;
}

.ch-chevron {
  width: 10px;
  height: 6px;
  flex-shrink: 0;
  opacity: 0.4;
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.15s;
}

.ch-toggle-btn:hover .ch-chevron {
  opacity: 0.7;
}

.ch-toggle-btn[aria-expanded="true"] .ch-chevron {
  transform: rotate(180deg);
  opacity: 0.7;
}


/* ── Collapsible panel ───────────────────────────────────────────────────── */

.ch-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  border-top: 0px solid var(--border);
}

.ch-panel.ch-open {
  max-height: 280px;
  border-top-width: 1px;
  overflow-y: auto;
}

/* Scrollbar */
.ch-panel::-webkit-scrollbar       { width: 3px; }
.ch-panel::-webkit-scrollbar-track { background: transparent; }
.ch-panel::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 4px; }


/* ── Session list ────────────────────────────────────────────────────────── */

.ch-list {
  padding: 4px 0 6px;
}


/* ── Empty state ─────────────────────────────────────────────────────────── */

.ch-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 12px;
  color: var(--text-dim);
  font-size: 11px;
  text-align: center;
}

.ch-empty svg {
  width: 18px;
  height: 18px;
  opacity: 0.3;
}


/* ── Individual session row ──────────────────────────────────────────────── */

.ch-item {
  display: flex;
  align-items: center;
  position: relative;
  transition: background 0.12s;
  border-radius: 0;
}

.ch-item:hover {
  background: var(--surface-hover);
}

/* Active / currently loaded session */
.ch-item-active {
  background: rgba(var(--accent-rgb), 0.06);
}

.ch-item-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  opacity: 0.7;
}

.ch-item-active:hover {
  background: rgba(var(--accent-rgb), 0.09);
}


/* ── Row body (clickable area) ───────────────────────────────────────────── */

.ch-item-body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  min-width: 0;
}


/* ── Subject colour dot ──────────────────────────────────────────────────── */

.ch-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.9;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.15);
}


/* ── Text meta ───────────────────────────────────────────────────────────── */

.ch-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ch-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.ch-item-active .ch-title {
  color: var(--text);
  font-weight: 600;
}

.ch-sub {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  letter-spacing: 0.01em;
}


/* ── Delete button ───────────────────────────────────────────────────────── */

.ch-del {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  border-radius: 6px;
  margin-right: 6px;
}

.ch-del svg {
  width: 12px;
  height: 12px;
}

.ch-item:hover .ch-del {
  opacity: 1;
}

.ch-del:hover {
  color: var(--danger);
  background: rgba(212, 90, 90, 0.08);
}


/* ── Divider between sessions (subtle) ──────────────────────────────────── */

.ch-item + .ch-item {
  border-top: 1px solid var(--border);
}


/* ── Loading shimmer ─────────────────────────────────────────────────────── */

.ch-loading-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  opacity: 0.5;
}

.ch-shimmer-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-hi);
  flex-shrink: 0;
  animation: ch-shimmer 1.4s ease-in-out infinite;
}

.ch-shimmer-line {
  height: 9px;
  border-radius: 4px;
  background: var(--border-hi);
  animation: ch-shimmer 1.4s ease-in-out infinite;
}

.ch-shimmer-line.ch-sl-wide  { width: 70%; }
.ch-shimmer-line.ch-sl-short { width: 40%; margin-top: 4px; }

@keyframes ch-shimmer {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.9; }
}


/* ── "Auto-saved" indicator — tiny pill shown briefly after save ──────────── */

.ch-autosave-pill {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 7px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.ch-autosave-pill.visible {
  opacity: 1;
}


/* ── Three-dot menu button ───────────────────────────────────────────────── */

.ch-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  border-radius: 6px;
  margin-right: 6px;
}

.ch-item .ch-more-btn {
  opacity: 1;
}

.ch-more-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

/* Keep visible when menu is open for this item */
.ch-item .ch-more-btn.active {
  opacity: 1;
  color: var(--text);
  background: var(--surface-hover);
}


/* ── Pinned session row ──────────────────────────────────────────────────── */

.ch-item-pinned {
  background: rgba(var(--accent-rgb), 0.04);
}

.ch-item-pinned .ch-title {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ch-pin-badge {
  display: inline-flex;
  align-items: center;
  color: var(--text-mid);
  flex-shrink: 0;
  opacity: 0.75;
  margin-right: 2px;
}


/* ── Rename input ────────────────────────────────────────────────────────── */

.ch-rename-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 6px;
  outline: none;
  line-height: 1.4;
}

.ch-rename-input:focus {
  border-color: var(--accent);
}


/* ── Context menu ────────────────────────────────────────────────────────── */

.ch-ctx-menu {
  position: fixed;
  z-index: 10000;
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  padding: 4px;
  min-width: 180px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.2);
  opacity: 0;
  transform: scale(0.95) translateY(-4px);
  transform-origin: top right;
  transition: opacity 0.15s ease, transform 0.15s cubic-bezier(0.34, 1.3, 0.64, 1);
  pointer-events: none;
}

.ch-ctx-menu.ch-ctx-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

.ch-ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 450;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}

.ch-ctx-item:hover {
  background: var(--surface-hover);
}

.ch-ctx-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--text-mid);
  width: 15px;
  height: 15px;
}

.ch-ctx-icon svg {
  width: 15px;
  height: 15px;
}

.ch-ctx-label {
  flex: 1;
}

/* Danger item (delete) */
.ch-ctx-danger {
  color: var(--danger);
}

.ch-ctx-danger .ch-ctx-icon {
  color: var(--danger);
}

.ch-ctx-danger:hover {
  background: rgba(212, 90, 90, 0.08);
}

/* Divider before delete */
.ch-ctx-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 4px;
}

/* Disabled menu item — coming soon */
.ch-ctx-item.ch-ctx-disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

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

.ch-sidebar-toast {
  position: sticky;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 4px 8px 8px;
  padding: 8px 13px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 450;
  color: var(--text-mid);
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  backdrop-filter: blur(10px);
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  margin-top: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, max-height 0.18s ease, margin 0.18s ease, padding 0.18s ease;
  transform: translateY(4px);
}

.ch-sidebar-toast.show {
  opacity: 1;
  max-height: 60px;
  margin: 4px 8px 8px;
  padding: 8px 13px;
  transform: translateY(0);
}

.ch-sidebar-toast-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.ch-sidebar-toast-icon svg {
  width: 13px;
  height: 13px;
}

.ch-sidebar-toast.st-success { border-color: rgba(100, 200, 120, 0.25); }
.ch-sidebar-toast.st-success .ch-sidebar-toast-icon { color: #64c878; }

.ch-sidebar-toast.st-error { border-color: rgba(239, 68, 68, 0.3); }
.ch-sidebar-toast.st-error .ch-sidebar-toast-icon { color: var(--danger); }

.ch-sidebar-toast.st-info .ch-sidebar-toast-icon { color: var(--text-dim); }
