:root {
  --bg: #0f1117;
  --surface: #171a22;
  --surface-2: #1e2230;
  --border: #2a3040;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5b9cff;
  --accent-dim: #3d6fbf;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --err: #ff6b6b;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

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

.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-panel {
  width: min(420px, 100%);
}

.history-panel {
  margin-top: 1.25rem;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.history-header h2 {
  margin: 0;
}

.history-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
  word-break: break-all;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  background: var(--surface-2);
}

.history-item.is-active {
  border-color: var(--accent);
}

.history-item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}

.history-quote {
  font-weight: 500;
  margin: 0 0 0.35rem;
}

.history-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

.history-status {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.history-status.completed { border-color: var(--ok); color: var(--ok); }
.history-status.failed { border-color: var(--err); color: #ffb4b4; }
.history-status.running,
.history-status.queued { border-color: var(--accent); color: var(--accent); }

.history-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.history-actions button,
.history-actions a {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  width: auto;
}

.log-tail {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  overflow-x: auto;
  max-height: 200px;
  margin-bottom: 1rem;
  white-space: pre-wrap;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.status-pill {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
}

.status-pill[data-state="ok"] { border-color: var(--ok); color: var(--ok); }
.status-pill[data-state="warn"] { border-color: var(--warn); color: var(--warn); }
.status-pill[data-state="err"] { border-color: var(--err); color: var(--err); }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.field span {
  font-size: 0.85rem;
  font-weight: 500;
}

.field small { color: var(--muted); font-weight: 400; }

input, textarea, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font: inherit;
  width: 100%;
}

textarea { resize: vertical; min-height: 4.5rem; }

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.checkbox input { width: auto; margin-top: 0.2rem; }

.advanced {
  margin-bottom: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.advanced summary {
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  user-select: none;
}

.advanced-body { padding: 0 0.85rem 0.85rem; }

button.primary, a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1.2rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  width: 100%;
}

button.primary:hover, a.button:hover { background: var(--accent-dim); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.hidden { display: none !important; }

.progress {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  padding: 1rem;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 1rem;
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
  margin-top: 0.15rem;
}

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

.progress-step { font-weight: 600; }
.progress-detail { color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }

.error {
  padding: 0.85rem 1rem;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid var(--err);
  border-radius: 8px;
  color: #ffb4b4;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.input-prompt {
  padding: 1rem;
  background: rgba(240, 180, 41, 0.08);
  border: 1px solid var(--warn);
  border-radius: 8px;
  margin-bottom: 1rem;
}

.input-prompt p { margin: 0 0 0.75rem; }

.candidate-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
}

.candidate-list li {
  margin-bottom: 0.4rem;
}

.candidate-list button {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}

.candidate-list button:hover { border-color: var(--accent); }

.meta {
  font-size: 0.9rem;
  margin-bottom: 1rem;
  color: var(--muted);
}

.meta strong { color: var(--text); }

.preview {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

.preview img, .preview video {
  max-width: 100%;
  max-height: 420px;
  display: block;
}

.actions { margin-bottom: 1rem; }

.timings summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.timings table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.timings th, .timings td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.timings td:last-child { text-align: right; font-family: var(--mono); }

.idle-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal {
  width: min(720px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-quote {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.trim-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.trim-slider {
  position: relative;
  height: 2.5rem;
  margin: 0.5rem 0 1rem;
}

.trim-slider-rail {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  background: var(--border);
  border-radius: 999px;
}

.trim-slider-selection {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  background: var(--accent);
  border-radius: 999px;
  pointer-events: none;
}

.trim-slider input[type="range"] {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
  margin: 0;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  height: 0;
}

.trim-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--accent);
  cursor: pointer;
  pointer-events: auto;
}

.trim-slider input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--accent);
  cursor: pointer;
  pointer-events: auto;
}

.trim-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.trim-preview-panel {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.trim-preview-panel img,
.trim-preview-panel video {
  max-width: 100%;
  max-height: 320px;
  display: block;
}

.trim-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.trim-actions button,
.trim-actions a {
  width: auto;
  flex: 1;
  min-width: 120px;
}

.trim-error {
  color: #ffb4b4;
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
}

.history-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  margin-left: 0.35rem;
  vertical-align: middle;
}
