:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1d2330; --muted: #667085; --border: #e3e6eb;
  --primary: #0f6cbd; --primary-ink: #fff; --primary-soft: #e8f1fb;
  --ok: #107c41; --ok-soft: #e6f4ea; --warn: #b25e00; --warn-soft: #fff4e5; --err: #c50f1f; --err-soft: #fde7e9;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1b1f27; --text: #e6e8ec; --muted: #98a2b3; --border: #2c323d;
    --primary: #4ea1f3; --primary-ink: #0b1220; --primary-soft: #18324d;
    --ok: #4cc38a; --ok-soft: #133524; --warn: #f0a44b; --warn-soft: #3a2a12; --err: #f87171; --err-soft: #3b1a1d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; font-weight: 600; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; font-weight: 600; }
h3 { font-size: 1rem; margin: 0 0 .5rem; font-weight: 600; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.text-err { color: var(--err); } .text-ok { color: var(--ok); }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-right { margin-left: auto; display: flex; gap: 1rem; align-items: center; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); display: inline-flex; align-items: center; gap: .4rem; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--primary); color: var(--primary-ink); font-size: 15px; }
.brand-lg { font-size: 1.3rem; margin-bottom: 1.25rem; }
.org-switch select { min-width: 220px; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 600; }

.shell { display: flex; min-height: calc(100vh - 53px); }
.sidebar { width: 220px; flex-shrink: 0; padding: 1rem .75rem; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 2px; }
.sidebar a { padding: .45rem .7rem; border-radius: 7px; color: var(--text); }
.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-section { margin: 1rem .7rem .3rem; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.nav-foot { margin-top: auto; padding: .7rem; display: flex; flex-direction: column; gap: .3rem; }
.nav-foot a { padding: 0; }
.content { flex: 1; padding: 1.5rem 2rem 3rem; min-width: 0; max-width: 1400px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 560px; }
.card-highlight { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.danger-zone { border-color: var(--err); margin-top: 2rem; }
.callout { padding: .9rem 1.1rem; border-radius: var(--radius); background: var(--primary-soft); margin-bottom: 1rem; }
.callout-warn { background: var(--warn-soft); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem 1.5rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); }
.tile-label { color: var(--muted); font-size: 12px; }
.tile-value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 12px; }

.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .75rem; }
.flash-success { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--err-soft); color: var(--err); }
.flash-info { background: var(--primary-soft); }

label { display: block; font-weight: 500; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: .45rem .6rem; width: 100%; margin-top: .25rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
input[type=checkbox], input[type=radio] { width: auto; margin: 0 .35rem 0 0; vertical-align: -2px; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack > label input[type=checkbox] { margin-top: 0; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline-form input { width: auto; flex: 1; margin: 0; min-width: 160px; }
.inline-form.compact input { flex: 0; min-width: 0; }
.w-num { width: 5rem !important; display: inline-block; margin: 0 .2rem; padding: .25rem .4rem; }
.w-plan { width: 7rem !important; }

.btn { display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-weight: 600; padding: .45rem .9rem; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.btn-sm { padding: .25rem .6rem; font-size: 12.5px; }
.btn-link, button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.inline-details { display: inline-block; }
.inline-details summary { list-style: none; }
.inline-details[open] form { margin-top: .4rem; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; }
.card .table { border: 0; }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: color-mix(in srgb, var(--bg) 60%, var(--surface)); }
.table tr:last-child td { border-bottom: 0; }
.table td input, .table td select { margin: 0 0 .25rem; padding: .3rem .45rem; }
.url-cell { word-break: break-all; max-width: 360px; }
.row-off td { opacity: .55; }
.row-off td:first-child { opacity: 1; }

.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.badge-running, .badge-queued { background: var(--primary-soft); color: var(--primary); }
.badge-paused, .badge-cancelling, .badge-completed_with_errors { background: var(--warn-soft); color: var(--warn); }
.badge-completed { background: var(--ok-soft); color: var(--ok); }
.badge-failed { background: var(--err-soft); color: var(--err); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: .3rem; }
.dot-on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

.bar { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar-lg { height: 12px; margin: .5rem 0 1rem; }
.bar-fill { height: 100%; background: var(--primary); transition: width .6s ease; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.progress-head .muted { word-break: break-all; }
.big-pc { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.counters { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .75rem; margin-bottom: .75rem; }
.counters > div { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.counters label { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.c-failed span { color: var(--err); }

.tabs { display: flex; gap: .25rem; margin-bottom: .75rem; border-bottom: 1px solid var(--border); }
.tabs a { padding: .45rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

.log-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.log-head h2 { margin: 0; }
.log-tools { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.log-tools input, .log-tools select { width: auto; margin: 0; padding: .3rem .5rem; }
.log { margin-top: .75rem; height: 420px; overflow: auto; background: #0d1117; color: #c9d1d9; border-radius: 8px; padding: .6rem .75rem; font-family: var(--mono); font-size: 12px; line-height: 1.55; }
.log-line { display: flex; gap: .6rem; white-space: pre-wrap; word-break: break-word; }
.log-ts { color: #6e7681; flex-shrink: 0; }
.log-lvl { width: 3.2rem; flex-shrink: 0; text-transform: uppercase; color: #8b949e; }
.log-warn .log-lvl, .log-warn .log-msg { color: #e3b341; }
.log-error .log-lvl, .log-error .log-msg { color: #ff7b72; }
.log-debug { opacity: .65; }
.log-comp { color: #79c0ff; flex-shrink: 0; }
.log-item { color: #8b949e; }
.log .muted { color: #8b949e; }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: .35rem 1rem; margin: .75rem 0 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }

.step h2 { margin-top: 0; display: flex; align-items: center; gap: .5rem; }
.step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: var(--primary-ink); font-size: 13px; }
.mode-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.mode-card { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; cursor: pointer; display: grid; grid-template-columns: auto 1fr; gap: .1rem .5rem; font-weight: 400; }
.mode-card input { grid-row: span 2; margin-top: .25rem; }
.mode-card span { color: var(--muted); font-size: 13px; }
.mode-card:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .45rem 1rem; }
.check-grid label { font-weight: 400; }
.discover-status { margin-top: .4rem; min-height: 1.4em; }
details.sub { margin-top: 1rem; }
details.sub summary { cursor: pointer; font-weight: 600; }
.form-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.copy-row { display: flex; gap: .5rem; align-items: center; margin: .5rem 0; }
.token { display: block; flex: 1; padding: .5rem .7rem; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; word-break: break-all; }
pre.code { background: var(--bg); border: 1px solid var(--border); border-radius: 7px; padding: .75rem; overflow: auto; }
.list-row { display: flex; justify-content: space-between; align-items: center; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.list-row form { margin: 0; }

.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 2rem; }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav-foot, .nav-section { display: none; }
  .content { padding: 1rem; }
  .topbar { flex-wrap: wrap; }
  .org-switch select { min-width: 0; }
  .table { display: block; overflow-x: auto; }
}

/* ---- migration pipeline ---- */
.run-title { font-size: 1rem; margin: 0 0 .5rem; }
.pipeline { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .75rem; }
.ph { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; display: flex; gap: .6rem; background: var(--surface); min-width: 0; }
.ph-no { flex: 0 0 1.8rem; height: 1.8rem; border-radius: 50%; display: grid; place-items: center; font-weight: 600; background: var(--bg); border: 1px solid var(--border); }
.ph-body { min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.ph-title { font-weight: 600; display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.ph-help { line-height: 1.35; }
.ph-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: auto; padding-top: .3rem; }
.ph-is-next { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.ph-is-next .ph-no { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.ph-completed .ph-no, .ph-completed_with_errors .ph-no { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.ph-running .ph-no, .ph-queued .ph-no { background: var(--primary-soft); color: var(--primary); }
.ph-failed .ph-no { background: var(--err-soft); color: var(--err); border-color: var(--err); }
@media (max-width: 1100px) { .pipeline { grid-template-columns: 1fr; } }

/* ---- pre-pass report ---- */
.estimate { background: var(--primary-soft); border-radius: var(--radius); padding: .75rem 1rem; margin: 1rem 0; }
.estimate h3 { margin-top: 0; }
.est-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.est-grid > div { display: flex; flex-direction: column; }
.est-grid label { font-size: .8rem; color: var(--muted); }
.est-grid strong { font-size: 1.15rem; }
@media (max-width: 800px) { .est-grid { grid-template-columns: 1fr 1fr; } }
.mini-bar { background: var(--bg); border-radius: 4px; height: .5rem; overflow: hidden; }
.mini-bar > div { background: var(--primary); height: 100%; }
.table .num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.text-warn { color: var(--warn); }
.mono-list { font-family: var(--mono); }
.code-input { font-family: var(--mono); letter-spacing: .15em; text-transform: uppercase; width: 9.5rem; }
.counters-live { border-top: 1px dashed var(--border); padding-top: .5rem; margin-top: .25rem; }
.alert { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .75rem; }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--err-soft); color: var(--err); }
.auth-card:has(.download-page) { max-width: 640px; }
.download-page .card { margin: .75rem 0; }
