:root {
  --bg: #F6F7F9; --surface: #FFFFFF; --surface-alt: #EEF1F5; --border: #D3D8E0; --fg: #1C2330; --muted: #5B6577;
  --accent: #2F6FEB; --accent-fg: #FFFFFF; --danger: #C62828; --danger-bg: #FDECEC; --warn: #9A6700; --warn-bg: #FFF6DD;
  --ok: #1A7F37; --ok-bg: #E6F4EA; --info: #3B5BA9; --info-bg: #E8EEFB;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171C; --surface: #1C2027; --surface-alt: #252A33; --border: #363C47; --fg: #E3E7EE; --muted: #99A2B2;
    --accent: #5B8DEF; --accent-fg: #FFFFFF; --danger: #FF7B72; --danger-bg: #3D1F22; --warn: #E3B341; --warn-bg: #3A3020;
    --ok: #56D364; --ok-bg: #1E3324; --info: #8AB4F8; --info-bg: #1F2A40;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171C; --surface: #1C2027; --surface-alt: #252A33; --border: #363C47; --fg: #E3E7EE; --muted: #99A2B2;
  --accent: #5B8DEF; --accent-fg: #FFFFFF; --danger: #FF7B72; --danger-bg: #3D1F22; --warn: #E3B341; --warn-bg: #3A3020;
  --ok: #56D364; --ok-bg: #1E3324; --info: #8AB4F8; --info-bg: #1F2A40;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 "Segoe UI", system-ui, sans-serif; }
a { color: var(--accent); }
header.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
header.top .brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; text-decoration: none; color: var(--fg); }
header.top .brand-icon { display: block; border-radius: 5px; }
header.top nav { display: flex; gap: 4px; }
header.top nav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--fg); }
header.top nav a[aria-current="page"] { background: var(--surface-alt); font-weight: 600; }
header.top .spacer { flex: 1; }
header.top .user { color: var(--muted); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; }
button { font: inherit; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--fg); cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button:disabled { opacity: .5; cursor: default; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--surface-alt); color: var(--muted); }
.badge.running, .badge.queued { background: var(--info-bg); color: var(--info); }
.badge.succeeded { background: var(--ok-bg); color: var(--ok); }
.badge.failed, .badge.interrupted { background: var(--danger-bg); color: var(--danger); }
.badge.cancelled { background: var(--warn-bg); color: var(--warn); }
.notice { padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.error { background: var(--danger-bg); color: var(--danger); }
.notice.info { background: var(--info-bg); color: var(--info); }
.hidden { display: none !important; }
progress { width: 100%; height: 10px; appearance: none; border: none; border-radius: 5px; background: var(--surface-alt); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-alt); border-radius: 5px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 5px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 5px; }
progress.item::-webkit-progress-value { background: var(--info); }
progress.item::-moz-progress-bar { background: var(--info); }
.progress-line { display: flex; justify-content: space-between; gap: 10px; margin: 8px 0 3px; }
.log { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; height: 180px; overflow-y: auto; white-space: pre-wrap; margin-top: 10px; }
.log .phase { color: var(--ok); }
.log .warning { color: var(--danger); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-alt); }
.counts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.counts .label { color: var(--muted); }
.conflict { color: var(--danger); font-weight: 600; }
details summary { cursor: pointer; margin: 6px 0; }
.theme-toggle { display: inline-flex; align-items: center; gap: 6px; }
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.profiles .card { cursor: pointer; margin: 0; }
.profiles .card:hover { border-color: var(--accent); }
@media (max-width: 800px) {
  main { padding: 10px; }
  .hide-narrow { display: none; }
}
main.wide { max-width: 1500px; }
.tabs { display: flex; gap: 4px; margin: 8px 0; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.split { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 12px; align-items: start; }
.split .card { margin: 0; }
.side input[type="search"] { width: 100%; font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--fg); }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
.list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.list li { padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.list li:hover { background: var(--surface-alt); }
.list li[aria-selected="true"] { border-color: var(--accent); background: var(--surface-alt); }
.list li .name { font-weight: 600; overflow-wrap: anywhere; }
.list li .sub { font-size: 12px; color: var(--muted); }
.list li .sub.needs { color: var(--danger); font-weight: 600; }
.list li .sub.done { color: var(--ok); }
.controls { margin: 8px 0; }
select, textarea { font: inherit; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--fg); }
textarea { width: 100%; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.pre { white-space: pre-wrap; }
.diff-wrap { max-height: 60vh; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
table.diff { border-collapse: collapse; width: 100%; font-size: 12.5px; table-layout: fixed; }
table.diff th { position: sticky; top: 0; background: var(--surface-alt); z-index: 1; }
table.diff col.num { width: 3.5em; }
table.diff td { padding: 0 6px; border-bottom: none; white-space: pre-wrap; overflow-wrap: anywhere; vertical-align: top; }
table.diff td.num { width: 3.5em; text-align: right; color: var(--muted); user-select: none; border-right: 1px solid var(--border); }
table.diff tr.current td { outline: 1px solid var(--accent); }
td.k-Changed { background: var(--warn-bg); }
td.k-Added { background: var(--ok-bg); }
td.k-Removed { background: var(--danger-bg); }
td.k-Padding { background: repeating-linear-gradient(45deg, transparent, transparent 4px, var(--surface-alt) 4px, var(--surface-alt) 8px); }
td.left mark { background: var(--danger); color: var(--accent-fg); border-radius: 2px; }
td.right mark { background: var(--ok); color: var(--accent-fg); border-radius: 2px; }
.hunks li { display: flex; gap: 10px; align-items: center; cursor: default; }
.hunks li .summary { flex: 1; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
.hunks li[aria-current="true"] { border-color: var(--accent); }
table.rows td, table.cells td { font-size: 13px; overflow-wrap: anywhere; }
table.rows tr.selected td { background: var(--surface-alt); }
table.rows tr.needs td:nth-child(6) { color: var(--danger); font-weight: 600; }
table.cells tr.differs td:nth-child(3), table.cells tr.differs td:nth-child(4) { background: var(--warn-bg); }
table.cells tr.conflict td:first-child { color: var(--danger); font-weight: 600; }
table.cells input[type="text"] { width: 9em; font: inherit; padding: 2px 4px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--fg); }
.picks { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
@media (max-width: 1000px) {
  .split { grid-template-columns: 1fr; }
  .list { max-height: 30vh; }
}
.list li .sub.conflict { color: var(--danger); font-weight: 600; }
.list li .sub.warn { color: var(--warn); }
.list li.problem { border-left: 3px solid var(--danger); }
.apply-items { max-height: 60vh; overflow: auto; }
.apply-items li { cursor: default; }
.done { color: var(--ok); font-weight: 600; }
pre.script { max-height: 60vh; overflow: auto; background: var(--surface-alt); padding: 8px; border-radius: 6px; white-space: pre; font-size: 12px; }
.split > * { min-width: 0; }
header.top form { margin: 0; }
label.field { display: block; margin: 8px 0; }
label.field input { display: block; width: 100%; margin-top: 4px; }
body.auth { min-height: 100vh; }
.auth-split { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100vh; }
.auth-brand { display: flex; flex-direction: column; justify-content: space-between; gap: 32px; padding: 44px 48px 28px; color: #fff;
  background: radial-gradient(120% 90% at 85% 100%, rgba(94, 178, 170, .85) 0%, rgba(94, 178, 170, 0) 55%), linear-gradient(135deg, #18265c 0%, #253f8c 55%, #2f4f99 100%); }
.auth-logo { display: inline-flex; align-items: center; gap: 8px; align-self: flex-start; background: #fff; color: #1d2f6f; border-radius: 10px; padding: 9px 14px; box-shadow: 0 6px 18px rgba(8, 18, 52, .25); }
.auth-mark { font-weight: 700; font-size: 20px; letter-spacing: -.3px; }
.auth-by { font-size: 11px; color: #5a6b9a; text-transform: uppercase; letter-spacing: .6px; }
.auth-pitch { max-width: 520px; }
.auth-pitch h1 { font-size: 34px; line-height: 1.2; margin: 0 0 14px; font-weight: 700; letter-spacing: -.4px; }
.auth-accent { color: #6fd3c4; }
.auth-pitch p { font-size: 15.5px; line-height: 1.6; color: rgba(255, 255, 255, .86); margin: 0 0 18px; }
.auth-points { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px 20px; }
.auth-points li { font-size: 13.5px; color: rgba(255, 255, 255, .92); }
.auth-points li::before { content: "✓"; margin-right: 6px; color: #6fd3c4; font-weight: 700; }
.auth-foot { margin: 0; font-size: 12.5px; color: rgba(255, 255, 255, .7); }
.auth-panel { position: relative; margin: 0; max-width: none; display: flex; align-items: center; justify-content: center; padding: 48px 24px; background: var(--bg); }
.auth-theme { position: absolute; top: 16px; right: 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px 30px;
  box-shadow: 0 10px 30px rgba(16, 28, 64, .08), 0 2px 6px rgba(16, 28, 64, .05); }
.auth-card h2 { margin: 0 0 4px; font-size: 21px; font-weight: 700; }
.auth-sub { margin: 0 0 20px; color: var(--muted); }
.ms-button { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 11px 16px; border-radius: 8px;
  background: #1f3570; color: #fff; text-decoration: none; font-weight: 600; font-size: 14.5px; border: 1px solid #1f3570; transition: background .15s, box-shadow .15s; }
.ms-button svg { background: #fff; padding: 2px; border-radius: 3px; box-sizing: content-box; }
.ms-button:hover { background: #26408a; box-shadow: 0 4px 12px rgba(31, 53, 112, .3); }
.ms-button:focus-visible { outline: 3px solid #6fd3c4; outline-offset: 2px; }
.auth-fine { margin: 18px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.auth-actions { margin-top: 16px; }
.auth-card .notice { margin-bottom: 14px; }
@media (max-width: 860px) {
  .auth-split { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .auth-brand { padding: 24px 20px 20px; gap: 18px; }
  .auth-pitch h1 { font-size: 24px; }
  .auth-pitch p, .auth-points, .auth-foot { display: none; }
  .auth-panel { padding: 28px 16px 40px; align-items: flex-start; }
  .auth-theme { position: fixed; top: 22px; right: 16px; z-index: 2; }
}
:root[data-theme="dark"] .ms-button { background: #3559b8; border-color: #4a6dcc; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ms-button { background: #3559b8; border-color: #4a6dcc; } }
.auth-icon { display: block; border-radius: 6px; }
.mask-checks { list-style: none; padding: 0; margin: 0 0 8px; font-size: 12.5px; }
.mask-checks li::before { content: "• "; }
