/* ═══════════════════════════════════════════════════════════
   AI Faculty Test UI — Styles
   ═══════════════════════════════════════════════════════════ */

/* ─── CSS Variables ───────────────────────────────────────── */
:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #22263a;
  --bg-sidebar: #13151e;
  --bg-input: #242838;
  --border: #2a2e3e;
  --border-focus: #4f7df9;
  --text: #e4e6ef;
  --text-dim: #8b8fa7;
  --text-hint: #6c7093;
  --accent: #4f7df9;
  --accent-hover: #6a93ff;
  --accent-glow: rgba(79, 125, 249, 0.25);
  --success: #3dd68c;
  --warning: #f5a623;
  --danger: #f44;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 240px;
  --assets-w: 320px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Reset ───────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

body {
  display: flex;
}

/* ─── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ─── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
}

.sidebar-brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand-icon {
  font-size: 32px;
  margin-bottom: 4px;
}

.sidebar-brand h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.beta-tag {
  font-size: 8px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  -webkit-text-fill-color: #fff;
  padding: 1px 4px;
  border-radius: 3px;
  vertical-align: super;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 2px;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-dim);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.nav-btn:hover:not(.disabled) {
  background: var(--bg-card);
  color: var(--text);
}

.nav-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

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

.nav-btn.highlight {
  opacity: 1;
  animation: pulse-glow 1.5s infinite;
}

.nav-icon {
  font-size: 18px;
}

.nav-lock {
  font-size: 12px;
  position: absolute;
  right: 12px;
}

@keyframes pulse-glow {

  0%,
  100% {
    box-shadow: 0 0 0 0 var(--accent-glow);
  }

  50% {
    box-shadow: 0 0 12px 4px var(--accent-glow);
  }
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.settings-btn {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.settings-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ─── Main Content ────────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.page {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  padding: 24px 32px;
}

.page.active {
  display: flex;
}

.page.hidden {
  display: none;
}

.page-header {
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-dim);
  font-size: 13px;
}

/* ─── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.card-hint {
  font-size: 12px;
  color: var(--text-hint);
  margin-bottom: 12px;
}

/* ─── Forms ───────────────────────────────────────────────── */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"],
input[type="password"],
textarea,
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.2s;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-hint);
}

/* ─── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary.disabled,
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-accent {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-accent:hover {
  background: var(--accent);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #000;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 11px;
}

.btn-lg {
  padding: 12px 28px;
  font-size: 15px;
}

/* ─── Upload List ─────────────────────────────────────────── */
.upload-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-entry {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
}

.upload-entry.uploaded {
  border-color: var(--success);
  background: rgba(61, 214, 140, 0.05);
}

.upload-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.upload-entry-title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.upload-entry-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.upload-entry-remove:hover {
  opacity: 1;
}

.upload-entry-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.file-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-picker-input {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  position: relative;
  color: var(--text-dim);
  font-size: 12px;
}

.file-picker-input:hover {
  border-color: var(--accent);
}

.file-picker-input.has-file {
  border-color: var(--success);
  color: var(--success);
  border-style: solid;
}

.file-picker-input input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.upload-status {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.upload-status.success {
  color: var(--success);
}

.upload-status.error {
  color: var(--danger);
}

.upload-status.uploading {
  color: var(--warning);
}

.upload-progress {
  flex: 1;
  height: 4px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}

.empty-state {
  text-align: center;
  padding: 24px;
  color: var(--text-hint);
  font-size: 13px;
}

.empty-state.hidden {
  display: none;
}

/* ─── Screenshots Grid ────────────────────────────────────── */
.screenshots-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.screenshot-slot {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px 10px;
  text-align: center;
  cursor: pointer;
  position: relative;
  font-size: 11px;
  color: var(--text-hint);
  transition: border-color 0.2s;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screenshot-slot:hover {
  border-color: var(--accent);
}

.screenshot-slot.has-file {
  border-color: var(--success);
  border-style: solid;
  color: var(--success);
}

.screenshot-slot input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.screenshot-thumb {
  width: 100%;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 4px;
}

/* ─── Ingestion Status ────────────────────────────────────── */
.ingestion-trigger-card .card-header {
  border-bottom: none;
}

.ingestion-status {
  margin-top: 16px;
}

.ingestion-status.hidden {
  display: none;
}

.job-status-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.job-icon {
  font-size: 20px;
}

.job-info {
  flex: 1;
}

.job-info-title {
  font-weight: 600;
  font-size: 13px;
}

.job-info-status {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.job-progress {
  width: 120px;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}

.job-progress-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.job-progress-bar.processing {
  background: var(--accent);
}

.job-progress-bar.completed {
  background: var(--success);
}

.job-progress-bar.failed {
  background: var(--danger);
}

/* ─── Settings Panel ──────────────────────────────────────── */
.settings-panel {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 60px;
}

.settings-panel.hidden {
  display: none;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.settings-body {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 460px;
  max-height: 80vh;
  overflow-y: auto;
}

.setting-group {
  margin-bottom: 14px;
}

.setting-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setting-group input {
  width: 100%;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  transition: color 0.2s;
}

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

/* ─── Chat Layout ─────────────────────────────────────────── */
#page-chat {
  padding: 0;
}

.chat-layout {
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-title h1 {
  margin-bottom: 0;
}

/* ─── Token Monitor ───────────────────────────────────────── */
.token-monitor {
  display: flex;
  gap: 16px;
  background: var(--bg-input);
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.token-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
}

.token-stat.total {
  border-left: 1px solid var(--border);
  padding-left: 16px;
}

.token-label {
  font-size: 10px;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.token-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--mono);
}

/* ─── Chat Metadata Bar ──────────────────────────────────── */
.chat-meta-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.meta-inline {
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-inline label {
  font-size: 11px;
  color: var(--text-hint);
  text-transform: uppercase;
  font-weight: 600;
  white-space: nowrap;
}

.meta-inline input {
  width: 140px;
  padding: 4px 8px;
  font-size: 12px;
}

/* ─── Chat Messages ───────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome-msg {
  text-align: center;
  padding: 60px 40px;
  color: var(--text-dim);
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.welcome-msg h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.welcome-msg p {
  font-size: 13px;
  max-width: 420px;
  margin: 0 auto;
}

.chat-message {
  max-width: 85%;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 14px;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  max-width: 92%;
}

/* Markdown content styling */
.chat-message.assistant h1 {
  font-size: 18px;
  margin: 12px 0 8px;
}

.chat-message.assistant h2 {
  font-size: 16px;
  margin: 12px 0 6px;
  color: var(--accent);
}

.chat-message.assistant h3 {
  font-size: 14px;
  margin: 10px 0 4px;
}

.chat-message.assistant ul,
.chat-message.assistant ol {
  padding-left: 20px;
  margin: 6px 0;
}

.chat-message.assistant li {
  margin: 3px 0;
}

.chat-message.assistant p {
  margin: 6px 0;
}

.chat-message.assistant strong {
  color: var(--accent);
}

.chat-message.assistant code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 12px;
}

.chat-message.assistant pre {
  background: var(--bg-input);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
}

.chat-message.assistant pre code {
  background: none;
  padding: 0;
}

.chat-message.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}

.chat-message.assistant th,
.chat-message.assistant td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.chat-message.assistant th {
  background: var(--bg-input);
  font-weight: 600;
}

.chat-message.assistant blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-dim);
}

.chat-message.assistant .citations-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.citation-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  padding: 3px 8px;
  border-radius: 4px;
  margin: 2px 4px 2px 0;
  font-size: 11px;
}

/* Loading indicator */
.chat-message.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
}

.loading-dots {
  display: flex;
  gap: 4px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: dot-bounce 1.2s infinite ease-in-out;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot-bounce {

  0%,
  80%,
  100% {
    transform: scale(0.4);
    opacity: 0.4;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ─── Chat Input ──────────────────────────────────────────── */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.chat-input-bar textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  line-height: 1.5;
}

.btn-send {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 18px;
}

.btn-send:disabled {
  opacity: 0.3;
}

/* ─── Media Panel ─────────────────────────────────────────── */
.media-panel {
  width: var(--assets-w);
  min-width: 200px;
  max-width: 70vw;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  position: relative;
}

/* ─── Resize Handle ──────────────────────────────────────── */
.resize-handle {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.2s;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.resize-handle:hover,
.resize-handle.active {
  background: var(--accent);
}

.resize-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: var(--border);
  opacity: 0;
  transition: opacity 0.2s;
}

.resize-handle:hover::after,
.resize-handle.active::after {
  opacity: 1;
  background: #fff;
}

.media-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.media-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.asset-count {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 22px;
  text-align: center;
}

.media-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.media-empty {
  text-align: center;
  color: var(--text-hint);
  font-size: 13px;
  padding: 40px 0;
}

.media-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.media-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.media-card .media-thumb {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.2);
}

.media-card .media-label {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.media-card .media-type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  flex-shrink: 0;
}

.media-type.figure {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-hover);
}

.media-type.model3d {
  background: rgba(6, 182, 212, 0.15);
  color: #06b6d4;
}

/* ─── Inline Media Viewer ─────────────────────────────────── */
.media-viewer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  min-width: 250px;
  max-width: 80vw;
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
}

.viewer-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  transition: background 0.2s;
  z-index: 12;
}

.viewer-resize-handle:hover,
.viewer-resize-handle.active {
  background: var(--accent);
}

.viewer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.viewer-close:hover {
  background: var(--danger);
  border-color: transparent;
}

.viewer-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  position: relative;
}

.viewer-content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
}

.viewer-content model-viewer {
  width: 100%;
  height: 100%;
  min-height: 300px;
  border-radius: var(--radius);
  --poster-color: transparent;
}

/* ─── Spinner / Loading Cursor ────────────────────────────── */
body.loading-cursor,
body.loading-cursor * {
  cursor: progress !important;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Toast Notifications ─────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  animation: toast-in 0.3s ease;
  max-width: 360px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.toast.success {
  background: var(--success);
  color: #000;
}

.toast.error {
  background: var(--danger);
}

.toast.info {
  background: var(--accent);
}

.toast.warning {
  background: var(--warning);
  color: #000;
}

@keyframes toast-in {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ─── Misc ────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

.tags-input {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 36px;
  align-items: center;
}

.tags-input input {
  border: none;
  background: transparent;
  flex: 1;
  min-width: 80px;
  padding: 4px;
  font-size: 12px;
  outline: none;
  box-shadow: none !important;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-glow);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.tag-remove {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}

.description-field textarea {
  width: 100%;
  min-height: 60px;
  resize: vertical;
}

/* ─── Mic Button (Voice Input) ───────────────────────────── */
.btn-mic {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-mic:hover {
  border-color: var(--accent);
  color: var(--text);
}

.btn-mic.listening {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
  color: var(--danger);
  animation: mic-pulse 1.5s infinite;
}

@keyframes mic-pulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3);
  }

  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
}

/* ─── TTS Button (Voice Output) ──────────────────────────── */
.tts-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 5px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.tts-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tts-btn.playing {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* ─── 3D Model Loading Overlay ───────────────────────────── */
.model-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 0.6s ease;
}

.model-loading-content {
  text-align: center;
  padding: 32px 24px;
  max-width: 340px;
}

.model-loading-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.model-loading-msg {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 20px;
  animation: msg-fade 3s ease-in-out infinite;
}

.model-loading-quote {
  font-size: 12px;
  color: var(--text-hint);
  font-style: italic;
  line-height: 1.6;
  animation: msg-fade 3s ease-in-out infinite;
  animation-delay: 1.5s;
  opacity: 0.6;
}

.model-loading-quote .quote-author {
  font-style: normal;
  font-weight: 600;
  color: var(--accent);
}

@keyframes msg-fade {

  0%,
  100% {
    opacity: 0.4;
  }

  50% {
    opacity: 1;
  }
}

/* ─── 3D Model Pan Controls ──────────────────────────────── */
.model-pan-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.model-pan-controls:hover {
  opacity: 1;
}

.pan-row {
  display: flex;
  gap: 2px;
}

.pan-btn {
  width: 32px;
  height: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.pan-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.pan-btn:active {
  transform: scale(0.9);
}

/* ─── Mobile Sidebar Toggle (desktop hidden) ─────────────── */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  width: 40px;
  height: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.sidebar-toggle:hover {
  background: var(--accent);
  border-color: var(--accent);
}

/* Sidebar overlay backdrop */
.sidebar-overlay {
  display: none;
}

.sidebar-overlay.active {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
}

/* Mobile Assets Toggle (desktop hidden) */
.btn-assets-toggle {
  display: none;
}

/* Mobile Panel Close Button */
.mobile-panel-close {
  display: none;
}

/* ─── KaTeX overflow fix ─────────────────────────────────── */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
}

/* ─── Responsive — Tablet (≤ 768px) ──────────────────────── */
@media (max-width: 768px) {

  /* Sidebar: slide off-screen, toggle-able */
  #sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 200;
    transition: left 0.3s ease;
  }

  #sidebar.mobile-open {
    left: 0;
  }

  /* Show hamburger toggle */
  .sidebar-toggle {
    display: flex;
  }

  /* Main content takes full width */
  #main-content {
    width: 100%;
  }

  /* Ingestion page: tighter padding + room for hamburger */
  .page {
    padding: 16px;
    padding-top: 60px;
  }

  /* Token monitor: hide on mobile */
  .token-monitor {
    display: none;
  }

  /* Hide button labels — icon-only on mobile */
  .btn-label {
    display: none;
  }

  /* Compact buttons */
  .btn.btn-sm {
    padding: 5px 8px;
    font-size: 12px;
  }

  /* Show mobile assets toggle */
  .btn-assets-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
  }

  .btn-assets-toggle .asset-badge {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    min-width: 18px;
    text-align: center;
  }

  /* Hide media panel by default */
  .media-panel {
    display: none;
  }

  /* Media panel as full-screen overlay */
  .media-panel.mobile-open {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 200;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0;
    border-left: none;
    background: var(--bg);
  }

  .media-panel.mobile-open .mobile-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    z-index: 10;
    transition: all 0.2s;
  }

  .media-panel.mobile-open .mobile-panel-close:hover {
    background: var(--danger);
    border-color: transparent;
  }

  /* Hide resize handle */
  .resize-handle {
    display: none;
  }

  /* Chat messages wider */
  .chat-message {
    max-width: 95%;
  }

  .chat-message.assistant {
    max-width: 95%;
  }

  /* Chat header compact */
  .chat-header {
    padding: 12px 16px;
    padding-left: 56px;
  }

  .chat-title h1 {
    font-size: 18px;
  }

  /* Chat input tighter */
  .chat-input-bar {
    padding: 12px 16px;
  }

  /* Media viewer full-screen */
  .media-viewer {
    width: 100% !important;
    max-width: 100vw;
  }

  .viewer-resize-handle {
    display: none;
  }

  /* Settings dialog fit mobile */
  .settings-body {
    width: 90vw;
    max-width: 460px;
  }

  /* Meta grid: 2 columns */
  .meta-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

/* ─── Responsive — Phone (≤ 480px) ───────────────────────── */
@media (max-width: 480px) {

  .page-header h1 {
    font-size: 18px;
  }

  .page-header p {
    font-size: 12px;
  }

  .card {
    padding: 14px;
  }

  /* Single column grids */
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .upload-entry-fields {
    grid-template-columns: 1fr;
  }

  .screenshots-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Chat */
  .chat-messages {
    padding: 12px;
  }

  .welcome-msg {
    padding: 40px 16px;
  }

  .welcome-msg h3 {
    font-size: 16px;
  }

  /* Chat meta bar compact */
  .meta-inline input {
    width: 100px;
  }

  /* Page padding */
  .page {
    padding: 12px;
    padding-top: 56px;
  }
}