/* NAI Official History UI Styles
 * 1:1 replication of NovelAI official history interface
 * Extracted from official HTML snapshot */

/* === VIEW SHELL === */
.view-container {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary, #13152c);
}

.view-container.sf-hidden,
#view-nai-image.sf-hidden {
  display: none !important;
}

body.nai-history-active {
  overflow: hidden;
}

body.nai-history-active > .toasts,
body.nai-history-active > .modal-backdrop {
  z-index: 1200;
}

/* === MAIN CONTAINER === */
.history-toolbar {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary, #1a1b26);
  border-bottom: 1px solid var(--border-color, #2e3141);
  align-items: center;
}

.history-back-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-color, #3e4151);
  border-radius: 6px;
  background: var(--button-bg, #2e3141);
  color: var(--text-primary, #ffffff);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.history-back-btn:hover {
  background: var(--button-hover, #3a3c4e);
  border-color: var(--accent-color, #4a9eff);
}

.history-search-wrapper {
  flex: 1;
  max-width: 400px;
}

.history-search {
  width: 100%;
  padding: 8px 12px;
  background: var(--input-bg, #13152c);
  border: 1px solid var(--border-color, #2e3141);
  border-radius: 6px;
  color: var(--text-primary, #ffffff);
  font-size: 14px;
  font-family: inherit;
}

.history-search:focus {
  outline: none;
  border-color: var(--accent-color, #4a9eff);
}

.history-search::placeholder {
  color: var(--text-secondary, #9ca3af);
}

/* === FILTERS === */
.history-filters {
  display: flex;
  gap: 8px;
}

.history-filter-btn,
.history-sort-btn,
.history-action-btn {
  padding: 8px 16px;
  background: var(--button-bg, #2e3141);
  border: 1px solid var(--border-color, #3e4151);
  border-radius: 6px;
  color: var(--text-primary, #ffffff);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.history-filter-btn:hover,
.history-sort-btn:hover,
.history-action-btn:hover {
  background: var(--button-hover, #3a3c4e);
  border-color: var(--accent-color, #4a9eff);
}

.history-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === GRID LAYOUT === */
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
  height: calc(100vh - 120px);
}

.history-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px;
  color: var(--text-secondary, #9ca3af);
  font-size: 16px;
}

/* === HISTORY ITEM === */
.history-item {
  position: relative;
  cursor: pointer;
  transition: transform 0.2s;
}

.history-item:hover {
  transform: translateY(-2px);
}

.history-item:has(.history-checkbox:checked) .history-thumbnail-wrapper {
  box-shadow: 0 0 0 2px var(--accent-color, #4a9eff);
}

.history-thumbnail-wrapper {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-tertiary, #13152c);
}

.history-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}

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

.history-meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #ffffff;
}

.history-checkbox {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  cursor: pointer;
  z-index: 10;
}

/* === DETAIL PANEL === */
.history-detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  height: 100vh;
  background: var(--bg-secondary, #1a1b26);
  border-left: 1px solid var(--border-color, #2e3141);
  box-shadow: -2px 0 8px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform 0.3s;
}

.history-detail-panel.sf-hidden {
  transform: translateX(100%);
}

.history-detail-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color, #2e3141);
  display: flex;
  justify-content: flex-end;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-primary, #ffffff);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.close-btn:hover {
  color: var(--accent-color, #4a9eff);
}

.history-detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.history-detail-image {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 16px;
}

.meta-section {
  margin-bottom: 24px;
}

.meta-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary, #ffffff);
}

.meta-section p {
  font-size: 14px;
  color: var(--text-secondary, #d1d5db);
  line-height: 1.6;
  word-wrap: break-word;
}

.meta-section dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 14px;
}

.meta-section dt {
  color: var(--text-secondary, #9ca3af);
  font-weight: 500;
}

.meta-section dd {
  color: var(--text-primary, #ffffff);
  margin: 0;
}

.history-detail-actions {
  padding: 16px;
  border-top: 1px solid var(--border-color, #2e3141);
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1;
  padding: 10px 16px;
  background: var(--button-bg, #2e3141);
  border: 1px solid var(--border-color, #3e4151);
  border-radius: 6px;
  color: var(--text-primary, #ffffff);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--button-hover, #3a3c4e);
  border-color: var(--accent-color, #4a9eff);
}

.action-btn.danger {
  background: var(--danger-bg, #dc2626);
  border-color: var(--danger-border, #b91c1c);
}

.action-btn.danger:hover {
  background: var(--danger-hover, #b91c1c);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .history-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 12px;
  }
  
  .history-detail-panel {
    width: 100%;
  }
  
  .history-toolbar {
    flex-wrap: wrap;
  }

  .history-back-btn {
    width: 34px;
    height: 34px;
  }
  
  .history-filters {
    width: 100%;
    overflow-x: auto;
  }
}
