/* ── History Side Panel (Left) ─────────────────────────────────────────── */

.history-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.history-panel-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-panel-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.history-panel-body {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.history-panel-body::-webkit-scrollbar { width: 4px; }
.history-panel-body::-webkit-scrollbar-track { background: transparent; }
.history-panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Section headers ──────────────────────────────────────────────────── */
.history-section-header {
  padding: 10px 14px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-sub);
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 1;
}

/* ── History item ─────────────────────────────────────────────────────── */
.history-item {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.history-item:last-child {
  border-bottom: none;
}

.history-item-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 20px;
}

.history-item-meta {
  font-size: 0.68rem;
  color: var(--text-sub);
  margin-top: 2px;
}

.history-item-preview {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Delete button ────────────────────────────────────────────────────── */
.history-item-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

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

.history-item-del:hover {
  color: var(--c1);
  background: rgba(248, 113, 113, 0.1);
}

/* ── Empty state ──────────────────────────────────────────────────────── */
.history-empty {
  padding: 14px;
  font-size: 0.75rem;
  color: var(--text-sub);
  text-align: center;
}

/* ── Toggle button (collapse/expand) ──────────────────────────────────── */
.history-toggle {
  position: fixed;
  top: 50%;
  left: 220px;
  transform: translateY(-50%);
  width: 14px;
  height: 48px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  color: var(--text-sub);
  font-size: 0.65rem;
  transition: left 0.15s, color 0.15s;
}

.history-toggle:hover {
  color: var(--text-primary);
}

/* ── Collapsed state ──────────────────────────────────────────────────── */
.history-panel.collapsed {
  width: 0;
  border-right: none;
  overflow: visible;
}

.history-panel.collapsed .history-panel-header,
.history-panel.collapsed .history-panel-body {
  display: none;
}

.history-panel.collapsed ~ .history-toggle {
  left: 0;
}

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .history-panel {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: 260px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  .history-panel.mobile-open {
    transform: translateX(0);
  }

  /* Collapsed state on mobile: still allow opening */
  .history-panel.collapsed {
    width: 260px;
    border-right: 1px solid var(--border);
    overflow: hidden;
  }

  .history-panel.collapsed .history-panel-header,
  .history-panel.collapsed .history-panel-body {
    display: flex;
    flex-direction: column;
  }
  .history-panel.collapsed .history-panel-body {
    flex: 1;
    overflow-y: auto;
  }

  /* Toggle button becomes a floating hamburger */
  .history-toggle {
    position: fixed;
    top: calc(var(--topbar-h) + 8px);
    left: 8px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    z-index: 65;
    font-size: 0.85rem;
    transform: none;
    transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1), color 0.15s;
  }

  .history-toggle.shifted {
    left: 268px;
  }

  /* Override collapsed sibling selector on mobile */
  .history-panel.collapsed ~ .history-toggle {
    left: 8px;
  }
  .history-panel.collapsed ~ .history-toggle.shifted {
    left: 268px;
  }

  /* Backdrop overlay */
  .history-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 55;
  }

  .history-backdrop.visible {
    display: block;
  }
}
