:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #cbd5e1;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --toolbar: rgba(15, 23, 42, 0.92);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #334155;
    --accent: #3b82f6;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.view { min-height: 100%; }

/* Connect screen */
#connect-view { display: flex; align-items: center; justify-content: center; padding: 16px; }
.card {
  width: 100%; max-width: 400px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px 24px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}
h1 { margin: 0; font-size: 26px; display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; flex: none; }
.brand { height: 40px; width: auto; flex: none; color: var(--text); }
.sub { margin: 4px 0 20px; color: var(--muted); }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 6px; }
input {
  width: 100%; font-size: 18px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
#remote-id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 1px; font-size: 22px; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; cursor: pointer; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); padding: 11px 16px;
}
button:disabled { opacity: 0.6; cursor: default; }
#connect-btn { width: 100%; margin-top: 20px; font-size: 17px; font-weight: 600; }
.status { min-height: 1.4em; margin: 14px 0 0; font-size: 15px; }
.status.error { color: var(--danger); }
.hint { font-size: 13px; color: var(--muted); margin: 14px 0 0; }

/* Download ("Загрузить Vizor") */
button.secondary {
  width: 100%; margin-top: 18px; background: transparent; color: var(--accent);
  border: 1px solid var(--accent); font-weight: 600;
}
.dl-manual { display: block; margin-top: 8px; text-align: center; font-size: 14px; color: var(--accent); }
.download-panel { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.dl-detected { margin: 0 0 10px; font-size: 15px; }
.dl-actions { display: flex; flex-direction: column; gap: 8px; }
.dl-link { color: var(--accent); word-break: break-word; }
.dl-link.primary {
  display: block; text-align: center; text-decoration: none; font-weight: 600;
  background: var(--accent); color: var(--accent-text); border-radius: 8px; padding: 11px 16px;
}
.dl-status { margin: 0 0 8px; min-height: 0; }
.dl-note { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.dl-note a, .dl-all a { color: var(--accent); }
.dl-all { margin-top: 10px; font-size: 14px; }
.dl-mac { margin-top: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
.dl-mac p { margin: 0 0 8px; color: var(--muted); }
.dl-mac p:last-child { margin-bottom: 0; }
.dl-mac .dl-mac-title { color: var(--text); font-weight: 600; font-size: 15px; }
.dl-mac-cmd { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; margin: 0 0 10px; }
.dl-mac-cmd code {
  align-self: stretch; padding: 8px 10px; border-radius: 8px; background: var(--bg);
  font-size: 13px; word-break: break-all; user-select: all;
}
.dl-mac-cmd button { width: auto; padding: 6px 14px; font-size: 14px; }
.dl-all ul { margin: 8px 0 0; padding-left: 18px; }
.dl-all li { margin: 4px 0; }

/* Session screen */
#session-view { position: fixed; inset: 0; display: flex; flex-direction: column; background: #000; }
#toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--toolbar); color: #e2e8f0; font-size: 14px;
  z-index: 3;
}
.tb-id { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; }
.tb-stats { color: #94a3b8; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.tb-btn { background: #1e293b; color: #e2e8f0; padding: 6px 10px; font-size: 14px; }
.tb-btn.danger { background: var(--danger); color: #fff; }
.tb-btn.on { background: var(--accent); }
.tb-select { background: #1e293b; color: #e2e8f0; border: 0; border-radius: 8px; padding: 6px 8px; font-size: 13px; max-width: 180px; }
#body { flex: 1; min-height: 0; display: flex; }
#stage { position: relative; flex: 1; min-height: 0; }
#screen, #screen-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000;
}
#screen {
  touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: default; outline: none;
}
#screen.picture-hidden { opacity: 0; }
#screen-canvas { pointer-events: none; }

/* A message from the remote computer (e.g. why input does not get through). */
.notice {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 24px)); z-index: 4;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--toolbar); color: #f1f5f9; font-size: 14px; line-height: 1.4;
  border-left: 3px solid #f59e0b; border-radius: 8px; padding: 10px 10px 10px 14px;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.35);
}
.notice span { flex: 1; }
.notice button { background: transparent; color: #cbd5e1; padding: 0 4px; font-size: 14px; }

/* File panel */
#files-panel {
  width: 340px; flex: none; background: var(--card); color: var(--text);
  border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 3;
}
.fp-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.fp-head .tb-btn { background: var(--border); color: var(--text); }
.fp-path { padding: 6px 12px; font-size: 12px; color: var(--muted); word-break: break-all; border-bottom: 1px solid var(--border); }
.fp-list { flex: 1; min-height: 0; overflow: auto; }
.fp-row { display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: default; border-bottom: 1px solid var(--bg); }
.fp-row:hover { background: var(--bg); }
.fp-row.dir { cursor: pointer; }
.fp-row .fp-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-row .fp-size { color: var(--muted); font-size: 12px; }
.fp-row .fp-get { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; }
.fp-icon { width: 18px; text-align: center; }
.fp-drop { margin: 10px 12px; padding: 14px; border: 2px dashed var(--border); border-radius: 8px; font-size: 13px; color: var(--muted); text-align: center; }
.fp-drop.over { border-color: var(--accent); color: var(--text); }
.fp-pick { color: var(--accent); cursor: pointer; text-decoration: underline; }
.fp-transfers { max-height: 160px; overflow: auto; padding: 0 12px 10px; }
.fp-xfer { font-size: 12px; margin-top: 8px; }
.fp-xfer .fp-bar { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.fp-xfer .fp-bar span { display: block; height: 100%; background: var(--accent); width: 0; }
.fp-xfer.err { color: var(--danger); }
.fp-xfer.done .fp-bar span { background: var(--ok); }
@media (max-width: 700px) {
  #files-panel { position: absolute; inset: 0; width: auto; }
}
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(2, 6, 23, 0.72); color: #f1f5f9; z-index: 2; padding: 16px; text-align: center;
}
.overlay-box { max-width: 420px; }
.overlay form { display: flex; gap: 8px; margin-top: 12px; }
.overlay input { font-size: 16px; }
.spinner {
  width: 36px; height: 36px; margin: 0 auto 14px;
  border: 3px solid rgba(255,255,255,0.25); border-top-color: #fff; border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.ime { position: fixed; left: -1000px; top: 0; width: 10px; height: 10px; opacity: 0; }
@media (pointer: fine) { #btn-keyboard { display: none; } }

.opt { color: #8a94a6; font-weight: 400; font-size: 0.85em; }

.overlay-action {
  margin-top: 14px; border: 0; border-radius: 9px; padding: 10px 14px;
  background: var(--accent); color: #fff; font: inherit; cursor: pointer;
}
.overlay-action:hover { filter: brightness(1.08); }
/* Always-visible build version. Kept above the session/file UI and out of the input path. */
.app-version {
  position: fixed; right: 10px; bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 20; pointer-events: none; user-select: none;
  padding: 3px 6px; border-radius: 5px;
  background: rgba(2, 6, 23, 0.62); color: rgba(255, 255, 255, 0.82);
  font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.2px;
}

.app-version.clickable { pointer-events: auto; cursor: pointer; }
.app-version.clickable:hover { background: rgba(2, 6, 23, 0.8); color: #fff; }
#session-view:not(.hidden) ~ .app-version { pointer-events: none; }

/* downloads.html: every agent build, chosen by hand */
.downloads-page { display: flex; justify-content: center; padding: 16px; }
.downloads-page .card { max-width: 760px; }
.dl-back { font-size: 14px; color: var(--accent); }
.dl-group { margin: 22px 0 0; font-size: 18px; }
.dl-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.dl-item h3 { margin: 0; font-size: 16px; }
.dl-item p { margin: 0; font-size: 14px; color: var(--muted); }
.dl-item .dl-meta { grid-column: 1 / -1; font-size: 12px; color: var(--muted); word-break: break-all; }
.dl-item a.dl-get {
  background: var(--accent); color: var(--accent-text); border-radius: 8px; padding: 8px 14px;
  text-decoration: none; font-weight: 600; white-space: nowrap;
}
.dl-item .dl-none { font-size: 14px; color: var(--muted); white-space: nowrap; }
.dl-item.mine { background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 8px; padding: 12px 10px; }
@media (max-width: 520px) {
  .dl-item { grid-template-columns: 1fr; }
  .dl-item a.dl-get, .dl-item .dl-none { justify-self: start; }
}
