/* ── Design System ── */
:root {
  --bg-deep: #08090d;
  --bg: #0c0e14;
  --bg-elevated: #11131b;
  --bg-card: #161923;
  --bg-hover: #1c1f2b;
  --bg-input: #0e1018;
  --border: #232636;
  --border-subtle: #1a1d28;
  --border-focus: #3a3f50;
  --text: #e2e4ea;
  --text-secondary: #8b90a0;
  --text-dim: #505468;
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.12);
  --accent-strong: rgba(0, 212, 170, 0.25);
  --blue: #38bdf8;
  --blue-dim: rgba(56, 189, 248, 0.12);
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.10);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.10);
  --amber: #fbbf24;
  --amber-dim: rgba(251, 191, 36, 0.10);
  --font: 'Ubuntu Mono', 'SF Mono', 'Cascadia Code', 'Consolas', 'Liberation Mono', 'Menlo', 'DejaVu Sans Mono', monospace;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { font-size: 13px; }
body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
#header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 52px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.logo {
  font-size: 15px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--accent);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.logo::before {
  content: ''; display: block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

nav { display: flex; gap: 2px; margin-left: 24px; }
nav a {
  padding: 6px 14px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 13px; font-weight: 500;
  transition: var(--transition);
  text-decoration: none;
}
nav a:hover { color: var(--text); background: var(--bg-hover); text-decoration: none; }
nav a.active { color: var(--accent); background: var(--accent-dim); }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.conn-indicator {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim); transition: var(--transition);
}
.conn-indicator.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }

#app { max-width: 920px; margin: 0 auto; padding: 32px 24px 80px; }

/* ── Cards ── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
  transition: var(--transition);
}
.card + .card { margin-top: 12px; }

/* ── Form elements ── */
label {
  display: block; margin-bottom: 6px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-secondary);
}
input[type="text"], input[type="number"], input[type="url"], textarea {
  width: 100%; padding: 10px 14px; font-size: 13px;
  font-family: var(--font); color: var(--text);
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); outline: none;
  transition: var(--transition);
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
textarea { resize: vertical; min-height: 60px; }

.form-group { margin-bottom: 20px; }
.form-hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; font-size: 13px; font-weight: 600;
  font-family: var(--font); border: 1px solid transparent;
  border-radius: var(--radius); cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent); color: #000; border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 4px 16px var(--accent-strong); }

.btn-danger {
  background: var(--red-dim); color: var(--red); border-color: rgba(248,113,113,0.3);
}
.btn-danger:hover:not(:disabled) { background: rgba(248,113,113,0.18); }

.btn-ghost {
  background: transparent; color: var(--text-secondary); border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-hover); }

.btn-amber {
  background: var(--amber-dim); color: var(--amber); border-color: rgba(251,191,36,0.3);
}
.btn-amber:hover:not(:disabled) { background: rgba(251,191,36,0.18); }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; margin-top: 16px; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; font-size: 11px; font-weight: 600;
  border-radius: 99px; letter-spacing: 0.5px;
}
.badge-pending { background: var(--bg-hover); color: var(--text-dim); }
.badge-running { background: var(--blue-dim); color: var(--blue); }
.badge-review { background: var(--amber-dim); color: var(--amber); }
.badge-ok { background: var(--green-dim); color: var(--green); }
.badge-error { background: var(--red-dim); color: var(--red); }
.badge-skipped { background: var(--bg-hover); color: var(--text-dim); text-decoration: line-through; }

/* ── Step progress bar ── */
.stepper {
  display: flex; align-items: center; justify-content: center;
  gap: 0; margin-bottom: 32px; padding: 20px 0;
}
.stepper-dot {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  border: 2px solid var(--border);
  background: var(--bg-card); color: var(--text-dim);
  transition: var(--transition);
  position: relative; flex-shrink: 0;
}
.stepper-dot.ok { border-color: var(--green); background: var(--green-dim); color: var(--green); }
.stepper-dot.running { border-color: var(--blue); background: var(--blue-dim); color: var(--blue); animation: pulse 2s ease-in-out infinite; }
.stepper-dot.review { border-color: var(--amber); background: var(--amber-dim); color: var(--amber); }
.stepper-dot.error { border-color: var(--red); background: var(--red-dim); color: var(--red); }
.stepper-dot.skipped { border-color: var(--text-dim); border-style: dashed; color: var(--text-dim); }
.stepper-dot.active { box-shadow: 0 0 12px var(--accent-strong); border-color: var(--accent); color: var(--accent); }

.stepper-line {
  height: 2px; flex: 1; max-width: 48px;
  background: var(--border); transition: var(--transition);
}
.stepper-line.done { background: var(--green); }

/* ── Step cards ── */
.step-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 24px;
  transition: var(--transition); position: relative;
  overflow: hidden;
}
.step-card + .step-card { margin-top: 10px; }
.step-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; border-radius: 3px 0 0 3px;
  background: var(--border); transition: var(--transition);
}
.step-card.running { border-color: rgba(56,189,248,0.3); }
.step-card.running::before { background: var(--blue); box-shadow: 0 0 8px var(--blue); }
.step-card.review { border-color: rgba(251,191,36,0.3); }
.step-card.review::before { background: var(--amber); }
.step-card.ok { border-color: rgba(52,211,153,0.15); }
.step-card.ok::before { background: var(--green); }
.step-card.error { border-color: rgba(248,113,113,0.3); }
.step-card.error::before { background: var(--red); }
.step-card.skipped { opacity: 0.5; }
.step-card.skipped::before { background: var(--text-dim); border-style: dashed; }

.step-header { display: flex; align-items: center; gap: 12px; }
.step-num {
  font-size: 11px; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1px;
  min-width: 56px;
}
.step-label { font-size: 14px; font-weight: 600; flex: 1; }
.step-label.struck { text-decoration: line-through; color: var(--text-dim); }
.step-elapsed { font-size: 11px; color: var(--text-dim); }

.step-body { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-subtle); }
.step-error { color: var(--red); font-size: 12px; margin-top: 8px; padding: 8px 12px; background: var(--red-dim); border-radius: var(--radius-sm); }
.step-result { font-size: 12px; color: var(--text-secondary); margin-top: 8px; }
.step-skip-reason { font-size: 12px; color: var(--text-dim); font-style: italic; margin-top: 4px; }

/* ── Progress bar (running state) ── */
.progress-bar-container {
  margin-top: 12px; height: 4px; background: var(--bg-hover);
  border-radius: 2px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--blue); border-radius: 2px;
  animation: indeterminate 1.8s ease-in-out infinite;
}
.running-elapsed { font-size: 12px; color: var(--blue); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* ── Diff viewer ── */
.diff-viewer {
  font-size: 12px; line-height: 1.7;
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: var(--radius); overflow-x: auto;
  margin-top: 12px;
}
.diff-line { display: flex; white-space: pre; }
.diff-line-num {
  min-width: 42px; padding: 0 8px;
  text-align: right; color: var(--text-dim);
  user-select: none; flex-shrink: 0;
  border-right: 1px solid var(--border-subtle);
}
.diff-line-content { padding: 0 12px; flex: 1; }
.diff-line.add { background: rgba(52, 211, 153, 0.08); }
.diff-line.add .diff-line-content { color: var(--green); }
.diff-line.add .diff-line-content::before { content: '+'; margin-right: 8px; font-weight: 700; }
.diff-line.remove { background: rgba(248, 113, 113, 0.08); }
.diff-line.remove .diff-line-content { color: var(--red); }
.diff-line.remove .diff-line-content::before { content: '-'; margin-right: 8px; font-weight: 700; }
.diff-line.context .diff-line-content { color: var(--text-dim); }
.diff-line.context .diff-line-content::before { content: ' '; margin-right: 8px; }
.diff-separator {
  text-align: center; padding: 2px 0;
  color: var(--text-dim); font-size: 11px;
  background: var(--bg-elevated); border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

/* ── Table (credentials) ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th {
  text-align: left; padding: 8px 12px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky; top: 0;
}
.data-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.data-table tr:hover td { background: var(--bg-hover); color: var(--text); }
.data-table .cell-mono { font-variant-numeric: tabular-nums; }
.table-empty { text-align: center; padding: 40px; color: var(--text-dim); }
.table-container { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: 480px; }
.filter-row {
  display: flex; gap: 10px; margin-bottom: 16px; align-items: flex-end; flex-wrap: wrap;
}
.filter-row .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }
.filter-row select {
  width: 100%; padding: 8px 12px; font-size: 13px;
  font-family: var(--font); color: var(--text);
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); outline: none;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px;
  max-width: 640px; width: 90%; max-height: 80vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
.modal-title {
  font-size: 16px; font-weight: 700; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.modal-body { margin-bottom: 20px; }
.modal-code-preview {
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  font-size: 12px; max-height: 240px; overflow: auto;
  white-space: pre; line-height: 1.6; color: var(--text-secondary);
}
.modal-checkbox {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0; padding: 12px;
  background: var(--bg-hover); border-radius: var(--radius);
}
.modal-checkbox input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--accent);
  cursor: pointer;
}
.modal-checkbox label { font-size: 13px; cursor: pointer; margin: 0; text-transform: none; letter-spacing: 0; }
.modal-confirm-section {
  margin-top: 16px; padding: 16px;
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.confirm-code {
  font-size: 28px; font-weight: 700; letter-spacing: 6px;
  color: var(--amber); text-align: center;
  padding: 12px 0; margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}
.confirm-input {
  text-align: center; font-size: 20px; letter-spacing: 4px;
  font-weight: 600;
}
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Toast ── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 300;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; max-width: 360px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  pointer-events: all; cursor: pointer;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.removing { opacity: 0; transform: translateX(80px); }
.toast-error { background: var(--red-dim); color: var(--red); border-color: rgba(248,113,113,0.3); }
.toast-success { background: var(--green-dim); color: var(--green); border-color: rgba(52,211,153,0.3); }
.toast-info { background: var(--blue-dim); color: var(--blue); border-color: rgba(56,189,248,0.3); }

/* ── Overlay (locked screens) ── */
.lock-overlay {
  position: relative;
}
.lock-overlay::after {
  content: ''; position: absolute; inset: 0;
  background: rgba(8, 9, 13, 0.85); backdrop-filter: blur(6px);
  border-radius: var(--radius-lg); z-index: 10;
}
.lock-message {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 11; text-align: center;
}
.lock-message-icon { font-size: 32px; margin-bottom: 12px; opacity: 0.5; }
.lock-message-text { font-size: 14px; color: var(--text-secondary); }
.lock-message-link { color: var(--accent); cursor: pointer; font-weight: 600; }

/* ── Section headers ── */
.section-title {
  font-size: 18px; font-weight: 700; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
}
.section-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 24px; }

/* ── Draft text area ── */
.draft-preview {
  background: var(--bg-deep); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  font-size: 12px; line-height: 1.7; white-space: pre-wrap;
  color: var(--text-secondary); max-height: 300px; overflow: auto;
}

/* ── Report ── */
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.report-stat {
  background: var(--bg-elevated); border: 1px solid var(--border-subtle);
  border-radius: var(--radius); padding: 16px; text-align: center;
}
.report-stat-value { font-size: 28px; font-weight: 700; color: var(--accent); }
.report-stat-label { font-size: 11px; color: var(--text-dim); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Recovery dialog ── */
.recovery-dialog {
  text-align: center; padding: 48px 24px;
}
.recovery-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.recovery-title { font-size: 16px; font-weight: 700; color: var(--red); margin-bottom: 8px; }
.recovery-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 24px; max-width: 400px; margin-left: auto; margin-right: auto; }

/* ── Relay mode selector ── */
.relay-mode-selector {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px;
}
.relay-mode-option {
  display: block; padding: 14px 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  transition: var(--transition); text-transform: none; letter-spacing: 0;
  margin: 0;
}
.relay-mode-option:hover { border-color: var(--border-focus); background: var(--bg-hover); }
.relay-mode-option.selected,
.relay-mode-option:has(input:checked) {
  border-color: var(--accent); background: var(--accent-dim);
}
.relay-mode-option input[type="radio"] { display: none; }
.relay-mode-label { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.relay-mode-desc { font-size: 11px; color: var(--text-dim); }

/* ── Relay controls ── */
.relay-controls {
  margin-top: 14px; padding: 14px;
  background: var(--bg-elevated); border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}
.relay-status-bar {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
}
.relay-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim); transition: var(--transition);
}
.relay-dot.active {
  background: var(--green); box-shadow: 0 0 8px var(--green);
  animation: pulse-green 2s ease-in-out infinite;
}
.relay-status-text { color: var(--text-secondary); }
.relay-sessions {
  margin-left: auto; font-size: 12px; color: var(--blue);
  font-variant-numeric: tabular-nums;
}
.relay-info { margin-top: 10px; font-size: 12px; }
.relay-info-row { color: var(--text-secondary); margin-bottom: 4px; }
.relay-info-row code {
  background: var(--bg-deep); padding: 2px 6px;
  border-radius: var(--radius-sm); color: var(--accent); font-size: 12px;
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 4px transparent; }
  50% { box-shadow: 0 0 12px var(--green-dim); }
}

/* ── Animations ── */
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 4px transparent; }
  50% { box-shadow: 0 0 12px var(--blue-dim); }
}
@keyframes indeterminate {
  0% { width: 0; margin-left: 0; }
  50% { width: 60%; margin-left: 20%; }
  100% { width: 0; margin-left: 100%; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-100%); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(80px); }
  to { opacity: 1; transform: translateX(0); }
}
