:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1f2630;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b96a3;
  --accent: #3ddc84;
  --accent-ink: #062b16;
  --danger: #ff6b6b;
  --app-h: 100dvh;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* ---------- формы ---------- */
.screen {
  min-height: var(--app-h);
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 22px 22px;
  display: grid;
  gap: 14px;
}
.brand { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: .02em; }
.brand .prompt { color: var(--accent); }
.hint { margin: -6px 0 4px; color: var(--muted); font-size: 14px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input {
  font: 16px var(--sans); /* 16px — iOS не зумит поле */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 12px;
  outline: none;
}
input:focus { border-color: var(--accent); }
input[name="code"] { font-family: var(--mono); letter-spacing: .35em; }
button { font: inherit; cursor: pointer; }
.primary {
  margin-top: 4px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 10px;
  padding: 12px;
  font-weight: 600;
}
.primary:disabled { opacity: .6; cursor: progress; }
.link { background: none; border: 0; color: var(--muted); padding: 4px; text-decoration: underline; }
.error { margin: 0; min-height: 1.2em; color: var(--danger); font-size: 14px; }

/* ---------- терминал ---------- */
.term-screen {
  height: var(--app-h);
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  place-items: stretch;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.status { display: flex; align-items: center; gap: 8px; font: 13px var(--mono); color: var(--muted); min-width: 0; }
.status span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
#status-dot.on { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
#status-dot.wait { background: #e3b341; }
.actions { display: flex; gap: 4px; }
.actions button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 36px;
  height: 32px;
  padding: 0 8px;
  font-size: 14px;
}
.actions .danger { color: var(--danger); }

#terminal {
  flex: 1 1 auto;
  min-height: 0;
  padding: 4px 0 0 6px;
  padding-left: max(6px, env(safe-area-inset-left));
  background: var(--bg);
}
#terminal .xterm { height: 100%; }
#terminal .xterm-viewport { background: var(--bg) !important; }

#keybar {
  flex: none;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: var(--panel);
  border-top: 1px solid var(--line);
}
#keybar::-webkit-scrollbar { display: none; }
#keybar button {
  flex: none;
  min-width: 44px;
  height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: 14px var(--mono);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
#keybar button:active { background: var(--line); }
#keybar button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* На устройствах с настоящей клавиатурой и мышью панель не нужна */
@media (hover: hover) and (pointer: fine) {
  #keybar { display: none; }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, .78);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
  overflow-y: auto;
}
#overlay .card { text-align: center; }
#overlay-text { margin: 0; }

code {
  font-family: var(--mono);
  font-size: .92em;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
  color: var(--text);
}
.hint { line-height: 1.45; }
input[name="code"] { font-family: var(--mono); letter-spacing: .2em; text-transform: uppercase; }
.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px;
}

/* ---------- PIN ---------- */
.pin-card { justify-items: center; text-align: center; max-width: 340px; }
.agent-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font: 13px var(--mono);
  color: var(--muted);
  min-height: 1.3em;
}
.agent-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.agent-status.on i { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.agent-status.off i { background: var(--danger); }
.pin-dots { display: flex; gap: 14px; justify-content: center; min-height: 18px; margin-top: 8px; }
.pin-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--muted);
  transition: background .1s, border-color .1s;
}
.pin-dots span.full { background: var(--accent); border-color: var(--accent); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.pin-error { text-align: center; }
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 14px 22px;
  justify-content: center;
}
.keypad button {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: 500 26px var(--sans);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.keypad button:active { background: var(--line); }
.keypad .fn { background: transparent; border-color: transparent; font-size: 24px; color: var(--muted); }
.keypad .ok { color: var(--accent); }
.keypad:has(button:disabled) { opacity: .6; }

/* ---------- меню ---------- */
.sheet { max-width: 420px; gap: 12px; }
.sheet h2 { margin: 0; font-size: 18px; }
.sheet h3 { margin: 8px 0 0; font-size: 14px; color: var(--muted); font-weight: 500; }
.newdev { text-align: center; }
.newdev .code {
  font: 600 30px var(--mono);
  letter-spacing: .12em;
  color: var(--accent);
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  user-select: all;
}
.newdev .hint { margin: 8px 0 0; }
.dev-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.dev-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.dev-list .meta { min-width: 0; }
.dev-list .name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-list .sub { font-size: 12px; color: var(--muted); }
.dev-list button {
  flex: none;
  background: none; border: 1px solid var(--line); border-radius: 8px;
  color: var(--danger); padding: 6px 10px; font-size: 13px;
}
.dev-list button.confirm { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------- файлы ---------- */
.actions .accent { color: var(--accent); font-size: 16px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
}
.up-dir { display: flex; gap: 8px; }
.up-dir select {
  flex: 1; min-width: 0;
  font: 16px var(--sans);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  height: 40px;
}
.up-path { margin: -4px 0 0; font: 12px var(--mono); color: var(--muted); word-break: break-all; min-height: 1em; }
.dirs-panel { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.dirs-panel .dev-list li { background: var(--panel); }
.dirs-panel .sub { font-family: var(--mono); word-break: break-all; white-space: normal; }
.dirs-panel .hint { margin: 0; font-size: 12px; }
.dir-add { display: grid; gap: 8px; }
.dir-add input { padding: 10px 12px; }
.drop {
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
  padding: 22px 12px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(61, 220, 132, .06); }
.drop-main { font-weight: 600; color: var(--accent); }
.drop-sub { font-size: 12px; color: var(--muted); }
.up-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 40vh; overflow-y: auto; }
.up-list li { padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; display: grid; gap: 6px; }
.up-row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.up-size { flex: none; color: var(--muted); font-size: 12px; }
.up-bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.up-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.up-state { font: 12px var(--mono); color: var(--muted); word-break: break-all; }
.up-list li.done .up-state { color: var(--accent); }
.up-list li.fail .up-state { color: var(--danger); }
.up-list li.fail .up-bar i { background: var(--danger); }
#upsheet.dragging .card { outline: 2px dashed var(--accent); outline-offset: 6px; }
