:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --console-bg: #0b1020;
  --console-text: #d6deeb;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --surface: #121826;
    --surface-2: #161d2e;
    --border: #232c40;
    --text: #e5e9f0;
    --muted: #8b95a8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-soft: #1e1f3d;
    --accent: #14b8a6;
    --accent-hover: #2dd4bf;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --console-bg: #070a12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
[hidden] { display: none !important; }
a { color: var(--primary); }
h2 { font-size: 16px; margin: 0; font-weight: 650; }
h3 { font-size: 14px; margin: 18px 0 8px; font-weight: 650; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; display: block; }

/* ---------- controls */
label { display: block; font-weight: 550; font-size: 13px; margin: 10px 0 0; }
input, select {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit; font-weight: 400; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
label.check { display: block; font-weight: 450; margin-top: 10px; }
label.check input { display: inline-block; width: auto; margin: 0 8px 0 0; vertical-align: -2px; accent-color: var(--primary); }
label.check.small { font-size: 12px; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--muted) 40%, var(--border)); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.wide { width: 100%; margin-top: 18px; }
.form-error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }
.form-error.good { color: var(--ok); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand-lg { font-size: 20px; margin-bottom: 4px; }
.logo { width: 30px; height: 30px; border-radius: 8px; flex: none; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { white-space: nowrap; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 550; padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.active { color: var(--primary); background: var(--primary-soft); }
#logout { margin-left: auto; }
main { padding: 24px; max-width: 1500px; margin: 0 auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 6px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row .grow { flex: 1; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.narrow-2 { grid-template-columns: 1fr 130px; }
.two-col { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.migrate-grid { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.15fr); gap: 20px; align-items: start; }
.col-console { position: sticky; top: 76px; }
.migrate-grid > *, .two-col > * { min-width: 0; } /* let wide tables scroll inside their card */

.step-no { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.card.chain { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 7%, var(--surface)), var(--surface)); }

/* extras */
.extras-head { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-weight: 550; font-size: 13px; }
.extras { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.extra-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center; }
.extra-row input { margin: 0; }
.extra-row .arrow { color: var(--muted); }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--danger); background: var(--surface-2); }

/* preview results */
.result { margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.result-head { padding: 10px 12px; background: var(--surface-2); font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.result table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.result td { padding: 6px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.result td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.result td.zero { color: var(--muted); font-weight: 400; }
.result code { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.creds { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 6px 0 12px; align-items: center; }
.creds dt { font-weight: 600; font-size: 13px; }
.creds dd { margin: 0; display: flex; align-items: center; gap: 8px; min-width: 0; }
.creds code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 3px 7px; border-radius: 6px; word-break: break-all; user-select: all; }
label.inline { margin-top: 10px; font-weight: 500; }
label.inline select { width: auto; min-width: 160px; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.badge.valid { background: #dcfce7; color: #166534; }
.badge.expiring { background: #fef3c7; color: #92400e; }
.badge.expired { background: #fee2e2; color: #991b1b; }
.badge.none { background: var(--surface-2); color: var(--muted); }
.dom-table tr.server-row td { background: var(--surface-2); font-weight: 650; font-size: 12.5px; }
.dom-table tr.server-row .muted { font-weight: 400; }
.dom-table tr.pick { cursor: pointer; }
.dom-table tr.pick.selected td { background: var(--primary-soft); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---------- console */
.console { background: var(--console-bg); border-radius: var(--radius); overflow: hidden; border: 1px solid #1c2438; box-shadow: var(--shadow); display: flex; flex-direction: column; height: calc(100vh - 110px); min-height: 420px; }
.console-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #1c2438; color: #c7d0e0; flex-wrap: wrap; }
.console-title { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.console-title #job-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.console-tools { display: flex; align-items: center; gap: 10px; }
.console-tools .btn.ghost { color: #c7d0e0; border-color: #2a3550; }
.console-tools .btn.ghost:hover { background: #151c2f; }
.console-tools label.check { color: #8b95a8; }
.console-body { flex: 1; overflow: auto; padding: 12px 14px 20px; font: 12.5px/1.6 var(--mono); color: var(--console-text); }
.console-empty { color: #5b6680; padding: 30px 0; text-align: center; font-family: var(--font); }
.ln { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-word; }
.ln .ts { color: #4b5670; flex: none; user-select: none; }
.ln.step { color: #fff; font-weight: 700; margin-top: 12px; padding-top: 8px; border-top: 1px dashed #26304a; }
.ln.step .msg::before { content: "▸ "; color: #818cf8; }
.ln.ok .msg { color: #4ade80; }
.ln.warn .msg { color: #fbbf24; }
.ln.err .msg { color: #f87171; font-weight: 600; }
.ln.cmd .msg { color: #7dd3fc; }
.ln.out .msg { color: #9aa6bd; }
.ln.screen .msg { color: #b4c0d6; background: #0f1528; border: 1px solid #1c2438; border-radius: 6px; padding: 6px 10px; display: block; width: 100%; }
.ln.trace .msg { color: #fca5a5; font-size: 11px; }

.pill { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 99px; text-transform: uppercase; letter-spacing: .03em; }
.pill.idle { background: #1c2438; color: #8b95a8; }
.pill.running { background: #1e3a8a; color: #bfdbfe; animation: pulse 1.4s ease-in-out infinite; }
.pill.success { background: #14532d; color: #bbf7d0; }
.pill.failed, .pill.interrupted { background: #7f1d1d; color: #fecaca; }
.pill.cancelled { background: #78350f; color: #fde68a; }
@keyframes pulse { 50% { opacity: .65; } }

/* ---------- lists / tables */
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.list-item .meta { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.list-item .btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:hover td { background: var(--surface-2); }
.table .err-text { color: var(--danger); font-size: 12px; max-width: 360px; }
.table .pill.success { background: #dcfce7; color: #166534; }
.table .pill.failed, .table .pill.interrupted { background: #fee2e2; color: #991b1b; }
.table .pill.cancelled { background: #fef3c7; color: #92400e; }
.table .pill.running { background: #dbeafe; color: #1e40af; }

/* ---------- modal & toast */
.modal { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--surface); border-radius: 14px; padding: 22px; width: min(520px, 100%); border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card.wide { width: min(1100px, 100%); }
.modal-card h3 { margin-top: 0; font-size: 16px; }
.modal-body { color: var(--muted); }
.modal-body ul { padding-left: 18px; margin: 8px 0; }
.modal-body strong { color: var(--text); }
.logview { background: var(--console-bg); color: var(--console-text); font: 12px/1.55 var(--mono); padding: 14px; border-radius: 10px; max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 12px 0 0; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 10px; z-index: 60; font-weight: 550; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .migrate-grid, .two-col { grid-template-columns: 1fr; }
  .col-console { position: static; }
  .console { height: 70vh; }
}
@media (max-width: 640px) {
  main { padding: 14px; }
  .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .tabs { order: 3; flex-basis: 100%; }
  .grid2, .grid3, .narrow-2 { grid-template-columns: 1fr; }
  .row { flex-direction: column; align-items: stretch; }
  .card.chain { flex-direction: column; align-items: stretch; }
  .extra-row { grid-template-columns: 1fr 1fr auto; }
  .extra-row .arrow { display: none; }
}
