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

:root {
  --bg: #111111;
  --bg-elevated: #191919;
  --bg-input: #1e1e1e;
  --surface: #242424;
  --border: #2a2a2a;
  --border-focus: #454545;
  --text: #ececec;
  --text-secondary: #888888;
  --text-dim: #555555;
  --accent: #e8e8e8;
  --accent-hover: #ffffff;
  --progress-bg: #1a1a1a;
  --progress-bar: #d4d4d4;
  --error: #e55a5a;
  --success: #5ae87a;
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 180ms ease;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── Auth Overlay ─────────────────────────────────────── */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(24px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 300ms ease;
}

.auth-overlay.hidden { display: none; }

.auth-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px 36px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  animation: slideUp 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-icon {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.auth-card h2 {
  font-size: 1.15rem;
  font-weight: 500;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.auth-card p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

.auth-card input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 14px;
}

.auth-card input:focus {
  border-color: var(--border-focus);
}

.auth-card button {
  width: 100%;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}

.auth-card button:hover {
  background: var(--accent-hover);
}

/* ── App Layout ───────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ── Header ───────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.token-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-dim);
  padding: 6px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
}

.token-btn:hover {
  color: var(--text-secondary);
  border-color: var(--border);
  background: var(--bg-elevated);
}

/* ── Center Area ──────────────────────────────────────── */
.center-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-bottom: 40px;
  min-height: 0;
}

/* ── Landing ──────────────────────────────────────────── */
.landing {
  text-align: center;
  animation: fadeIn 500ms ease;
}

.landing.hidden { display: none; }

.landing h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 10px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 300;
}

/* ── Result Area ──────────────────────────────────────── */
.result-area {
  animation: fadeIn 400ms ease;
  overflow-y: auto;
  padding-bottom: 16px;
}

.result-area.hidden { display: none; }

/* Status card during loading */
.status-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  animation: slideUp 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

.status-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  flex-shrink: 0;
}

.status-dot.running {
  background: var(--progress-bar);
  animation: pulse 1.5s ease infinite;
}

.status-dot.succeeded { background: var(--success); }
.status-dot.failed { background: var(--error); }

.status-query {
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin-bottom: 20px;
  font-style: italic;
}

/* Progress bar */
.progress-track {
  height: 3px;
  background: var(--progress-bg);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 16px;
}

.progress-fill {
  height: 100%;
  background: var(--progress-bar);
  border-radius: 3px;
  width: 0%;
  transition: width 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

.progress-fill.indeterminate {
  width: 40%;
  animation: indeterminate 1.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* Stats summary */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 20px;
  animation: fadeIn 500ms ease 200ms both;
}

.stat-item {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

/* Media result (video/image) */
.media-result {
  margin-top: 20px;
  border-radius: var(--radius);
  overflow: hidden;
  animation: fadeIn 500ms ease 300ms both;
}

.media-result video,
.media-result img {
  width: 100%;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.media-result video {
  background: #000;
}

/* Artifact links */
.artifact-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  animation: fadeIn 500ms ease 400ms both;
}

.artifact-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-decoration: none;
  font-family: var(--font-mono);
  transition: all var(--transition);
}

.artifact-link:hover {
  color: var(--text);
  border-color: var(--border-focus);
}

/* Error state */
.error-message {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 12px;
}

/* ── Input Area ───────────────────────────────────────── */
.input-area {
  flex-shrink: 0;
  padding-bottom: 24px;
}

/* Example chips */
.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 14px;
  animation: fadeIn 600ms ease 200ms both;
}

.examples.hidden { display: none; }

.chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.chip:hover {
  color: var(--text);
  border-color: var(--border-focus);
  background: var(--surface);
}

/* Search bar */
.search-bar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 18px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  transition: border-color var(--transition);
}

.search-bar:focus-within {
  border-color: var(--border-focus);
}

.search-bar textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  resize: none;
  padding: 10px 0;
  line-height: 1.4;
  max-height: 120px;
}

.search-bar textarea::placeholder {
  color: var(--text-dim);
}

.search-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 4px;
  flex-shrink: 0;
}

/* Video toggle */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text-dim);
  transition: color var(--transition);
  user-select: none;
  white-space: nowrap;
}

.toggle-label:hover {
  color: var(--text-secondary);
}

.toggle-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 18px;
  background: var(--surface);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle-label input[type="checkbox"]::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--text-dim);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: all var(--transition);
}

.toggle-label input[type="checkbox"]:checked {
  background: var(--border-focus);
}

.toggle-label input[type="checkbox"]:checked::after {
  left: 16px;
  background: var(--text);
}

/* Submit button */
.submit-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--surface);
  color: var(--text-dim);
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.submit-btn.active {
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}

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

/* ── Animations ───────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 500px) {
  .app { padding: 0 14px; }
  .auth-card { margin: 0 16px; padding: 32px 24px 28px; }
  .examples { justify-content: flex-start; }
  .stats-summary { grid-template-columns: 1fr 1fr; }
}
