:root {
  --primary: #5E3BF6;
  --primary-dark: #4a2bd6;
  --primary-soft: #efeafe;
  --bg: #f4f3fa;
  --card: #ffffff;
  --text: #1c1a2b;
  --muted: #6d6a80;
  --line: #e7e5f0;
  --ok: #17a34a;
  --ok-soft: #e6f6ec;
  --warn: #c98200;
  --warn-soft: #fff5df;
  --bad: #dc2f2f;
  --bad-soft: #fde9e9;
  --log-bg: #15131f;
  --log-text: #dcd9ea;
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0e16;
    --card: #1b1926;
    --text: #ecebf3;
    --muted: #9b98ad;
    --line: #2c2a3a;
    --primary-soft: #2a2350;
    --ok-soft: #12301f;
    --warn-soft: #33270b;
    --bad-soft: #3a1717;
    --log-bg: #0b0a10;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 18px 0 8px; }
h3 { font-size: 16px; margin: 0; }
small { display: block; color: var(--muted); font-size: 12.5px; }
code, pre, .log { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 14px 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.error { color: var(--bad); margin: 0; min-height: 0; font-size: 14px; }
p.error:empty, p.ok:empty { display: none; }
.ok { color: var(--ok); margin: 0; font-size: 14px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(20, 10, 60, .06); overflow: hidden; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%;
  min-height: 46px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
input.code { font-size: 26px; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }
input.code.small { font-size: 20px; letter-spacing: 5px; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px; min-height: 46px;
  background: var(--primary-soft); color: var(--primary); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:active:not(:disabled) { background: var(--primary-dark); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.link { background: none; color: var(--primary); padding: 6px 0; min-height: 0; font-weight: 500; align-self: flex-start; }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 14px; }
.btn.wide { width: 100%; }

/* Вход */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 24px 20px; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { font-size: 18px; }
.logo { width: 38px; height: 38px; border-radius: 11px; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; }
.brand.small .logo { width: 30px; height: 30px; font-size: 16px; border-radius: 9px; }
.qr-box { display: flex; justify-content: center; background: #fff; border-radius: 12px; padding: 10px; }
.qr-box img { width: 220px; height: 220px; image-rendering: pixelated; }
.secret { display: block; word-break: break-all; background: var(--bg); padding: 10px; border-radius: 10px; margin-top: 8px; font-size: 15px; letter-spacing: 1px; user-select: all; }
details summary { cursor: pointer; color: var(--primary); font-size: 14px; }

/* Каркас */
#app { padding: 0 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 12px 0 10px; background: var(--bg); }
.top .who { margin-left: auto; color: var(--muted); font-size: 13px; max-width: 30%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-pill { border: 0; background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 6px 12px; font: inherit; font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 11.5px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; padding: 4px 0; cursor: pointer; min-height: 48px; max-width: 120px;
}
.tabs button .ico { font-size: 17px; line-height: 22px; font-weight: 700; }
.tabs button.active { color: var(--primary); }
.view { display: flex; flex-direction: column; gap: 10px; }

.banner { border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }

/* Репозитории */
.repo { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.repo-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.repo-head b { font-size: 16px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: 12.5px; font-weight: 600; background: var(--primary-soft); color: var(--primary); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.commit { font-size: 14px; }
.commit code { color: var(--primary); font-weight: 600; margin-right: 6px; }
.commit .meta { color: var(--muted); font-size: 12.5px; }
.incoming { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.incoming li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.incoming li:last-child { border-bottom: 0; }

/* Сервисы */
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item .name { font-weight: 600; }
.list .item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.down { background: var(--bad); }
.dot.pulse { background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.http { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.icon-btn { border: 1px solid var(--line); background: none; color: var(--text); border-radius: 10px; width: 38px; height: 38px; font-size: 17px; cursor: pointer; flex: none; }

/* Деплой */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.mode { flex-direction: row; cursor: pointer; }
.mode input { display: none; }
.mode span { flex: 1; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; color: var(--text); }
.mode input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-bottom: 8px; }
.check { flex-direction: row; cursor: pointer; }
.check input { display: none; }
.check span { flex: 1; text-align: center; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 6px; color: var(--text); font-weight: 600; font-size: 14px; }
.check input:checked + span { border-color: var(--primary); background: var(--primary); color: #fff; }
.switch { flex-direction: row; align-items: center; gap: 10px; color: var(--text); cursor: pointer; padding: 6px 0; }
.switch input { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); flex: none; }
.switch.small { font-size: 13px; color: var(--muted); }
.switch.small input { width: 18px; height: 18px; }
#branch-row { margin-bottom: 8px; }

.live-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; }
.live-head small { margin-top: 2px; }
.badge { border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: 13px; background: var(--line); color: var(--muted); white-space: nowrap; }
.badge.running { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.failed, .badge.interrupted { background: var(--bad-soft); color: var(--bad); }
.stage { padding: 0 16px 10px; font-weight: 600; color: var(--primary); font-size: 14px; }
.stage:empty { display: none; }
.log {
  background: var(--log-bg); color: var(--log-text); font-size: 12px; line-height: 1.5; padding: 10px 12px;
  height: 52vh; height: 52dvh; overflow: auto; -webkit-overflow-scrolling: touch; white-space: pre-wrap; word-break: break-word;
}
.log.tall { height: 64vh; height: 64dvh; }
#result-log { height: 40vh; border-radius: 10px; }
.log .l { min-height: 1.5em; }
.log .stage { padding: 0; color: #b9a6ff; font-weight: 700; font-size: 12.5px; margin-top: 8px; display: block; }
.log .error { color: #ff7b7b; font-size: inherit; display: block; }
.log .ok { color: #6ee59a; font-size: inherit; display: block; }
.log .done-ok { color: #0b0a10; background: #6ee59a; font-weight: 800; padding: 2px 6px; border-radius: 4px; display: inline-block; margin-top: 6px; }
.log .done-fail { color: #fff; background: var(--bad); font-weight: 800; padding: 2px 6px; border-radius: 4px; display: inline-block; margin-top: 6px; }
.log .note { color: #8a86a0; font-style: italic; display: block; }
.live-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; gap: 8px; }

/* История */
.run { padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
.run:active { background: var(--primary-soft); }
.run .row-between b { font-size: 15px; }
.run .sum { font-size: 13.5px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Диалоги */
dialog {
  border: 0; border-radius: 20px; padding: 20px 18px; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(15, 10, 40, .45); }
pre.cmd { background: var(--log-bg); color: #d7cdfd; padding: 10px 12px; border-radius: 10px; font-size: 12.5px; white-space: pre-wrap; word-break: break-all; margin: 0; }
.warnings { margin: 0; padding-left: 18px; color: var(--warn); font-size: 14px; }
.warnings:empty { display: none; }
#confirm-summary { margin: 0; font-weight: 500; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 20;
  background: #1c1a2b; color: #fff; border-radius: 12px; padding: 12px 14px; font-size: 14px; text-align: center;
  max-width: 520px; margin: 0 auto;
}
.toast.bad { background: var(--bad); }

@media (min-width: 700px) {
  .modes { grid-template-columns: repeat(4, 1fr); }
}
