:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --line: #30363d;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --accent2: #1f6feb;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --radius: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { overscroll-behavior: none; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
code { background: var(--bg3); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 14px; }
.error { color: var(--err); margin: 8px 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }

.view { min-height: 100%; }
.center-view { display: flex; align-items: center; justify-content: center; padding: 24px 16px; min-height: 100dvh; }

.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand.small h1 { font-size: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 16px; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; outline: none; width: 100%;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,129,247,.25); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--fg); user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn { font: inherit; font-size: 14px; font-weight: 500; color: var(--fg); background: var(--bg3); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 14px; cursor: pointer; touch-action: manipulation; }
.btn:hover { border-color: #8b949e; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--fg); }
.btn.block { width: 100%; padding: 12px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.row.center { justify-content: center; }

/* Lista de PCs */
.topnav { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) 12px calc(16px + var(--safe-l));
  background: rgba(13,17,23,.9); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.list-wrap { max-width: 960px; margin: 0 auto; padding: 20px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l)); }
.pc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.pc { position: relative; display: flex; flex-direction: column; gap: 10px; text-align: left; cursor: pointer; font: inherit; color: inherit;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; transition: border-color .15s, transform .15s; }
.pc:hover { border-color: var(--accent); }
.pc:active { transform: scale(.99); }
.pc.offline { cursor: default; opacity: .75; }
.pc.offline:hover { border-color: var(--line); }
.pc-top { display: flex; align-items: center; gap: 12px; }
.pc-icon { width: 42px; height: 42px; border-radius: 10px; background: var(--bg3); display: grid; place-items: center; flex: none; }
.pc-icon svg { width: 24px; height: 24px; stroke: var(--fg); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pc-name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(63,185,80,.2); }
.pc-meta { font-size: 13px; color: var(--muted); display: grid; gap: 2px; }
.pc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pc-actions .btn { padding: 6px 10px; font-size: 13px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--bg3); border: 1px solid var(--line); color: var(--muted); }
.badge.warn { color: var(--warn); border-color: rgba(210,153,34,.4); }
.empty { text-align: left; max-width: 560px; margin: 24px auto; }
.empty h2 { margin-bottom: 8px; }
.empty p { color: var(--muted); }

/* Sessão remota */
#view-remote { position: fixed; inset: 0; background: #000; overflow: hidden; }
#stage { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#screen { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; background: #000;
  image-rendering: auto; cursor: default; touch-action: none; }
#screen.pixelated { image-rendering: pixelated; }

#kbd-input { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; border: 0; padding: 0;
  background: transparent; color: transparent; caret-color: transparent; z-index: -1; }

.toolbar { position: absolute; z-index: 5; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 5px; max-width: calc(100% - 16px - var(--safe-l) - var(--safe-r));
  background: rgba(22,27,34,.92); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px); box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: transform .2s, opacity .2s; }
.toolbar.hidden { transform: translate(-50%, -140%); opacity: 0; pointer-events: none; }
.tb-group { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tb-group::-webkit-scrollbar { display: none; }
.tb { width: 40px; height: 40px; flex: none; display: grid; place-items: center; background: transparent; border: 0; border-radius: 10px;
  color: var(--fg); cursor: pointer; touch-action: manipulation; }
.tb:hover { background: var(--bg3); }
.tb.active { background: var(--accent2); }
.tb svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tb-title { display: flex; flex-direction: column; min-width: 0; padding: 0 8px 0 2px; line-height: 1.2; }
.tb-title span { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.tb-title small { color: var(--muted); font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.handle { position: absolute; z-index: 4; top: calc(2px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: 64px; height: 22px;
  border: 0; background: transparent; cursor: pointer; padding: 0; touch-action: manipulation; }
.handle span { display: block; margin: 6px auto; width: 44px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.55);
  box-shadow: 0 0 0 1px rgba(0,0,0,.4); }

.toolbar:not(.hidden) + .handle { display: none; }
body:not(.touch) .touch-only { display: none !important; }

.panel { position: absolute; z-index: 6; top: calc(64px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  width: min(440px, calc(100% - 16px - var(--safe-l) - var(--safe-r))); max-height: calc(100% - 80px - var(--safe-t) - var(--safe-b));
  overflow-y: auto; -webkit-overflow-scrolling: touch; background: rgba(22,27,34,.97); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; box-shadow: 0 12px 32px rgba(0,0,0,.5); touch-action: pan-y; }
.panel .field { margin-bottom: 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h3 { font-size: 16px; }
.x { background: transparent; border: 0; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px; }
.x:hover { color: var(--fg); }
.mods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.keygrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
.keygrid button, .mods button { font: inherit; font-size: 13px; color: var(--fg); background: var(--bg3); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 6px; cursor: pointer; touch-action: manipulation; }
.keygrid button:active, .mods button:active { background: var(--line); }
.keygrid .wide { grid-column: span 2; }
.keygrid .warn { border-color: rgba(210,153,34,.5); }
.mod.on { background: var(--accent2) !important; border-color: var(--accent) !important; }
.mod.locked { background: #0b4fbf !important; border-color: #fff !important; box-shadow: inset 0 0 0 1px #fff; }
.help h4 { font-size: 14px; margin: 14px 0 6px; }
.help ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; }

#view-remote.kb #stage { height: calc(100% - 47px); }
#accessory { position: absolute; z-index: 7; left: 0; right: 0; bottom: 0; display: flex; gap: 4px; padding: 5px 6px; overflow-x: auto;
  background: rgba(22,27,34,.97); border-top: 1px solid var(--line); scrollbar-width: none; }
#accessory::-webkit-scrollbar { display: none; }
#accessory button { flex: none; min-width: 44px; height: 36px; font: inherit; font-size: 14px; color: var(--fg); background: var(--bg3);
  border: 1px solid var(--line); border-radius: 7px; padding: 0 9px; touch-action: manipulation; }

#touch-ring { position: absolute; z-index: 2; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  border: 3px solid rgba(47,129,247,.9); background: rgba(47,129,247,.18); pointer-events: none; animation: ring .45s ease-out; }
#touch-ring.long { border-color: rgba(210,153,34,.95); background: rgba(210,153,34,.2); animation: none; }
@keyframes ring { from { transform: scale(.4); opacity: .2; } to { transform: scale(1); opacity: 1; } }

.overlay { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; background: rgba(13,17,23,.78);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.overlay-box { text-align: center; padding: 24px; max-width: 360px; }
.overlay-box p { margin: 14px 0; font-size: 15px; }
.spinner { width: 36px; height: 36px; margin: 0 auto; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: var(--bg3); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.toast .btn { padding: 5px 10px; font-size: 13px; }

@media (max-width: 520px) {
  .tb { width: 38px; height: 38px; }
  .tb-title span { max-width: 90px; }
}
