:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-hover: #5a9dff;
  --danger: #ff6b6b;
  --success: #3dd68c;
  --border: #2f3f57;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(160deg, #0b1020 0%, #121a28 50%, #0f1419 100%);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

.login-card {
  max-width: 400px;
  margin: 12vh auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(26, 35, 50, 0.8);
  backdrop-filter: blur(8px);
}

.topbar h1 { margin: 0; font-size: 1.5rem; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 24px 32px 48px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .two-cols { grid-template-columns: 1fr !important; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card h2 { margin-top: 0; }

.subtitle {
  color: var(--muted);
  margin: 4px 0 0;
}

label {
  display: block;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--muted);
}

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
}

textarea { resize: vertical; font-family: ui-monospace, monospace; }

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}

.tab.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}

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

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

.btn.primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

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

.btn.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  margin-top: 8px;
}

.btn.danger:hover { background: rgba(255, 107, 107, 0.12); }

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

.error { color: var(--danger); margin-top: 8px; }

.error-box {
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  max-height: 200px;
  font-size: 0.85rem;
}

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

.section-header h2 { margin: 0; }

.reports-list {
  max-height: 520px;
  overflow-y: auto;
}

.report-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--surface-2);
}

.report-item .name {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  word-break: break-all;
}

.report-item .meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.report-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-left: 12px;
}

.report-actions a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.report-actions a:hover { text-decoration: underline; }

.muted { color: var(--muted); }

.job-status {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.job-meta code {
  font-family: ui-monospace, monospace;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.job-id-hint {
  font-size: 0.85rem;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}

.progress-bar {
  flex: 1;
  height: 12px;
  background: var(--surface-2);
  border-radius: 6px;
  overflow: hidden;
}

#job-progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #5a9dff);
  transition: width 0.4s ease;
  border-radius: 6px;
}

#job-progress.indeterminate {
  width: 40% !important;
  animation: progress-indeterminate 1.2s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

.progress-text {
  font-size: 0.9rem;
  color: var(--muted);
  min-width: 5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.job-log-block {
  margin-top: 12px;
}

.job-log-block summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  user-select: none;
}

.job-log {
  margin: 8px 0 0;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

#job-state.running { color: var(--accent); }
#job-state.completed { color: var(--success); }
#job-state.failed { color: var(--danger); }
#job-state.cancelled { color: var(--danger); }

dialog {
  width: min(95vw, 1000px);
  max-height: 90vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

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

#report-content {
  margin: 0;
  padding: 20px;
  overflow: auto;
  max-height: calc(90vh - 80px);
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
