:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f9;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #b91c1c;
  --ok: #166534;
  --border: #d6dcea;
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #121a2b;
  --surface-2: #1a253b;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --danger: #f87171;
  --ok: #4ade80;
  --border: #24324a;
  --shadow: 0 18px 34px rgba(2, 6, 23, 0.4);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  background: radial-gradient(circle at top, rgba(37, 99, 235, 0.15), transparent 42%), var(--bg);
  color: var(--text);
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

.topbar {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.2rem;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 2vw, 2rem);
}

.subtitle {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 0.6rem;
}

.layout {
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.8rem;
  resize: vertical;
  min-height: 8.5rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  font-size: 0.92rem;
  cursor: pointer;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--primary);
}

.small-note {
  color: var(--muted);
  margin: 0.7rem 0 0;
  font-size: 0.86rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.meta-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}

.meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.progress-text {
  font-weight: 600;
}

.progress-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin: 0 0 0.8rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary), color-mix(in oklab, var(--primary), #ffffff 25%));
  transition: width 180ms ease;
}

.results-container {
  overflow-x: auto;
}

.action-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 120px;
}

.action-link {
  text-decoration: none;
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  padding: 0.7rem 0.5rem;
  font-size: 0.92rem;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.price {
  font-weight: 600;
}

.status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
  font-size: 0.78rem;
  border: 1px solid;
}

.status-ok {
  color: var(--ok);
  border-color: color-mix(in oklab, var(--ok), transparent 55%);
  background: color-mix(in oklab, var(--ok), transparent 88%);
}

.status-error {
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger), transparent 55%);
  background: color-mix(in oklab, var(--danger), transparent 88%);
}

.status-running {
  color: var(--primary);
  border-color: color-mix(in oklab, var(--primary), transparent 55%);
  background: color-mix(in oklab, var(--primary), transparent 88%);
}

.status-queued {
  color: var(--muted);
  border-color: color-mix(in oklab, var(--muted), transparent 55%);
  background: color-mix(in oklab, var(--muted), transparent 90%);
}

.error-detail {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.progress-detail {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
}

.alert {
  border-radius: 12px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
}

.alert.error {
  border-color: color-mix(in oklab, var(--danger), transparent 55%);
  color: var(--danger);
}

.alert.success {
  border-color: color-mix(in oklab, var(--ok), transparent 55%);
  color: var(--ok);
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.45);
  padding: 1rem;
  display: grid;
  place-items: center;
  z-index: 99;
}

.modal-card {
  width: min(100%, 980px);
  max-height: 92vh;
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header,
.modal-footer {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-footer {
  border-bottom: 0;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-body {
  padding: 1rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.setting-field {
  display: grid;
  gap: 0.3rem;
}

.setting-field-wide {
  grid-column: 1 / -1;
}

.setting-field input,
.setting-field select,
.setting-field textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.5rem 0.55rem;
}

@media (max-width: 860px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .action-group {
    min-width: 96px;
  }
}
