/* =========================================================
   History Panel — bottom-sheet overlay styles
   ========================================================= */

/* Full-screen overlay backdrop */
.history-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.history-overlay.hidden {
  display: none !important;
}

/* Bottom-sheet panel */
.history-panel {
  background: var(--bg-secondary, #1e1e2e);
  color: var(--text-primary, #cdd6f4);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 600px;
  height: 75vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
  animation: history-slide-up 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}

@keyframes history-slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* Panel header */
.history-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border-color, #313244);
  flex-shrink: 0;
}

.history-panel__title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary, #cdd6f4);
}

.history-panel__header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-panel__edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-color, #89b4fa);
  padding: 6px 10px;
  border-radius: 8px;
  font-family: inherit;
  transition: background 0.18s, opacity 0.18s;
}
.history-panel__edit-btn:hover {
  background: rgba(137, 180, 250, 0.12);
}
.history-panel__edit-btn:active {
  opacity: 0.85;
}

.history-panel--detail .history-panel__edit-btn {
  display: none;
}

.history-panel__close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-muted, #6c7086);
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.18s, background 0.18s;
}
.history-panel__close:hover {
  color: var(--text-primary, #cdd6f4);
  background: rgba(255, 255, 255, 0.07);
}

/* Scrollable content area */
.history-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

/* Loading / empty state */
.history-status {
  text-align: center;
  color: var(--text-muted, #6c7086);
  font-size: 0.9rem;
  padding: 32px 20px;
}

/* ── Conversation List ── */
.history-list {
  display: flex;
  flex-direction: column;
}

.history-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color, #313244);
  transition: background 0.15s;
  position: relative;
}
.history-item.conv-item.selected {
  background: rgba(137, 180, 250, 0.12);
}
.history-item:last-child {
  border-bottom: none;
}
.history-item:hover {
  background: rgba(137, 180, 250, 0.06);
}

.history-item__title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary, #cdd6f4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item__meta {
  font-size: 0.78rem;
  color: var(--text-muted, #6c7086);
}

.history-item__check-wrap {
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  cursor: pointer;
}
.batch-mode .history-item__check-wrap {
  display: flex;
}

.conv-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-color, #89b4fa);
  cursor: pointer;
}

/* ── Conversation Detail ── */
.history-detail {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.history-detail__back {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color, #313244);
  flex-shrink: 0;
}

.history-detail__header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  margin-left: auto;
}

.history-detail__back-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent-color, #89b4fa);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 4px 0;
  font-family: inherit;
}
.history-detail__back-btn:hover {
  opacity: 0.8;
}

.history-detail__title-row {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 120px;
  gap: 4px;
}

.history-detail__conv-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary, #cdd6f4);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-rename-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 2px 6px;
  margin: 0;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.18s ease;
  font-family: inherit;
  border-radius: 6px;
  color: var(--text-primary, #cdd6f4);
}

.history-rename-btn:hover,
.history-rename-btn:focus {
  opacity: 1;
}

.history-detail__conv-title:hover + .history-rename-btn,
.history-detail__title-row:hover .history-rename-btn {
  opacity: 1;
}

.history-rename-input {
  flex: 1;
  min-width: 0;
  display: inline-block;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-primary, #cdd6f4);
  background: var(--bg-primary, #181825);
  border: 1px solid var(--border-color, #313244);
  border-radius: 8px;
  padding: 4px 8px;
  box-sizing: border-box;
}

.history-rename-input:focus {
  outline: none;
  border-color: var(--accent-color, #89b4fa);
}

@media (hover: none) {
  .history-rename-btn {
    opacity: 0.8;
  }
}

@media (pointer: coarse) {
  .history-rename-btn {
    opacity: 0.8;
  }
}

.history-detail__messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}
.history-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}
.history-msg--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.history-msg__bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.history-msg--user .history-msg__bubble {
  background: var(--accent-color, #89b4fa);
  color: var(--bg-primary, #1e1e2e);
  border-bottom-right-radius: 4px;
}
.history-msg--assistant .history-msg__bubble {
  background: var(--bg-primary, #181825);
  color: var(--text-primary, #cdd6f4);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color, #313244);
}

.history-msg__time {
  font-size: 0.7rem;
  color: var(--text-muted, #6c7086);
  margin-top: 3px;
  padding: 0 4px;
}

.history-detail__footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color, #313244);
  flex-shrink: 0;
}

.history-resume-btn {
  width: 100%;
  margin-top: 12px;
  flex-shrink: 0;
  padding: 12px;
  background: var(--accent-color, #89b4fa);
  color: var(--bg-primary, #1e1e2e);
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.18s;
}
.history-resume-btn:hover {
  opacity: 0.88;
}

/* ── Search bar ── */
.history-search {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color, #313244);
  flex-shrink: 0;
}

.history-search__input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #313244);
  background: var(--bg-primary, #181825);
  color: var(--text-primary, #cdd6f4);
  font-size: 0.9rem;
  font-family: inherit;
  box-sizing: border-box;
}

.history-search__input:focus {
  outline: none;
  border-color: var(--accent-color, #89b4fa);
}

.history-search__meta {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted, #a6adc8);
  min-height: 1.2em;
}

/* ── Item layout with delete button ── */
.history-item__content {
  flex: 1;
  min-width: 0;
  padding-right: 40px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item__delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted, #6c7086);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.batch-mode .history-item__delete {
  display: none !important;
}

/* Touch devices: always show delete at reduced opacity */
@media (hover: none) {
  .history-item__delete {
    opacity: 0.8;
  }
  .batch-mode .history-item__delete {
    display: none !important;
  }
}

@media (pointer: coarse) {
  .history-item__delete {
    opacity: 0.8;
  }
}

/* ── Batch mode toolbar ── */
.batch-bar {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color, #313244);
  background: var(--bg-secondary, #1e1e2e);
  position: sticky;
  top: 0;
  z-index: 2;
}

.batch-bar__btn {
  background: var(--bg-primary, #181825);
  border: 1px solid var(--border-color, #313244);
  color: var(--text-primary, #cdd6f4);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s, border-color 0.15s;
}
.batch-bar__btn:hover:not(:disabled) {
  border-color: var(--accent-color, #89b4fa);
}
.batch-bar__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.batch-bar__btn--danger {
  background: rgba(243, 139, 168, 0.15);
  border-color: rgba(243, 139, 168, 0.45);
  color: #f38ba8;
}

.batch-bar__count {
  font-size: 0.84rem;
  color: var(--text-muted, #6c7086);
  min-width: 5em;
  text-align: center;
}

/* ── Message count badge ── */
.history-item__meta-count {
  color: var(--text-muted, #6c7086);
}

/* ── Load more button ── */
.history-load-more {
  width: 100%;
  padding: 14px;
  background: none;
  border: none;
  border-top: 1px solid var(--border-color, #313244);
  color: var(--accent-color, #89b4fa);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  min-height: 44px;
  transition: opacity 0.15s;
}

.history-load-more:hover { opacity: 0.8; }
.history-load-more:active { opacity: 0.6; }

/* ── Empty state ── */
.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  gap: 12px;
}

.history-empty__icon {
  font-size: 2.5rem;
  opacity: 0.4;
}

.history-empty__text {
  font-size: 0.9rem;
  color: var(--text-muted, #6c7086);
  text-align: center;
}

.history-item__rename {
  position: absolute;
  right: 56px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

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