/* ══════════════════════════════════════════════════════════════════
   AI HISTORY PAGE — fully scoped to .ai-history-page
   DO NOT add rules outside .ai-history-page {}
   References parent app's :root variables for colour consistency.
══════════════════════════════════════════════════════════════════ */

/* ── Local tokens (extend, never override :root) ─────────────── */
.ai-history-page {
  --aih-blue:       #3b82f6;
  --aih-blue-dim:   rgba(59,130,246,0.10);
  --aih-blue-glow:  rgba(59,130,246,0.22);
  --aih-green:      #10b981;
  --aih-green-dim:  rgba(16,185,129,0.10);
  --aih-amber:      #f59e0b;
  --aih-amber-dim:  rgba(245,158,11,0.10);
  --aih-red:        #ef4444;
  --aih-red-dim:    rgba(239,68,68,0.10);
  --aih-purple:     #8b5cf6;
  --aih-purple-dim: rgba(139,92,246,0.10);
  --aih-radius:     10px;
  --aih-radius-lg:  14px;
  --aih-transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
  padding: 0 2px 32px;
}

/* ── Header ──────────────────────────────────────────────────── */
.ai-history-page .aih-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.ai-history-page .aih-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.ai-history-page .aih-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  margin: 0;
}

.ai-history-page .aih-online-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  background: var(--aih-green-dim);
  border: 1px solid rgba(16,185,129,0.25);
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--aih-green);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.ai-history-page .aih-online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--aih-green);
  animation: aihPulse 2s infinite;
}

.ai-history-page .aih-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.ai-history-page .aih-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ai-history-page .aih-last-updated {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: monospace;
  white-space: nowrap;
}

/* ── Shared button ───────────────────────────────────────────── */
.ai-history-page .aih-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--aih-radius);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--aih-transition);
  border: none;
  outline: none;
  white-space: nowrap;
}
.ai-history-page .aih-btn svg { flex-shrink: 0; }

.ai-history-page .aih-btn-ghost {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.ai-history-page .aih-btn-ghost:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: rgba(0,212,170,0.06);
}

.ai-history-page .aih-btn-primary {
  background: linear-gradient(135deg, var(--aih-blue), #2563eb);
  color: #fff;
  box-shadow: 0 0 16px var(--aih-blue-glow);
}
.ai-history-page .aih-btn-primary:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.ai-history-page .aih-btn-danger {
  background: var(--aih-red-dim);
  color: var(--aih-red);
  border: 1px solid rgba(239,68,68,0.25);
}
.ai-history-page .aih-btn-danger:hover {
  background: rgba(239,68,68,0.18);
}

/* spinning class on button icon */
.ai-history-page .aih-spin {
  animation: aihSpin 0.7s linear infinite;
}

/* ── Stats grid ──────────────────────────────────────────────── */
.ai-history-page .aih-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.ai-history-page .aih-stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--aih-radius-lg);
  transition: var(--aih-transition);
  cursor: default;
}
.ai-history-page .aih-stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.ai-history-page .aih-stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-history-page .aih-stat-icon svg { width: 18px; height: 18px; }

.ai-history-page .aih-icon-blue   { background: var(--aih-blue-dim);   color: var(--aih-blue);   }
.ai-history-page .aih-icon-green  { background: var(--aih-green-dim);  color: var(--aih-green);  }
.ai-history-page .aih-icon-amber  { background: var(--aih-amber-dim);  color: var(--aih-amber);  }
.ai-history-page .aih-icon-purple { background: var(--aih-purple-dim); color: var(--aih-purple); }

.ai-history-page .aih-stat-value {
  font-family: 'Syne', sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 2px;
}

.ai-history-page .aih-stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* ── Filter bar ──────────────────────────────────────────────── */
.ai-history-page .aih-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.ai-history-page .aih-search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
}
.ai-history-page .aih-search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}
.ai-history-page .aih-search {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--aih-radius);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  outline: none;
  transition: var(--aih-transition);
}
.ai-history-page .aih-search:focus {
  border-color: var(--aih-blue);
  box-shadow: 0 0 0 3px var(--aih-blue-dim);
}
.ai-history-page .aih-search::placeholder { color: var(--text-muted); }

.ai-history-page .aih-select {
  padding: 8px 30px 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--aih-radius);
  color: var(--text-secondary);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
  transition: var(--aih-transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234a6080' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.ai-history-page .aih-select:focus { border-color: var(--aih-blue); }
.ai-history-page .aih-select option { background: var(--bg-elevated); }

/* ── Table ───────────────────────────────────────────────────── */
.ai-history-page .aih-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--aih-radius-lg);
  overflow: hidden;
}

.ai-history-page .aih-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.ai-history-page .aih-table thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ai-history-page .aih-table thead th:first-child { border-radius: var(--aih-radius-lg) 0 0 0; }
.ai-history-page .aih-table thead th:last-child  { border-radius: 0 var(--aih-radius-lg) 0 0; }

.ai-history-page .aih-table tbody tr {
  transition: var(--aih-transition);
  animation: aihFadeIn 0.25s ease both;
}
.ai-history-page .aih-table tbody tr:hover td {
  background: rgba(59,130,246,0.04);
}
.ai-history-page .aih-table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-secondary);
  vertical-align: middle;
}
.ai-history-page .aih-table tbody tr:last-child td { border-bottom: none; }

.ai-history-page .aih-job-id {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.ai-history-page .aih-task-cell {
  display: flex;
  align-items: center;
  gap: 9px;
}
.ai-history-page .aih-task-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ai-history-page .aih-task-name {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 0.83rem;
}

.ai-history-page .aih-provider {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.ai-history-page .aih-provider svg { width: 12px; height: 12px; }

/* ── Status badges ───────────────────────────────────────────── */
.ai-history-page .aih-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  white-space: nowrap;
}
.ai-history-page .aih-badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.ai-history-page .aih-badge-success {
  background: var(--aih-green-dim);
  color: var(--aih-green);
  border: 1px solid rgba(16,185,129,0.22);
}
.ai-history-page .aih-badge-success .aih-badge-dot { background: var(--aih-green); }

.ai-history-page .aih-badge-failed {
  background: var(--aih-red-dim);
  color: var(--aih-red);
  border: 1px solid rgba(239,68,68,0.22);
}
.ai-history-page .aih-badge-failed .aih-badge-dot { background: var(--aih-red); }

.ai-history-page .aih-badge-processing {
  background: var(--aih-amber-dim);
  color: var(--aih-amber);
  border: 1px solid rgba(245,158,11,0.22);
}
.ai-history-page .aih-badge-processing .aih-badge-dot {
  background: var(--aih-amber);
  animation: aihPulse 1s infinite;
}

.ai-history-page .aih-badge-queue {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.ai-history-page .aih-badge-queue .aih-badge-dot { background: var(--text-muted); }

.ai-history-page .aih-time-cell {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
}

.ai-history-page .aih-duration-cell {
  font-size: 0.78rem;
  color: var(--aih-blue);
  font-family: monospace;
  font-weight: 600;
}

.ai-history-page .aih-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  background: var(--aih-blue-dim);
  border: 1px solid rgba(59,130,246,0.22);
  border-radius: 7px;
  color: var(--aih-blue);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--aih-transition);
  font-family: 'DM Sans', sans-serif;
}
.ai-history-page .aih-action-btn:hover {
  background: rgba(59,130,246,0.18);
  transform: translateY(-1px);
}
.ai-history-page .aih-action-btn svg { width: 12px; height: 12px; }

/* ── Empty state ─────────────────────────────────────────────── */
.ai-history-page .aih-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
}
.ai-history-page .aih-empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}
.ai-history-page .aih-empty-icon svg {
  width: 28px;
  height: 28px;
  color: var(--text-muted);
  opacity: 0.6;
}
.ai-history-page .aih-empty h3 {
  font-family: 'Syne', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 6px;
}
.ai-history-page .aih-empty p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 20px;
  max-width: 260px;
  line-height: 1.6;
}

/* ── Modal overlay ───────────────────────────────────────────── */
.ai-history-page .aih-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6,13,26,0.82);
  z-index: 1200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: aihFadeIn 0.18s ease;
}
.ai-history-page .aih-modal-overlay.open {
  display: flex;
}

.ai-history-page .aih-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(59,130,246,0.08);
  animation: aihSlideUp 0.22s cubic-bezier(0.34,1.56,0.64,1);
}

.ai-history-page .aih-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
  border-radius: 18px 18px 0 0;
}
.ai-history-page .aih-modal-title {
  font-family: 'Syne', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}
.ai-history-page .aih-modal-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--aih-transition);
  flex-shrink: 0;
}
.ai-history-page .aih-modal-close:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}
.ai-history-page .aih-modal-close svg { width: 14px; height: 14px; }

.ai-history-page .aih-modal-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.ai-history-page .aih-modal-meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  color: var(--text-muted);
}
.ai-history-page .aih-modal-meta-item svg { width: 12px; height: 12px; }
.ai-history-page .aih-modal-meta-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.4;
}

.ai-history-page .aih-modal-body {
  padding: 18px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-history-page .aih-modal-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 7px;
}
.ai-history-page .aih-modal-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--aih-radius);
  padding: 14px;
  font-size: 0.82rem;
  line-height: 1.75;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.ai-history-page .aih-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px 20px;
  gap: 10px;
  flex-wrap: wrap;
}
.ai-history-page .aih-token-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--aih-purple-dim);
  border: 1px solid rgba(139,92,246,0.22);
  border-radius: 20px;
  font-size: 0.72rem;
  color: var(--aih-purple);
  font-family: monospace;
}
.ai-history-page .aih-token-chip svg { width: 11px; height: 11px; }

/* ── Scrollbar inside modal ──────────────────────────────────── */
.ai-history-page .aih-modal::-webkit-scrollbar,
.ai-history-page .aih-modal-box::-webkit-scrollbar { width: 4px; }
.ai-history-page .aih-modal::-webkit-scrollbar-thumb,
.ai-history-page .aih-modal-box::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 4px;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .ai-history-page .aih-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 640px) {
  .ai-history-page .aih-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .ai-history-page .aih-stat-card {
    padding: 12px 13px;
  }
  .ai-history-page .aih-table-wrap {
    overflow-x: auto;
  }
  .ai-history-page .aih-table {
    min-width: 560px;
  }
  .ai-history-page .aih-header {
    flex-direction: column;
    gap: 10px;
  }
  .ai-history-page .aih-filter {
    gap: 8px;
  }
  .ai-history-page .aih-search-wrap {
    min-width: 100%;
  }
  .ai-history-page .aih-modal {
    max-height: 92vh;
  }
}
@media (max-width: 400px) {
  .ai-history-page .aih-stats {
    grid-template-columns: 1fr 1fr;
  }
  .ai-history-page .aih-stat-value { font-size: 1.1rem; }
}

/* ── Keyframes (aih-prefixed to avoid global collision) ──────── */
@keyframes aihPulse {
  0%, 100% { opacity: 1;   transform: scale(1);    }
  50%       { opacity: 0.4; transform: scale(0.88); }
}
@keyframes aihSpin {
  to { transform: rotate(360deg); }
}
@keyframes aihFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes aihSlideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}
@keyframes aihRowIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0);    }
}
